Compiler Optimization
Motivation for SSA Form
Many optimizations can be simplified by using SSA form. Consider this counterexample with the presented algorithms.
1. Constant Folding
Algorithm:
Create a map where is a variable. Initialize to undefined.
For each statement, if it is of form:
x = c
setM[x] = c
x = y
setM[x] = M[y]
Replace y with M[y] if defined
v = Op x y
setM[v] = Op(M[x], M[y])
where Op(...) may return undefinedReplace
Op x y
with Op(M[x], M[y]) if definedOtherwise replace x with M[x] if defined and y with M[y] if defined
This only works with SSA. Consider the above snippet as the counterexample.
2. Copy Propagation
Algorithm:
Create a map . Initialize
M[x]=x
For each statement, if it is of form:
x = y
setM[x] = M[y]
v = Op x y
replace withv = Op M[x] M[y]
Again, this only works with SSA.
3. Dead Code Elimination
Algorithm:
Last updated