





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Project 3 – should have started work on this
Schedule for the rest of the semester » Today – Dataflow analysis » Wednes 11/29 – Finish dataflow, optimizations » Mon 12/4 – Optimizations, start on register allocation » Wednes 12/6 – Register allocation, Exam 2 review » Mon 12/11 – Exam 2 in class » Wednes 12/13 – No class (Project 3 due)
Reading for today’s class » 10.5, 10.6. 10.10, 10.
Liveness and reaching defs are basically the samething!!!!!!!!!!!!!!!!!! » All dataflow is basically the same with a few parameters y Meaning of gen/kill (use/def) y Backward / Forward y All paths / some paths (must/may) So far, we have looked at may analysis algorithms How do you adjust to do must algorithms?
Dataflow can be slow » How to implement it efficiently? (Block traversal order can speed things up) » How to represent the info? (Bitvectors)
Transfer function » How information is changed by “something” (BB) » OUT = GEN + (IN – KILL) forward analysis » IN = GEN + (OUT – KILL) backward analysis Meet function » How information from multiple paths is combined » IN = Union(OUT(predecessors)) forward analysis » OUT = Union(IN(successors)) backward analysis » Note, this is only for “any path
Liveness = upward exposed uses for each basic block in the procedure, X, do up_use_GEN(X) = 0 up_use_KILL(X) = 0 for each operation in reverse sequential order in X, op, do for each destination operand of op, dest, do^ up_use_GEN(X) -= dest^ up_use_KILL(X) += dest endfor for each source operand of op, src, do^ up_use_GEN(X) += src^ up_use_KILL(X) -= src endfor endfor endfor
Example - Liveness with GEN/KILL
Up to this point » Any path problems (maybe relations) y Definition reaches along some path y Some sequence of branches in which def reaches y Lots of defs of the same variable may reach a point » Use of Union operator in meet function
All-path: Definition guaranteed to reach » Regardless of sequence of branches taken, def reaches » Can always count on this » Only 1 def can be guaranteed to reach » Availability (as opposed to reaching) y Available definitions y Available expressions (could also have reaching expressions,but not that useful)
1: r1 = r2 + r32: r6 = r4 – r 3: r4 = 44: r6 = 8 5: r6 = r2 + r36: r7 = r4 – r 1,2,3,4 reach 1 available 1,2 reach 1,2 available 1,3,4 reach 1,3,4 available 1,2 reach1,2 available
for each basic block in the procedure, X, do GEN(X) = 0 KILL(X) = 0 for each operation in sequential order in X, op, do for each destination operand of op, dest, do G = op K = {all ops which define dest – op} GEN(X) = G + (GEN(X) – K) KILL(X) = K + (KILL(X) – G) endfor endfor endfor Exactly the same as reaching defs !!!!!!!
U = universal set of all operations in the Procedure IN(0) = 0 OUT(0) = GEN(0) for each basic block in procedure, W, (W != 0), do IN(W) = 0 OUT(W) = U – KILL(W) change = 1 while (change) do change = 0 for each basic block in procedure, X, do old_OUT = OUT(X) IN(X) = Intersect(OUT(Y)) for all predecessors Y of X OUT(X) = GEN(X) + (IN(X) – KILL(X)) if (old_OUT != OUT(X)) then change = 1 endif endfor endfor
1: r1 = r6 * r92: r2 = r2 + 13: r5 = r3 * r 4: r1 = r2 + 15: r3 = r3 * r46: r8 = r3 * 2 7: r7 = r3 * r48: r1 = r1 + 59: r7 = r1 - 6 10: r8 = r2 + 111: r1 = r3 * r412: r3 = r6 * r Compute the Aexpr IN/OUT sets for each BB
Make the code run faster on the target processor » Anything goes y Look at benchmark kernels, what’s the bottleneck?? y Invent your own optis
Classes of optimization » 1. Classical (machine independent) y Reducing operation count (redundancy elimination) y Simplifying operations » 2. Machine specific y Peephole optimizations y Take advantage of specialized hardware features » 3. ILP enhancing y Increasing parallelism y Possibly increase instructions
Traditional compiler class » Fancy implementations of optimizations, efficient algorithms » Bla bla bla » Spend entire class on 1 optimization For this class – Go over concepts of eachoptimization » What it is » When can it be applied (set of conditions that must be satisfied)
Simplify operation based on values of src operands » Constant propagation creates opportunities for this
All constant operands » Evaluate the op, replace with a move y r1 = 3 * 4
r1 = 12 y r1 = 3 / 0
??? Don’t evaluate excepting ops !, what about FP? » Evaluate conditional branch, replace with BRU or noop y if (1 < 2) goto BB
y if (1 > 2) goto BB
convert to a noop
Algebraic identities » r1 = r2 + 0, r2 – 0, r2 | 0, r2 ^ 0, r2 << 0, r2 >> 0 Æ r1 = r » r1 = 0 * r2, 0 / r2, 0 & r Æ r1 = 0 » r1 = r2 * 1, r2 / 1 Æ r1 = r