GATE Computer ScienceVery hardGATE CS

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], [12,16] in increasing order of start point with 3 registers. Ranges whose end precedes the new start are expired; if no register is free the algorithm spills whichever of the active ranges or the new range ends last. How many ranges are spilled?

  1. A. 2
  2. B. 4
  3. C. 5
  4. D. 3

Correct answer: D. 3

Spills: at [4,6] the active [3,9] ends last and is spilled; at [10,14] the active [9,15] ends last and is spilled; at [12,16] the new range itself ends last and is spilled. Total 3.

More Compiler Design questions

Exams that ask this topic