Dataflow Analysis: Liveness and Reaching Definitions in EECS 483 at University of Michigan, Study Guides, Projects, Research of Electrical and Electronics Engineering

A lecture note from the university of michigan's eecs 483 course, focusing on dataflow analysis. The notes cover the concepts of liveness analysis and reaching definitions analysis. Students are encouraged to work on project 3 and prepare for exam 2. Examples and calculations for both liveness and reaching definitions analysis.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/17/2009

koofers-user-vtw-1
koofers-user-vtw-1 🇺🇸

10 documents

1 / 33

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dataflow I:
Dataflow Analysis
EECS 483 – Lecture 23
University of Michigan
Monday, November 27, 2006
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21

Partial preview of the text

Download Dataflow Analysis: Liveness and Reaching Definitions in EECS 483 at University of Michigan and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

Dataflow I: Dataflow Analysis

EECS 483 – Lecture 23 University of Michigan Monday, November 27, 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 -

Dataflow Analysis Introduction

Pick an arbitrary point in the program Which VRs contain useful data values?(liveness or upward exposed uses)Which definitions may reachthis point? (reaching defns)Which definitions are guaranteedto reach this point? (available defns)Which uses below are exposed?(downward exposed uses)

r1 = r2 + r3r6 = r4 – r

r4 = 4r6 = 8

r6 = r2 + r3r7 = r4 – r

Dataflow analysis

  • Collection of information

that summarizes the creation/destruction of values in a program. Used to identify legal optimization opportunities.

  • 4 -

Live Variable (Liveness) Analysis

Defn: For each point p in a program and each variabley, determine whether y can be used before beingredefined starting at p

Algorithm sketch

» For each BB, y is live if it is used before defined in the BB or

it is live leaving the block

» Backward dataflow analysis as propagation occurs from uses

upwards to defs

4 sets

» USE = set of external variables consumed in the BB » DEF = set of variables defined in the BB » IN = set of variables that are live at the entry point of a BB » OUT = set of variables that are live at the exit point of a BB

  • 6 -

Compute USE/DEF Sets For Each BB

for

each basic block in the procedure, X, do

DEF(X) = 0 USE(X) = 0 for

each operation in sequential order in X, op, do

for

each source operand of op, src, do if

(src not in DEF(X)) then

USE(X) += src

endif

endfor for

each destination operand of op, dest, do DEF(X) += dest

endfor

endfor

endfor

def is the union of all the LHS’s use is all the VRs that are used before defined

Example USE/DEF Calculation

  • 9 -

Example IN/OUT Calculation

r1 = MEM[r2+0]

r2 = r2 + 1 r3 = r1 * r

r1 = r1 + 5 r3 = r5 – r

r7 = r3 * 2

r2 = 0

r7 = 23

r1 = 4

r8 = r7 + 5 r1 = r3 – r

r3 = r1 * 2

USE = r2,r4 DEF = r1,r2,r

USE =

DEF = r1,r2,r

USE = r1,r5 DEF = r1,r3,r

USE = r3,r7 DEF = r1,r3,r

  • 10 -

Class Problem

r1 = 3 r2 = r3r3 = r

r1 = r1 + 1 r7 = r1 * r

r2 = 0

r2 = r2 + 1

r4 = r2 + r1 r9 = r4 + r

Compute liveness, ie calculate USE/DEF calculate IN/OUT

  • 12 -

Reaching Defs Example

1: r1 = r2 + r32: r6 = r4 – r

3: r4 = 44: r6 = 8

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

defs 1 and 2 reach this point

defs 1, 3, 4 reach this point def 2 is killed by 4

defs 1, 3, 5, 6 reach this point defs 2, 4 are killed by 5

  • 13 -

Reaching Definition Analysis (rdefs)

™

Algorithm sketch

» Forward dataflow analysis as propagation

occurs from defs downwards

™

4 sets

» GEN = set of definitions generated in the BB

(operations not registers like liveness !!)

» KILL = set of definitions killed in the BB » IN = set of definitions reaching the BB entry » OUT = set of definitions reaching the BB exit

  • 15 -

Example Rdef GEN/KILL Calculation

1: r1 = MEM[r2+0]2: r2 = r2 + 13: r3 = r1 * r

4: r1 = r1 + 55: r3 = r5 – r16: r7 = r3 * 2

7: r2 = 08: r7 = 239: r1 = 4

10: r8 = r7 + 511: r1 = r3 – r812: r3 = r1 * 2

  • 16 -

Compute Rdef IN/OUT Sets for all BBs

initialize IN(X) = 0 for all basic blocks X initialize OUT(X) = GEN(X) for all basic blocks X change = 1 while

(change) do

change = 0 for

each basic block in procedure, X, do

old_OUT = OUT(X) IN(X) = Union(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

IN = set of definitions reaching the entry of BB OUT = set of definitions leaving BB

  • 18 -

Class Problem

1: r1 = 32: r2 = r33: r3 = r4 4: r1 = r1 + 15: r7 = r1 * r

6: r2 = 0

7: r2 = r2 + 1

8: r4 = r2 + r1 9: r9 = r4 + r

Reaching definitions

Calculate GEN/KILL Calculate IN/OUT

  • 19 -

DU/UD Chains

™

Convenient way to access/use reaching defsinfo

™

Def-Use chains

» Given a def, what are all the possible

consumers of the operand produced

» Maybe consumer

™

Use-Def chains

» Given a use, what are all the possible

producers of the operand consumed

» Maybe producer