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:
| Block | USE | DEF | Successors |
|---|---|---|---|
| B1 | ∅ | a, b | B2, B3 |
| B2 | b | c | B3 |
| B3 | a, c | d | B4 |
| B4 | d | a | B5 |
| B5 | a | ∅ | EXIT |
| Block | USE | DEF | Successors |
|---|---|---|---|
| B1 | j | i | B2 |
| B2 | i, v | i, t1, t2 | B3, B4 |
| B3 | j | j | B5 |
| B4 | i | a | B5 |
| B5 | i, j | i, t3, t4 | B6 |
| B6 | j | a | B2 (Loop Back) |