Cranelift: Add heap_load and heap_store instructions (#5300)
* Cranelift: Define `heap_load` and `heap_store` instructions
* Cranelift: Implement interpreter support for `heap_load` and `heap_store`
* Cranelift: Add a suite runtests for `heap_{load,store}`
There are so many knobs we can twist for heaps and I wanted to exhaustively test
all of them, so I wrote a script to generate the tests. I've checked in the
script in case we want to make any changes in the future, but I don't think it
is worth adding this to CI to check that scripts are up to date or anything like
that.
* Review feedback
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
use crate::entity::SecondaryMap;
|
||||
use crate::ir::entities::AnyEntity;
|
||||
use crate::ir::immediates::{HeapImmData, Uimm32};
|
||||
use crate::ir::{Block, DataFlowGraph, Function, Inst, SigRef, Type, Value, ValueDef};
|
||||
use crate::packed_option::ReservedValue;
|
||||
use alloc::string::{String, ToString};
|
||||
@@ -476,6 +477,47 @@ pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt
|
||||
dynamic_stack_slot,
|
||||
..
|
||||
} => write!(w, " {}, {}", arg, dynamic_stack_slot),
|
||||
HeapLoad {
|
||||
opcode: _,
|
||||
heap_imm,
|
||||
arg,
|
||||
} => {
|
||||
let HeapImmData {
|
||||
flags,
|
||||
heap,
|
||||
offset,
|
||||
} = dfg.heap_imms[heap_imm];
|
||||
write!(
|
||||
w,
|
||||
" {heap} {flags} {arg}{optional_offset}",
|
||||
optional_offset = if offset == Uimm32::from(0) {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!("+{offset}")
|
||||
}
|
||||
)
|
||||
}
|
||||
HeapStore {
|
||||
opcode: _,
|
||||
heap_imm,
|
||||
args,
|
||||
} => {
|
||||
let HeapImmData {
|
||||
flags,
|
||||
heap,
|
||||
offset,
|
||||
} = dfg.heap_imms[heap_imm];
|
||||
let [index, value] = args;
|
||||
write!(
|
||||
w,
|
||||
" {heap} {flags} {index}{optional_offset}, {value}",
|
||||
optional_offset = if offset == Uimm32::from(0) {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!("+{offset}")
|
||||
}
|
||||
)
|
||||
}
|
||||
HeapAddr {
|
||||
heap,
|
||||
arg,
|
||||
|
||||
Reference in New Issue
Block a user