∑GateAndNet
PlannerSign Up
ADVANCEDFrequently Tested 4 min read 4 views

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:

  1. It is the very first instruction (1) of the intermediate program; OR
  2. It is the target of any conditional or unconditional jump (goto L); OR
  3. 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) & ϕ\phi-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 + 1 into x2 = x1 + 1.
  • Where two control-flow branches merge at a ** Dominance Frontier** join block (e.g., after if-else or at a loop header) with different versions x1 and x2, SSA inserts a ϕ\phi-function: x3=ϕ(x1,x2)x_3 = \phi(x_1, x_2)
  • 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 dd dominates node nn (d dom nd \text{ dom } n) iff every path from the entry block to nn must pass through dd (reflexive, antisymmetric, transitive   ⟹  \implies forms a Dominator Tree rooted at Entry!). A Natural Loop is defined by a Back Edge n→dn \to d where the target dd dominates source nn!

Key Formulas Summary
Backward Live-Variable Data-Flow Equations for Basic Block B
OUT⁡[B]=⋃S∈succ⁡(B)IN⁡[S],IN⁡[B]=USE⁡[B]  ∪  (OUT⁡[B]−DEF⁡[B])\operatorname{OUT}[B] = \bigcup_{S \in \operatorname{succ}(B)} \operatorname{IN}[S], \qquad \operatorname{IN}[B] = \operatorname{USE}[B] \;\cup\; \big(\operatorname{OUT}[B] - \operatorname{DEF}[B]\big)
Note: USE[B] = variables read in B BEFORE any assignment to them in B; DEF[B] = variables assigned in B!
Register Interference Graph Chromatic Bound
Min Architectural Registers (Zero Spills)=χ(Ginterference)≥max⁡program point p∣Live(p)∣\text{Min Architectural Registers (Zero Spills)} = \chi(G_{\text{interference}}) \ge \max_{\text{program point } p} |\text{Live}(p)|
Note: Two variables share an undirected interference edge iff one is LIVE at a point where the other is DEFINED (or simultaneously live)!
#Compiler Design#Basic Blocks#SSA Form#Dominator Tree#Liveness Analysis#Register Allocation

Practice Questions on This Chapter (2)

Q1GATE CS 2027 Expected NATNATMEDIUM
+2M • 0 Neg

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?

Q2GATE CS 2026–27 ExpectedMCQMEDIUM
+2M • -0.67

In Static Single Assignment (SSA) intermediate representation, what is the exact role of a ϕ\phi-function such as x3=ϕ(x1,x2)x_3 = \phi(x_1, x_2) placed at the entry of a join basic block?

⚡ Click an option above to verify instantly
Previous TopicSyntax-Directed Translation (SDT), Three-Address Code & Register LivenessNext Topic CPU Scheduling, Semaphores & Deadlock Banker’s Formula