GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Register allocation by graph colouring is done on the loop 1: L1: v1 = v4 + 1; 2: v2 = v5 + 1; 3: v3 = v1 + 1; 4: v4 = v2 + 1; 5: v5 = v3 + 1; 6: if v5 > n goto L1; 7: return v5, n is an input live throughout. Two variables interfere if one is live at the point where the other is defined. Variables: n, v1, v2, v3, v4, v5. What is the minimum number of registers that allows allocation with no spill?
- A. 3
- B. 5
- C. 2
- D. 4
Correct answer: D. 4
The interference graph is the 5-cycle v1-v2-v3-v4-v5 (each value overlaps the next one around the loop) plus n, adjacent to all five. An odd cycle needs 3 colours and n needs a fourth, although no more than 3 values are ever live together (max-live is only a lower bound).
More Compiler Design questions
- An array is declared A[L..10][−4..5] with 4-byte elements and stored in row-major order starting at address 1744. If the address of…
- For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION…
- S → C C; C → c C | d is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column…
- For S → A b | B c; A → a A | ε; B → a B | ε (augmented), in how many LR(0) states is there a conflict, how many ACTION cells of the LR(0)…
- How many distinct LR(0) items does the grammar S → i E t S Z | a; Z → e S | ε; E → b have (do not augment it; an ε-production gives…
- Only the lower triangle (i ≥ j) of a 10 × 10 matrix A[1..10][1..10] of 4-byte elements is stored, packed into consecutive words starting…