Skip to content

Replacing Stack IR with Poppy IR #3059

@tlively

Description

@tlively

The latest code pushed to my stackify branch (diff) implements a new form of IR ("Poppy IR") that directly represents the stack machine structure of WebAssembly and is meant to replace Stack IR for performing final stack machine optimizations before binary writing. This new system is motivated primarily by our need to emit efficient multivalue blocks and functions, which Stack IR cannot optimize.

The code I've written so far is sufficient to demonstrate that Poppy IR works and can generate smaller code with simpler passes than the current Stack IR pipeline, but it is very much a prototype. There are no tests, the validator is incomplete, the unstackify pass is buggy, and the pass runner does not prevent users from running passes on the incorrect form of IR. That being said, most of what has been written has been extensively fuzzed (although is not bug-free) and I expect that most of the code will eventually be able to land with minimal modifications. You can try it yourself by building my branch and running with BINARYEN_USE_STACKIFY=1 in your environment.

Here is a potential roadmap of discrete patches I plan to land to get Poppy IR upstream. I welcome discussion of how to better split up the work. As I land patches, I will check them off here and add links to the respective PRs.

  • Stack utils for analyzing Poppy IR with C++ API tests (Stack utils #3083)
  • Parsing of wast files directly to Poppy IR and validation (Poppy IR wast parsing and validation #3105)
  • Stackification with tests and fuzzing (Poppify pass #3541)
  • Unstackification with tests and fuzzing
  • Poppy IR optimization passes with tests and fuzzing
  • Pass runner integration and Stack IR replacement via environment variable
  • Remove Stack IR

Follow up work to immediately take advantage of Stack IR:

  • Move Binaryen to C++17 (prerequisite)
  • Replace wast parser with wasp

Follow up related investigative work:

  • Investigate removing unreachable control flow from Binaryen entirely.
  • Look at why Binaryen's DCE pass is so complicated and whether it could be shared with Poppy IR

Additional cleanup work to be done if at any point it would be helpful for achieving the other goals:

  • Move various test suites to a lit + FileCheck test framework

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions