next up previous
Next: Data-flow analysis: available expressions. Up: Compiler Theory: Code Optimization Previous: Data-flow analysis: reaching definitions

Data-flow analysis: copy propagation.

Many optimizations and user code introduce copy statements of the form
s:  x := y
It is sometimes possible to eliminate such copy statements.


COPY PROPAGATION CONDITIONS. Assume that for a statement u where x is used

Then we may substitute y for x in u.

Observe that

We shall set up


COPY REACHING A POINT. Let s: x := y be a copy statement and p be a point of the TAC program $ \cal {P}$. We say that the copy s: x := y reaches p if every path $ \gamma$ from the initial node of $ \cal {P}$ to p

This implies that the statement s: x := y reaches the point p.


COPY PROPAGATION DATA-FLOW SETS. For a basic block B

Observe that Observe that for every basic block B


DATA-FLOW EQUATIONS For every basic block B the data-flow sets inC(B) and outC(B) satisfy the following equations

inC(B) = $\displaystyle \bigcap_{{{\ B' \ \in \ {\mbox{\sf pred}}(B)}}}^{{}}$ outC(B'),
outC(B) = genC(B$\displaystyle \bigcup$ $\displaystyle \left(\vphantom{ in_C(B) \setminus kill_C(B) }\right.$inC(B) $\displaystyle \setminus$ killC(B)$\displaystyle \left.\vphantom{ in_C(B) \setminus kill_C(B) }\right)$.
(6)


COMPUTING THE DATA-FLOW SETS FOR THE COPY PROPAGATION PROBLEM Assume that the set C of all copy statements in $ \cal {P}$ has been computed. Then, for each basis block B one can compute genC(B) and killC(B). Now set

inC(B1)  =  $\displaystyle \emptyset$  and  outC(B1)  =  genC(B1) (7)

where B1 is the first block Then one can set up a completion algorithm initializing every for basic block B $ \neq$ B1

inC(B)  =  C (8)

and using the updating equations

outC(B) = genC(B$\displaystyle \bigcup$ $\displaystyle \left(\vphantom{ in_C(B) \setminus kill_C(B) }\right.$inC(B) $\displaystyle \setminus$ killC(B)$\displaystyle \left.\vphantom{ in_C(B) \setminus kill_C(B) }\right)$.
inC(B) = $\displaystyle \bigcap_{{{\ B' \ \in \ {\mbox{\sf pred}}(B)}}}^{{}}$ outC(B'),
(9)


next up previous
Next: Data-flow analysis: available expressions. Up: Compiler Theory: Code Optimization Previous: Data-flow analysis: reaching definitions
Marc Moreno Maza
2004-12-02