Skip to content

Commit a86d187

Browse files
tekknolagik0kubun
authored andcommitted
Add option to dump optimized HIR
1 parent 0a38850 commit a86d187

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

zjit/src/codegen.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use crate::{asm::CodeBlock, cruby::*, options::debug, virtualmem::CodePtr};
33
use crate::invariants::{iseq_escapes_ep, track_no_ep_escape_assumption};
44
use crate::backend::lir::{self, asm_comment, Assembler, Opnd, Target, CFP, C_ARG_OPNDS, C_RET_OPND, EC, SP};
55
use crate::hir::{self, Block, BlockId, BranchEdge, CallInfo};
6-
use crate::hir::{Const, FrameState, Function, Insn, InsnId};
6+
use crate::hir::{Const, FrameState, Function, Insn, InsnId, FunctionPrinter};
77
use crate::hir_type::{types::Fixnum, Type};
8+
use crate::options::{get_option, DumpHIR};
89

910
/// Ephemeral code generation state
1011
struct JITState {
@@ -88,6 +89,12 @@ fn iseq_gen_entry_point(iseq: IseqPtr) -> *const u8 {
8889
}
8990
};
9091
ssa.optimize();
92+
match get_option!(dump_hir_opt) {
93+
Some(DumpHIR::WithoutSnapshot) => println!("HIR:\n{}", FunctionPrinter::without_snapshot(&ssa)),
94+
Some(DumpHIR::All) => println!("HIR:\n{}", FunctionPrinter::with_snapshot(&ssa)),
95+
Some(DumpHIR::Raw) => println!("HIR:\n{:#?}", &ssa),
96+
None => {},
97+
}
9198

9299
// Compile High-level IR into machine code
93100
let cb = ZJITState::get_code_block();

zjit/src/hir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,22 +413,22 @@ impl Block {
413413
}
414414
}
415415

416-
struct FunctionPrinter<'a> {
416+
pub struct FunctionPrinter<'a> {
417417
fun: &'a Function,
418418
display_snapshot: bool,
419419
ptr_map: PtrPrintMap,
420420
}
421421

422422
impl<'a> FunctionPrinter<'a> {
423-
fn without_snapshot(fun: &'a Function) -> Self {
423+
pub fn without_snapshot(fun: &'a Function) -> Self {
424424
let mut ptr_map = PtrPrintMap::identity();
425425
if cfg!(test) {
426426
ptr_map.map_ptrs = true;
427427
}
428428
Self { fun, display_snapshot: false, ptr_map }
429429
}
430430

431-
fn with_snapshot(fun: &'a Function) -> FunctionPrinter<'a> {
431+
pub fn with_snapshot(fun: &'a Function) -> FunctionPrinter<'a> {
432432
let mut printer = Self::without_snapshot(fun);
433433
printer.display_snapshot = true;
434434
printer

zjit/src/options.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub struct Options {
1515
/// Dump High-level IR generated from ISEQ.
1616
pub dump_hir: Option<DumpHIR>,
1717

18+
/// Dump High-level IR after optimization, right before codegen.
19+
pub dump_hir_opt: Option<DumpHIR>,
20+
1821
/// Dump all compiled machine code.
1922
pub dump_disasm: bool,
2023
}
@@ -56,6 +59,7 @@ pub fn init_options() -> Options {
5659
Options {
5760
debug: false,
5861
dump_hir: None,
62+
dump_hir_opt: None,
5963
dump_disasm: false,
6064
}
6165
}
@@ -97,6 +101,10 @@ fn parse_option(options: &mut Options, str_ptr: *const std::os::raw::c_char) ->
97101
("dump-hir", "all") => options.dump_hir = Some(DumpHIR::All),
98102
("dump-hir", "raw") => options.dump_hir = Some(DumpHIR::Raw),
99103

104+
("dump-hir-opt", "") => options.dump_hir_opt = Some(DumpHIR::WithoutSnapshot),
105+
("dump-hir-opt", "all") => options.dump_hir_opt = Some(DumpHIR::All),
106+
("dump-hir-opt", "raw") => options.dump_hir_opt = Some(DumpHIR::Raw),
107+
100108
("dump-disasm", "") => options.dump_disasm = true,
101109

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

0 commit comments

Comments
 (0)