Clang ARC Lessons: AIMS Optimization Enhancements
6 sections
Overview
Adopt battle-tested ARC optimization patterns from Clang/LLVM and Swift into Ori's AIMS pipeline: effect-aware coalescing barriers, compile-time statistics, physical-refcount-based nested pair elimination, late COW compound contraction, and PRE-style global RC code motion. AIMS is architecturally stronger than Clang's per-pointer state machine — these enhancements add the "outer ring" of legality/profitability machinery around the existing semantic core.
Planned
6 sections
Compile-Time ARC Statistics
Every AIMS pipeline pass reports before/after RC operation counts via tracing, enabling measurable optimization development
Effect-Aware Coalescing Barriers
Coalescing barriers use MemoryContract to selectively flush only variables whose callee params are Owned+!Dead, reducing unnecessary barrier flushes by 40%+
KnownSafe Nested Pair Elimination
Post-emission analysis proves physical refcount positivity within retain/release brackets, eliminating redundant inner RC pairs regardless of intervening side effects
Late COW Compound Contraction
Post-emission contraction pass fuses IsShared+branch+clone+mutate sequences into compound COW operations, reducing runtime overhead and enabling backend-level optimization
PRE-Style Global RC Code Motion
Bidirectional dataflow analysis moves RcInc/RcDec across basic blocks to optimal placement points, with path-counting CFG hazard detection preventing unsafe motion through loops
Verification
Comprehensive test matrix, behavioral equivalence verification, and code journey proving all ARC optimizations are correct across the full type × pattern × CFG matrix