lattice theoretic framework for data flow analysis
play

Lattice-Theoretic Framework for Data-Flow Analysis Last time - PDF document

Lattice-Theoretic Framework for Data-Flow Analysis Last time Generalizing data-flow analysis Today Introduce lattice-theoretic frameworks for data-flow analysis CS553 Lecture Lattice Theoretic Framework for DFA 1 Context


  1. Lattice-Theoretic Framework for Data-Flow Analysis � Last time – � Generalizing data-flow analysis � Today – � Introduce lattice-theoretic frameworks for data-flow analysis CS553 Lecture Lattice Theoretic Framework for DFA 1 Context for Lattice-Theoretic Framework � Goals – � Provide a single formal model that describes all data-flow analyses – � Formalize the notions of “correct,” “conservative,” and “optimistic” – � Correctness proof for IDFA (iterative data-flow analysis) – � Place bounds on time complexity of data-flow analysis � Approach – � Define domain of program properties (flow values) computed by data- flow analysis, and organize the domain of elements as a lattice – � Define flow functions and a merge function over this domain using lattice operations – � Exploit lattice theory in achieving goals CS553 Lecture Lattice Theoretic Framework for DFA 2

  2. Lattices {} � Define lattice L = (V, ! ) – � V is a set of elements of the lattice {i} {j} {k} – � ! is a binary relation over the elements of V ( meet or greatest lower bound ) {i,j} {i,k} {j,k} {i,j,k} � Properties of ! – � x,y � V � x ! y � V (closure) – � x � V � x ! x = x (idempotence) – � x,y � V � x ! y = y ! x (commutativity) – � x,y,z � V � (x ! y) ! z = x ! (y ! z) (associativity) CS553 Lecture Lattice Theoretic Framework for DFA 3 Lattices (cont) ! = {} � Under ( " ) – � Imposes a partial order on V {i} {j} {k} – � x " y � x ! y = x {i,j} {i,k} {j,k} � Top ( ! ) – � A unique “greatest” element of V (if it exists) � = {i,j,k} – � � x � V – { ! }, x " ! � Bottom ( � ) – � A unique “least” element of V (if it exists) – � � x � V – { � }, � " x � Height of lattice L – � The longest path through the partial order from greatest to least element (top to bottom) CS553 Lecture Lattice Theoretic Framework for DFA 4

  3. Data-Flow Analysis via Lattices � Relationship – � Elements of the lattice (V) represent flow values (in[] and out[] sets) – � e.g ., Sets of live variables for liveness – � ! represents “best-case” information (initial flow value) – � e.g ., Empty set {} – � � represents “worst-case” information – � e.g ., Universal set {i} {j} {k} – � ! (meet) merges flow values {i,j} {i,k} {j,k} – � e.g ., Set union – � If x " y, then x is a conservative approximation of y {i,j,k} – � e.g ., Superset CS553 Lecture Lattice Theoretic Framework for DFA 5 Data-Flow Analysis via Lattices (cont) � Remember what these flow values represent – � At each program point a lattice element represents {} an in[] set or an out[] set {x} {y} { } Initially x = y { } {x,y} { } { } print(x) print(y) { } { } { y } Finally x = y { x,y } { x } { y } print(x) print(y) { } { } CS553 Lecture Lattice Theoretic Framework for DFA 6

  4. Data-Flow Analysis Frameworks � Data-flow analysis framework – � A set of flow values (V) – � A binary meet operator ( ! ) – � A set of flow functions (F) (also known as transfer functions ) � Flow Functions – � F = {f: V � V} f describes how each node in CFG affects the flow values – � Flow functions map program behavior onto lattices CS553 Lecture Lattice Theoretic Framework for DFA 7 Visualizing DFA Frameworks as Lattices Example : Liveness analysis with 3 variables U = {v1, v2, v3} � = ! – � V: 2 S = {{v1,v2,v3}, � {v1,v2},{v1,v3},{v2,v3}, { v1 } { v2 } {v1},{v2},{v3}, � } { v3 } – � Meet ( ! ): � � – � " : � ! { v2,v3 } { v1,v2 } { v1,v3 } � – � Top( T ): � � – � Bottom ( � ): U � { v1,v2,v3 } = � { f n (X) = Gen n � (X – Kill n ), � n } – � F: � Inferior solutions are lower on the lattice More conservative solutions are lower on the lattice CS553 Lecture Lattice Theoretic Framework for DFA 8

  5. Lattice Example � What are the data-flow sets for liveness? � What is the meet operation for liveness? � What partial order does the meet operation induce? � What is the liveness lattice for this example? CS553 Lecture Lattice Theoretic Framework for DFA 9 Recall Liveness Analysis � Data-flow equations for liveness � in[n] = use [n] � (out[n] – def [n]) � out[n] = � in[s] s � succ[n] Liveness equations in terms of Gen and Kill � in[n] = gen [n] � (out[n] – kill [n]) A use of a variable generates liveness A def of a variable kills liveness � out[n] = � in[s] s � succ[n] � Gen: New information that’s added at a node � Kill: Old information that’s removed at a node � Can define many data-flow analysis in terms of Gen and Kill CS553 Lecture Lattice Theoretic Framework for DFA 10

  6. Reaching Constants (aka Constant Propagation) � Goal – � Compute value of each variable at each program point (if possible) � Flow values – � Set of (variable,constant) pairs � Merge function – � Intersection � Data-flow equations – � Effect of node n x = c – � kill[n] = {(x,d)| � d} – � gen[n] = {(x,c)} – � Effect of node n x = y + z – � kill[n] = {(x,c)| � c} – � gen[n] = {(x,c) | c=val(y)+valz, (y, valy) � in[n], (z, valz) � in[n]} CS553 Lecture Generalizing Data-flow Analysis 11 Direction of Flow � Backward data-flow analysis – � Information at a node is based on what happens later in the flow graph i.e., in[] is defined in terms of out[] n in[n] = gen[n] � (out[n] – kill[n]) in � liveness out[n] = � in[s] out � s � succ[n] � Forward data-flow analysis – � Information at a node is based on what happens earlier in the flow graph i.e., out[] is defined in terms of in[] n in[n] = � out[p] in reaching � p � pred[n] out[n] = gen[n] � (in[n] – kill[n]) definitions out � � Some problems need both forward and backward analysis – � e.g., Partial redundancy elimination (uncommon) CS553 Lecture Lattice Theoretic Framework for DFA 12

  7. More Examples � Reaching Constants � Reaching definitions – � V: 2 v � c , variables v and – � V: � 2 S (S = set of all defs) � constants c – � ! : � � – � ! : � � � – � " : � ! – � " : � � � – � Top( ! ): � � U – � Top( ! ): � – � Bottom ( � ): U � � – � Bottom ( � ): � – � F: . . . � – � F: . . . � CS553 Lecture Lattice Theoretic Framework for DFA 13 Merging Flow Values � Live variables and reaching definitions – � Merge flow values via set union Reaching Definitions Live Variables in[n] = � out[s] out[n] = � in[s] � � p � pred[n] s � succ[n] out[n] = gen[n] � (in[n] – kill[n]) in[n] = gen[n] � (out[n] – kill[n]) � � � Why? � When might this be inappropriate? CS553 Lecture Lattice Theoretic Framework for DFA 14

  8. Reaching Defs Example � What is the lattice? � What is the initial guess? � What is the meet operation? CS553 Lecture Lattice Theoretic Framework for DFA 15 Available Expressions Iterative Algorithm Data-Flow Equations in[n] = � out[p] p � pred[n] out[n] = gen[n] � (in[n] – kill[n]) Plug it in to our general DFA algorithm for each node n in[n] = U; out[n] = U repeat for each n in � [n] = in[n] out � [n] = out[n] in[n] = � out[p] p � pred[n] out[n] = gen[n] � (in[n] – kill[n]) until in � [n]=in[n] and out � [n]=out[n] for all n CS553 Lecture Lattice Theoretic Framework for DFA 16

  9. Available Expressions Example � What is the initial guess? � What is the meet operation? � What does the lattice look like? CS553 Lecture Lattice Theoretic Framework for DFA 17 Solving Data-Flow Analyses � Goal – � For a forward problem, consider all paths from the v entry entry to a given program point, compute the flow values at the end of each path, and then meet these entry values together – � Meet-over-all-paths (MOP) solution at each program point – � ! all paths n1, n2, ..., ni (f ni (...f n2 (f n1 (v entry )))) CS553 Lecture Lattice Theoretic Framework for DFA 18

  10. Solving Data-Flow Analyses (cont) � Problems – � Loops result in an infinite number of paths – � Statements following merge must be analyzed for all preceding paths – � Exponential blow-up � Solution – � Compute meets early (at merge points) rather than at the end – � Maximum fixed-point (MFP) � Questions – � Is this correct? – � Is this efficient? – � Is this accurate? CS553 Lecture Lattice Theoretic Framework for DFA 19 Correctness � “Is v MFP correct?” � “Is v MFP " v MOP ?” p2 p1 v p1 v p2 � Look at Merges F r � v MOP = F r (v p1 ) ! F r (v p2 ) v MFP v MOP � v MFP = F r (v p1 ! v p2 ) � v MFP " v MOP � F r (v p1 ! v p2 ) " F r (v p1 ) ! F r (v p2 ) � Observation � x,y � V f(x ! y) " f(x) ! f(y) � x " y � f(x) " f(y) � � v MFP correct when F r (really, the flow functions) are monotonic CS553 Lecture Lattice Theoretic Framework for DFA 20

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend