Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data-flow Analysis: Reaching Definitions, Expressions, and Constants, Study notes of Computer Science

A lecture note from a cs553 course on generalizing data-flow analysis. Topics such as reaching definitions, available expressions, and reaching constants. It explains how to determine if a statement can be moved out of a loop based on reaching definitions, and discusses the definition and uses of reaching definitions, available expressions, and reaching constants. The document also touches upon the concept of common subexpression elimination (cse) and the importance of available expressions in this context.

Typology: Study notes

Pre 2010

Uploaded on 11/08/2009

koofers-user-jr2-2
koofers-user-jr2-2 🇺🇸

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS553 Lecture Generalizing Data-flow Analysis 1
Generalizing Data-flow Analysis
!Announcements
!Read Section 9.3 in the book
!Today
!Other types of data-flow analysis
!Reaching definitions, available expressions, reaching constants
!Abstracting data-flow analysis
What’s common among the different analyses?
CS553 Lecture Generalizing Data-flow Analysis 2
1 a = . . .;
2 b = . . .;
3 for (. . .) {
4 x = a + b;
5 . . .
6 }
To determine whether it’s legal to move statement 4
out of the loop, we need to ensure that there are no
reaching definitions of a or b inside the loop
Reaching Definitions
!Definition
!A definition (statement) d of a variable v reaches
node n if there is a path from d to n such that v is
not redefined along that path
!Uses of reaching definitions
!Build use/def chains
!Constant propagation
!Loop invariant code motion
v :=...
d
n
Reaching definitions of a and b
x := 5
d
n f(x)
Does this def of x reach n?
can we replace n with f(5)?
! def[v]
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Data-flow Analysis: Reaching Definitions, Expressions, and Constants and more Study notes Computer Science in PDF only on Docsity!

CS553 Lecture Generalizing Data-flow Analysis 1

Generalizing Data-flow Analysis

! Announcements

-! Read Section 9.3 in the book ! Today -! Other types of data-flow analysis -! Reaching definitions, available expressions, reaching constants -! Abstracting data-flow analysis What’s common among the different analyses? 1 a =.. .; 2 b =.. .; 3 for (.. .) { 4 x = a + b; 5... 6 } To determine whether it’s legal to move statement 4 out of the loop, we need to ensure that there are no reaching definitions of a or b inside the loop

Reaching Definitions

! Definition

-! A definition (statement) d of a variable v reaches node n if there is a path from d to n such that v is not redefined along that path ! Uses of reaching definitions -! Build use/def chains -! Constant propagation -! Loop invariant code motion d v :=... n Reaching definitions of a and b d x := 5 n (^) f(x) Does this def of x reach n? can we replace n with f(5)? ! def[v]

CS553 Lecture Generalizing Data-flow Analysis 3 ! Defining Gen and Kill for various statement types ! statement Gen[s] Kill[s] ! s: t = b op c {s} def[t] – {s} ! s: t = M[b] {s} def[t] – {s} ! s: M[a] = b {} {} ! s: if a op b goto L {} {} statement Gen[s] Kill[s] s: goto L {} {} s: L: {} {} s: f(a,…) {} {} s: t=f(a, …) {s} def[t] – {s}

Computing Reaching Definitions

! Assumption

-! At most one definition per node -! We can refer to definitions by their node “number” ! Gen[n]: Definitions that are generated by node n (at most one) Kill[n]: Definitions that are killed by node n

A Better Formulation of Reaching Definitions

! Problem

-! Reaching definitions gives you a set of definitions (nodes) -! Doesn’t tell you what variable is defined -! Expensive to find definitions of variable v ! Solution -! Reformulate to include variable e.g., Use a set of (var, def) pairs a (^) x= b y= n (^) in[n] = {(x,a),(y,b),...}

CS553 Lecture Generalizing Data-flow Analysis 7

Available Expressions for CSE

! How is this information useful? ! Common Subexpression Elimination (CSE)

  • !If an expression is available at a point where it is evaluated, it need not be recomputed ! Example (^3) c := 4 * i (^2) i := i + 1 t := 4 * i b := t (^1) i := j t := 4 * i a := t (^3) c := t (^1) i := j a := 4 * i (^2) i := i + 1 b := 4 * i guaranteed or possible forward or backward variables, definitions, ... universal or empty set due to semantics of stmt what is removed from set due to semantics of stmt what is added to set how sets from two control paths compose ! Must or may Information ! Direction ! Flow values ! Initial guess ! Kill ! Gen ! Merge

Aspects of Data-flow Analysis

CS553 Lecture Generalizing Data-flow Analysis 9

Must vs. May Information

! Must information

-! Implies a guarantee ! May information -! Identifies possibilities !!!!!!! !May Must safe overly large set overly small set desired information small set large set Gen add everything that add only facts that are might be true guaranteed to be true Kill remove only facts that remove everything that are guaranteed to be true might be false merge union intersection initial guess empty set universal set Liveness? Available expressions?

Reaching Definitions: Must or May Analysis?

! Consider uses of reaching definitions d x = 5 n (^) f(x) We need to know if d’ might reach node n d’ x = 4

CS553 Lecture Generalizing Data-flow Analysis 13

Reaching Constants Example

! Must or may info? ! Direction? ! Initial guess?

Reality Check!

! Some definitions and uses are ambiguous

-! We can’t tell whether or what variable is involved e.g., *p = x; / what variable are we assigning?! / -! Unambiguous assignments are called strong updates -! Ambiguous assignments are called weak updates ! Solutions -! Be conservative -! Sometimes we assume that it could be everything e.g., Defining *p (generating reaching definitions) -! Sometimes we assume that it is nothing e.g., Defining *p (killing reaching definitions) -! Try to figure it out: alias/pointer analysis (more later)

CS553 Lecture Generalizing Data-flow Analysis 15

Side Effects

! What happens at function calls?

-! For example, the call foo(&x) might use or define -! any local or heap variable x that has been passed by address/reference -! any global variable ! Solution -! How do we handle this for liveness used for register allocation? -! In general -! Be conservative: assume all globals and all vars passed by address/ reference may be used and/or modified -! Or Figure it out: calculate side effects (example of an interprocedural analysis)

Concepts

Data-flow analyses are distinguished by

-! Flow values (initial guess, type) -! May/must -! Direction -! Gen -! Kill -! Merge ! Complication -! Ambiguous references (strong/weak updates) -! Side effects