WebAssembly
Wikipedia
SSA2
LLVM IR
FireFox
JavaScript
︎I
Wasm
No matching tags
No matching tags
No matching tags
Wasmtime
No matching tags
This means that you have overhead associated with compilation - knowing the liveness of variables is extremely important for generating efficient assembly, but instead of the liveness being calculated when creating the IR and stored as a part of it you have to recalculate this data every time.If the IR is entirely in-memory this isn’t so bad, especially if your code is in SSA form, but it means that you have to do extra work for the same quality of code and it means that a streaming compiler (like FireFox’s Wasm baseline compiler) is unable to produce good code.You can, of course, add liveness analysis metadata to the machine, but that liveness analysis is only useful if your code is in SSA form - if it’s not SSA form then the liveness is extremely coarse-grained.Well, that’s where WebAssembly comes in. Even a function that never uses any of its arguments still can’t reuse the space used by those arguments for anything else.This essentially makes WebAssembly a register machine without liveness analysis, but not only that, it’s a register machine that isn’t even in SSA form - both of the tools at our disposal to do optimisation are unavailable. It wasn’t clear that having locals would be problematic - after all, C gets by just fine using local variables that the compiler constructs the SSA graph for.It’s only by working on a streaming WebAssembly compiler for integration with Wasmtime that I realised these issues, as well as more issues that I’ll get to in later articles in this series. Although it has problems, it’s incredible how much the WebAssembly working group got right considering it was such relatively unknown territory at the time of the specification’s writing.So currently locals represent both function arguments and local variables. Again, the compilers almost always have this information, and removing locals makes accessing undefined memory statically impossible.Join me next time where I tackle WebAssembly’s problematic control flow.Yes, I know that many register machines such as x86 output into one of the input registers, but that’s still conceptually the same as taking separate arguments for input and output, just more limited.
As said here by