Compiler Design

Live Variable Analysis


Live Variable Analysis

Live Variable Analysis is a global data-flow analysis used to determine which variables are "live" (hold a value that may be needed in the future) at each point in a program. It is critical for register allocation and dead code elimination.

For each basic block B, we compute:

  • USE[B]: The set of variables that are read (used) in block B before they are overwritten (defined) in that same block.
  • DEF[B]: The set of variables that are written to (defined) in block B prior to any use of that variable in the block.

Solved PYQs: USE and DEF Sets

In this flow graph, variables were defined and used across basic blocks. Below is the computed result:

BlockUSEDEFSuccessors
B1a, bB2, B3
B2bcB3
B3a, cdB4
B4daB5
B5aEXIT
BlockUSEDEFSuccessors
B1jiB2
B2i, vi, t1, t2B3, B4
B3jjB5
B4iaB5
B5i, ji, t3, t4B6
B6jaB2 (Loop Back)