From 9fc5a5dbedf70d6026ff8b76a57297b8021c5dcd Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Tue, 22 Apr 2025 12:17:35 -0400 Subject: [PATCH] ZJIT: Add option to dump LIR (#13139) Now we can dump HIR, optimized HIR, LIR, and assembly. --- zjit/src/codegen.rs | 5 +++++ zjit/src/options.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs index 1235eab9af..0963aaa5b8 100644 --- a/zjit/src/codegen.rs +++ b/zjit/src/codegen.rs @@ -10,6 +10,7 @@ use crate::backend::lir::{self, asm_comment, Assembler, Opnd, Target, CFP, C_ARG use crate::hir::{iseq_to_hir, Block, BlockId, BranchEdge, CallInfo}; use crate::hir::{Const, FrameState, Function, Insn, InsnId}; use crate::hir_type::{types::Fixnum, Type}; +use crate::options::get_option; /// Ephemeral code generation state struct JITState { @@ -223,6 +224,10 @@ fn gen_function(cb: &mut CodeBlock, iseq: IseqPtr, function: &Function) -> Optio } } + if get_option!(dump_lir) { + println!("LIR:\nfn {}:\n{:?}", iseq_name(iseq), asm); + } + // Generate code if everything can be compiled asm.compile(cb).map(|(start_ptr, _)| (start_ptr, jit.branch_iseqs)) } diff --git a/zjit/src/options.rs b/zjit/src/options.rs index 5a51b9f2c1..ebcad7bef2 100644 --- a/zjit/src/options.rs +++ b/zjit/src/options.rs @@ -27,6 +27,9 @@ pub struct Options { /// Dump High-level IR after optimization, right before codegen. pub dump_hir_opt: Option, + /// Dump low-level IR + pub dump_lir: bool, + /// Dump all compiled machine code. pub dump_disasm: bool, } @@ -70,6 +73,7 @@ pub fn init_options() -> Options { debug: false, dump_hir_init: None, dump_hir_opt: None, + dump_lir: false, dump_disasm: false, } } @@ -127,6 +131,8 @@ fn parse_option(options: &mut Options, str_ptr: *const std::os::raw::c_char) -> ("dump-hir-init", "all") => options.dump_hir_init = Some(DumpHIR::All), ("dump-hir-init", "debug") => options.dump_hir_init = Some(DumpHIR::Debug), + ("dump-lir", "") => options.dump_lir = true, + ("dump-disasm", "") => options.dump_disasm = true, _ => return None, // Option name not recognized