From f7eaa398ad892d9e3d208f1a9ca780e412b5a19c Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Thu, 12 Dec 2024 15:49:20 +0000 Subject: [PATCH] Add a guard's `gidx` and `safepoint_id`. These two pieces of information can be useful when debugging. We could probably find a nicer syntax than this, but this causes guards to print out as e.g.: ``` guard true, %18, [0:%0_6: %0, 0:%0_7: %1, 0:%0_8: %2, 0:%0_9: %3, 0:%9_1: 0i1]; trace_gidx 0 safepoint_id 1 ``` --- tests/c/guard_consting.c | 2 +- ykrt/src/compile/jitc_yk/codegen/x64/mod.rs | 8 +++--- ykrt/src/compile/jitc_yk/jit_ir/dead_code.rs | 2 +- ykrt/src/compile/jitc_yk/jit_ir/mod.rs | 26 ++++++++++---------- ykrt/src/compile/jitc_yk/jit_ir/parser.rs | 1 + ykrt/src/compile/jitc_yk/trace_builder.rs | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/c/guard_consting.c b/tests/c/guard_consting.c index fb4fd4f35..4b7a7345c 100644 --- a/tests/c/guard_consting.c +++ b/tests/c/guard_consting.c @@ -4,7 +4,7 @@ // stderr: // ... // %{{30}}: i1 = sgt %{{_}}, 0i32 -// guard true, %{{30}}, [{{0}}:%{{0_2}}: %{{0}}, {{0}}:%{{0_6}}: %{{1}}, {{0}}:%{{0_7}}: %{{2}}, {{0}}:%{{0_8}}: %{{3}}, {{0}}:%{{0_9}}: %{{4}}, {{0}}:%{{9_1}}: 0i1] +// guard true, %{{30}}, [{{0}}:%{{0_2}}: %{{0}}, {{0}}:%{{0_6}}: %{{1}}, {{0}}:%{{0_7}}: %{{2}}, {{0}}:%{{0_8}}: %{{3}}, {{0}}:%{{0_9}}: %{{4}}, {{0}}:%{{9_1}}: 0i1] ; ... // ... // Check that if a guard's life variables include the condition operand, that diff --git a/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs b/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs index 2f2936706..6a671acd2 100644 --- a/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs +++ b/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs @@ -3741,7 +3741,7 @@ mod tests { ", " ... - ; guard true, %0, [] + ; guard true, %0, [] ; ... cmp r.8.b, 0x01 jnz 0x... ... @@ -3770,7 +3770,7 @@ mod tests { ", " ... - ; guard false, %0, [] + ; guard false, %0, [] ; ... cmp r.8.b, 0x00 jnz 0x... ... @@ -3802,7 +3802,7 @@ mod tests { ", " ... - ; guard false, %0, [0:%0_0: %0, 0:%0_1: 10i8, 0:%0_2: 32i8, 0:%0_3: 42i8] + ; guard false, %0, [0:%0_0: %0, 0:%0_1: 10i8, 0:%0_2: 32i8, 0:%0_3: 42i8] ; trace_gidx 0 safepoint_id 0 cmp r.8.b, 0x00 jnz 0x... ... @@ -3857,7 +3857,7 @@ mod tests { ; %1: i1 = eq %0, 3i8 movzx r.64.x, r.8._ cmp r.64.x, 0x03 - ; guard true, %1, [] + ; guard true, %1, [] ; ... jnz 0x... ... ", diff --git a/ykrt/src/compile/jitc_yk/jit_ir/dead_code.rs b/ykrt/src/compile/jitc_yk/jit_ir/dead_code.rs index 90475ff45..e0ee3d3c2 100644 --- a/ykrt/src/compile/jitc_yk/jit_ir/dead_code.rs +++ b/ykrt/src/compile/jitc_yk/jit_ir/dead_code.rs @@ -139,7 +139,7 @@ mod test { entry: %0: i8 = param ... %1: i1 = ult %0, 1i8 - guard true, %1, [] + guard true, %1, [] ; ... black_box %1 ", ); diff --git a/ykrt/src/compile/jitc_yk/jit_ir/mod.rs b/ykrt/src/compile/jitc_yk/jit_ir/mod.rs index fa05f6562..61dc30699 100644 --- a/ykrt/src/compile/jitc_yk/jit_ir/mod.rs +++ b/ykrt/src/compile/jitc_yk/jit_ir/mod.rs @@ -1274,9 +1274,12 @@ pub(crate) struct GuardInfo { bid: aot_ir::BBlockId, /// Live variables, mapping AOT vars to JIT [Operand]s. live_vars: Vec<(aot_ir::InstID, PackedOperand)>, - // Inlined frames info. - // FIXME With this field, the aotlives field is redundant. + /// Inlined frames info. + /// FIXME With this field, the aotlives field is redundant. inlined_frames: Vec, + /// What AOT safepoint does this guard correspond to? This is used solely for debugging + /// purposes. + safepoint_id: u64, } impl GuardInfo { @@ -1284,11 +1287,13 @@ impl GuardInfo { bid: aot_ir::BBlockId, live_vars: Vec<(aot_ir::InstID, PackedOperand)>, inlined_frames: Vec, + safepoint_id: u64, ) -> Self { Self { bid, live_vars, inlined_frames, + safepoint_id, } } @@ -1734,15 +1739,9 @@ impl fmt::Display for DisplayableInst<'_> { x.lhs(self.m).display(self.m), x.rhs(self.m).display(self.m) ), - Inst::Guard( - x @ GuardInst { - cond, - expect, - gidx: _, - }, - ) => { - let live_vars = x - .guard_info(self.m) + Inst::Guard(x @ GuardInst { cond, expect, gidx }) => { + let gi = x.guard_info(self.m); + let live_vars = gi .live_vars() .iter() .map(|(x, y)| { @@ -1751,16 +1750,17 @@ impl fmt::Display for DisplayableInst<'_> { usize::from(x.funcidx()), usize::from(x.bbidx()), usize::from(x.iidx()), - y.unpack(self.m).display(self.m) + y.unpack(self.m).display(self.m), ) }) .collect::>() .join(", "); write!( f, - "guard {}, {}, [{live_vars}]", + "guard {}, {}, [{live_vars}] ; trace_gidx {gidx} safepoint_id {}", if *expect { "true" } else { "false" }, cond.unpack(self.m).display(self.m), + gi.safepoint_id ) } Inst::Param(x) => { diff --git a/ykrt/src/compile/jitc_yk/jit_ir/parser.rs b/ykrt/src/compile/jitc_yk/jit_ir/parser.rs index b59a6de24..a6c151a44 100644 --- a/ykrt/src/compile/jitc_yk/jit_ir/parser.rs +++ b/ykrt/src/compile/jitc_yk/jit_ir/parser.rs @@ -204,6 +204,7 @@ impl<'lexer, 'input: 'lexer> JITIRParser<'lexer, 'input, '_> { aot_ir::BBlockId::new(0.into(), 0.into()), live_vars, Vec::new(), + 0, )) .unwrap(); let inst = GuardInst::new(self.process_operand(cond)?, is_true, gidx); diff --git a/ykrt/src/compile/jitc_yk/trace_builder.rs b/ykrt/src/compile/jitc_yk/trace_builder.rs index 3de0e13bf..49a6e24f1 100644 --- a/ykrt/src/compile/jitc_yk/trace_builder.rs +++ b/ykrt/src/compile/jitc_yk/trace_builder.rs @@ -562,7 +562,7 @@ impl TraceBuilder { } } - let gi = jit_ir::GuardInfo::new(bid.clone(), live_vars, callframes); + let gi = jit_ir::GuardInfo::new(bid.clone(), live_vars, callframes, safepoint.id); let gi_idx = self.jit_mod.push_guardinfo(gi).unwrap(); Ok(jit_ir::GuardInst::new(cond.clone(), expect, gi_idx))