Docsity

Finish Basic Dataflow Analysis Predicate Relation Analysis - Fall 2006 | EECS 583, Assignments of Electrical and Electronics Engineering

Partial preview of the text

Download Finish Basic Dataflow Analysis Predicate Relation Analysis - Fall 2006 | EECS 583 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

EECS 583 – Class 8 Finish Basic Dataflow Analysis Predicate Relation Analysis

University of Michigan February 6, 2006

  • 1 -

Reading Material^ Y^ Today’s class

»^ “Analysis Techniques for Predicated Code”,^ R. Johnson and M. Schlansker, MICRO-29, 1996 Y Material for the next lecture »^ Compilers: Principles, Techniques, and Tools

A. Aho, R. Sethi, and J. Ullman, Addison-Wesley, 1988, 9.9, 10.2, 10.3, 10.

  • 3 -

Homework Problem from Lecture 5 (Cont)

Assume Left edges are negative and Right edges are positive CD(1) =

φ CD(2) = -1 CD(3) = -2 CD(4) = -3 CD(5) = +2,+3 CD(6) = -4 CD(7) = +4 CD(8) = -1 CD(9) =

φ

u = v + 1 x = y + 1

b > 0 c > 0

a <= 0

b <= 0 c <= 0 d <= 0

BB1 d > 0 BB3 BB^

BB

BB

BB8 BB

BB

a > 0 BB2 r = t + s z = z + 1

  • 4 -

Homework Problem from Lecture 5 (Cont)

Predicate assignment (K set) BB1 BB2 BB3 BB4 BB5 BB6 BB7 BB8 BB9 True p

p^

p3^ p

p^

p6^ p

True

Predicates (R set) -1 -2 -3 +2,+3 -4 +4 p1 p2 p

p^

p5 p

If-converted code p4 = 0 p1 = CMPP.UN(a>0) if T r = t + s if p1 p2,p4 = CMPP.UC.ON(b>0) if p1 p3,p4 = CMPP.UC.ON(c>0) if p2 u = v + 1 if p4 p5,p6 = CMPP.UC.UN(d>0) if p3 x = y + 1 if p6 z = z + 1 if p

  • 6 -

DU/UD Chains^ Y^ Convenient way to access/use reaching defs info^ Y^ Def-Use chains » Given a def, what are all the possible consumers of theoperand produced » Maybe consumer Y Use-Def chains » Given a use, what are all the possible producers of theoperand consumed » Maybe producer

  • 7 -

Example – DU/UD Chains

r1 = 3 r2 = r3 r3 = r4 r1 = r1 + 1 r7 = r1 * r r4 = r4 + 1

r4 = r r8 = 8 r9 = r7 + r

  • 9 -

DU/UD Chains in Elcor (2)^ Y^ Region-level analysis »^ Efficiency – just analyze overwhat you are interested in »^ What about uses/defs outside theregion of analysis?? »^ Can’t have direct connection, orits not region analysis »^ But, can’t ignore them Y External def/use refs »^ El_ref has a type^ y^

EXP_SRC, EXP_DEST(explicit) y IMP_SRC, IMP_DEST (implicit) y LIVEIN_DEST (outside def) y LIVEOUT_SRC (outside use) Y^ Use global liveness info to createexternal def/use refs Y^ UD/DU chains contain both insideand outside refs

1: r1 = MEM[r2+0] 2: r2 = r2 + 1 3: r3 = r1 * r 4: r1 = r1 + 5 5: r3 = r5 – r1 6: r7 = r3 * 2

7: r7 = r6 8: r2 = 0 9: r7 = r7 + 1 10: r8 = r7 + 5 11: r1 = r3 – r8 12: r3 = r1 * 2

  • 10 -

Some Things to Think About^ Y^ Liveness and rdefs are basically the same thing

»^ All dataflow is basically the same with a few parameters^ y^

Meaning of gen/kill – src vs dest, variable vs operation y Backward / Forward y All paths / some paths (must/may)^ X^ So far, we have looked at may analysis algorithms^ X^ How do you adjust to do must algorithms?

Y^ Dataflow can be slow^ »^

How to implement it efficiently? » How to represent the info?

Y^ Predicates^ »^

Throw a monkey wrench into this stuff » So, how are predicates handled?

  • 12 -

Beyond Liveness or Upward Exposed Uses^ Y^ Upward exposed defs »^ IN = GEN + (OUT – KILL) »^ OUT = Union(IN(successors)) »^ Walk ops reverse order^ y^

GEN += dest; KILL += dest

Y^ Downward exposed uses^ »^

