SSA (Static Single Assignment) is an intermediate representation in which every variable is assigned exactly once. When a variable would be reassigned, a new variable with a new name is created instead.
In SSA form the same code looks like this:
Why It Works
Every name is defined in exactly one place, so “where did this value come from?” always has a single answer. That makes optimizations such as constant propagation, dead code elimination and common subexpression elimination much simpler.
Branches and phi
When a value can arrive along two different paths, SSA places a phi instruction at the join point. The phi picks the right value depending on which block control came from.
phi is not a real machine instruction. During code generation it becomes copy instructions placed on the incoming edges.
Sources
- R. Cytron, J. Ferrante, B. K. Rosen, M. N. Wegman, F. K. Zadeck. “Efficiently computing static single assignment form and the control dependence graph.” ACM TOPLAS 13(4), 1991, 451–490. doi:10.1145/115372.115320
- LLVM Language Reference Manual, “phi instruction”. llvm.org/docs/LangRef
- K. D. Cooper, L. Torczon. Engineering a Compiler, 2nd ed., Morgan Kaufmann, 2011, ch. 9.