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:
@@ -1,60 +1,18 @@
|
||||
use anyhow::anyhow;
|
||||
use cranelift_codegen::ir::{ArgumentPurpose, Function};
|
||||
use cranelift_reader::parse_heap_command;
|
||||
use cranelift_reader::{Comment, HeapCommand};
|
||||
use cranelift_reader::Comment;
|
||||
|
||||
/// Stores info about the expected environment for a test function.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RuntestEnvironment {
|
||||
pub heaps: Vec<HeapCommand>,
|
||||
}
|
||||
pub struct RuntestEnvironment {}
|
||||
|
||||
impl RuntestEnvironment {
|
||||
/// Parse the environment from a set of comments
|
||||
pub fn parse(comments: &[Comment]) -> anyhow::Result<Self> {
|
||||
let mut env = RuntestEnvironment { heaps: Vec::new() };
|
||||
|
||||
for comment in comments.iter() {
|
||||
if let Some(heap_command) = parse_heap_command(comment.text)? {
|
||||
let heap_index = env.heaps.len() as u64;
|
||||
let expected_ptr = heap_index * 16;
|
||||
if Some(expected_ptr) != heap_command.ptr_offset.map(|p| p.into()) {
|
||||
return Err(anyhow!(
|
||||
"Invalid ptr offset, expected vmctx+{}",
|
||||
expected_ptr
|
||||
));
|
||||
}
|
||||
|
||||
let expected_bound = (heap_index * 16) + 8;
|
||||
if Some(expected_bound) != heap_command.bound_offset.map(|p| p.into()) {
|
||||
return Err(anyhow!(
|
||||
"Invalid bound offset, expected vmctx+{}",
|
||||
expected_bound
|
||||
));
|
||||
}
|
||||
|
||||
env.heaps.push(heap_command);
|
||||
};
|
||||
}
|
||||
|
||||
let mut env = RuntestEnvironment {};
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
pub fn is_active(&self) -> bool {
|
||||
!self.heaps.is_empty()
|
||||
}
|
||||
|
||||
/// Allocates memory for heaps
|
||||
pub fn allocate_memory(&self) -> Vec<HeapMemory> {
|
||||
self.heaps
|
||||
.iter()
|
||||
.map(|cmd| {
|
||||
let size: u64 = cmd.size.into();
|
||||
vec![0u8; size as usize]
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Validates the signature of a [Function] ensuring that if this environment is active, the
|
||||
/// function has a `vmctx` argument
|
||||
pub fn validate_signature(&self, func: &Function) -> Result<(), String> {
|
||||
@@ -76,5 +34,3 @@ impl RuntestEnvironment {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type HeapMemory = Vec<u8>;
|
||||
|
||||
Reference in New Issue
Block a user