wasm2lua icon indicating copy to clipboard operation
wasm2lua copied to clipboard

Graph IR

Open MDFL64 opened this issue 5 years ago • 2 comments

Began work on an IR today. It is locked behind a compiler flag (--useGraphIR) to facilitate easy testing + continued development alongside the main branch. It currently does not work at all.

  • [x] Convert WASM control flow to graph IR.
  • [x] Add all instructions to IR (No good dataflow yet, just for testing control flow).
  • [ ] Test basic control flow. (Just link blocks together with gotos for now)
  • [ ] Local dataflow: Each control block tracks which locals it uses, and the values locals are bound to when they terminate.
  • [ ] Better control flow code generation.
  • [ ] Proper bounding of variable lifetimes.
  • [ ] Handling for very large jumps.
  • [ ] Proper handling of setjmp/longjmp (setjmp should split control blocks).

Other thoughts:

  • Planning to deal with block results by creating an extra pseudo-local and throwing it in block outputs.
  • Track nesting to avoid the parser throwing a fit. Might be able to decompose expressions that are too large by creating a small scope with temp vars.
  • Track estimate of LJ opcodes to avoid large jumps.
  • Might be able to convert some loops into lua for loops.
  • Maybe convert some blocks to functions? I'm not sure how the JIT feels about lambdas, will need to test.

MDFL64 avatar Jun 16 '19 06:06 MDFL64

Progress is being made on adding instructions to IR. Yet to do:

  • ~~Indirect calls.~~
  • ~~All memory reads/writes.~~
  • ~~Global reads.~~
  • ~~All conversions.~~
  • ~~Select.~~
  • ~~grow_memory / current_memory~~
  • ~~"bitwise" float ops (neg, abs, copysign)~~
  • ~~(Temp) local init~~

Some minor TODOS:

  • Write barriers are broken trash.
  • I started on a function for stripping parens from statements that don't need them (function args and the like) but never finished it.

MDFL64 avatar Jun 24 '19 05:06 MDFL64

Todo: Bools should be preserved for select opcode.

MDFL64 avatar Jun 29 '19 20:06 MDFL64