GATE Computer ScienceVery hardGATE CS (PYQ pattern)
SSA form is built for 1: i = 0; 2: L1: if i >= n goto L4; 3: if i > k goto L2; 4: x = i * 2; 5: goto L3; 6: L2: x = i + 1; 7: y = x; 8: L3: i = i + 1; 9: goto L1; 10: L4: return x. How many φ-functions does minimal SSA without pruning place, and how many does pruned SSA place (a φ only where the variable is live on entry to the block)?
- A. 5 unpruned, 5 pruned
- B. 5 unpruned, 3 pruned
- C. 3 unpruned, 3 pruned
- D. 4 unpruned, 2 pruned
Correct answer: B. 5 unpruned, 3 pruned
Blocks: {1}, {2}, {3}, {4, 5}, {6, 7}, {8, 9}, {10}. x and y are defined in the two arms, whose dominance frontier is L3 {8, 9}; L3's frontier is the header L1 {2}. i is defined in the entry and in L3, so its φ goes at L1. Unpruned: x at L3 and L1, y at L3 and L1, i at L1 = 5. y is never used, so it is not live anywhere: drop its 2 φ's; x is live at L3 and at L1 (return x after the loop): pruned = 3.
More Compiler Design questions
- Minimal SSA form without liveness pruning (φ-functions at the iterated dominance frontier of every block that assigns the variable) is…
- In 1: a = 1; 2: b = 2; 3: if p > 0 goto L1; 4: a = a + 1; 5: goto L2; 6: L1: b = b + 1; 7: L2: c = a + b; 8: if c > q goto L3; 9: a = c…
- The statement r = ((x y) + (y x)) ((x y) − z) + (z − x y) is turned into a DAG (+ and commutative, − not), and code is generated with one…
- For the grammar S → a A | A b; A → c | ε, what is FOLLOW(A)?
- For S′ → S; S → A A A; A → a A | b, how many states of the canonical LR(1) automaton contain the complete item A → b · ?
- int f(int k) { if (k <= 0) return 0; return g(k - 1) + 1; } int g(int k) { if (k <= 1) return 1; return f(k - 2) + f(k - 1); } During the…