cranelift: Add a conditional branch instruction with two targets (#5446)
Add a conditional branch instruction with two targets: brif. This instruction will eventually replace brz and brnz, as it encompasses the behavior of both. This PR also changes the InstructionData layout for instruction formats that hold BlockCall values, taking the same approach we use for Value arguments. This allows branch_destination to return a slice to the BlockCall values held in the instruction, rather than requiring that we pattern match on InstructionData to fetch the then/else blocks. Function generation for fuzzing has been updated to generate uses of brif, and I've run the cranelift-fuzzgen target locally for hours without triggering any new failures.
This commit is contained in:
@@ -176,25 +176,23 @@ pub(crate) fn visit_block_succs<F: FnMut(Inst, Block, bool)>(
|
||||
mut visit: F,
|
||||
) {
|
||||
for inst in f.layout.block_likely_branches(block) {
|
||||
if f.dfg.insts[inst].opcode().is_branch() {
|
||||
visit_branch_targets(f, inst, &mut visit);
|
||||
}
|
||||
}
|
||||
}
|
||||
match f.dfg.insts[inst].analyze_branch() {
|
||||
BranchInfo::NotABranch => {}
|
||||
BranchInfo::SingleDest(dest) => {
|
||||
visit(inst, dest.block(&f.dfg.value_lists), false);
|
||||
}
|
||||
BranchInfo::Conditional(block_then, block_else) => {
|
||||
visit(inst, block_then.block(&f.dfg.value_lists), false);
|
||||
visit(inst, block_else.block(&f.dfg.value_lists), 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);
|
||||
|
||||
fn visit_branch_targets<F: FnMut(Inst, Block, bool)>(f: &Function, inst: Inst, visit: &mut F) {
|
||||
match f.dfg.insts[inst].analyze_branch() {
|
||||
BranchInfo::NotABranch => {}
|
||||
BranchInfo::SingleDest(dest) => {
|
||||
visit(inst, dest.block(&f.dfg.value_lists), 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);
|
||||
for &dest in f.jump_tables[table].as_slice() {
|
||||
visit(inst, dest, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user