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:
@@ -4,17 +4,14 @@
|
||||
//! using [RunCommand](cranelift_reader::RunCommand)s.
|
||||
|
||||
use crate::runone::FileUpdate;
|
||||
use crate::runtest_environment::RuntestEnvironment;
|
||||
use crate::subtest::SubTest;
|
||||
use anyhow::{anyhow, Context};
|
||||
use cranelift_codegen::data_value::DataValue;
|
||||
use cranelift_codegen::ir::types::I64;
|
||||
use anyhow::Context;
|
||||
use cranelift_codegen::ir::Function;
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::settings::Flags;
|
||||
use cranelift_codegen::{self, ir};
|
||||
use cranelift_interpreter::environment::FunctionStore;
|
||||
use cranelift_interpreter::interpreter::{HeapInit, Interpreter, InterpreterState};
|
||||
use cranelift_interpreter::interpreter::{Interpreter, InterpreterState};
|
||||
use cranelift_interpreter::step::ControlFlow;
|
||||
use cranelift_reader::{parse_run_command, Details, TestCommand, TestFile};
|
||||
use log::{info, trace};
|
||||
@@ -62,10 +59,7 @@ impl SubTest for TestInterpret {
|
||||
for (func, details) in &testfile.functions {
|
||||
info!("Test: {}({}) interpreter", self.name(), func.name);
|
||||
|
||||
let test_env = RuntestEnvironment::parse(&details.comments[..])?;
|
||||
test_env.validate_signature(&func).map_err(|s| anyhow!(s))?;
|
||||
|
||||
run_test(&test_env, &func_store, func, details).context(self.name())?;
|
||||
run_test(&func_store, func, details).context(self.name())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -80,12 +74,7 @@ impl SubTest for TestInterpret {
|
||||
}
|
||||
}
|
||||
|
||||
fn run_test(
|
||||
test_env: &RuntestEnvironment,
|
||||
func_store: &FunctionStore,
|
||||
func: &Function,
|
||||
details: &Details,
|
||||
) -> anyhow::Result<()> {
|
||||
fn run_test(func_store: &FunctionStore, func: &Function, details: &Details) -> anyhow::Result<()> {
|
||||
for comment in details.comments.iter() {
|
||||
if let Some(command) = parse_run_command(comment.text, &func.signature)? {
|
||||
trace!("Parsed run command: {}", command);
|
||||
@@ -94,14 +83,9 @@ fn run_test(
|
||||
.run(|func_name, run_args| {
|
||||
// Rebuild the interpreter state on every run to ensure that we don't accidentally depend on
|
||||
// some leftover state
|
||||
let mut state =
|
||||
InterpreterState::default().with_function_store(func_store.clone());
|
||||
let state = InterpreterState::default().with_function_store(func_store.clone());
|
||||
|
||||
let mut args = Vec::with_capacity(run_args.len());
|
||||
if test_env.is_active() {
|
||||
let vmctx_addr = register_heaps(&mut state, test_env);
|
||||
args.push(vmctx_addr);
|
||||
}
|
||||
args.extend_from_slice(run_args);
|
||||
|
||||
// Because we have stored function names with a leading %, we need to re-add it.
|
||||
@@ -119,34 +103,3 @@ fn run_test(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Build a VMContext struct with the layout described in docs/testing.md.
|
||||
pub fn register_heaps<'a>(
|
||||
state: &mut InterpreterState<'a>,
|
||||
test_env: &RuntestEnvironment,
|
||||
) -> DataValue {
|
||||
let mem = test_env.allocate_memory();
|
||||
let vmctx_struct = mem
|
||||
.into_iter()
|
||||
// This memory layout (a contiguous list of base + bound ptrs)
|
||||
// is enforced by the RuntestEnvironment when parsing the heap
|
||||
// directives. So we are safe to replicate that here.
|
||||
.flat_map(|mem| {
|
||||
let heap_len = mem.len() as u64;
|
||||
let heap = state.register_heap(HeapInit::FromBacking(mem));
|
||||
[
|
||||
state.get_heap_address(I64, heap, 0).unwrap(),
|
||||
state.get_heap_address(I64, heap, heap_len).unwrap(),
|
||||
]
|
||||
})
|
||||
.map(|addr| {
|
||||
let mut mem = [0u8; 8];
|
||||
addr.write_to_slice(&mut mem[..]);
|
||||
mem
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
let vmctx_heap = state.register_heap(HeapInit::FromBacking(vmctx_struct));
|
||||
state.get_heap_address(I64, vmctx_heap, 0).unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user