bytecodealliance / bytecodealliance/wasmtime
Add volatile flag to MemFlags
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 121
Description
Add Volatile flag to MemFlags.
#### Benefit
When some optimization pass knows about load/store type (is it volatile or not?) then it's possible to do a lot of optimizations. One of it is memory to register promotion. I tried to implement mem2reg pass there [cranelift-mem2reg](https://github.com/playXE/cranelift-mem2reg/) and this pass works but in some cases it fails e.g this simple C code:
```c
// compiled with rcc
typedef struct Foo {
int x;
int y;
} Foo;
int main() {
Foo foo;
foo.y = 42;
}
```
```
Message: definition error: Compilation error: Verifier errors
note: while compiling function u0:0() -> i32 system_v {
ss0 = explicit_slot 8
block0:
v1 = iconst.i64 4
v2 = iadd.i64 v0, v1
v3 = iconst.i32 42
store v3, v2
v4 = iconst.i32 0
return v4
}
```
All loads and stores might be marked as volatile and mem2reg will not optimize `struct Foo` into registers.
Volatile flag also can help in SRoA when it's possible to replace allocation on stack with single 32 or 64 bit register.
#### Implementation
Just add additional enum case in `codegen/ir/memflags.rs` and add 3 simple functions to MemFlags: `volatile() -> Self,is_volatile() -> bool, set_volatile(&mut self)`.
#### Alternatives
I do not see any alternatives.
UPD: This might be useful for this issue: [Support volatile store/loads](https://github.com/bytecodealliance/wasmtime/issues/1076)
Contributor guide
Assessment
This issue has not been assessed yet.