1
Fork 0

Auto merge of #138076 - tmiasko:pred-count, r=matthewjasper

Calculate predecessor count directly

Avoid allocating a vector of small vectors merely to determine how many
predecessors each basic block has.

Additionally use u8 and saturating operations. The pass only needs to
distinguish between [0..1] and [2..].
This commit is contained in:
bors 2025-03-12 22:33:54 +00:00
commit 0e76f8b7e0

View file

@ -32,9 +32,12 @@ pub(super) use self::AddCallGuards::*;
impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let mut pred_count: IndexVec<_, _> =
body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect();
pred_count[START_BLOCK] += 1;
let mut pred_count = IndexVec::from_elem(0u8, &body.basic_blocks);
for (_, data) in body.basic_blocks.iter_enumerated() {
for succ in data.terminator().successors() {
pred_count[succ] = pred_count[succ].saturating_add(1);
}
}
// We need a place to store the new blocks generated
let mut new_blocks = Vec::new();