feat: add optimizer infrastructure and post-lowering structural passes#29
Merged
feat: add optimizer infrastructure and post-lowering structural passes#29
Conversation
Add shared optimizer utilities and four post-lowering optimization passes: **Shared utilities** (optimizer/utils.rs): - terminator_successors: Get successor blocks for control flow terminators - build_predecessors: Build predecessor map for dominance analysis - for_each_use/for_each_use_terminator: Iterate over variable uses in instructions - instr_dest: Get destination variable of instructions - set_instr_dest: Redirect instruction output - replace_uses_of: Variable substitution in instructions - count_uses_of: Count how many times a variable is used - is_side_effect_free: Classify instructions **Post-lowering passes** (run after phi node lowering): - empty_blocks: Remove passthrough blocks (only Jump, no instructions) - merge_blocks: Merge single-predecessor blocks with their predecessors - dead_instrs: Remove unused variable definitions - dead_blocks: (refactored) Use shared utils Passes run in multiple iterations to handle cascading opportunities from each pass (e.g., dead_instrs can create empty blocks). The optimize_lowered_ir function coordinates these passes on phi-free IR. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This was referenced Mar 23, 2026
added 2 commits
March 23, 2026 09:45
…r-d/optimizer-infrastructure
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
Adds shared optimizer utilities and four post-lowering optimization passes (running after phi node lowering):
optimizer/utils.rs): Basic IR traversal, variable use tracking, instruction classificationHow it works
Structural passes run in multiple iterations (typically 2) in
optimize_lowered_ir()to handle cascading opportunities:dead_instrsmay remove assignments, leaving some blocks emptyempty_blocksandmerge_blockseliminate now-empty/redundant blocksKey design notes
MemoryFill,MemoryInit,DataDrop) are properly handledTest coverage
All unit tests pass for:
🤖 Generated with Claude Code