Skip to content

Commit

Permalink
cranelift: Remove the heap_{addr,load,store} instructions
Browse files Browse the repository at this point in the history
These are now legalized in the `cranelift-wasm` frontend.
  • Loading branch information
fitzgen committed Dec 6, 2022
1 parent 9a5cc8a commit 822f601
Show file tree
Hide file tree
Showing 14 changed files with 1 addition and 899 deletions.
9 changes: 0 additions & 9 deletions cranelift/codegen/meta/src/cdsl/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ impl InstructionFormatBuilder {
self
}

pub fn imm_with_name(mut self, name: &'static str, operand_kind: &OperandKind) -> Self {
let field = FormatField {
kind: operand_kind.clone(),
member: name,
};
self.0.imm_fields.push(field);
self
}

pub fn typevar_operand(mut self, operand_index: usize) -> Self {
assert!(self.0.typevar_operand.is_none());
assert!(operand_index < self.0.num_value_operands);
Expand Down
5 changes: 0 additions & 5 deletions cranelift/codegen/meta/src/shared/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ pub(crate) struct EntityRefs {
/// A reference to a jump table declared in the function preamble.
pub(crate) jump_table: OperandKind,

/// A reference to a heap declared in the function preamble.
pub(crate) heap: OperandKind,

/// A reference to a table declared in the function preamble.
pub(crate) table: OperandKind,

Expand Down Expand Up @@ -69,8 +66,6 @@ impl EntityRefs {

jump_table: new("table", "ir::JumpTable", "A jump table."),

heap: new("heap", "ir::Heap", "A heap."),

table: new("table", "ir::Table", "A table."),

varargs: OperandKind::new(
Expand Down
22 changes: 0 additions & 22 deletions cranelift/codegen/meta/src/shared/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pub(crate) struct Formats {
pub(crate) cond_trap: Rc<InstructionFormat>,
pub(crate) float_compare: Rc<InstructionFormat>,
pub(crate) func_addr: Rc<InstructionFormat>,
pub(crate) heap_addr: Rc<InstructionFormat>,
pub(crate) heap_load: Rc<InstructionFormat>,
pub(crate) heap_store: Rc<InstructionFormat>,
pub(crate) int_compare: Rc<InstructionFormat>,
pub(crate) int_compare_imm: Rc<InstructionFormat>,
pub(crate) int_add_trap: Rc<InstructionFormat>,
Expand Down Expand Up @@ -200,25 +197,6 @@ impl Formats {
.imm(&entities.dynamic_stack_slot)
.build(),

// Accessing a WebAssembly heap.
heap_addr: Builder::new("HeapAddr")
.imm(&entities.heap)
.value()
.imm_with_name("offset", &imm.uimm32)
.imm_with_name("size", &imm.uimm8)
.build(),

heap_load: Builder::new("HeapLoad").imm(&imm.heap_imm).value().build(),

heap_store: Builder::new("HeapStore")
// We have more fields for this instruction than
// `InstructionData` can hold without growing in size, so we
// push the immediates out into a side table.
.imm(&imm.heap_imm)
.value()
.value()
.build(),

// Accessing a WebAssembly table.
table_addr: Builder::new("TableAddr")
.imm(&entities.table)
Expand Down
17 changes: 0 additions & 17 deletions cranelift/codegen/meta/src/shared/immediates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ pub(crate) struct Immediates {
/// counts on shift instructions.
pub uimm8: OperandKind,

/// An unsigned 32-bit immediate integer operand.
pub uimm32: OperandKind,

/// An unsigned 128-bit immediate integer operand.
///
/// This operand is used to pass entire 128-bit vectors as immediates to instructions like
Expand Down Expand Up @@ -59,9 +56,6 @@ pub(crate) struct Immediates {
/// Flags for memory operations like `load` and `store`.
pub memflags: OperandKind,

/// A reference to out-of-line immediates for heap accesses.
pub heap_imm: OperandKind,

/// A trap code indicating the reason for trapping.
///
/// The Rust enum type also has a `User(u16)` variant for user-provided trap codes.
Expand Down Expand Up @@ -110,11 +104,6 @@ impl Immediates {
"ir::immediates::Uimm8",
"An 8-bit immediate unsigned integer.",
),
uimm32: new_imm(
"imm",
"ir::immediates::Uimm32",
"A 32-bit immediate unsigned integer.",
),
uimm128: new_imm(
"imm",
"ir::Immediate",
Expand Down Expand Up @@ -186,12 +175,6 @@ impl Immediates {

memflags: new_imm("flags", "ir::MemFlags", "Memory operation flags"),

heap_imm: new_imm(
"heap_imm",
"ir::HeapImm",
"Reference to out-of-line heap access immediates",
),

trapcode: {
let mut trapcode_values = HashMap::new();
trapcode_values.insert("stk_ovf", "StackOverflow");
Expand Down
83 changes: 0 additions & 83 deletions cranelift/codegen/meta/src/shared/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,89 +1121,6 @@ pub(crate) fn define(
.operands_out(vec![a]),
);

let HeapOffset = &TypeVar::new(
"HeapOffset",
"An unsigned heap offset",
TypeSetBuilder::new().ints(32..64).build(),
);

let H = &Operand::new("H", &entities.heap);
let index = &Operand::new("index", HeapOffset);
let Offset = &Operand::new("Offset", &imm.uimm32).with_doc("Static offset immediate in bytes");
let Size = &Operand::new("Size", &imm.uimm8).with_doc("Static size immediate in bytes");

ig.push(
Inst::new(
"heap_addr",
r#"
Bounds check and compute absolute address of ``index + Offset`` in heap memory.
Verify that the range ``index .. index + Offset + Size`` is in bounds for the
heap ``H``, and generate an absolute address that is safe to dereference.
1. If ``index + Offset + Size`` is less than or equal ot the heap bound, return an
absolute address corresponding to a byte offset of ``index + Offset`` from the
heap's base address.
2. If ``index + Offset + Size`` is greater than the heap bound, return the
``NULL`` pointer or any other address that is guaranteed to generate a trap
when accessed.
"#,
&formats.heap_addr,
)
.operands_in(vec![H, index, Offset, Size])
.operands_out(vec![addr]),
);

let heap_imm = &Operand::new("heap_imm", &imm.heap_imm);
let index =
&Operand::new("index", HeapOffset).with_doc("Dynamic index (in bytes) into the heap");
let a = &Operand::new("a", Mem).with_doc("The value loaded from the heap");

ig.push(
Inst::new(
"heap_load",
r#"
Load a value from the given heap at address ``index + offset``,
trapping on out-of-bounds accesses.
Checks that ``index + offset .. index + offset + sizeof(a)`` is
within the heap's bounds, trapping if it is not. Otherwise, when
that range is in bounds, loads the value from the heap.
Traps on ``index + offset + sizeof(a)`` overflow.
"#,
&formats.heap_load,
)
.operands_in(vec![heap_imm, index])
.operands_out(vec![a])
.can_load(true)
.can_trap(true),
);

let a = &Operand::new("a", Mem).with_doc("The value stored into the heap");

ig.push(
Inst::new(
"heap_store",
r#"
Store ``a`` into the given heap at address ``index + offset``,
trapping on out-of-bounds accesses.
Checks that ``index + offset .. index + offset + sizeof(a)`` is
within the heap's bounds, trapping if it is not. Otherwise, when
that range is in bounds, stores the value into the heap.
Traps on ``index + offset + sizeof(a)`` overflow.
"#,
&formats.heap_store,
)
.operands_in(vec![heap_imm, index, a])
.operands_out(vec![])
.can_store(true)
.can_trap(true),
);

// Note this instruction is marked as having other side-effects, so GVN won't try to hoist it,
// which would result in it being subject to spilling. While not hoisting would generally hurt
// performance, since a computed value used many times may need to be regenerated before each
Expand Down
4 changes: 0 additions & 4 deletions cranelift/codegen/src/isa/aarch64/lower_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ pub(crate) fn lower_insn_to_regs(
panic!("Direct stack memory access not supported; should not be used by Wasm");
}

Opcode::HeapLoad | Opcode::HeapStore | Opcode::HeapAddr => {
panic!("heap access instructions should have been removed by legalization!");
}

Opcode::TableAddr => {
panic!("table_addr should have been removed by legalization!");
}
Expand Down
3 changes: 0 additions & 3 deletions cranelift/codegen/src/isa/s390x/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ impl LowerBackend for S390xBackend {
Opcode::StackLoad | Opcode::StackStore => {
panic!("Direct stack memory access not supported; should not be used by Wasm");
}
Opcode::HeapLoad | Opcode::HeapStore | Opcode::HeapAddr => {
panic!("heap access instructions should have been removed by legalization!");
}
Opcode::TableAddr => {
panic!("table_addr should have been removed by legalization!");
}
Expand Down
4 changes: 0 additions & 4 deletions cranelift/codegen/src/isa/x64/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,6 @@ fn lower_insn_to_regs(
panic!("global_value should have been removed by legalization!");
}

Opcode::HeapLoad | Opcode::HeapStore | Opcode::HeapAddr => {
panic!("heap access instructions should have been removed by legalization!");
}

Opcode::TableAddr => {
panic!("table_addr should have been removed by legalization!");
}
Expand Down
Loading

0 comments on commit 822f601

Please sign in to comment.