Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: finish initial rewrite of backend using hir2
This commit builds on the last one with the remaining changes to get all of the necessary pieces of the codegen backend rebuilt on top of the HIR2 infrastructure. NOTE: The new backend changes are untested, that will follow in a subsequent commit that cleans things up a bit more, and validates that the new codegen stage components work as expected. There are many changes here, but in summary: * The old IR maintained a duplicate representation of MASM for historical reasons. We're at a stage where that is no longer particularly useful, so we are now lowering directly to the AST nodes provided in miden-assembly. * Original op/inst emitter code remains largely unchanged * Original operand stack management code and optimization remains unchanged * Linker is now part of the backend, and handles examining a Component to be compiled in order to extract data segments and global variables for layout in memory. This information is provided to the instruction lowering code. * Conversion pass infra is replaced with a ToMasmComponent trait, implemented for Component (possibly will implement it for Module, to support classic Wasm inputs). * Old FunctionEmitter is removed. * BlockEmitter remains, but acts primarily as a driver for visiting operations in the entry block of a Function operation, and invoking the instruction lowering trait. It is assumed that by the time we reach the backend, only structured control flow remains. * Instruction lowering is facilitated by an HirLowering trait, which is implemented for all of the operations in the 'hir' dialect. These are given the current BlockEmitter and other important context, and use the emitter to handle any lowering details. There are a variety of other changes as well, mostly things that fell out of this work, e.g. symbol management has been reworked in HIR2 to better reflect the Wasm Component Model, and recent packaging efforts. There are various TODOs noted in the code, but the main things remaining for this to be ready for use are: * Figure out if any of the old tests from the codegen crate are still useful, as well as the old MasmCompiler type, and if so, port them over and validate they are still good * Revisit spills analysis/transform once we have useful tests to work with. These passes were hard to port cleanly to the new IR and dataflow analysis framework, so need to be revalidated. * Rework compiler stage(s) in frontend * Lower from Wasm to HIR2 * Implement CFG-to-SCF pass and ensure it is run on initial IR to recover structured control flow needed for codegen. * Remove old IR crates that are deprecated, rename HIR2 crates to remove references to HIR2.
- Loading branch information