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:
Trevor Elliott
2023-01-17 16:31:15 -08:00
committed by GitHub
parent 3a2ca67570
commit 1e6c13d83e
32 changed files with 475 additions and 422 deletions

View File

@@ -11,9 +11,13 @@ fn new(format_field_name: &'static str, rust_type: &'static str, doc: &'static s
}
pub(crate) struct EntityRefs {
/// A reference to a basic block in the same function, with its arguments provided.
/// This is primarily used in control flow instructions.
pub(crate) block_call: OperandKind,
/// A reference to a basic block in the same function.
/// This is primarliy used in control flow instructions.
pub(crate) block: OperandKind,
/// This is primarily used in control flow instructions.
pub(crate) label: OperandKind,
/// A reference to a stack slot declared in the function preamble.
pub(crate) stack_slot: OperandKind,
@@ -45,11 +49,18 @@ pub(crate) struct EntityRefs {
impl EntityRefs {
pub fn new() -> Self {
Self {
block: new(
block_call: new(
"destination",
"ir::BlockCall",
"a basic block in the same function, with its arguments provided.",
),
label: new(
"destination",
"ir::Block",
"a basic block in the same function.",
),
stack_slot: new("stack_slot", "ir::StackSlot", "A stack slot"),
dynamic_stack_slot: new(

View File

@@ -111,17 +111,16 @@ impl Formats {
.value()
.build(),
jump: Builder::new("Jump").imm(&entities.block).varargs().build(),
jump: Builder::new("Jump").imm(&entities.block_call).build(),
branch: Builder::new("Branch")
.value()
.imm(&entities.block)
.varargs()
.imm(&entities.block_call)
.build(),
branch_table: Builder::new("BranchTable")
.value()
.imm(&entities.block)
.imm(&entities.label)
.imm(&entities.jump_table)
.build(),

View File

@@ -17,8 +17,9 @@ fn define_control_flow(
imm: &Immediates,
entities: &EntityRefs,
) {
let block = &Operand::new("block", &entities.block).with_doc("Destination basic block");
let args = &Operand::new("args", &entities.varargs).with_doc("block arguments");
let block_call = &Operand::new("block_call", &entities.block_call)
.with_doc("Destination basic block, with its arguments provided");
let label = &Operand::new("label", &entities.label).with_doc("Destination basic block");
ig.push(
Inst::new(
@@ -32,7 +33,7 @@ fn define_control_flow(
"#,
&formats.jump,
)
.operands_in(vec![block, args])
.operands_in(vec![block_call])
.is_terminator(true)
.is_branch(true),
);
@@ -56,7 +57,7 @@ fn define_control_flow(
"#,
&formats.branch,
)
.operands_in(vec![c, block, args])
.operands_in(vec![c, block_call])
.is_branch(true),
);
@@ -70,7 +71,7 @@ fn define_control_flow(
"#,
&formats.branch,
)
.operands_in(vec![c, block, args])
.operands_in(vec![c, block_call])
.is_branch(true),
);
}
@@ -105,7 +106,7 @@ fn define_control_flow(
"#,
&formats.branch_table,
)
.operands_in(vec![x, block, JT])
.operands_in(vec![x, label, JT])
.is_terminator(true)
.is_branch(true),
);