Add TypeAliasPass optimization pass#473
Open
daniellerozenblit wants to merge 6 commits intofacebook:devfrom
Open
Add TypeAliasPass optimization pass#473daniellerozenblit wants to merge 6 commits intofacebook:devfrom
daniellerozenblit wants to merge 6 commits intofacebook:devfrom
Conversation
Summary: This diff splits `CompilerTest.cpp` into separate test files per compiler stage. This makes it easier to test the functionality of each component in isolation; e.g making sure the parser produces the expected AST before optimizations. Differential Revision: D95084293
Summary: # Stack The goal of this stack is to add support for variable assignments and assume operations to SDDL2. # Diff This diff implements variable assignment and reference support in the code generator. This enables SDDL2 programs to use global variables for parameterizing field sizes and reusing type definitions. - Implemented `Op::ASSIGN` codegen: evaluates the RHS expression, allocates a VM register via `getOrAssignRegister()`, and emits `var.store`. - Implemented `ASTVar` reference codegen: looks up the variable's register and emits `var.load`. If this is the last reference to a particular variable, returns the register to the free pool. - Added a register allocator (`var_registry_`, `free_registers_`, `next_register_`) that reuses freed registers and enforces the `SDDL2_VAR_REGISTER_COUNT` (256) limit at compile time. Differential Revision: D94947414
Summary: # Stack The goal of this stack is to add support for variable assignments and assume operations to SDDL2. # Diff This diff adds a `MEMBER` op to the SDDL grammar, which can be used to access fields of consumed recrds. This operator (`.`) was already supported in the syntax. Differential Revision: D95396139
Summary: # Stack The goal of this stack is to add support for variable assignments and assume operations to SDDL2. # Diff This diff handles the `MEMBER` op in the dead var optimizer. Differential Revision: D95396507
Summary: # Stack The goal of this stack is to add support for variable assignments and assume operations to SDDL2. # Diff The diff updates the semantic analyzer to support the `MEMBER` operation. This mainly validates that operands are semantically correct (e.g., LHS is a consumed record, RHS is a field). Differential Revision: D95430690
Summary: Add a new optimization pass that resolves type aliases in the AST before codegen runs. When the pass encounters `ASSIGN(MyType, Int32LE)` where the RHS is a field type (builtin, bytes, array, or record), it records the alias. Later, when it encounters a variable reference to that alias, it substitutes the resolved type inline. This runs between ConstFoldPass (which may simplify expressions like array lengths) and DeadVarPass (which removes the now-dead ASSIGN definitions whose variables are no longer referenced). Key behaviors: - Simple aliases: `MyType = Int32LE` → `: MyType` resolves to Int32LE - Chained aliases: `A = Int32LE`, `B = A` → `: B` resolves transitively (because A was already resolved when B's RHS was optimized) - Record field scoping: type aliases inside record fields are scoped to the record body (save/restore pattern matching ConstFoldPass) Differential Revision: D95455849
|
@daniellerozenblit has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95455849. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Add a new optimization pass that resolves type aliases in the AST before
codegen runs. When the pass encounters
ASSIGN(MyType, Int32LE)wherethe RHS is a field type (builtin, bytes, array, or record), it records
the alias. Later, when it encounters a variable reference to that alias,
it substitutes the resolved type inline.
This runs between ConstFoldPass (which may simplify expressions like
array lengths) and DeadVarPass (which removes the now-dead ASSIGN
definitions whose variables are no longer referenced).
Key behaviors:
MyType = Int32LE→: MyTyperesolves to Int32LEA = Int32LE,B = A→: Bresolves transitively(because A was already resolved when B's RHS was optimized)
to the record body (save/restore pattern matching ConstFoldPass)
Differential Revision: D95455849