Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structural Data-flow Analysis Algorithms: Allen-Cocke Interval Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students.

Similar presentations


Presentation on theme: "Structural Data-flow Analysis Algorithms: Allen-Cocke Interval Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students."— Presentation transcript:

1 Structural Data-flow Analysis Algorithms: Allen-Cocke Interval Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission to make copies of these materials for their personal use. Faculty from other educational institutions may use these materials for nonprofit educational purposes, provided this copyright notice is preserved. Comp 512 Spring 2011

2 COMP 512, Rice University2 Structural Data-flow Analysis While strong arguments favor iterative data-flow analysis, you should be aware of the other methods proposed in the literature, in part because they offer insight into the problems and techniques of analysis, and in part because they are, in some situations, techniques that merit serious consideration. Structural Data-flow Algorithms  Interval analysis, T1-T2, Balanced-tree path compression,  All of these follow a reduction-expansion discipline  Partitioned variable technique  Operates on a variable-by-variable basis  These methods rely on structural analysis of the CFG to choose an evaluation order for the data-flow equations We will focus on Allen-Cocke Interval Analysis  F.E. Allen and J. Cocke, “A Program Data Flow Analysis Procedure”, Comm. ACM, 19(3), March 1976, pp. 137—147  Kennedy’s “Survey of Data Flow Analysis Techniques”

3 COMP 512, Rice University3 Background Material Definitions Interval: an interval I(h) in a control-flow graph is a maximal, single entry subgraph in which h is the only entry to I(h) and all closed paths in I(h) contain h. Interval header: h, in I(h), is the sole entry point of the interval and is called the interval header By selecting the proper set of interval headers, a CFG can be partitioned into a unique set of disjoint intervals.

4 COMP 512, Rice University4 Finding Intervals A simple algorithm finds the “right” set of intervals & headers Order of H and each I(h) is important — “interval order” H  n 0 while (H  Ø) do remove next h from H /* create interval h */ create I(h) I(h)  { h } while  n  N s.t. n  I(h) /* build the interval */ I(h)  I(h) + n while  n  N s.t. n  I(h) and /* find next headers */  m  preds(n) s.t. m  I(h) H  H + n + creates an ordered set

5 COMP 512, Rice University5 Example 1 2 3 4 6 7 8 5 HeaderInterval 11 22 33456 778 Notice that taking intervals in order (1,2,3,7) and following the order of creation within each interval produces an order with the same effects as reverse postorder (look at I(3) )

6 COMP 512, Rice University6 Interval Derived Graphs Replacing each interval with a single node, we derive a new graph 1 2 9 10 1 2 3 4 6 7 8 5 If we call the original graph our first graph, G 1, then this graph is the second graph, G 2. HeaderInterval 11 22 9 10

7 COMP 512, Rice University7 Interval Derived Graphs Continuing the process, … 1 2 9 10 HeaderInterval 11 11 1 11 G2G2 G3G3 And, of course, G 4 is a single node 1 G4G4

8 COMP 512, Rice University8 Derived Sequence of Interval Graphs 1 2 9 10 1 11 G2G2 G3G3 1 G4G4 1 2 3 4 6 7 8 5 G1G1 This sequence of graphs establish that G 1 is “reducible” — that is, it reduces to a single node Allen & Cocke envision a system where we derive the set of interval graphs as a first step in analysis We can then use the interval graphs to choose an evaluation order for the data-flow equations The same interval graphs can be used to solve many data-flow problems

9 COMP 512, Rice University9 Computing Available Expressions For interval analysis, we need to reformulate the equations in a straight-forward way In the iterative framework, we used a single equation: A VAIL (b) =  x  pred(b) (D E E XPR (x)  (A VAIL (x)  E XPR K ILL (x) )) where preds(b) is the set of b’s predecessors in the control-flow graph In the interval analysis framework, we use two equations A VAIL A T N ODE (n) =  e=(m,n)  E A VAIL (e) A VAIL (e =(m,n) ) = D E E XPR (m)  (A VAIL A T N ODE (m)  E XPR K ILL (m) ))

10 COMP 512, Rice University10 The Big Picture — Phase 1: Local to Global 1 2 3 4 6 7 8 5 G1G1 Step 1:Compute initial sets DEE XPR and E XPR K ILL for each node in G 1

11 COMP 512, Rice University11 1 2 3 4 6 7 8 5 G1G1 Step 1:Compute initial sets DEE XPR and E XPR K ILL for each node in G 1 Step 2: Compute AVAIL for each interval exit edge and each internal edge that enters interval’s header The Big Picture — Phase 1: Local to Global

12 COMP 512, Rice University12 1 2 9 10 G2G2 1 2 3 4 6 7 8 5 G1G1 Step 1:Compute initial sets DEE XPR and E XPR K ILL for each node in G 1 Step 2: Compute A VAIL for each interval exit edge and each internal edge that enters interval’s header Step 3: Map constants from intervals in G 1 to nodes in G 2 and A VAIL sets from exit edges in G 1 to corresponding edges in G 2 The Big Picture — Phase 1: Local to Global

