Skip to content

Commit

Permalink
Merge pull request #1507 from ltratt/gidx_safepoint_id
Browse files Browse the repository at this point in the history
Add a guard's `gidx` and `safepoint_id`.
  • Loading branch information
ptersilie authored Dec 16, 2024
2 parents c9611c3 + f7eaa39 commit 0b3c8ce
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/c/guard_consting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ykrt/src/compile/jitc_yk/codegen/x64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3741,7 +3741,7 @@ mod tests {
",
"
...
; guard true, %0, []
; guard true, %0, [] ; ...
cmp r.8.b, 0x01
jnz 0x...
...
Expand Down Expand Up @@ -3770,7 +3770,7 @@ mod tests {
",
"
...
; guard false, %0, []
; guard false, %0, [] ; ...
cmp r.8.b, 0x00
jnz 0x...
...
Expand Down Expand Up @@ -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...
...
Expand Down Expand Up @@ -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...
...
",
Expand Down
2 changes: 1 addition & 1 deletion ykrt/src/compile/jitc_yk/jit_ir/dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod test {
entry:
%0: i8 = param ...
%1: i1 = ult %0, 1i8
guard true, %1, []
guard true, %1, [] ; ...
black_box %1
",
);
Expand Down
26 changes: 13 additions & 13 deletions ykrt/src/compile/jitc_yk/jit_ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,21 +1274,26 @@ 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<InlinedFrame>,
/// What AOT safepoint does this guard correspond to? This is used solely for debugging
/// purposes.
safepoint_id: u64,
}

impl GuardInfo {
pub(crate) fn new(
bid: aot_ir::BBlockId,
live_vars: Vec<(aot_ir::InstID, PackedOperand)>,
inlined_frames: Vec<InlinedFrame>,
safepoint_id: u64,
) -> Self {
Self {
bid,
live_vars,
inlined_frames,
safepoint_id,
}
}

Expand Down Expand Up @@ -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)| {
Expand All @@ -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::<Vec<_>>()
.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) => {
Expand Down
1 change: 1 addition & 0 deletions ykrt/src/compile/jitc_yk/jit_ir/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ykrt/src/compile/jitc_yk/trace_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 0b3c8ce

Please sign in to comment.