GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A DAG is built for the basic block x = a * b; y = b * a; z = x + y; a = z − x; w = a * b; v = y + x (+ and * commutative, a new leaf for each variable's initial value, a reassigned variable refers to its new node). How many nodes does the DAG have, and how many instructions does the optimised block need if only v and w are live on exit (one instruction per needed interior node)?
- A. 7 nodes; 4 instructions
- B. 6 nodes; 4 instructions
- C. 6 nodes; 5 instructions
- D. 8 nodes; 6 instructions
Correct answer: B. 6 nodes; 4 instructions
Leaves a0, b0. x and y are the same node n1 = a0 * b0; z = n1 + n1 = n2, and v = y + x is n2 again; a = n2 − n1 = n3; w = a * b uses the new a: n4 = n3 * b0 (a different node from n1). Nodes: 2 leaves + 4 interior = 6. v and w need n1, n2, n3, n4: t = a * b; v = t + t; u = v − t; w = u * b — 4 instructions.
More Compiler Design questions
- In the LL(1) table of S → i E t S Z | a; Z → e S | ε; E → b the only multiply-defined cell is M[Z, e]. A parser generator resolves it by…
- Which of the following is/are true for the grammar S → a S | S b | c? I. It is ambiguous. II. It is LL(1). III. It is SLR(1). IV. It is…
- In the LL(1) table of S → A B C; A → a | ε; B → b | ε; C → c | ε, how many cells hold an ε-production, and how many cells of the column…
- Consider the grammar G with productions S → A B C; A → a | ε; B → b | ε; C → c | ε. Which of the following statements is/are true? I. G is…
- int x = 1; int g() { x = x + 1; return x; } int f(int n) { int x = n; if (n == 0) return g(); int r = f(n − 1); return r + g(); } What…
- The standard algorithm removes all left recursion from S → A a | b; A → A c | S d | e, taking the non-terminals in the order S, A…