bytecodealliance / bytecodealliance/wasmtime

cranelift: Allow allocating heaps in clif filetests

Open
#7,215 2 comments 1 reaction 0 assignees View on GitHub
cranelift
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

👋 Hey,

This was something that @jameysharp brought up during today's cranelift meeting.

#### Feature

We could add support to our runtests to allocate a heap memory region and pass it to the function under test.

#### Benefit

This allows us to do a few things:

* We can start testing load+op fusion for vector instructions in the cranelift fuzzer for x64. We can't do this currently because they require the address to be aligned to 16bytes, and we can't guarantee that yet for stack addresses.

* We can test our alias analysis memflags in the fuzzer using this. We could for example map different heaps to a different alias analysis bits, and ensure that our optimizations work.

* We can also fuzz global values better. Since the heap is passed in via an argument, we can mark that argument as `vmctx` and start issuing global value loads based on that.

#### Implementation

We used to have something similar to this in https://github.com/bytecodealliance/wasmtime/pull/3302 that was then removed in https://github.com/bytecodealliance/wasmtime/pull/5386

We had an annotation like `; heap: static, size=0x1000, ptr=vmctx+0, bound=vmctx+8` which would pass the address of the heap via the `vmctx` parameter.

That used to involve some special handling for `vmctx` parameters that I think is incompatible with what we do today (don't quote me on this).

But we could do something similar like:

```
function %test(i64, i8) -> i64 {
...
}
; heap: size=16, align=8
; run: %test(, 10) == 10
```

And the `` annotation would be resolved with the address of the heap when calling the test.

#### Alternatives

An alternative to testing load fusion for vectors, is to add stack alignment flags to our stack slots. But doing the alias analysis bits is slightly harder although there are probably workarounds there too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.