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:
parent
508b803c44
commit
5bae3adde9
1 changed files with 6 additions and 2 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue