9.4 Live Variables

Live variables at a program point P are those for which there is a subsequent use before a redefinition.

We compute live variables for a number of reasons. If there is a definition not followed by a use, then we may want to issue a warning message to the programmer.

Even if there is no definition at a program point P, we may want to keep track of what variables are live to know which ones to keep in registers. If the variable is not to be kept in a register, we may want to store it to reuse the register, but if the variable is not live, we do not need to store it; that is, the code generator does not need to emit a store instruction.

Formally, we define a variable to be live at some point in the program if there is some path through the flow graph from that point along which we shall encounter a use of that variable before any redefinition; otherwise, the variable is dead

Equations for Live Variable Analysis

Algorithm for Computing Live Variables

Data Structures for Live Variables

Send questions and comments to: Karen Lemone