cranelift: Rework block instructions to use BlockCall (#5464)
Add a new type BlockCall that represents the pair of a block name with arguments to be passed to it. (The mnemonic here is that it looks a bit like a function call.) Rework the implementation of jump, brz, and brnz to use BlockCall instead of storing the block arguments as varargs in the instruction's ValueList. To ensure that we're processing block arguments from BlockCall values in instructions, three new functions have been introduced on DataFlowGraph that both sets of arguments: inst_values - returns an iterator that traverses values in the instruction and block arguments map_inst_values - applies a function to each value in the instruction and block arguments overwrite_inst_values - overwrite all values in an instruction and block arguments with values from the iterator Co-authored-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
@@ -1899,8 +1899,8 @@ impl<'a> Parser<'a> {
|
||||
// all references refer to a definition.
|
||||
for block in &ctx.function.layout {
|
||||
for inst in ctx.function.layout.block_insts(block) {
|
||||
for value in ctx.function.dfg.inst_args(inst) {
|
||||
if !ctx.map.contains_value(*value) {
|
||||
for value in ctx.function.dfg.inst_values(inst) {
|
||||
if !ctx.map.contains_value(value) {
|
||||
return err!(
|
||||
ctx.map.location(AnyEntity::Inst(inst)).unwrap(),
|
||||
"undefined operand value {}",
|
||||
@@ -2582,21 +2582,22 @@ impl<'a> Parser<'a> {
|
||||
// Parse the destination block number.
|
||||
let block_num = self.match_block("expected jump destination block")?;
|
||||
let args = self.parse_opt_value_list()?;
|
||||
let destination = ctx.function.dfg.block_call(block_num, &args);
|
||||
InstructionData::Jump {
|
||||
opcode,
|
||||
destination: block_num,
|
||||
args: args.into_value_list(&[], &mut ctx.function.dfg.value_lists),
|
||||
destination,
|
||||
}
|
||||
}
|
||||
InstructionFormat::Branch => {
|
||||
let ctrl_arg = self.match_value("expected SSA value control operand")?;
|
||||
let arg = self.match_value("expected SSA value control operand")?;
|
||||
self.match_token(Token::Comma, "expected ',' between operands")?;
|
||||
let block_num = self.match_block("expected branch destination block")?;
|
||||
let args = self.parse_opt_value_list()?;
|
||||
let destination = ctx.function.dfg.block_call(block_num, &args);
|
||||
InstructionData::Branch {
|
||||
opcode,
|
||||
destination: block_num,
|
||||
args: args.into_value_list(&[ctrl_arg], &mut ctx.function.dfg.value_lists),
|
||||
arg,
|
||||
destination,
|
||||
}
|
||||
}
|
||||
InstructionFormat::BranchTable => {
|
||||
|
||||
Reference in New Issue
Block a user