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:
Trevor Elliott
2023-01-24 14:37:16 -08:00
committed by GitHub
parent ec6922ff24
commit b58a197d33
35 changed files with 943 additions and 159 deletions

View File

@@ -587,6 +587,15 @@ impl<'a> Verifier<'a> {
Jump { destination, .. } | Branch { destination, .. } => {
self.verify_block(inst, destination.block(&self.func.dfg.value_lists), errors)?;
}
Brif {
arg,
blocks: [block_then, block_else],
..
} => {
self.verify_value(inst, arg, errors)?;
self.verify_block(inst, block_then.block(&self.func.dfg.value_lists), errors)?;
self.verify_block(inst, block_else.block(&self.func.dfg.value_lists), errors)?;
}
BranchTable {
table, destination, ..
} => {
@@ -1303,6 +1312,25 @@ impl<'a> Verifier<'a> {
let args = block.args_slice(&self.func.dfg.value_lists);
self.typecheck_variable_args_iterator(inst, iter, args, errors)?;
}
BranchInfo::Conditional(block_then, block_else) => {
let iter = self
.func
.dfg
.block_params(block_then.block(&self.func.dfg.value_lists))
.iter()
.map(|&v| self.func.dfg.value_type(v));
let args_then = block_then.args_slice(&self.func.dfg.value_lists);
self.typecheck_variable_args_iterator(inst, iter, args_then, errors)?;
let iter = self
.func
.dfg
.block_params(block_else.block(&self.func.dfg.value_lists))
.iter()
.map(|&v| self.func.dfg.value_type(v));
let args_else = block_else.args_slice(&self.func.dfg.value_lists);
self.typecheck_variable_args_iterator(inst, iter, args_else, errors)?;
}
BranchInfo::Table(table, block) => {
let arg_count = self.func.dfg.num_block_params(block);
if arg_count != 0 {