Refactor BranchInfo::Table to no longer have an optional default branch (#5593)

This commit is contained in:
Trevor Elliott
2023-01-18 17:17:03 -08:00
committed by GitHub
parent e260abfce7
commit 7cea73a81d
6 changed files with 22 additions and 28 deletions

View File

@@ -360,9 +360,7 @@ impl DominatorTree {
for succ in func.jump_tables[jt].iter() { for succ in func.jump_tables[jt].iter() {
self.push_if_unseen(*succ); self.push_if_unseen(*succ);
} }
if let Some(dest) = dest { self.push_if_unseen(dest);
self.push_if_unseen(dest);
}
} }
BranchInfo::NotABranch => {} BranchInfo::NotABranch => {}
} }

View File

@@ -126,9 +126,8 @@ impl ControlFlowGraph {
self.add_edge(block, inst, dest.block(&func.dfg.value_lists)); self.add_edge(block, inst, dest.block(&func.dfg.value_lists));
} }
BranchInfo::Table(jt, dest) => { BranchInfo::Table(jt, dest) => {
if let Some(dest) = dest { self.add_edge(block, inst, dest);
self.add_edge(block, inst, dest);
}
for dest in func.jump_tables[jt].iter() { for dest in func.jump_tables[jt].iter() {
self.add_edge(block, inst, *dest); self.add_edge(block, inst, *dest);
} }

View File

@@ -169,12 +169,11 @@ fn visit_branch_targets<F: FnMut(Inst, Block, bool)>(f: &Function, inst: Inst, v
BranchInfo::SingleDest(dest) => { BranchInfo::SingleDest(dest) => {
visit(inst, dest.block(&f.dfg.value_lists), false); visit(inst, dest.block(&f.dfg.value_lists), false);
} }
BranchInfo::Table(table, maybe_dest) => { BranchInfo::Table(table, dest) => {
if let Some(dest) = maybe_dest { // The default block is reached via a direct conditional branch,
// The default block is reached via a direct conditional branch, // so it is not part of the table.
// so it is not part of the table. visit(inst, dest, false);
visit(inst, dest, false);
}
for &dest in f.jump_tables[table].as_slice() { for &dest in f.jump_tables[table].as_slice() {
visit(inst, dest, true); visit(inst, dest, true);
} }

View File

@@ -308,7 +308,7 @@ impl FunctionStencil {
} }
}); });
if default_dest == Some(old_dest) { if default_dest == old_dest {
match &mut self.dfg.insts[inst] { match &mut self.dfg.insts[inst] {
InstructionData::BranchTable { destination, .. } => { InstructionData::BranchTable { destination, .. } => {
*destination = new_dest; *destination = new_dest;

View File

@@ -273,7 +273,7 @@ impl InstructionData {
Self::Branch { destination, .. } => BranchInfo::SingleDest(destination), Self::Branch { destination, .. } => BranchInfo::SingleDest(destination),
Self::BranchTable { Self::BranchTable {
table, destination, .. table, destination, ..
} => BranchInfo::Table(table, Some(destination)), } => BranchInfo::Table(table, destination),
_ => { _ => {
debug_assert!(!self.opcode().is_branch()); debug_assert!(!self.opcode().is_branch());
BranchInfo::NotABranch BranchInfo::NotABranch
@@ -456,8 +456,8 @@ pub enum BranchInfo {
/// This is a branch or jump to a single destination block, possibly taking value arguments. /// This is a branch or jump to a single destination block, possibly taking value arguments.
SingleDest(BlockCall), SingleDest(BlockCall),
/// This is a jump table branch which can have many destination blocks and maybe one default block. /// This is a jump table branch which can have many destination blocks and one default block.
Table(JumpTable, Option<Block>), Table(JumpTable, Block),
} }
/// Information about call instructions. /// Information about call instructions.

View File

@@ -1304,18 +1304,16 @@ impl<'a> Verifier<'a> {
self.typecheck_variable_args_iterator(inst, iter, args, errors)?; self.typecheck_variable_args_iterator(inst, iter, args, errors)?;
} }
BranchInfo::Table(table, block) => { BranchInfo::Table(table, block) => {
if let Some(block) = block { let arg_count = self.func.dfg.num_block_params(block);
let arg_count = self.func.dfg.num_block_params(block); if arg_count != 0 {
if arg_count != 0 { return errors.nonfatal((
return errors.nonfatal(( inst,
inst, self.context(inst),
self.context(inst), format!(
format!( "takes no arguments, but had target {} with {} arguments",
"takes no arguments, but had target {} with {} arguments", block, arg_count,
block, arg_count, ),
), ));
));
}
} }
for block in self.func.jump_tables[table].iter() { for block in self.func.jump_tables[table].iter() {
let arg_count = self.func.dfg.num_block_params(*block); let arg_count = self.func.dfg.num_block_params(*block);