Docsity

Dataflow Analysis: Generalized Dataflow Analysis and Liveness, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Dataflow Analysis: Generalized Dataflow Analysis and Liveness and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Dataflow Analysis/Opti II Generalized Dataflow Analysis, Intro to Optimization

EECS 483 – Lecture 19 University of Michigan Monday, November 17, 2003

  • 1 -

Summary From Last Time

Y

Liveness

» For each point p in a program and each variable y,

determine whether y can be used before beingredefined starting at p

Y

Reaching defs:

» A definition d reaches a point p if there is a path from

the point immediately following d to p such that d isnot “killed” along that path

» A definition is killed between 2 points when there is

another definition of the same variable along the path

» Represent with DU/UD chains

  • 3 -

Class Problem – From Last Time

r1 = 3 r2 = r3r3 = r

r1 = r1 + 1 r7 = r1 * r

r2 = 0

r2 = r2 + 1

r4 = r2 + r1 r9 = r4 + r

Find the DU/UD Chains

Note, I’ve shown the DU chains. UD chains are the reverse

  • 4 -

Some Things to Think About

Y

Liveness and reaching defs are basicallythe same thing!!!!!!!!!!!!!!!!!!

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

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?

  • 6 -

Generalized Dataflow Algorithm

Y

while (change)

» change = false » for each BB

y

apply meet function

y

apply transfer function

y

if any changes

Æ

change = true

  • 7 -

Liveness Using GEN/KILL

Y

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

  • 9 -

Beyond Liveness (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;

- 10 -

Example – Upward Exposed Defs

up_def_OUT =

  • BB meet: OUT = Union(IN(succs))xfer: IN = GEN + (OUT – KILL)
    • r2 = r2 + r1 = MEM[r2+0]
      • r3 = r1 * r
    • up_use_GEN(1) = r2,r4 up_use_KILL(1) = r1,r - r1 = r1 + - r3 = r5 – r - r7 = r3 * - r2 = - r7 = - r1 = - up_use_GEN(2) = r1,r5 up_use_KILL(2) = r3,r - BB - BB - up_use_GEN(3) = 0 up_use_KILL(3) = r1, r2, r - r3 = r3 + r - r1 = r3 – r - r3 = r1 * - BB - up_use_GEN(4.3) = r3,r7,r - up_use_KILL(4.3) = r - up_use_GEN(4.2) = r3,r - up_use_KILL(4.2) = r - up_use_GEN(4.1) = r - up_use_KILL(4.1) = r
      • r2 = r2 + r1 = MEM[r2+0]
        • r3 = r1 * r
    • up_def_GEN = r1,r2,r3up_def_KILL = r1,r2,r - up_def_GEN = r1,r2,r7up_def_KILL = r1,r2,r - up_def_GEN = r1,r3up_def_KILL = r1,r - up_def_IN = r1,r ∅ - up_def_IN = r1,r2,r3,r IN = GEN + (OUT – KILL)OUT = Union(IN(successors))
  • up_def_IN = r1,r2,r3,r - up_def_OUT =r1,r2,r3,r - up_def_OUT = r1,r - up_def_IN = r1,r3,r - r1 = r1 + - r3 = r5 – r - r7 = r3 * - r2 = - r7 = - r1 = - up_def_GEN = r1,r3,r7 up_def_KILL = r1,r3,r - up_def_OUT = r1,r - r3 = r3 + r7 r1 = r3 – r - r3 = r1 *
  • 12 -

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 reach 1,2 available

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

1,2,3,4 reach 1 available

  • 13 -

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 definitionof that variable along the path

» r1 = r2 + r3 kills previous definitions of r

Y

Algorithm

» Forward dataflow analysis as propagation occurs from

defs downwards

» Use the Intersect function as the meet operator to

guarantee the all-path requirement

» GEN/KILL/IN/OUT similar to reaching defs

y

Initialization of IN/OUT is the tricky part

  • 15 -

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

  • 16 -

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

  • 18 -

Class Problem - Aexprs Calculation

Compute the Aexpr IN/OUT sets for each BB

1: r1 = r6 * r9 2: r2 = r2 + 1 3: r5 = r3 * r

4: r1 = r2 + 1 5: r3 = r3 * r4 6: r8 = r3 * 2

7: r7 = r3 * r4 8: r1 = r1 + 5 9: r7 = r1 - 6

10: r8 = r2 + 1 11: r1 = r3 * r4 12: r3 = r6 * r

  • 19 -

Efficient Calculation of Dataflow

Y

Order basic blocks are visited is important(faster convergence)

Y

Forward analysis – DFS order

» Visit a node only when all its predecessors

have been visited

Y

Backward analysis – PostDFS order

» Visit a node only when all of its successors

have been visited