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();
loop {
let mut changed = false;
}
let mut inner_changed = true;
+ merged_blocks.clear();
while inner_changed {
inner_changed = false;
inner_changed |= self.simplify_branch(&mut terminator);
changed |= inner_changed;
}
- let merged_block_count =
+ let statements_to_merge =
merged_blocks.iter().map(|&i| self.basic_blocks[i].statements.len()).sum();
- if merged_block_count > 0 {
+ if statements_to_merge > 0 {
let mut statements = std::mem::take(&mut self.basic_blocks[bb].statements);
- statements.reserve(merged_block_count);
+ statements.reserve(statements_to_merge);
for &from in &merged_blocks {
statements.append(&mut self.basic_blocks[from].statements);
}
self.basic_blocks[bb].statements = statements;
}
- merged_blocks.clear();
self.basic_blocks[bb].terminator = Some(terminator);
};
let first_succ = {
- if let Some(&first_succ) = terminator.successors().nth(0) {
+ if let Some(&first_succ) = terminator.successors().next() {
if terminator.successors().all(|s| *s == first_succ) {
let count = terminator.successors().count();
self.pred_count[first_succ] -= (count - 1) as u32;