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:
Trevor Elliott
2023-02-08 15:42:24 -08:00
committed by GitHub
parent cacc416080
commit 34ec4b4e44
2 changed files with 8 additions and 55 deletions

View File

@@ -2,7 +2,8 @@
use crate::entity::SecondaryMap; use crate::entity::SecondaryMap;
use crate::flowgraph::{BlockPredecessor, ControlFlowGraph}; 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::packed_option::PackedOption;
use crate::timing; use crate::timing;
use alloc::vec::Vec; 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. 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. /// post-order except for the insertion of the new block header at the split point.
fn push_successors(&mut self, func: &Function, block: Block) { fn push_successors(&mut self, func: &Function, block: Block) {
if let Some(inst) = func.layout.last_inst(block) { inst_predicates::visit_block_succs(func, block, |_, succ, _| self.push_if_unseen(succ))
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()),
}
}
} }
/// Push `block` onto `self.stack` if it has not already been seen. /// Push `block` onto `self.stack` if it has not already been seen.

View File

@@ -22,7 +22,8 @@
use crate::bforest; use crate::bforest;
use crate::entity::SecondaryMap; 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 crate::timing;
use core::mem; use core::mem;
@@ -116,34 +117,9 @@ impl ControlFlowGraph {
} }
fn compute_block(&mut self, func: &Function, block: Block) { fn compute_block(&mut self, func: &Function, block: Block) {
if let Some(inst) = func.layout.last_inst(block) { inst_predicates::visit_block_succs(func, block, |inst, dest, _| {
match &func.dfg.insts[inst] { self.add_edge(block, inst, dest);
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()),
}
}
} }
fn invalidate_block_successors(&mut self, block: Block) { fn invalidate_block_successors(&mut self, block: Block) {