runtime/vm/compiler/compiler_pass.cc and executed in a specific order for maximum effectiveness.
Compilation Pipeline
The main compilation pipeline (RunPipeline) executes passes in the following order:
Phase 1: SSA Construction
ComputeSSA
ComputeSSA
compiler_pass.cc:368Transform the flow graph into Static Single Assignment (SSA) form.Phase 2: Type Propagation and Specialization
TypePropagation
TypePropagation
compiler_pass.cc:386Propagate type information through the flow graph.- Infer precise types for values
- Enable type-based optimizations
- Support better code generation
ApplyClassIds
ApplyClassIds
compiler_pass.cc:389Apply class ID information from type propagation.ApplyICData
ApplyICData
compiler_pass.cc:373Apply Inline Cache data from runtime profiling.Phase 3: Inlining
SetOuterInliningId
SetOuterInliningId
compiler_pass.cc:377Set up inlining metadata before inlining begins.Inlining
Inlining
compiler_pass.cc:381
Critical: Yes - major optimizationInline function calls to eliminate call overhead and enable further optimizations.- Eliminates call overhead
- Exposes optimization opportunities
- Improves constant propagation
- Enables better register allocation
Phase 4: Simplification and Canonicalization
Canonicalize
Canonicalize
compiler_pass.cc:397
Repeating: YesSimplify and normalize IL instructions.- Strength reduction (e.g.,
x * 2→x << 1) - Algebraic simplification (e.g.,
x + 0→x) - Instruction normalization
TryOptimizePatterns
TryOptimizePatterns
compiler_pass.cc:375Pattern-based optimizations before representation selection.(a << b) & cbit manipulation- Instruction merging opportunities
BranchSimplify
BranchSimplify
compiler_pass.cc:404Simplify branch instructions.- Remove redundant branches
- Merge blocks
- Eliminate empty blocks
IfConvert
IfConvert
compiler_pass.cc:406Convert simple if-then-else patterns to conditional moves.Phase 5: Constant Propagation
ConstantPropagation
ConstantPropagation
compiler_pass.cc:408
Repeating: Yes (up to 2 rounds)Propagate constant values and evaluate constant expressions.- Constant folding
- Dead code elimination
- Unreachable code removal
OptimizeBranches
OptimizeBranches
compiler_pass.cc:466Optimize branches using constant propagation results.Phase 6: Integer Optimizations
OptimisticallySpecializeSmiPhis
OptimisticallySpecializeSmiPhis
compiler_pass.cc:415Specialize loop phi nodes to Smi when profitable.Phase 7: Representation Selection
SelectRepresentations
SelectRepresentations
compiler_pass.cc:420
Critical: Yes - affects performance significantlyChoose optimal representations for values (boxed vs unboxed).- Unbox doubles for arithmetic
- Unbox integers where profitable
- Minimize boxing/unboxing overhead
SelectRepresentations_Final
SelectRepresentations_Final
compiler_pass.cc:427Final representation selection after all optimizations.Phase 8: Common Subexpression Elimination
CSE (Common Subexpression Elimination)
CSE (Common Subexpression Elimination)
compiler_pass.cc:438
Repeating: YesEliminate redundant computations.Phase 9: Loop Optimizations
LICM (Loop Invariant Code Motion)
LICM (Loop Invariant Code Motion)
compiler_pass.cc:440Move loop-invariant computations outside loops.Phase 10: Dead Store Elimination
DSE (Dead Store Elimination)
DSE (Dead Store Elimination)
compiler_pass.cc:452Remove stores to variables that are never read.Phase 11: Range Analysis
RangeAnalysis
RangeAnalysis
compiler_pass.cc:454
Critical: Yes - enables bounds check eliminationInfer integer value ranges to eliminate bounds checks.- Eliminates redundant array bounds checks
- Enables better integer optimizations
- Proves overflow cannot occur
Phase 12: Dead Code Elimination
EliminateDeadPhis
EliminateDeadPhis
compiler_pass.cc:483Remove unused phi instructions.DCE (Dead Code Elimination)
DCE (Dead Code Elimination)
compiler_pass.cc:486Remove unreachable code and unused definitions.Phase 13: Allocation Optimizations
DelayAllocations (AOT only)
DelayAllocations (AOT only)
compiler_pass.cc:488Delay allocations to reduce pressure on allocator.AllocationSinking_Sink
AllocationSinking_Sink
compiler_pass.cc:490
Critical: Yes - major optimizationSink allocations to reduce heap pressure and enable scalar replacement.- Move allocations closer to use
- Eliminate allocations that escape only to deopt
- Enable stack allocation
AllocationSinking_DetachMaterializations
AllocationSinking_DetachMaterializations
compiler_pass.cc:498Detach materialization instructions after allocation sinking.Phase 14: Environment and Stack Optimizations
TryCatchOptimization
TryCatchOptimization
compiler_pass.cc:476Optimize try-catch blocks.EliminateEnvironments
EliminateEnvironments
compiler_pass.cc:481Remove deoptimization environments where safe.EliminateStackOverflowChecks
EliminateStackOverflowChecks
compiler_pass.cc:391Remove redundant stack overflow checks.Phase 15: Write Barrier Elimination
EliminateWriteBarriers
EliminateWriteBarriers
compiler_pass.cc:528Remove unnecessary write barriers for GC.Phase 16: Dispatch and Call Optimizations
UseTableDispatch (AOT only)
UseTableDispatch (AOT only)
compiler_pass.cc:434Replace instance calls with dispatch table calls.OptimizeTypedDataAccesses (AOT only)
OptimizeTypedDataAccesses (AOT only)
compiler_pass.cc:473Optimize typed data array accesses.Phase 17: Code Generation Preparation
FinalizeGraph
FinalizeGraph
compiler_pass.cc:530Finalize the graph before code generation.ReorderBlocks
ReorderBlocks
compiler_pass.cc:526Reorder basic blocks for better code locality.AllocateRegisters
AllocateRegisters
compiler_pass.cc:508
Critical: Yes - required for code generationAssign registers to values.Phase 18: Final Transformations
LoweringAfterCodeMotionDisabled
LoweringAfterCodeMotionDisabled
compiler_pass.cc:563Lower high-level operations after code motion completes.TestILSerialization
TestILSerialization
compiler_pass.cc:545Test IL serialization (if enabled).Pass Flags and Control
Control passes with--compiler-passes flag:
+: