1 / 31

Foundations of Data-Flow Analysis

Foundations of Data-Flow Analysis. Basic Questions. Under what circumstances is the iterative algorithm used in the data-flow analysis correct ? How precise is the solution obtained by the iterative algorithm? Will the iterative algorithm converge ?

deidra
Télécharger la présentation

Foundations of Data-Flow Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Foundations of Data-Flow Analysis

  2. Basic Questions • Under what circumstances is the iterative algorithm used in the data-flow analysis correct? • How precise is the solution obtained by the iterative algorithm? • Will the iterative algorithm converge? • What is the meaning of the solution to the equations?

  3. Data-Flow Analysis Framework • A direction of the data flow D, which is either forwards or backwards • A semilattice, which includes a domain of values V and a meet operator • A family F of transfer functions from V to V. This family must include functions suitable for the boundary conditions, which are constant transfer functions for the special nodes ENTRY and EXIT in any control flow graph

  4. Example: Reaching Definitions • The direction: forwards • The domain of values: the set of subsets of the set of all definitions in the program • The meet operator: set union • The family of transfer functions: the set of transfer functions for various statements

  5. Semilattices • A semilattice is a set V and a binary meet operator  such that for all x, y, and z in V: • xx = x (meetis idempotent) • xy = y x(meetis commutative) • x(yz) = (x y)z(meetis associative) • A semilattice has a top element, denoted 丅, such that for all x in V, 丅 x = x • Optionally, a semilattice may have a bottom element, denoted , such that for all x in V, x = 

  6. Example: Reaching Definitions • The domain of values is the set of all subsets of the universal set U, or the power set of U, denoted 2U • The meet operator is the set union • The set union is idempotent, commutative, and associative • The top element is the empty set  • The bottom element is the universal set U

  7. Partial Orders • A relation  is a partial order on a set V if for all x, y, and z in V: • xx (the partial orderis reflexive) • Ifxyandy x, thenx = y (the partial orderis antisymmetric) • Ifxyandy z, thenxz(the partial orderis transitive) • The pair (V, ) is called a poset, or partially ordered set • We definex<yif and only ifxyandx y

  8. The Partial Order for a Semilattice • It is useful to define a partial order  for a semilattice (V, ). For all x and y in V, we define xyif and only ifxy = x •  is reflexive: xx = xxx •  is antisymmetric:xy xy = x, yx yx = y,x = (xy) = (yx) = y •  is transitive:xy xy = x, yz yz = y,(xz) = ((xy)z) = (x(yz )) = (xy) =x xz

  9. Example: Reaching Definitions • The relation  is the set inclusion xy = xxy • This says that sets larger in size is smaller in the partial order • The set inclusion is reflexive, antisymmetric, and transitive

  10. Greatest Lower Bounds • A greatest lower bound (or glb) of domain elements x and y is an element g such that • gx, • gy, and • If z is any element such that zx and zy, then zg

  11. Meet and Greatest Lower Bound • The meet of x and y is the greatest lower bound of x and y • Let g = xy • gx:gx= (xy)x= x(y x)= x(x y)= (xx)y = x y = g • gy • zx and zy zgzg= z(x y)= (zx)y= zy = z

  12. {d1} {d2} {d3} {d1, d2} {d2, d3} {d1, d3} {d1, d2, d3} Lattice Diagrams 丅 

  13. Product Lattices • The product lattice for lattices (A, A) and (B, B) is defined as follows: • The domain of the product lattice is A  B • The meet  for the product lattice: (a, b)  (a’, b’) = (a A a’, b B b’) • The partial order  for the product lattice: (a, b) (a’, b’) iff a A a’ and b B b’ • This definition can be extended to the product of any number of lattices

  14. Example 丅 ({},{},{}) ({d1},{},{}) ({},{d2},{}) ({},{},{d3}) ({d1},{d2},{}) ({d1},{},{d3}) ({},{d2},{d3}) ({d1}, {d2}, {d3}) 

  15. Height of a Semilattice • An ascending chain in a poset (V, ) is a sequence x1 < x2 < … < xn • The height of a semilattice is the largest number of < relations in any ascending chain • An iterative data flow analysis algorithm is convergent if the corresponding semilattice has finite height • A lattice consisting of a finite set of values will have a finite height • It is also possible for a lattice with an infinite number of values to have a finite height

  16. Transfer Functions • The family of transfer functions F: V  V in a data-flow framework has the following properties: • F has an identity function I, such that I(x) = x for all x in V • F is closed under composition; that is, for any two functions f and g in F, the function h defined by h(x) = g(f(x)) is in F

  17. Example: Reaching Definitions • The identity function: gen[B] = kill[B] =  • Closure under composition:f1(x) = G1 (x - K1),f2(x) = G2 (x - K2),f2(f1(x)) = G2 ((G1 (x - K1)) - K2) = (G2 (G1 - K2 ))  (x - (K1 K2)). Let G = G2 (G1 - K2 ) and K = K1 K2.f(x) = f2(f1(x)) = G  (x - K).

  18. Monotone Frameworks • A framework (D, F, V, ) is monotone ifx y implies f(x)  f(y),for all x andy in V, and f in F • Equivalently, a framework (D, F, V, ) is monotone iff(xy)  f(x) f(y), for all x andy in V, and f in F

  19. Proof of Equivalence () xy xandxy y f(xy)  f(x) andf(xy)  f(y) f(x)  f(y) is the glb of f(x) andf(y) f(xy)  f(x)  f(y) () xy xy= x  f(xy) = f(x)  f(x)  f(y)  f(y) f(x)  f(y)

  20. Distributive Frameworks • A framework (D, F, V, ) is distributive iff(xy) =f(x) f(y)for all x andy in V, and f in F • Distributivity implies monotonicity

  21. Example: Reaching Definitions Lety and z be sets of definitions, and f(x) = G (x - K) ThenG ((yz) - K) = (G (y- K))  (G (z- K))

  22. The Iterative Algorithm for General Frameworks: Input • A control flow graph, with specially labeled ENTRY and EXIT nodes, • A direction of the data flow D, • A set of values V, • A meet operator , • A set of functions F, where fB in F is the transfer function for basic block B, and • A constant value vENTRY or vEXIT in V, representing the boundary condition for forward and backward frameworks, respectively

  23. The Iterative Algorithm for General Frameworks: Output • Values in V for IN[B] and OUT[B] for each basic block B in the control flow graph

  24. The Iterative Algorithm for General Frameworks: Forward OUT[ENTRY] =vENTRY; for (each basic block B other thanENTRY) OUT[B] := 丅; while (changes to any OUT occur) for (each basic block B other thanENTRY) { IN[B] := p pred(B)OUT[p]; OUT[B] := fB(IN[B]); }

  25. The Iterative Algorithm for General Frameworks: Backward IN[EXIT] =vEXIT; for (each basic block B other thanEXIT) IN[B] := 丅; while (changes to any IN occur) for (each basic block B other thanEXIT) { OUT[B] := s  succ(B)IN[s]; IN[B] := fB(OUT[B]); }

  26. Properties of the Iterative Algorithm • If the algorithm converges, the result is a solution to the data-flow equations • If the framework is monotone, then the solution found is the maximum fixedpoint (MFP) of the data-flow equations. The maximum fixedpoint is a solution with the property that in any other solution, the value of IN[B] and OUT[B] are  the corresponding values of MFP • If the semilattice of the framework is monotone and finite height, then the algorithm is guaranteed to converge

  27. The Ideal Solution • Consider any pathP = ENTRY  B1 …  Bk-1 Bk • The transfer function for P isfP = fBk-1(fBk-2 ( … (fB1) … )) • The ideal solution isIDEAL[B] = Ppossible paths from ENTRY to BfP(vENTRY) • Any answer that is greater than IDEAL is incorrect • Any value smaller than or equal to IDEAL is conservative, i.e., safe

  28. The Meet-Over-Paths Solution • Finding all possible paths is undecidable • The meet-over-paths solution is MOP[B] = P  paths from ENTRY to BfP(vENTRY) • The paths considered in the MOP solution is a superset of all the paths that are possibly executed • MOP[B]  IDEAL[B]

  29. MFP Solution versus MOP Solution • The iterative algorithm visits basic blocks, not necessarily in the order of execution • At each confluence point, the algorithm applies the meet operator to the data-flow values obtained so far. Some of these values used were introduced artificially in the initialization process, not representing the result of any execution from the beginning of the program

  30. Early Meet over Paths ENTRY B1 B2 B3 B4 MOP[B4] = ((f B3 f B1)  (f B3 f B2))(vENTRY) IN[B4] = f B3((f B1 (vENTRY)f B2 (vENTRY)))

  31. Comparison of Solutions • Using the iterative algorithm, we have IN[B]  MOP[B]for monotone frameworks and IN[B] =MOP[B]for distributive frameworks • MFP  MOP  IDEAL

More Related