- is the copy of a_24 (x_1).
-
- The problem with this approach is that it may fail to discover copy
- relations in PHI cycles. Instead of propagating copy-of
- values, we actually propagate copy-of chains. For instance:
-
- A_3 = B_1;
- C_9 = A_3;
- D_4 = C_9;
- X_i = D_4;
-
- In this code fragment, COPY-OF (X_i) = { D_4, C_9, A_3, B_1 }.
- Obviously, we are only really interested in the last value of the
- chain, however the propagator needs to access the copy-of chain
- when visiting PHI nodes.
-
- To represent the copy-of chain, we use the array COPY_CHAINS, which
- holds the first link in the copy-of chain for every variable.
- If variable X_i is a copy of X_j, which in turn is a copy of X_k,
- the array will contain:
-
- COPY_CHAINS[i] = X_j
- COPY_CHAINS[j] = X_k
- COPY_CHAINS[k] = X_k
-
- Keeping copy-of chains instead of copy-of values directly becomes
- important when visiting PHI nodes. Suppose that we had the
- following PHI cycle, such that x_52 is already considered a copy of
- x_53:
-
- 1 x_54 = PHI <x_53, x_52>
- 2 x_53 = PHI <x_898, x_54>
-
- Visit #1: x_54 is copy-of x_53 (because x_52 is copy-of x_53)
- Visit #2: x_53 is copy-of x_898 (because x_54 is a copy of x_53,
- so it is considered irrelevant
- as a copy).
- Visit #1: x_54 is copy-of nothing (x_53 is a copy-of x_898 and
- x_52 is a copy of x_53, so
- they don't match)
- Visit #2: x_53 is copy-of nothing
-
- This problem is avoided by keeping a chain of copies, instead of
- the final copy-of value. Propagation will now only keep the first
- element of a variable's copy-of chain. When visiting PHI nodes,
- arguments are considered equal if their copy-of chains end in the
- same variable. So, as long as their copy-of chains overlap, we
- know that they will be a copy of the same variable, regardless of
- which variable that may be).
-
- Propagation would then proceed as follows (the notation a -> b
- means that a is a copy-of b):
-
- Visit #1: x_54 = PHI <x_53, x_52>
- x_53 -> x_53
- x_52 -> x_53
- Result: x_54 -> x_53. Value changed. Add SSA edges.
-
- Visit #1: x_53 = PHI <x_898, x_54>
- x_898 -> x_898
- x_54 -> x_53
- Result: x_53 -> x_898. Value changed. Add SSA edges.
-
- Visit #2: x_54 = PHI <x_53, x_52>
- x_53 -> x_898
- x_52 -> x_53 -> x_898
- Result: x_54 -> x_898. Value changed. Add SSA edges.
-
- Visit #2: x_53 = PHI <x_898, x_54>
- x_898 -> x_898
- x_54 -> x_898
- Result: x_53 -> x_898. Value didn't change. Stable state
-
- Once the propagator stabilizes, we end up with the desired result
- x_53 and x_54 are both copies of x_898. */