Compilers
What does liveness analysis, done in preparation for register allocation, determine?
- AThe line number where each variable is declared in the program
- BThe maximum and minimum values of each variable
- CAt each point, whether a value may still be used later
Show answer and explanation
Answer: C. At each point, whether a value may still be used later
Liveness analysis traverses the control-flow graph to determine, at each point in the program, whether a value may be read later (whether it is live). Live values must be kept in registers, while registers holding dead values can be reused. Values live at the same time cannot share a register, so the interference graph is built from this result. It does not find declaration positions or value ranges.
- A. It examines possible future use, not declaration position.
- B. It is distinct from value-range analysis.
- C. Correct. It determines at each point whether a value is still needed.