Skip to content

Commit

Permalink
Merge pull request #1454 from ltratt/assert_promotions_used
Browse files Browse the repository at this point in the history
Assert that all promotion data has been consumed.
  • Loading branch information
vext01 authored Nov 13, 2024
2 parents c1fc7b4 + 43b346b commit 7bfab90
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions ykrt/src/compile/jitc_yk/trace_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ impl TraceBuilder {
Ok(())
}

/// Process promotions inside an otherwise outlined block.
fn process_promotions_only(&mut self, bid: &aot_ir::BBlockId) -> Result<(), CompilationError> {
let blk = self.aot_mod.bblock(bid);

for inst in blk.insts.iter() {
if let aot_ir::Inst::Promote {
val: aot_ir::Operand::LocalVariable(_),
tyidx,
..
} = inst
{
let width_bits = match self.aot_mod.type_(*tyidx) {
aot_ir::Ty::Integer(it) => it.num_bits(),
_ => unreachable!(),
};
let width_bytes = usize::try_from(width_bits.div_ceil(8)).unwrap();
self.promote_idx += width_bytes;
}
}
Ok(())
}

/// Walk over a traced AOT block, translating the constituent instructions into the JIT module.
fn process_block(
&mut self,
Expand Down Expand Up @@ -1258,7 +1280,28 @@ impl TraceBuilder {
// blocks normally.
self.outline_target_blk = None;
} else {
// We are outlining so just skip this block.
// We are outlining so just skip this block. However, we still need to
// process promoted values to make sure we've processed all promotion
// data and haven't messed up the mapping.
#[cfg(tracer_hwt)]
{
last_blk_is_return = self.aot_mod.bblock(&bid).is_return();
// Due to hardware tracing we see the same block twice whenever
// there is a call. We only need to process one of them. We can
// skip the block if:
// a) The previous block had a return.
// b) The previous block is unmappable and the current block isn't
// an entry block.
if last_blk_is_return {
prev_bid = Some(bid);
continue;
}
if prev_bid.is_none() && !bid.is_entry() {
prev_bid = Some(bid);
continue;
}
}
self.process_promotions_only(&bid)?;
prev_bid = Some(bid);
continue;
}
Expand Down Expand Up @@ -1306,12 +1349,17 @@ impl TraceBuilder {
prev_bid = Some(bid);
}
None => {
// UnmappableBBlock block
// Unmappable block
#[cfg(tracer_hwt)]
{
last_blk_is_return = false;
}
prev_bid = None;
}
}
}

debug_assert_eq!(self.promote_idx, self.promotions.len());
let blk = self.aot_mod.bblock(self.cp_block.as_ref().unwrap());
let cpcall = blk.insts.iter().rev().nth(1).unwrap();
debug_assert!(cpcall.is_control_point(self.aot_mod));
Expand Down

0 comments on commit 7bfab90

Please sign in to comment.