13 COMP 512, Rice University13 1 2 9 10 G2G2 1 2 3 4 6 7 8 5 G1G1 Step 1:Compute initial sets DEE XPR and E XPR K ILL for each node in G 1 Step 2: Compute A VAIL for each interval exit edge and each internal edge that enters interval’s header Step 3: Map constants from intervals in G 1 to nodes in G 2 and A VAIL sets from exit edges in G 1 to corresponding edges in G 2 The Big Picture — Phase 1: Local to Global

14 COMP 512, Rice University14 1 2 9 10 1 11 G2G2 G3G3 1 G4G4 1 2 3 4 6 7 8 5 G1G1 Step 2: Compute A VAIL for each interval exit edge and each internal edge that enters interval’s header Step 3: Map constants from intervals in G 1 to nodes in G 2 and A VAIL sets from exit edges in G 1 to corresponding edges in G 2 Repeat steps 2 & 3 for successive derived graphs The Big Picture — Phase 1: Local to Global

15 COMP 512, Rice University15 1 2 9 10 1 11 G2G2 G3G3 1 G4G4 1 2 3 4 6 7 8 5 G1G1 Step 1: Map A VAIL A T N ODE sets from nodes in G 4 to interval heads G 3 Step 2: Using constants, and AVAIL sets from phase 1 plus A VAIL A T N ODE for interval headers, solve for AVAIL at each node and edge in intervals The Big Picture — Phase 2: Global to Local

16 COMP 512, Rice University16 1 2 9 10 1 11 G2G2 G3G3 1 G4G4 1 2 3 4 6 7 8 5 G1G1 The Big Picture — Phase 2: Global to Local Step 1: Map A VAIL A T N ODE sets from nodes in G 4 to interval heads G 3 Step 2: Using constants, and AVAIL sets from phase 1 plus A VAIL A T N ODE for interval headers, solve for AVAIL at each node and edge in intervals Repeat steps 1 & 2 until we solve G 1

17 COMP 512, Rice University17 Solving the Equations Phase 1 & Phase 2 solve local equations on acyclic subgraphs Make a single pass, in interval order, over each interval in each derived graph  Interval order has same effect as reverse postorder  Solver runs innermost loop to outermost loop  Avoids some unproductive set operations  Why compute outer loops when solving for inner loops?  Fewer total set operations than iterative algorithm Number of derived graphs, k, is related to loop nesting  Hecht showed that k  d(G ) Graph manipulation & set mapping G i to G k incur some costs

18 COMP 512, Rice University18 Interval Analysis — The Three Questions Termination  Interval construction halts (if graph is reducible; more later)  Phases 1 & 2 perform fixed steps on each derived graph Correctness  Allen & Cocke studied underpinnings of the graph theory  Don’t say much about theory of the problems & frameworks  Clearly works for Kam-Ullman rapid problems (classic DFA )  More complex problems need a closure in cyclic intervals  Result due to Rosen (1980-1982)  Similar issue arises in other structural frameworks (Tarjan, GW) Speed  Interval depth determines number of derived graphs  # of set operations is comparable to iterative for rapid prob’s  Add closure computation for non-rapid problems Interval Sequence Length  d(G), Hecht & Ullman 1975.

19 COMP 512, Rice University19 What About Procedures with Irreducible Graphs? Most CFGs are reducible, but we must handle those that are not Allen & Cocke suggest “node splitting” & give an example Papers always make this transformation look easy Handling arbitrary irreducible graphs is hard  Interval analysis simplifies the issue by reducing all irreducible graphs to an interval like our example  Reduce the interval graph that makes the problem easy 1 32 1 3 2 3’ The interval {2,3} now has a single entry. Can change CFG for analysis without rewriting the code (unless change enables some optimization). Alternative is to iterate over irreducible intervals Interval construction finds only single node intervals

20 COMP 512, Rice University20 Perspective Having the set of derived interval graphs is useful for other optimization purposes L ICM, O SR, copy folding, & others work better inner to outer  Process most-frequent instances first  Build more accurate cost models for traces & such Global optimizations ( PRE, RA ) don’t benefit from loop structure  But, fast global DFA helps both of them … Extensive work on how to incrementally update the solution to interval-derived answers to data-flow problems in response to changes in facts & in graph structure  Editing procedures with whole-program compilation  Carroll & Ryder, T OPLAS, Jan. 1987; Burke, T OPLAS, July 1990  Not easy to do incremental update in an iterative framework  Delete one edge in a graph with complex cyles  Now, find its former effects… STOP

21 End of Lecture Extra Slides Start Here COMP 512, Rice University21

22 COMP 512, Rice University22 The Big Picture 1 2 9 10 1 11 G2G2 G3G3 1 G4G4 1 2 3 4 6 7 8 5 G1G1

23 COMP 512, Rice University23 Background Material Reaching Definitions: A definition, d reaches a use u, if  a path from d to u that does not redefine the name defined in d R EACHES (n) = Ø,  nodes n R EACHES (n) =  p  preds(n) (DED EF (p)  (R EACHES (p)  D EF K ILL (p) ) To simplify the formulation of the algorithm, we will factor the system of equations into a set of available definitions on each edge and a set of reaching definitions for each block R EACHES (n) =  e= (n,m )  E A VAIL D EFS (e) A VAIL D EFS (e =(n,m) ) = (DED EF (m)  (R EACHES (m)  D EF K ILL (m) )


Download ppt "Structural Data-flow Analysis Algorithms: Allen-Cocke Interval Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students."

Similar presentations


Ads by Google