IN = Union(OUT(predecessors)) » OUT = GEN + (IN-KILL) » Walk ops forward order^ y^ GEN += src; KILL -= src;^ y^ GEN -= dest; KILL += dest;

Y^ Downward exposed defs^ »^

IN = Union(OUT(predecessors)) » OUT = GEN + (IN-KILL) » Walk ops forward order^ y^ GEN += dest; KILL += dest;

» IN = Union(OUT(predecessors)) » OUT = GEN + (IN-KILL) » Walk ops forward order^ y GEN += src; KILL -= src;^ y GEN -= dest; KILL += dest;

 - r = t + s b > 0 c > 0 u = v + 1 x = y + r = t + s if (b > 0 || c > 0) u = v + 1 else if (d > 0) x = y + 1 else z = z + 1 } a. Draw the CFGb. Compute CDc. If-convert the code - a <= - b <= 0 c <= 0 d <= 
  • BB1 d > - BB3 BB - BB - BB - BB8 BB - BB
    • a > 0 BB - z = z +
    • 1: r1 = 3 2: r2 = r3 3: r3 = r Compute reaching defs Calculate GEN/KILL for each BB Calculate IN/OUT for each BB
  • IN = φ GEN = 1,2,3 KILL = 4 OUT = 1,2, - 4: r1 = r1 + 1 5: r7 = r1 * r - IN = 2,3,4, - Æ 2,3,4,5,6,7, - GEN = 6KILL = 7OUT = 2,3,4,5, - 6: r4 = r4 + 1 Æ 2,3,4,5,6, - IN = 1,2, - Æ 1,2,3,4,5,6,7, - GEN = 4,5KILL = 1OUT = 2,3,4, - Æ 2,3,4,5,6,7,8IN = 2,3,4, - Æ 2,3,4,5,6,7, - GEN = 7KILL = 6OUT = 2,3,4,5, - Æ 2,3,4,5,7, - IN = 2,3,4,5,6, - Æ 2,3,4,5,6,7, - GEN = 8KILL = φ OUT = 2,3,4,5,6,7, - 7: r4 = r3 + r Æ no change (so done iterating) - 8: r8 = - IN = 2,3,4,5,6,7,8 GEN = 9 KILL = φ OUT = 2,3,4,5,6,7,8, - 9: r9 = r7 + r
  • BB Example - Downward Exposed Uses (ReverseProblem of Liveness)
    • r1 = MEM[r2+0] r2 = r2 + 1 r3 = r1 * r IN = NULL
      • GEN = r1, r4 KILL = r2, r3 OUT = r1, r - r1 = r1 + 5 r3 = r5 – r1 r7 = r3 * - r2 = 0 r7 = 23 r1 = - BB
        • IN = r1, r - BB
          • IN = r1, r4 GEN = r1, r3, r5 KILL = r - GEN = NULL KILL = r1, r2, r7 OUT = r - OUT = r1, r3, r4, r - r3 = r3 + r7 r1 = r3 – r8 r3 = r1 * - BB - IN = r1, r3, r4, r5 GEN = r1, r7, r8 KILL = r3 OUT = r1, r4, r5, r7, r
  • 15 -

Reaching vs Available Definitions

1:r1 = r2 + r3^ 2:r6 = r4 – r

1,2 reach 1,2 available 3:r4 = 4 4:r6 = 8

5:r6 = r2 + r36:r7 = r4 – r

1,2,3,4 reach1 available

1,2 reach 1,2 available

1,3,4 reach 1,3,4 available

  • 16 -

Available Definition Analysis (Adefs)^ Y^ A definition d is available

at a point p if along all

paths

from d to p, d is not killed Y Remember, a definition of a variable is killed

between 2

points when there is another definition of that variablealong the path^ »^ r1 = r2 + r3 kills previous definitions of r1 Y Algorithm^ »^ Forward dataflow analysis as propagation occurs from defsdownwards^ »^ Use the Intersect function as the meet operator to guarantee theall-path requirement^ »^ GEN/KILL/IN/OUT similar to reaching defs^ y

Initialization of IN/OUT is the tricky part

  • 18 -

Compute IN/OUT Sets for all BBs (Adefs)

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

  • 19 -

Example Adefs Calculation

1: r1 = MEM[r2+0] 2: r2 = r2 + 1 3: r3 = r1 * r 4: r1 = r1 + 5 5: r3 = r5 – r1 6: r8 = r3 * 2

7: r7 = 0 8: r1 = r1 + 5 9: r7 = r1 - 6 10: r8 = r7 + r8 11: r1 = r3 – r8 12: r3 = r1 * 2