Clarify mir block merging

This commit is contained in:
Markus Westerlind 2020-02-16 23:23:44 +01:00
parent 2440998666
commit 84c024d92f

View File

@ -95,6 +95,10 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
let mut start = START_BLOCK; let mut start = START_BLOCK;
// Vec of the blocks that should be merged. We store the indices here, instead of the
// statements itself to avoid moving the (relatively) large statements twice.
// We do not push the statements directly into the target block (`bb`) as that is slower
// due to additional reallocations
let mut merged_blocks = Vec::new(); let mut merged_blocks = Vec::new();
loop { loop {
let mut changed = false; let mut changed = false;
@ -116,6 +120,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
} }
let mut inner_changed = true; let mut inner_changed = true;
merged_blocks.clear();
while inner_changed { while inner_changed {
inner_changed = false; inner_changed = false;
inner_changed |= self.simplify_branch(&mut terminator); inner_changed |= self.simplify_branch(&mut terminator);
@ -134,7 +139,6 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
} }
self.basic_blocks[bb].statements = statements; self.basic_blocks[bb].statements = statements;
} }
merged_blocks.clear();
self.basic_blocks[bb].terminator = Some(terminator); self.basic_blocks[bb].terminator = Some(terminator);