Description
Wasmi's translator uses a simple linear register allocator.
This is particularly easy since Wasmi provides up to 2^15 registers per function, so register spilling isn't even considered. However, this register allocation still is somewhat complicated and costly. In the last audit it was understood as one of the more complex components within the Wasmi codebase.
Furthermore in order to make it work correctly it uses a weird multi-stash
data structure and additionally to make it work in linear time we also had to be creative with local variable preservation.
At the cost of producing minimally worse Wasmi IR we can simplify all of this entirely.
The idea is to simply use Wasm's stack. This will certainly produce more Wasmi IR instructions and may lead to worse register allocation schemes, but overall this is probably still worth to implement since it will be so much simpler. Another very beneficial side effect is that function calls will also become way simpler since this allows that we can then just use the default Wasm stack and its properties respecting calls. With Wasmi's current IR we have to work with function frames whereas with the stack oriented approach we can work on stack regions again as we did with the old stack based Wasmi which was naturally faster for function calls.
To avoid confusion: this does not mean that Wasmi goes back to being a stack-based interpreter. It will still use so-called registers, altough a better name for Reg
is probably Stack
then, since they will be referring to stack slots (which funnily they always did).