Commit 823406d
feat: add optimizer infrastructure and post-lowering structural passes
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>1 parent 136373b commit 823406d
6 files changed
Lines changed: 1786 additions & 25 deletions
File tree
- crates/herkos-core/src/optimizer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 12 | | |
30 | 13 | | |
31 | 14 | | |
| |||
61 | 44 | | |
62 | 45 | | |
63 | 46 | | |
64 | | - | |
| 47 | + | |
65 | 48 | | |
66 | 49 | | |
67 | 50 | | |
| |||
0 commit comments