Skip to main content
Definition Website Computer and Technology

Static Single Assignment

Subject: Computer and Technology noun /ˈstæt.ɪk ˈsɪŋ.ɡəl əˈsaɪn.mənt/ 1 definition

  1. Definition (noun)

    Entry #268 · Updated

    Static Single Assignment (SSA) is a property of a compiler intermediate representation (IR) in which every variable is assigned a value exactly once in the program text and defined before every use. When source code reassigns a variable, converting the IR into SSA form splits it into distinct versioned names—such as x1 and x2—and inserts pseudo-instructions called phi functions at control-flow merge points to select the active version based on which predecessor basic block executed. By making use-definition chains explicit and eliminating value overwrites, SSA dramatically simplifies static analysis and optimizations such as constant propagation, dead-code elimination, and global value numbering. Because physical processors operate on mutable, finite registers rather than unbounded immutable names, SSA acts strictly as an analysis and optimization representation—widely used in compilers such as LLVM, GCC, and V8—and must be lowered back to conventional destructive-assignment instructions during code generation.

    Common Forms

    • Minimal SSA: Places phi functions strictly at the iterated dominance frontier of each variable's assignments, producing the smallest structural set of merge nodes dictated by the control-flow graph without checking whether variables remain live.

    • Pruned SSA: Refines minimal SSA with global liveness analysis to omit phi functions at merge blocks where a variable is dead, eliminating unnecessary pseudo-assignments and shrinking the IR.

    • Semi-Pruned SSA: Eliminates phi functions for variables confined within a single basic block without running full global liveness analysis, offering a faster trade-off between minimal SSA and pruned SSA.

    • Block-Argument SSA: Replaces phi instructions with parameterized basic blocks—as used in Swift SIL, MLIR, and Cranelift—so branch instructions explicitly pass SSA values as arguments to successor blocks rather than encoding predecessor-indexed merge nodes.

    Example

    When Clang compiles a conditional branch that sets x = a + 1 in the then block and x = a * 2 in the else block, LLVM's mem2reg pass promotes the mutable stack alloca into distinct SSA virtual registers %x1 = add i32 %a, 1 and %x2 = mul i32 %a, 2. At the converging %merge basic block, the IR inserts %x3 = phi i32 [ %x1, %then ], [ %x2, %else ], allowing subsequent optimization passes to reason directly about immutable value flow.