





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 9
This page cannot be seen from the preview
Don't miss anything!
CS553 Lecture Generalizing Data-flow Analysis 1
! 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
! 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}
! 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
! 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
! How is this information useful? ! Common Subexpression Elimination (CSE)
CS553 Lecture Generalizing Data-flow Analysis 9
! 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?
! 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
! Must or may info? ! Direction? ! Initial guess?
! 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
! 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)
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