diff options
| author | bors <bors@rust-lang.org> | 2025-03-12 22:33:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-12 22:33:54 +0000 |
| commit | 0e76f8b7e02b1ddd349dde1501f73426a4e764cf (patch) | |
| tree | 327c36271cadd1c1fc939762ded4a35934d75085 | |
| parent | 249cb84316401daf040832cdbb8a45e0f5ab6af8 (diff) | |
| parent | 5bae3adde9410c4f0f7363ec44b183a255463a0e (diff) | |
| download | rust-0e76f8b7e02b1ddd349dde1501f73426a4e764cf.tar.gz rust-0e76f8b7e02b1ddd349dde1501f73426a4e764cf.zip | |
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..].
| -rw-r--r-- | compiler/rustc_mir_transform/src/add_call_guards.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_mir_transform/src/add_call_guards.rs b/compiler/rustc_mir_transform/src/add_call_guards.rs index bc335cee147..bacff287859 100644 --- a/compiler/rustc_mir_transform/src/add_call_guards.rs +++ b/compiler/rustc_mir_transform/src/add_call_guards.rs @@ -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(); |
