GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A basic block is converted to a DAG with value numbering (+ and * commutative; a new leaf is made for each variable's initial value; a reassigned variable refers to its new node). How many nodes does the DAG have? a1 = x * y; b1 = a1 + z; x = b1; c1 = x * y; d1 = c1 + z; e1 = d1 + b1
- A. 7
- B. 9
- C. 8
- D. 10
Correct answer: C. 8
3 leaves for the initial x, y, z; x is reassigned, so c1 = x * y is a different node from a1; total 8 nodes.
More Compiler Design questions
- A basic block has 8 three-address statements, of which 3 compute a triple identical to an earlier one. A compiler stores it as (i)…
- 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…
- In the loop 1: i = 0; 2: j = 5; 3: L1: t1 = i 4; 4: t2 = t1 + b; 5: j = j + 3; 6: k = j 2; 7: m = m 2; 8: u = i + n; 9: i = i + 1; 10: if…
- With instructions OP R, R and OP R, M (a leaf that is a right child can be a memory operand), the Sethi-Ullman algorithm labels a left…
- For S′ → S; S → ( L ) | x; L → S | L , S, LALR(1) is formed by merging canonical LR(1) states with equal cores. The LALR state reached…
- int j = 2; int A[0..4] = {0, 3, 1, 4, 2}; int Sum(k, lo, hi, e) { int s = 0; for (k = lo; k <= hi; k++) s = s + e; return s; } All…