Refactor BranchInfo::Table to no longer have an optional default branch (#5593)
This commit is contained in:
@@ -360,9 +360,7 @@ impl DominatorTree {
|
||||
for succ in func.jump_tables[jt].iter() {
|
||||
self.push_if_unseen(*succ);
|
||||
}
|
||||
if let Some(dest) = dest {
|
||||
self.push_if_unseen(dest);
|
||||
}
|
||||
self.push_if_unseen(dest);
|
||||
}
|
||||
BranchInfo::NotABranch => {}
|
||||
}
|
||||
|
||||
@@ -126,9 +126,8 @@ impl ControlFlowGraph {
|
||||
self.add_edge(block, inst, dest.block(&func.dfg.value_lists));
|
||||
}
|
||||
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() {
|
||||
self.add_edge(block, inst, *dest);
|
||||
}
|
||||
|
||||
@@ -169,12 +169,11 @@ fn visit_branch_targets<F: FnMut(Inst, Block, bool)>(f: &Function, inst: Inst, v
|
||||
BranchInfo::SingleDest(dest) => {
|
||||
visit(inst, dest.block(&f.dfg.value_lists), false);
|
||||
}
|
||||
BranchInfo::Table(table, maybe_dest) => {
|
||||
if let Some(dest) = maybe_dest {
|
||||
// The default block is reached via a direct conditional branch,
|
||||
// so it is not part of the table.
|
||||
visit(inst, dest, false);
|
||||
}
|
||||
BranchInfo::Table(table, dest) => {
|
||||
// The default block is reached via a direct conditional branch,
|
||||
// so it is not part of the table.
|
||||
visit(inst, dest, false);
|
||||
|
||||
for &dest in f.jump_tables[table].as_slice() {
|
||||
visit(inst, dest, true);
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ impl FunctionStencil {
|
||||
}
|
||||
});
|
||||
|
||||
if default_dest == Some(old_dest) {
|
||||
if default_dest == old_dest {
|
||||
match &mut self.dfg.insts[inst] {
|
||||
InstructionData::BranchTable { destination, .. } => {
|
||||
*destination = new_dest;
|
||||
|
||||
@@ -273,7 +273,7 @@ impl InstructionData {
|
||||
Self::Branch { destination, .. } => BranchInfo::SingleDest(destination),
|
||||
Self::BranchTable {
|
||||
table, destination, ..
|
||||
} => BranchInfo::Table(table, Some(destination)),
|
||||
} => BranchInfo::Table(table, destination),
|
||||
_ => {
|
||||
debug_assert!(!self.opcode().is_branch());
|
||||
BranchInfo::NotABranch
|
||||
@@ -456,8 +456,8 @@ pub enum BranchInfo {
|
||||
/// This is a branch or jump to a single destination block, possibly taking value arguments.
|
||||
SingleDest(BlockCall),
|
||||
|
||||
/// This is a jump table branch which can have many destination blocks and maybe one default block.
|
||||
Table(JumpTable, Option<Block>),
|
||||
/// This is a jump table branch which can have many destination blocks and one default block.
|
||||
Table(JumpTable, Block),
|
||||
}
|
||||
|
||||
/// Information about call instructions.
|
||||
|
||||
@@ -1304,18 +1304,16 @@ impl<'a> Verifier<'a> {
|
||||
self.typecheck_variable_args_iterator(inst, iter, args, errors)?;
|
||||
}
|
||||
BranchInfo::Table(table, block) => {
|
||||
if let Some(block) = block {
|
||||
let arg_count = self.func.dfg.num_block_params(block);
|
||||
if arg_count != 0 {
|
||||
return errors.nonfatal((
|
||||
inst,
|
||||
self.context(inst),
|
||||
format!(
|
||||
"takes no arguments, but had target {} with {} arguments",
|
||||
block, arg_count,
|
||||
),
|
||||
));
|
||||
}
|
||||
let arg_count = self.func.dfg.num_block_params(block);
|
||||
if arg_count != 0 {
|
||||
return errors.nonfatal((
|
||||
inst,
|
||||
self.context(inst),
|
||||
format!(
|
||||
"takes no arguments, but had target {} with {} arguments",
|
||||
block, arg_count,
|
||||
),
|
||||
));
|
||||
}
|
||||
for block in self.func.jump_tables[table].iter() {
|
||||
let arg_count = self.func.dfg.num_block_params(*block);
|
||||
|
||||
Reference in New Issue
Block a user