simplified
Pass Manager
Turn individual optimizations on and off and watch what each one does — including the two that refuse to fire, because firing would change what the program means.
simplifiedReal passes on real SSA
Every pass below is implemented in src/compilers/sim/optimize.ts and runs on the SSA form of the program you type. The pass manager iterates to a fixed point, because passes expose work for each other.
AtlasLang source
Examples
✓ No diagnostics. The program lexes, parses and type-checks.
Passes
✓ observable behavior unchanged
Unoptimized output ["6"] · optimized ["6"]. This is the property that makes an optimization an optimization, and it is asserted for every example in scripts/compilers-sim.test.ts.
7 → 3 instructions · 6 pass runs over 2 iterations
Before — SSA as constructed
fn main(): void {
b0: ; entry
%0 = int 2 * 3
%2 = int %0 + 0
branch false ? b1 : b2
b1: ; if.then preds=b0
print 999
jump b2
b2: ; if.join preds=b0,b1
print %2
ret
}After — the enabled passes, run to a fixed point
fn main(): void {
b0: ; entry
jump b2
b2: ; if.join preds=b0
print 6
ret
}Show all 6 pass runs in order
1. constant-folding — 1 change
fn main(): void {
b0: ; entry
%0 = const 6
%2 = int %0 + 0
branch false ? b1 : b2
b1: ; if.then preds=b0
print 999
jump b2
b2: ; if.join preds=b0,b1
print %2
ret
}2. strength-reduction — 1 change
fn main(): void {
b0: ; entry
%0 = const 6
branch false ? b1 : b2
b1: ; if.then preds=b0
print 999
jump b2
b2: ; if.join preds=b0,b1
print %0
ret
}3. constant-propagation — 1 change
fn main(): void {
b0: ; entry
%0 = const 6
branch false ? b1 : b2
b1: ; if.then preds=b0
print 999
jump b2
b2: ; if.join preds=b0,b1
print 6
ret
}4. branch-simplification — 1 change
fn main(): void {
b0: ; entry
%0 = const 6
jump b2
b1: ; if.then
print 999
jump b2
b2: ; if.join preds=b0,b1
print 6
ret
}5. unreachable-block-elimination — 1 change
fn main(): void {
b0: ; entry
%0 = const 6
jump b2
b2: ; if.join preds=b0
print 6
ret
}6. dead-code-elimination — 1 change
fn main(): void {
b0: ; entry
jump b2
b2: ; if.join preds=b0
print 6
ret
}