Remove heaps from core Cranelift, push them into cranelift-wasm (#5386)

* cranelift-wasm: translate Wasm loads into lower-level CLIF operations

Rather than using `heap_{load,store,addr}`.

* cranelift: Remove the `heap_{addr,load,store}` instructions

These are now legalized in the `cranelift-wasm` frontend.

* cranelift: Remove the `ir::Heap` entity from CLIF

* Port basic memory operation tests to .wat filetests

* Remove test for verifying CLIF heaps

* Remove `heap_addr` from replace_branching_instructions_and_cfg_predecessors.clif test

* Remove `heap_addr` from readonly.clif test

* Remove `heap_addr` from `table_addr.clif` test

* Remove `heap_addr` from the simd-fvpromote_low.clif test

* Remove `heap_addr` from simd-fvdemote.clif test

* Remove `heap_addr` from the load-op-store.clif test

* Remove the CLIF heap runtest

* Remove `heap_addr` from the global_value.clif test

* Remove `heap_addr` from fpromote.clif runtests

* Remove `heap_addr` from fdemote.clif runtests

* Remove `heap_addr` from memory.clif parser test

* Remove `heap_addr` from reject_load_readonly.clif test

* Remove `heap_addr` from reject_load_notrap.clif test

* Remove `heap_addr` from load_readonly_notrap.clif test

* Remove `static-heap-without-guard-pages.clif` test

Will be subsumed when we port `make-heap-load-store-tests.sh` to generating
`.wat` tests.

* Remove `static-heap-with-guard-pages.clif` test

Will be subsumed when we port `make-heap-load-store-tests.sh` over to `.wat`
tests.

* Remove more heap tests

These will be subsumed by porting `make-heap-load-store-tests.sh` over to `.wat`
tests.

* Remove `heap_addr` from `simple-alias.clif` test

* Remove `heap_addr` from partial-redundancy.clif test

* Remove `heap_addr` from multiple-blocks.clif test

* Remove `heap_addr` from fence.clif test

* Remove `heap_addr` from extends.clif test

* Remove runtests that rely on heaps

Heaps are not a thing in CLIF or the interpreter anymore

* Add generated load/store `.wat` tests

* Enable memory-related wasm features in `.wat` tests

* Remove CLIF heap from fcmp-mem-bug.clif test

* Add a mode for compiling `.wat` all the way to assembly in filetests

* Also generate WAT to assembly tests in `make-load-store-tests.sh`

* cargo fmt

* Reinstate `f{de,pro}mote.clif` tests without the heap bits

* Remove undefined doc link

* Remove outdated SVG and dot file from docs

* Add docs about `None` returns for base address computation helpers

* Factor out `env.heap_access_spectre_mitigation()` to a local

* Expand docs for `FuncEnvironment::heaps` trait method

* Restore f{de,pro}mote+load clif runtests with stack memory
This commit is contained in:
Nick Fitzgerald
2022-12-14 16:26:45 -08:00
committed by GitHub
parent e03d65cca7
commit c0b587ac5f
198 changed files with 2494 additions and 4232 deletions

View File

@@ -6,7 +6,6 @@ use crate::state::{MemoryError, State};
use crate::value::{Value, ValueConversionKind, ValueError, ValueResult};
use cranelift_codegen::data_value::DataValue;
use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
use cranelift_codegen::ir::immediates::HeapImmData;
use cranelift_codegen::ir::{
types, AbiParam, Block, ExternalName, FuncRef, Function, InstructionData, Opcode, TrapCode,
Type, Value as ValueRef,
@@ -485,89 +484,6 @@ where
}
Opcode::SymbolValue => unimplemented!("SymbolValue"),
Opcode::TlsValue => unimplemented!("TlsValue"),
Opcode::HeapLoad => {
if let InstructionData::HeapLoad { heap_imm, arg, .. } = inst {
let HeapImmData {
flags,
heap,
offset,
} = state.get_current_function().dfg.heap_imms[heap_imm];
let offset = i128::from(u32::from(offset));
let addr_ty = state.get_current_function().dfg.value_type(arg);
let index = state.get_value(arg).unwrap().into_int().unwrap();
let load_ty = inst_context.controlling_type().unwrap();
let load_size = i128::from(load_ty.bytes());
assign_or_memtrap(AddressSize::try_from(addr_ty).and_then(|addr_size| {
let heap_address = index.saturating_add(offset).saturating_add(load_size);
let heap_address =
u64::try_from(heap_address).map_err(|e| MemoryError::OutOfBoundsLoad {
addr: Address::try_from(0).unwrap(),
load_size: load_size as usize,
})?;
let address = state.heap_address(addr_size, heap, heap_address)?;
state.checked_load(address, load_ty)
}))
} else {
unreachable!()
}
}
Opcode::HeapStore => {
if let InstructionData::HeapStore { heap_imm, args, .. } = inst {
let HeapImmData {
flags,
heap,
offset,
} = state.get_current_function().dfg.heap_imms[heap_imm];
let offset = i128::from(u32::from(offset));
let addr_ty = state.get_current_function().dfg.value_type(args[0]);
let index = state.get_value(args[0]).unwrap().into_int().unwrap();
let value = state.get_value(args[1]).unwrap();
let store_ty = state.get_current_function().dfg.value_type(args[1]);
let store_size = i128::from(store_ty.bytes());
continue_or_memtrap(AddressSize::try_from(addr_ty).and_then(|addr_size| {
let heap_address = index.saturating_add(offset).saturating_add(store_size);
let heap_address =
u64::try_from(heap_address).map_err(|e| MemoryError::OutOfBoundsStore {
addr: Address::try_from(0).unwrap(),
store_size: store_size as usize,
})?;
let address = state.heap_address(addr_size, heap, heap_address)?;
state.checked_store(address, value)
}))
} else {
unreachable!()
}
}
Opcode::HeapAddr => {
if let InstructionData::HeapAddr {
heap,
offset: imm_offset,
size,
..
} = inst
{
let addr_ty = inst_context.controlling_type().unwrap();
let dyn_offset = arg(0)?.into_int()? as u64;
assign_or_memtrap({
AddressSize::try_from(addr_ty).and_then(|addr_size| {
// Attempt to build an address at the maximum possible offset
// for this load. If address generation fails we know it's out of bounds.
let bound_offset =
(dyn_offset + u64::from(u32::from(imm_offset)) + u64::from(size))
.saturating_sub(1);
state.heap_address(addr_size, heap, bound_offset)?;
// Build the actual address
let mut addr = state.heap_address(addr_size, heap, dyn_offset)?;
addr.offset += u64::from(u32::from(imm_offset));
let dv = DataValue::try_from(addr)?;
Ok(dv.into())
})
})
} else {
unreachable!()
}
}
Opcode::GetPinnedReg => assign(state.get_pinned_reg()),
Opcode::SetPinnedReg => {
let arg0 = arg(0)?;