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

Slides:



Advertisements
Similar presentations
Operator Strength Reduction From Cooper, Simpson, & Vick, “Operator Strength Reduction”, ACM TOPLAS, 23(5), See also § of EaC2e. 1COMP 512,
Advertisements

Lecture 11: Code Optimization CS 540 George Mason University.
Jeffrey D. Ullman Stanford University. 2  A set of nodes N and edges E is a region if: 1.There is a header h in N that dominates all nodes in N. 2.If.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Dataflow Analysis Introduction Guo, Yao Part of the slides are adapted from.
A Deeper Look at Data-flow Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University.
Code Motion of Control Structures From the paper by Cytron, Lowry, and Zadeck, COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda.
SSA-Based Constant Propagation, SCP, SCCP, & the Issue of Combining Optimizations 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon,
The Last Lecture Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission.
Lazy Code Motion Comp 512 Spring 2011
Partial Redundancy Elimination & Lazy Code Motion
Lazy Code Motion C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
Jeffrey D. Ullman Stanford University Flow Graph Theory.
Introduction to Code Optimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Lecture 2 Emery Berger University of.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Scheduling II: Beyond Basic Blocks Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
1 Region-Based Data Flow Analysis. 2 Loops Loops in programs deserve special treatment Because programs spend most of their time executing loops, improving.
Global Common Subexpression Elimination with Data-flow Analysis Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Code Optimization, Part III Global Methods Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Introduction to Optimization, II Value Numbering & Larger Scopes Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Using SSA Dead Code Elimination & Constant Propagation C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
Operator Strength Reduction C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
Building SSA Form, III 1COMP 512, Rice University This lecture presents the problems inherent in out- of-SSA translation and some ways to solve them. Copyright.
Top Down Parsing - Part I Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Proliferation of Data-flow Problems Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University.
12/5/2002© 2002 Hal Perkins & UW CSER-1 CSE 582 – Compilers Data-flow Analysis Hal Perkins Autumn 2002.
Global Redundancy Elimination: Computing Available Expressions Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Cleaning up the CFG Eliminating useless nodes & edges C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
Data-Flow Analysis (Chapter 8). Outline What is Data-Flow Analysis? Structure of an optimizing compiler An example: Reaching Definitions Basic Concepts:
Terminology, Principles, and Concerns, III With examples from DOM (Ch 9) and DVNT (Ch 10) Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved.
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
Boolean & Relational Values Control-flow Constructs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
Cleaning up the CFG Eliminating useless nodes & edges This lecture describes the algorithm Clean, presented in Chapter 10 of EaC2e. The algorithm is due.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Iterative Data-flow Analysis C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
Building SSA Form, I 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Data flow analysis John Cavazos University.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Definition-Use Chains
Introduction to Optimization
Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm
Introduction to Optimization
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Control Flow Analysis CS 4501 Baishakhi Ray.
Code Optimization Chapter 10
Code Optimization Chapter 9 (1st ed. Ch.10)
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
Building SSA Form COMP 512 Rice University Houston, Texas Fall 2003
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Code Shape III Booleans, Relationals, & Control flow
Optimization through Redundancy Elimination: Value Numbering at Different Scopes COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Control Flow Analysis (Chapter 7)
Interval Partitioning of a Flow Graph
Introduction to Optimization
Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Algebraic Reassociation of Expressions COMP 512 Rice University Houston, Texas Fall 2003 P. Briggs & K.D. Cooper, “Effective Partial Redundancy Elimination,”
The Partitioning Algorithm for Detecting Congruent Expressions COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper.
Presentation transcript:

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

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”

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.

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

COMP 512, Rice University5 Example HeaderInterval 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) )

COMP 512, Rice University6 Interval Derived Graphs Replacing each interval with a single node, we derive a new graph If we call the original graph our first graph, G 1, then this graph is the second graph, G 2. HeaderInterval

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

COMP 512, Rice University8 Derived Sequence of Interval Graphs G2G2 G3G3 1 G4G 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

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) ))

COMP 512, Rice University10 The Big Picture — Phase 1: Local to Global G1G1 Step 1:Compute initial sets DEE XPR and E XPR K ILL for each node in G 1

COMP 512, Rice University 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

COMP 512, Rice University G2G 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

COMP 512, Rice University G2G 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

COMP 512, Rice University G2G2 G3G3 1 G4G 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

COMP 512, Rice University G2G2 G3G3 1 G4G 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

COMP 512, Rice University G2G2 G3G3 1 G4G 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

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

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 ( )  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.

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 ’ 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

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

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

COMP 512, Rice University22 The Big Picture G2G2 G3G3 1 G4G G1G1

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) )