3 CodeGeneration Unit5 Optimization of Basic Blocks
3 CodeGeneration Unit5 Optimization of Basic Blocks
Knowing when the value of a variable will be used next is essential for generating
good code. If the value of a variable that is currently in a register will never be
referenced subsequently, then that register can be assigned to another variable.
Wish to determine for each three-address statement x = y + z what the next uses
of x, y, and z are. For the present, we do not concern ourselves with uses outside
the basic block containing this three-address statement.
There is an algorithm to determine liveness and next-use information makes a
backward pass over each basic block.
We store the information in the symbol table.
Next Use Information
Optimization of Basic Blocks
If a and b are live but c and e are not, we can immediately remove the root labeled e. Then,
the node labeled c becomes a root and can be removed. The roots labeled a and b remain,
since they each have live variables attached.
Use of Algebraic Identities