Docsity

Dataflow II: Finish Dataflow Analysis, Start on Classical Optimizations | EECS 483, Study Guides, Projects, Research of Electrical and Electronics Engineering

Partial preview of the text

Download Dataflow II: Finish Dataflow Analysis, Start on Classical Optimizations | EECS 483 and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

Dataflow II: Finish Dataflow Analysis, Start on Classical Optimizations

EECS 483 – Lecture 24 University of Michigan Wednesday, November 29, 2006

  • 1 -

Announcements and Reading

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.

  • 3 -

Some Things to Think About

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)

  • 4 -

Generalizing Dataflow Analysis

™ 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

  • 6 -

Liveness Using GEN/KILL

™ 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

- 7 -

Example - Liveness with GEN/KILL

  • r2 = r2 + 1r3 = r1 * r r1 = MEM[r2+0] - r1 = r1 + 5r3 = r5 – r1r7 = r3 * - r2 = 0r7 = 23r1 = - r3 = r3 + r7r1 = r3 – r8r3 = r1 * - up_use_GEN(4.1) = r - up_use_KILL(4.1) = r - up_use_GEN(4.3) = r3,r7,r8 up_use_GEN(4.2) = r3,r - up_use_KILL(4.3) = r1 up_use_KILL(4.2) = r - up_use_KILL(3) = r1, r2, r
    • up_use_KILL(1) = r1,r
      • up_use_GEN(2) = r1,r5 up_use_KILL(2) = r3,r
        • BB
        • BB - BB - up_use_GEN(3) =
  • up_use_GEN(1) = r2,r
  • BB meet: OUT = Union(IN(succs))xfer: IN = GEN + (OUT – KILL)
  • 9 -

What About All Path Problems?

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)

  • 10 -

Reaching vs Available Definitions

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

  • 12 -

Compute Adef GEN/KILL Sets

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 !!!!!!!

  • 13 -

Compute Adef IN/OUT Sets

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

  • 15 -

Class Problem - Aexprs Calculation

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

  • 16 -

Optimization – Put Dataflow To Work!

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

  • 18 -

Caveat

™ 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)

  • 19 -

Constant Folding ™

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

Æ

BRU 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