Reuse inst_predicates::visit_block_succs in more places (#5750)
Following up from #5730, replace some explicit matching over branch instructions with a use of inst_predicates::visit_block_succs.
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
use crate::entity::SecondaryMap;
|
||||
use crate::flowgraph::{BlockPredecessor, ControlFlowGraph};
|
||||
use crate::ir::{self, Block, ExpandedProgramPoint, Function, Inst, Layout, ProgramOrder, Value};
|
||||
use crate::inst_predicates;
|
||||
use crate::ir::{Block, ExpandedProgramPoint, Function, Inst, Layout, ProgramOrder, Value};
|
||||
use crate::packed_option::PackedOption;
|
||||
use crate::timing;
|
||||
use alloc::vec::Vec;
|
||||
@@ -350,31 +351,7 @@ impl DominatorTree {
|
||||
/// post-order. Split-invariant means that if a block is split in two, we get the same
|
||||
/// post-order except for the insertion of the new block header at the split point.
|
||||
fn push_successors(&mut self, func: &Function, block: Block) {
|
||||
if let Some(inst) = func.layout.last_inst(block) {
|
||||
match &func.dfg.insts[inst] {
|
||||
ir::InstructionData::Jump {
|
||||
destination: succ, ..
|
||||
} => self.push_if_unseen(succ.block(&func.dfg.value_lists)),
|
||||
ir::InstructionData::Brif {
|
||||
blocks: [block_then, block_else],
|
||||
..
|
||||
} => {
|
||||
self.push_if_unseen(block_then.block(&func.dfg.value_lists));
|
||||
self.push_if_unseen(block_else.block(&func.dfg.value_lists));
|
||||
}
|
||||
ir::InstructionData::BranchTable {
|
||||
table: jt,
|
||||
destination: dest,
|
||||
..
|
||||
} => {
|
||||
for succ in func.stencil.dfg.jump_tables[*jt].iter() {
|
||||
self.push_if_unseen(*succ);
|
||||
}
|
||||
self.push_if_unseen(*dest);
|
||||
}
|
||||
inst => debug_assert!(!inst.opcode().is_branch()),
|
||||
}
|
||||
}
|
||||
inst_predicates::visit_block_succs(func, block, |_, succ, _| self.push_if_unseen(succ))
|
||||
}
|
||||
|
||||
/// Push `block` onto `self.stack` if it has not already been seen.
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
|
||||
use crate::bforest;
|
||||
use crate::entity::SecondaryMap;
|
||||
use crate::ir::{self, Block, Function, Inst};
|
||||
use crate::inst_predicates;
|
||||
use crate::ir::{Block, Function, Inst};
|
||||
use crate::timing;
|
||||
use core::mem;
|
||||
|
||||
@@ -116,34 +117,9 @@ impl ControlFlowGraph {
|
||||
}
|
||||
|
||||
fn compute_block(&mut self, func: &Function, block: Block) {
|
||||
if let Some(inst) = func.layout.last_inst(block) {
|
||||
match &func.dfg.insts[inst] {
|
||||
ir::InstructionData::Jump {
|
||||
destination: dest, ..
|
||||
} => {
|
||||
self.add_edge(block, inst, dest.block(&func.dfg.value_lists));
|
||||
}
|
||||
ir::InstructionData::Brif {
|
||||
blocks: [block_then, block_else],
|
||||
..
|
||||
} => {
|
||||
self.add_edge(block, inst, block_then.block(&func.dfg.value_lists));
|
||||
self.add_edge(block, inst, block_else.block(&func.dfg.value_lists));
|
||||
}
|
||||
ir::InstructionData::BranchTable {
|
||||
table: jt,
|
||||
destination: dest,
|
||||
..
|
||||
} => {
|
||||
self.add_edge(block, inst, *dest);
|
||||
|
||||
for dest in func.stencil.dfg.jump_tables[*jt].iter() {
|
||||
self.add_edge(block, inst, *dest);
|
||||
}
|
||||
}
|
||||
inst => debug_assert!(!inst.opcode().is_branch()),
|
||||
}
|
||||
}
|
||||
inst_predicates::visit_block_succs(func, block, |inst, dest, _| {
|
||||
self.add_edge(block, inst, dest);
|
||||
});
|
||||
}
|
||||
|
||||
fn invalidate_block_successors(&mut self, block: Block) {
|
||||
|
||||
Reference in New Issue
Block a user