diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2025-03-05 23:41:44 +0100 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2025-03-06 00:25:46 +0100 |
| commit | 5bae3adde9410c4f0f7363ec44b183a255463a0e (patch) | |
| tree | 5f8d12ea5dbba9590f9d2dc70508485beb7010e2 /compiler/rustc_mir_transform/src | |
| parent | 508b803c44e4df10fe189e8d1ae3a551ade9b2da (diff) | |
| download | rust-5bae3adde9410c4f0f7363ec44b183a255463a0e.tar.gz rust-5bae3adde9410c4f0f7363ec44b183a255463a0e.zip | |
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..].
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/add_call_guards.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/add_call_guards.rs b/compiler/rustc_mir_transform/src/add_call_guards.rs index f9e757dda43..60e6342d4ec 100644 --- a/compiler/rustc_mir_transform/src/add_call_guards.rs +++ b/compiler/rustc_mir_transform/src/add_call_guards.rs @@ -32,8 +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(); + 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(); |
