asterius
asterius copied to clipboard
Avoid using global `__asterius_pc` in the Cmm trampoline
Is your feature request related to a problem? Please describe. Our current solution to tail calls in Cmm can be summarized as:
- All Cmm functions have
[] -> []signature, and Cmm calls becomereturn_call/return_call_indirectin wasm at compile time - When the tail calls feature flag is on,
return_call/return_call_indirectare translated per se - When the tail calls feature flag is off, we store the call destination address in
__asterius_pcand return to the outerstgRuntrampoline loop.
It is possible to avoid __asterius_pc usage and eliminate a pair of memory load/store in each Cmm function invocation. This may improve Cmm code runtime performance, and we shall investigate this possibility after #640 lands.
Describe the solution you'd like
- [ ] Each Cmm function should now have
[] -> i64signature, returning the call destination address immediately. - [ ] The
stgRuntrampoline loop should use a wasm local to replace__asterius_pc. - [ ] Reserve a special wasm local for each Cmm function. Each Cmm function's code becomes a block containing two expressions: the original CFG, which stores the destination into that local, and a
GetLocalwhich fetches that local as the function return value. This works around a restriction about the relooper: each basic block must have the[] -> []stack type, not consuming or producing anything on the wasm value stack.