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:
commit
0e76f8b7e0
1 changed files with 6 additions and 3 deletions
|
@ -32,9 +32,12 @@ pub(super) use self::AddCallGuards::*;
|
||||||
|
|
||||||
impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
|
impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
|
||||||
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
let mut pred_count: IndexVec<_, _> =
|
let mut pred_count = IndexVec::from_elem(0u8, &body.basic_blocks);
|
||||||
body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect();
|
for (_, data) in body.basic_blocks.iter_enumerated() {
|
||||||
pred_count[START_BLOCK] += 1;
|
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
|
// We need a place to store the new blocks generated
|
||||||
let mut new_blocks = Vec::new();
|
let mut new_blocks = Vec::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue