Skip to content

Commit c1db3e8

Browse files
committed
[zjit] Add option to dump LIR
Now we can dump HIR, optimized HIR, LIR, and assembly.
1 parent 87d0014 commit c1db3e8

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

zjit/src/codegen.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::backend::lir::{self, asm_comment, Assembler, Opnd, Target, CFP, C_ARG
1010
use crate::hir::{iseq_to_hir, Block, BlockId, BranchEdge, CallInfo};
1111
use crate::hir::{Const, FrameState, Function, Insn, InsnId};
1212
use crate::hir_type::{types::Fixnum, Type};
13+
use crate::options::get_option;
1314

1415
/// Ephemeral code generation state
1516
struct JITState {
@@ -223,6 +224,10 @@ fn gen_function(cb: &mut CodeBlock, iseq: IseqPtr, function: &Function) -> Optio
223224
}
224225
}
225226

227+
if get_option!(dump_lir) {
228+
println!("LIR:\nfn {}:\n{:?}", iseq_name(iseq), asm);
229+
}
230+
226231
// Generate code if everything can be compiled
227232
asm.compile(cb).map(|(start_ptr, _)| (start_ptr, jit.branch_iseqs))
228233
}

zjit/src/options.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub struct Options {
2727
/// Dump High-level IR after optimization, right before codegen.
2828
pub dump_hir_opt: Option<DumpHIR>,
2929

30+
/// Dump low-level IR
31+
pub dump_lir: bool,
32+
3033
/// Dump all compiled machine code.
3134
pub dump_disasm: bool,
3235
}
@@ -70,6 +73,7 @@ pub fn init_options() -> Options {
7073
debug: false,
7174
dump_hir_init: None,
7275
dump_hir_opt: None,
76+
dump_lir: false,
7377
dump_disasm: false,
7478
}
7579
}
@@ -127,6 +131,8 @@ fn parse_option(options: &mut Options, str_ptr: *const std::os::raw::c_char) ->
127131
("dump-hir-init", "all") => options.dump_hir_init = Some(DumpHIR::All),
128132
("dump-hir-init", "debug") => options.dump_hir_init = Some(DumpHIR::Debug),
129133

134+
("dump-lir", "") => options.dump_lir = true,
135+
130136
("dump-disasm", "") => options.dump_disasm = true,
131137

132138
_ => return None, // Option name not recognized

0 commit comments

Comments
 (0)