This commit is contained in:
Chris Fallin 2022-12-01 20:36:28 -08:00
parent 77141d2177
commit 4140ed9ea6

View file

@ -84,7 +84,7 @@ impl FunctionBody {
id id
} }
fn add_edge(&mut self, from: Block, to: Block) { pub fn add_edge(&mut self, from: Block, to: Block) {
let succ_pos = self.blocks[from].succs.len(); let succ_pos = self.blocks[from].succs.len();
let pred_pos = self.blocks[to].preds.len(); let pred_pos = self.blocks[to].preds.len();
self.blocks[from].succs.push(to); self.blocks[from].succs.push(to);
@ -171,6 +171,7 @@ impl FunctionBody {
} }
pub fn set_terminator(&mut self, block: Block, terminator: Terminator) { pub fn set_terminator(&mut self, block: Block, terminator: Terminator) {
debug_assert_eq!(&self.blocks[block].terminator, &Terminator::None);
log::trace!("block {} terminator {:?}", block, terminator); log::trace!("block {} terminator {:?}", block, terminator);
terminator.visit_successors(|succ| { terminator.visit_successors(|succ| {
self.add_edge(block, succ); self.add_edge(block, succ);
@ -251,9 +252,17 @@ impl FunctionBody {
}; };
for (i, &inst) in block_def.insts.iter().enumerate() { for (i, &inst) in block_def.insts.iter().enumerate() {
self.values[inst].visit_uses(|u| { match &self.values[inst] {
visit_use(u, Some(i), Some(inst)); &ValueDef::Operator(_, ref args, _) => {
}); for &arg in args {
visit_use(arg, Some(i), Some(inst));
}
}
&ValueDef::PickOutput(val, _, _) => {
visit_use(val, Some(i), Some(inst));
}
_ => {}
}
} }
let terminator_idx = block_def.insts.len(); let terminator_idx = block_def.insts.len();
block_def.terminator.visit_uses(|u| { block_def.terminator.visit_uses(|u| {
@ -290,7 +299,7 @@ pub struct BlockDef {
pub params: Vec<(Type, Value)>, pub params: Vec<(Type, Value)>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct BlockTarget { pub struct BlockTarget {
pub block: Block, pub block: Block,
pub args: Vec<Value>, pub args: Vec<Value>,
@ -307,7 +316,7 @@ impl std::fmt::Display for BlockTarget {
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum Terminator { pub enum Terminator {
Br { Br {
target: BlockTarget, target: BlockTarget,