Rename --zjit-dump-ssa to --zjit-dump-hir (https://github.com/Shopify/zjit/pull/17)

* Rename --zjit-dump-ssa to --zjit-dump-hir

* Update comments

* Add a comment on iseq_to_hir
This commit is contained in:
Takashi Kokubun 2025-02-24 09:29:09 -08:00
parent e4d4ee7517
commit 3c38ad605a
Notes: git 2025-04-18 13:48:28 +00:00
4 changed files with 27 additions and 26 deletions

View File

@ -9,7 +9,7 @@ use crate::{
#[cfg(feature = "disasm")]
use crate::get_option;
/// Compile SSA IR into machine code
/// Compile High-level IR into machine code
pub fn gen_function(cb: &mut CodeBlock, function: &Function, iseq: IseqPtr) -> Option<CodePtr> {
// Set up special registers
let mut asm = Assembler::new();

View File

@ -4,7 +4,7 @@
use crate::{
cruby::*,
get_option,
options::DumpSSA
options::DumpHIR
};
use std::collections::{HashMap, HashSet};
@ -486,7 +486,8 @@ fn num_locals(iseq: *const rb_iseq_t) -> usize {
(unsafe { get_iseq_body_local_table_size(iseq) }) as usize
}
pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
/// Compile ISEQ into High-level IR
pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
let mut fun = Function::new(iseq);
// Compute a map of PC->Block by finding jump targets
let jump_targets = compute_jump_targets(iseq);
@ -721,10 +722,10 @@ pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
}
}
match get_option!(dump_ssa) {
Some(DumpSSA::WithoutSnapshot) => print!("SSA:\n{}", FunctionPrinter::without_snapshot(&fun)),
Some(DumpSSA::All) => print!("SSA:\n{}", FunctionPrinter::with_snapshot(&fun)),
Some(DumpSSA::Raw) => print!("SSA:\n{:#?}", &fun),
match get_option!(dump_hir) {
Some(DumpHIR::WithoutSnapshot) => print!("HIR:\n{}", FunctionPrinter::without_snapshot(&fun)),
Some(DumpHIR::All) => print!("HIR:\n{}", FunctionPrinter::with_snapshot(&fun)),
Some(DumpHIR::Raw) => print!("HIR:\n{:#?}", &fun),
None => {},
}
@ -790,7 +791,7 @@ mod tests {
crate::cruby::with_rubyvm(|| {
let program = "nil.itself";
let iseq = compile_to_iseq(program);
let function = iseq_to_ssa(iseq).unwrap();
let function = iseq_to_hir(iseq).unwrap();
assert!(matches!(function.insns.get(0), Some(Insn::Snapshot { .. })));
});
}
@ -800,7 +801,7 @@ mod tests {
crate::cruby::with_rubyvm(|| {
let program = "123";
let iseq = compile_to_iseq(program);
let function = iseq_to_ssa(iseq).unwrap();
let function = iseq_to_hir(iseq).unwrap();
assert_matches!(function.insns.get(1), Some(Insn::Const { val: VALUE(247) }));
assert_matches!(function.insns.get(3), Some(Insn::Return { val: InsnId(1) }));
});
@ -811,7 +812,7 @@ mod tests {
crate::cruby::with_rubyvm(|| {
let program = "1+2";
let iseq = compile_to_iseq(program);
let function = iseq_to_ssa(iseq).unwrap();
let function = iseq_to_hir(iseq).unwrap();
// TODO(max): Figure out a clean way to match against String
// TODO(max): Figure out a clean way to match against args vec
assert_matches!(function.insns.get(1), Some(Insn::Const { val: VALUE(3) }));
@ -825,7 +826,7 @@ mod tests {
crate::cruby::with_rubyvm(|| {
let program = "a = 1; a";
let iseq = compile_to_iseq(program);
let function = iseq_to_ssa(iseq).unwrap();
let function = iseq_to_hir(iseq).unwrap();
assert_matches!(function.insns.get(2), Some(Insn::Const { val: VALUE(3) }));
assert_matches!(function.insns.get(6), Some(Insn::Return { val: InsnId(2) }));
});
@ -836,7 +837,7 @@ mod tests {
crate::cruby::with_rubyvm(|| {
let program = "cond = true; if cond; 3; else; 4; end";
let iseq = compile_to_iseq(program);
let function = iseq_to_ssa(iseq).unwrap();
let function = iseq_to_hir(iseq).unwrap();
assert_matches!(function.insns.get(2), Some(Insn::Const { val: Qtrue }));
assert_matches!(function.insns.get(6), Some(Insn::Test { val: InsnId(2) }));
assert_matches!(function.insns.get(7), Some(Insn::IfFalse { val: InsnId(6), target: BranchEdge { target: BlockId(1), .. } }));

View File

@ -79,16 +79,16 @@ fn rb_bug_panic_hook() {
pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, _ec: EcPtr) -> *const u8 {
// TODO: acquire the VM barrier
// Compile ISEQ into SSA IR
let ssa = match hir::iseq_to_ssa(iseq) {
// Compile ISEQ into High-level IR
let ssa = match hir::iseq_to_hir(iseq) {
Ok(ssa) => ssa,
Err(err) => {
debug!("ZJIT: to_ssa: {:?}", err);
debug!("ZJIT: iseq_to_hir: {:?}", err);
return std::ptr::null();
}
};
// Compile SSA IR into machine code
// Compile High-level IR into machine code
let cb = ZJITState::get_code_block();
match gen_function(cb, &ssa, iseq) {
Some(start_ptr) => start_ptr.raw_ptr(cb),

View File

@ -12,20 +12,20 @@ pub struct Options {
/// Enable debug logging
pub debug: bool,
/// Dump SSA IR generated from ISEQ.
pub dump_ssa: Option<DumpSSA>,
/// Dump High-level IR generated from ISEQ.
pub dump_hir: Option<DumpHIR>,
/// Dump all compiled machine code.
pub dump_disasm: bool,
}
#[derive(Clone, Copy, Debug)]
pub enum DumpSSA {
// Dump SSA without Snapshot
pub enum DumpHIR {
// Dump High-level IR without Snapshot
WithoutSnapshot,
// Dump SSA with Snapshot
// Dump High-level IR with Snapshot
All,
// Pretty-print bare SSA structs
// Pretty-print bare High-level IR structs
Raw,
}
@ -55,7 +55,7 @@ pub extern "C" fn rb_zjit_init_options() -> *const u8 {
pub fn init_options() -> Options {
Options {
debug: false,
dump_ssa: None,
dump_hir: None,
dump_disasm: false,
}
}
@ -93,9 +93,9 @@ fn parse_option(options: &mut Options, str_ptr: *const std::os::raw::c_char) ->
("debug", "") => options.debug = true,
("dump-ssa", "") => options.dump_ssa = Some(DumpSSA::WithoutSnapshot),
("dump-ssa", "all") => options.dump_ssa = Some(DumpSSA::All),
("dump-ssa", "raw") => options.dump_ssa = Some(DumpSSA::Raw),
("dump-hir", "") => options.dump_hir = Some(DumpHIR::WithoutSnapshot),
("dump-hir", "all") => options.dump_hir = Some(DumpHIR::All),
("dump-hir", "raw") => options.dump_hir = Some(DumpHIR::Raw),
("dump-disasm", "") => options.dump_disasm = true,