Skip to content

Commit

Permalink
Refactor BranchInfo::Table to no longer have an optional default bran…
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt authored Jan 19, 2023
1 parent e260abf commit 7cea73a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
4 changes: 1 addition & 3 deletions cranelift/codegen/src/dominator_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
Expand Down
5 changes: 2 additions & 3 deletions cranelift/codegen/src/flowgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions cranelift/codegen/src/inst_predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions cranelift/codegen/src/ir/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 10 additions & 12 deletions cranelift/codegen/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7cea73a

Please sign in to comment.