Compilers 2027 Rank-Decider: Basic-Block Leaders, SSA Phi-Functions, Dominators & Graph Coloring
Exact 3-rule Basic-Block Leader algorithm, Control-Flow Dominator trees & Natural Loops, Static Single Assignment (SSA) minimal phi-nodes, backward Liveness fixpoint, and Chaitin k-coloring.
1. Three Exact Rules to Identify Basic-Block Leaders in TAC
Given a sequence of Three-Address Code (TAC) instructions 1..N, an instruction is a Leader iff:
- It is the very first instruction (
1) of the intermediate program; OR - It is the target of any conditional or unconditional jump (
goto L); OR - It immediately follows a conditional or unconditional jump!
Each Leader starts a Basic Block consisting of itself and all subsequent instructions up to (not including) the next Leader. Number of Basic Blocks = Number of Distinct Leaders!
2. Static Single Assignment (SSA) & -Functions (Hot GATE CS 2024–2027 Topic!)
In SSA form, every variable in the IR is assigned statically at most ONCE (x1, x2, x3):
- Straight-line reassignments rename
x = x + 1intox2 = x1 + 1. - Where two control-flow branches merge at a ** Dominance Frontier** join block (e.g., after
if-elseor at a loop header) with different versionsx1andx2, SSA inserts a -function: - Why compilers love SSA: Constant propagation, dead-code elimination, and global value numbering become sparse & ultra-fast because every use has a single unique reaching definition!
3. Dominators & Natural Loops in CFGs
Node dominates node () iff every path from the entry block to must pass through (reflexive, antisymmetric, transitive forms a Dominator Tree rooted at Entry!). A Natural Loop is defined by a Back Edge where the target dominates source !
Practice Questions on This Chapter (2)
Consider the Three-Address Code fragment below:
1: i = 1
2: s = 0
3: if i > 10 goto 8
4: if i % 2 == 0 goto 6
5: s = s + i
6: i = i + 1
7: goto 3
8: return s
How many Basic Blocks exist in its Control Flow Graph?
In Static Single Assignment (SSA) intermediate representation, what is the exact role of a -function such as placed at the entry of a join basic block?