Skip to content

Commit 543f8dc

Browse files
authored
ZJIT: Add the ISEQ name to Block asm comments (#14070)
1 parent 5a7be72 commit 543f8dc

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

zjit/src/codegen.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ fn gen_function(cb: &mut CodeBlock, iseq: IseqPtr, function: &Function) -> Optio
244244
let reverse_post_order = function.rpo();
245245
for &block_id in reverse_post_order.iter() {
246246
let block = function.block(block_id);
247-
asm_comment!(asm, "Block: {block_id}({})", block.params().map(|param| format!("{param}")).collect::<Vec<_>>().join(", "));
247+
asm_comment!(
248+
asm, "{block_id}({}): {}",
249+
block.params().map(|param| format!("{param}")).collect::<Vec<_>>().join(", "),
250+
iseq_get_location(iseq, block.insn_idx),
251+
);
248252

249253
// Write a label to jump to the basic block
250254
let label = jit.get_label(&mut asm, block_id);

zjit/src/cruby.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ pub fn iseq_name(iseq: IseqPtr) -> String {
715715
// Location is the file defining the method, colon, method name.
716716
// Filenames are sometimes internal strings supplied to eval,
717717
// so be careful with them.
718-
pub fn iseq_get_location(iseq: IseqPtr, pos: u16) -> String {
718+
pub fn iseq_get_location(iseq: IseqPtr, pos: u32) -> String {
719719
let iseq_path = unsafe { rb_iseq_path(iseq) };
720720
let iseq_lineno = unsafe { rb_iseq_line_no(iseq, pos as usize) };
721721

zjit/src/hir.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ impl std::fmt::Display for Insn {
796796
/// An extended basic block in a [`Function`].
797797
#[derive(Default, Debug)]
798798
pub struct Block {
799+
/// The index of the first YARV instruction for the Block in the ISEQ
800+
pub insn_idx: u32,
799801
params: Vec<InsnId>,
800802
insns: Vec<InsnId>,
801803
}
@@ -1024,9 +1026,11 @@ impl Function {
10241026
}
10251027
}
10261028

1027-
fn new_block(&mut self) -> BlockId {
1029+
fn new_block(&mut self, insn_idx: u32) -> BlockId {
10281030
let id = BlockId(self.blocks.len());
1029-
self.blocks.push(Block::default());
1031+
let mut block = Block::default();
1032+
block.insn_idx = insn_idx;
1033+
self.blocks.push(block);
10301034
id
10311035
}
10321036

@@ -2543,7 +2547,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
25432547
if insn_idx == 0 {
25442548
todo!("Separate entry block for param/self/...");
25452549
}
2546-
insn_idx_to_block.insert(insn_idx, fun.new_block());
2550+
insn_idx_to_block.insert(insn_idx, fun.new_block(insn_idx));
25472551
}
25482552

25492553
// Iteratively fill out basic blocks using a queue
@@ -3243,7 +3247,7 @@ mod rpo_tests {
32433247
fn jump() {
32443248
let mut function = Function::new(std::ptr::null());
32453249
let entry = function.entry_block;
3246-
let exit = function.new_block();
3250+
let exit = function.new_block(0);
32473251
function.push_insn(entry, Insn::Jump(BranchEdge { target: exit, args: vec![] }));
32483252
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
32493253
function.push_insn(entry, Insn::Return { val });
@@ -3254,8 +3258,8 @@ mod rpo_tests {
32543258
fn diamond_iftrue() {
32553259
let mut function = Function::new(std::ptr::null());
32563260
let entry = function.entry_block;
3257-
let side = function.new_block();
3258-
let exit = function.new_block();
3261+
let side = function.new_block(0);
3262+
let exit = function.new_block(0);
32593263
function.push_insn(side, Insn::Jump(BranchEdge { target: exit, args: vec![] }));
32603264
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
32613265
function.push_insn(entry, Insn::IfTrue { val, target: BranchEdge { target: side, args: vec![] } });
@@ -3269,8 +3273,8 @@ mod rpo_tests {
32693273
fn diamond_iffalse() {
32703274
let mut function = Function::new(std::ptr::null());
32713275
let entry = function.entry_block;
3272-
let side = function.new_block();
3273-
let exit = function.new_block();
3276+
let side = function.new_block(0);
3277+
let exit = function.new_block(0);
32743278
function.push_insn(side, Insn::Jump(BranchEdge { target: exit, args: vec![] }));
32753279
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
32763280
function.push_insn(entry, Insn::IfFalse { val, target: BranchEdge { target: side, args: vec![] } });
@@ -3325,7 +3329,7 @@ mod validation_tests {
33253329
fn iftrue_mismatch_args() {
33263330
let mut function = Function::new(std::ptr::null());
33273331
let entry = function.entry_block;
3328-
let side = function.new_block();
3332+
let side = function.new_block(0);
33293333
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
33303334
function.push_insn(entry, Insn::IfTrue { val, target: BranchEdge { target: side, args: vec![val, val, val] } });
33313335
assert_matches_err(function.validate(), ValidationError::MismatchedBlockArity(entry, 0, 3));
@@ -3335,7 +3339,7 @@ mod validation_tests {
33353339
fn iffalse_mismatch_args() {
33363340
let mut function = Function::new(std::ptr::null());
33373341
let entry = function.entry_block;
3338-
let side = function.new_block();
3342+
let side = function.new_block(0);
33393343
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
33403344
function.push_insn(entry, Insn::IfFalse { val, target: BranchEdge { target: side, args: vec![val, val, val] } });
33413345
assert_matches_err(function.validate(), ValidationError::MismatchedBlockArity(entry, 0, 3));
@@ -3345,7 +3349,7 @@ mod validation_tests {
33453349
fn jump_mismatch_args() {
33463350
let mut function = Function::new(std::ptr::null());
33473351
let entry = function.entry_block;
3348-
let side = function.new_block();
3352+
let side = function.new_block(0);
33493353
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
33503354
function.push_insn(entry, Insn::Jump ( BranchEdge { target: side, args: vec![val, val, val] } ));
33513355
assert_matches_err(function.validate(), ValidationError::MismatchedBlockArity(entry, 0, 3));
@@ -3377,8 +3381,8 @@ mod validation_tests {
33773381
// This tests that one branch is missing a definition which fails.
33783382
let mut function = Function::new(std::ptr::null());
33793383
let entry = function.entry_block;
3380-
let side = function.new_block();
3381-
let exit = function.new_block();
3384+
let side = function.new_block(0);
3385+
let exit = function.new_block(0);
33823386
let v0 = function.push_insn(side, Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(3)) });
33833387
function.push_insn(side, Insn::Jump(BranchEdge { target: exit, args: vec![] }));
33843388
let val1 = function.push_insn(entry, Insn::Const { val: Const::CBool(false) });
@@ -3396,8 +3400,8 @@ mod validation_tests {
33963400
// This tests that both branches with a definition succeeds.
33973401
let mut function = Function::new(std::ptr::null());
33983402
let entry = function.entry_block;
3399-
let side = function.new_block();
3400-
let exit = function.new_block();
3403+
let side = function.new_block(0);
3404+
let exit = function.new_block(0);
34013405
let v0 = function.push_insn(entry, Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(3)) });
34023406
function.push_insn(side, Insn::Jump(BranchEdge { target: exit, args: vec![] }));
34033407
let val = function.push_insn(entry, Insn::Const { val: Const::CBool(false) });
@@ -3437,7 +3441,7 @@ mod validation_tests {
34373441
let mut function = Function::new(std::ptr::null());
34383442
let entry = function.entry_block;
34393443
let val = function.push_insn(entry, Insn::Const { val: Const::Value(Qnil) });
3440-
let exit = function.new_block();
3444+
let exit = function.new_block(0);
34413445
function.push_insn(entry, Insn::Jump(BranchEdge { target: exit, args: vec![] }));
34423446
function.push_insn_id(exit, val);
34433447
function.push_insn(exit, Insn::Return { val });
@@ -3532,8 +3536,8 @@ mod infer_tests {
35323536
fn diamond_iffalse_merge_fixnum() {
35333537
let mut function = Function::new(std::ptr::null());
35343538
let entry = function.entry_block;
3535-
let side = function.new_block();
3536-
let exit = function.new_block();
3539+
let side = function.new_block(0);
3540+
let exit = function.new_block(0);
35373541
let v0 = function.push_insn(side, Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(3)) });
35383542
function.push_insn(side, Insn::Jump(BranchEdge { target: exit, args: vec![v0] }));
35393543
let val = function.push_insn(entry, Insn::Const { val: Const::CBool(false) });
@@ -3551,8 +3555,8 @@ mod infer_tests {
35513555
fn diamond_iffalse_merge_bool() {
35523556
let mut function = Function::new(std::ptr::null());
35533557
let entry = function.entry_block;
3554-
let side = function.new_block();
3555-
let exit = function.new_block();
3558+
let side = function.new_block(0);
3559+
let exit = function.new_block(0);
35563560
let v0 = function.push_insn(side, Insn::Const { val: Const::Value(Qtrue) });
35573561
function.push_insn(side, Insn::Jump(BranchEdge { target: exit, args: vec![v0] }));
35583562
let val = function.push_insn(entry, Insn::Const { val: Const::CBool(false) });

0 commit comments

Comments
 (0)