next up previous
Next: Invariant Code Motion Up: Compiler Theory: Code Optimization Previous: Global Copy Propagation and Dead

Global Recycling of Available Expressions

KEY IDEA.


ALGORITHM.

  1. Find all statements S: a := b op c occurring in a basic block B such that
  2. For each statement S found in the previous step,
    1. allocate a temporary variable t, and
    2. from block B search backwards along all possible paths the previous statement d := b op c, and immediately after it insert the statement t := d.
    3. Replace the statement S by a := t.


EXERCISE. Apply the previous algorithm to Figure 11.

Figure 11: A control flow graph.
\begin{figure}\htmlimage
\centering\includegraphics[scale=.5]{ControlFlowGraph8.eps}
\end{figure}
After applying these transformations, we obtain the control flow graph of Figure 12.
Figure 12: A control flow graph.
\begin{figure}\htmlimage
\centering\includegraphics[scale=.5]{ControlFlowGraph9.eps}
\end{figure}
Obviously, one would like to move out the first two lines of the basic block B2. This will be achieved using Invariant Code Motion to be described now.


next up previous
Next: Invariant Code Motion Up: Compiler Theory: Code Optimization Previous: Global Copy Propagation and Dead
Marc Moreno Maza
2004-12-02