Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let --yjit-dump-disasm=all dump ocb code as well #6309

Merged
merged 8 commits into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions yjit/src/backend/ir.rs
Expand Up @@ -1083,12 +1083,14 @@ impl Assembler
let gc_offsets = self.compile_with_regs(cb, alloc_regs);

#[cfg(feature = "disasm")]
if get_option!(dump_disasm) && !cb.outlined {
use crate::disasm::disasm_addr_range;
let last_ptr = cb.get_write_ptr();
let disasm = disasm_addr_range(cb, start_addr, last_ptr.raw_ptr() as usize - start_addr as usize);
if disasm.len() > 0 {
println!("{disasm}");
if let Some(dump_all) = get_option!(dump_disasm) {
if dump_all || !cb.outlined {
use crate::disasm::disasm_addr_range;
let last_ptr = cb.get_write_ptr();
let disasm = disasm_addr_range(cb, start_addr, last_ptr.raw_ptr() as usize - start_addr as usize);
if disasm.len() > 0 {
println!("{disasm}");
}
}
}
gc_offsets
Expand Down
8 changes: 5 additions & 3 deletions yjit/src/codegen.rs
Expand Up @@ -398,6 +398,7 @@ fn gen_code_for_exit_from_stub(ocb: &mut OutlinedCb) -> CodePtr {

gen_counter_incr!(asm, exit_from_branch_stub);

asm.comment("exit from branch stub");
asm.cpop_into(SP);
asm.cpop_into(EC);
asm.cpop_into(CFP);
Expand Down Expand Up @@ -525,7 +526,7 @@ fn gen_full_cfunc_return(ocb: &mut OutlinedCb) -> CodePtr {
// This chunk of code expects REG_EC to be filled properly and
// RAX to contain the return value of the C method.

// Call full_cfunc_return()
asm.comment("full cfunc return");
asm.ccall(
rb_full_cfunc_return as *const u8,
vec![EC, C_RET_OPND]
Expand Down Expand Up @@ -562,6 +563,7 @@ fn gen_leave_exit(ocb: &mut OutlinedCb) -> CodePtr {
// Every exit to the interpreter should be counted
gen_counter_incr!(asm, leave_interp_return);

asm.comment("exit from leave");
asm.cpop_into(SP);
asm.cpop_into(EC);
asm.cpop_into(CFP);
Expand Down Expand Up @@ -624,7 +626,7 @@ pub fn gen_entry_prologue(cb: &mut CodeBlock, iseq: IseqPtr, insn_idx: u32) -> O
let code_ptr = cb.get_write_ptr();

let mut asm = Assembler::new();
if get_option!(dump_disasm) {
if get_option!(dump_disasm).is_some() {
asm.comment(&format!("YJIT entry: {}", iseq_get_location(iseq)));
} else {
asm.comment("YJIT entry");
Expand Down Expand Up @@ -753,7 +755,7 @@ pub fn gen_single_block(
let mut asm = Assembler::new();

#[cfg(feature = "disasm")]
if get_option!(dump_disasm) {
if get_option!(dump_disasm).is_some() {
asm.comment(&format!("Block: {} (ISEQ offset: {})", iseq_get_location(blockid.iseq), blockid.idx));
}

Expand Down
1 change: 1 addition & 0 deletions yjit/src/core.rs
Expand Up @@ -1779,6 +1779,7 @@ fn get_branch_target(
let branch_ptr: *const RefCell<Branch> = BranchRef::into_raw(branchref.clone());

let mut asm = Assembler::new();
asm.comment("branch stub hit");

// Call branch_stub_hit(branch_ptr, target_idx, ec)
let jump_addr = asm.ccall(
Expand Down
14 changes: 10 additions & 4 deletions yjit/src/options.rs
Expand Up @@ -30,8 +30,9 @@ pub struct Options {
/// Dump compiled and executed instructions for debugging
pub dump_insns: bool,

/// Dump all compiled instructions in inlined CodeBlock
pub dump_disasm: bool,
/// Dump all compiled instructions. Some(false) dumps only inlined cb,
/// and Some(true) dumps both inlined and outlined cbs.
pub dump_disasm: Option<bool>,
k0kubun marked this conversation as resolved.
Show resolved Hide resolved

/// Print when specific ISEQ items are compiled or invalidated
pub dump_iseq_disasm: Option<String>,
Expand All @@ -56,7 +57,7 @@ pub static mut OPTIONS: Options = Options {
gen_stats: false,
gen_trace_exits: false,
dump_insns: false,
dump_disasm: false,
dump_disasm: None,
verify_ctx: false,
global_constant_state: false,
dump_iseq_disasm: None,
Expand Down Expand Up @@ -123,6 +124,12 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
}
},

("dump-disasm", _) => match opt_val.to_string().as_str() {
"all" => unsafe { OPTIONS.dump_disasm = Some(true) },
"" => unsafe { OPTIONS.dump_disasm = Some(false) },
_ => return None,
},

("dump-iseq-disasm", _) => unsafe {
OPTIONS.dump_iseq_disasm = Some(opt_val.to_string());
},
Expand All @@ -132,7 +139,6 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
("stats", "") => unsafe { OPTIONS.gen_stats = true },
("trace-exits", "") => unsafe { OPTIONS.gen_trace_exits = true; OPTIONS.gen_stats = true },
("dump-insns", "") => unsafe { OPTIONS.dump_insns = true },
("dump-disasm", "") => unsafe { OPTIONS.dump_disasm = true },
("verify-ctx", "") => unsafe { OPTIONS.verify_ctx = true },
("global-constant-state", "") => unsafe { OPTIONS.global_constant_state = true },

Expand Down