Compilers
In a function, at most five values are live at the same time. In a simple case where the interference graph imposes no further constraints, how many registers are needed at minimum to hold every value without spilling?
- A5
- B4
- C10
Show answer and explanation
Answer: A. 5
The five simultaneously live values all interfere with one another, forming a complete subgraph of five nodes in the interference graph, so at least five colors are needed. In simple cases such as straight-line code, where live ranges are intervals, the graph can be colored with as many colors as the maximum number of simultaneously live values, so five registers suffice. With four, some value must be spilled to memory somewhere. Ten is more than necessary.
- A. Correct. Five, the maximum live at once, are needed and suffice here.
- B. With four, a spill is needed somewhere.
- C. Ten is more than necessary.