GATE Computer ScienceHardGATE CS
The live ranges (inclusive of both end points, in instruction numbers) of ten variables are [1,8], [2,5], [3,9], [4,6], [7,12], [10,14], [11,13], [6,10], [9,15] and [12,16]. Two variables whose ranges share an instruction cannot share a register. What is the minimum number of registers needed so that no variable is spilled?
- A. 6
- B. 5
- C. 4
- D. 3
Correct answer: B. 5
Interval graphs are perfect, so the minimum number of registers equals the maximum number of simultaneously live ranges. At instruction 12 the ranges [7,12], [9,15], [10,14], [11,13] and [12,16] are all live: 5. No point has 6 live ranges.
More Compiler Design questions
- Linear-scan register allocation processes the same ten live ranges [1,8], [2,5], [3,9], [4,6], [7,12], [10,14], [11,13], [6,10], [9,15]…
- A syntax-directed translation scheme prints as it reduces: E → T + E { print('+') } | T; T → F T { print('') } | F; F → id {…
- A lexical rule recognises the language (ab | abc | c)(bc | a) over {a, b, c}. How many states does the minimal complete DFA (dead state…
- For the statement a = b (−c) + b (−c), common subexpressions are shared (so −c and b (−c) are each computed once) and the code is stored…
- Grammar: E → E + T | T; T → T F | F; F → ( E ) | id. An SLR(1) parser parses id + id ( id + id ) id. Counting every shift, every reduce…
- A table-driven predictive parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses ( id + id ) id + id. One…