1 Data-Flow Frameworks Lattice-Theoretic Formulation Meet-Over-Paths Solution Monotonicity/Distributivity.

Slides:



Advertisements
Similar presentations
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Advertisements

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.
Data Flow Analysis. Goal: make assertions about the data usage in a program Use these assertions to determine if and when optimizations are legal Local:
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
1 Introduction to Data Flow Analysis. 2 Data Flow Analysis Construct representations for the structure of flow-of-data of programs based on the structure.
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.
1 CS 201 Compiler Construction Data Flow Framework.
Partial Redundancy Elimination. Partial-Redundancy Elimination Minimize the number of expression evaluations By moving around the places where an expression.
1 Data flow analysis Goal : collect information about how a procedure manipulates its data This information is used in various optimizations For example,
Foundations of Data-Flow Analysis. Basic Questions Under what circumstances is the iterative algorithm used in the data-flow analysis correct? How precise.
1 Data flow analysis Goal : –collect information about how a procedure manipulates its data This information is used in various optimizations –For example,
1 Constant Propagation A More Complex Semilattice A Nondistributive Framework.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Data Flow Analysis Compiler Design Nov. 3, 2005.
From last time: reaching definitions For each use of a variable, determine what assignments could have set the value being read from the variable Information.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
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.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs, Data-flow Analysis Data-flow Frameworks --- today’s.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Data flow analysis Emery Berger University.
1 CS 201 Compiler Construction Lecture 4 Data Flow Framework.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
From last lecture We want to find a fixed point of F, that is to say a map m such that m = F(m) Define ?, which is ? lifted to be a map: ? = e. ? Compute.
Ben Livshits Based in part of Stanford class slides from
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis: Data-flow frameworks –Classic.
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
Constant Propagation. The constant propagation framework is different from all the data-flow problems discussed so far, in that It has an unbounded set.
1 Region-Based Data Flow Analysis. 2 Loops Loops in programs deserve special treatment Because programs spend most of their time executing loops, improving.
1 CS 201 Compiler Construction Data Flow Analysis.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
1 Data-Flow Analysis Proving Little Theorems Data-Flow Equations Major Examples.
Data Flow Analysis. 2 Source code parsed to produce AST AST transformed to CFG Data flow analysis operates on control flow graph (and other intermediate.
MIT Foundations of Dataflow Analysis Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
Solving fixpoint equations
Machine-Independent Optimizations Ⅱ CS308 Compiler Theory1.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
Jeffrey D. Ullman Stanford University. 2 boolean x = true; while (x) {... // no change to x }  Doesn’t terminate.  Proof: only assignment to x is at.
Global Redundancy Elimination: Computing Available Expressions Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
A Logic of Partially Satisfied Constraints Nic Wilson Cork Constraint Computation Centre Computer Science, UCC.
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Data Flow Analysis Extensions & Foundations.
Compilation Lecture 8 Abstract Interpretation Noam Rinetzky 1.
Compiler Principles Fall Compiler Principles Lecture 11: Loop Optimizations Roman Manevich Ben-Gurion University.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis: Data-flow frameworks –Classic.
Data Flow Analysis II AModel Checking and Abstract Interpretation Feb. 2, 2011.
Semilattices presented by Niko Simonson, CSS 548, Autumn 2012 Semilattice City, © 2009 Nora Shader.
Iterative Dataflow Problems Taken largely from notes of Alex Aiken (UC Berkeley) and Martin Rinard (MIT) Dataflow information used in optimization Several.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Week 8 - Wednesday.  What did we talk about last time?  Relations  Properties of relations  Reflexive  Symmetric  Transitive.
Compiler Principles Fall Compiler Principles Lecture 9: Dataflow & Optimizations 2 Roman Manevich Ben-Gurion University of the Negev.
Code Optimization Data Flow Analysis. Data Flow Analysis (DFA)  General framework  Can be used for various optimization goals  Some terms  Basic block.
DFA foundations Simone Campanoni
Lecture 5 Partial Redundancy Elimination
Simone Campanoni DFA foundations Simone Campanoni
CSC D70: Compiler Optimization Dataflow-2 and Loops
Dataflow Testing G. Rothermel.
CSC D70: Compiler Optimization Dataflow Analysis
Advanced Compiler Techniques
1. Reaching Definitions Definition d of variable v: a statement d that assigns a value to v. Use of variable v: reference to value of v in an expression.
Fall Compiler Principles Lecture 10: Global Optimizations
Data Flow Analysis Compiler Design
Lecture 20: Dataflow Analysis Frameworks 11 Mar 02
Static Single Assignment
Presentation transcript:

1 Data-Flow Frameworks Lattice-Theoretic Formulation Meet-Over-Paths Solution Monotonicity/Distributivity

2 Data-Flow Analysis Frameworks uGeneralizes and unifies each of the DFA examples from previous lecture. uImportant components: 1.Direction D: forward or backward. 2.Domain V (possible values for IN, OUT). 3.Meet operator ∧ (effect of path confluence). 4.Transfer functions F (effect of passing through a basic block).

3 Gary Kildall uThis theory was the thesis at U. Wash. of Gary Kildall. uGary is better known for CP/M, the first real PC operating system. uThere is an interesting story. wGoogle query: kildall cpm wwww.freeenterpriseland.com/BOOK /KILDALL.html

4 Semilattices  V and ∧ form a semilattice if for all x, y, and z in V: 1.x ∧ x = x (idempotence ). 2.x ∧ y = y ∧ x (commutativity ). 3.x ∧ (y ∧ z) = (x ∧ y) ∧ z (associativity ). 4.Top element ⊤ such that for all x, ⊤∧ x = x. 5.Bottom element (optional) ⊥ such that for all x, ⊥ ∧ x = ⊥.

5 Example: Semilattice u V = power set of some set.  ∧ = union.  Union is idempotent, commutative, and associative. uWhat are the top and bottom elements?

6 Partial Order for a Semilattice  Say x ≤ y iff x ∧ y = x.  Also, x < y iff x ≤ y and x ≠ y.  ≤ is really a partial order: 1.x ≤ y and y ≤ z imply x ≤ z (proof in text). 2.x ≤ y and y ≤ x iff x = y. Proof: x ∧ y = x and y ∧ x = y. Thus, x = x ∧ y = y ∧ x = y.

7 Axioms for Transfer Functions 1.F includes the identity function. wWhy needed? Constructions often require introduction of an empty block. 2.F is closed under composition. wWhy needed? The concatenation of two blocks is a block. Transfer function for a block can be constructed from individual statements.

8 Good News! uThe problems from the last lecture fit the model. wRD’s: Forward, meet = union, transfer functions based on Gen and Kill. wAE’s: Forward, meet = intersection, transfer functions based on Gen and Kill. wLV’s: Backward, meet = union, transfer functions based on Use and Def.

9 Example: Reaching Definitions uDirection D = forward. uDomain V = set of all sets of definitions in the flow graph.  ∧ = union.  Functions F = all “gen-kill” functions of the form f(x) = (x - K) ∪ G, where K and G are sets of definitions (members of V).

10 Example: Satisfies Axioms uUnion on a power set forms a semilattice (idempotent, commutative, associative).  Identity function: let K = G = ∅. uComposition: A little algebra.

11 Example: Partial Order  For RD’s, S ≤ T means S ∪ T = S.  Equivalently S ⊇ T. wSeems “backward,” but that’s what the definitions give you.  Intuition: ≤ measures “ignorance.” wThe more definitions we know about, the less ignorance we have.  ⊤ = “total ignorance.”

12 DFA Frameworks  (D, V, ∧, F). uA flow graph, with an associated function f B in F for each block B. uA boundary value v ENTRY or v EXIT if D = forward or backward, respectively.

13 Iterative Algorithm (Forward) OUT[entry] = v ENTRY ; for (other blocks B) OUT[B] = ⊤ ; while (changes to any OUT) for (each block B) { IN(B) = ∧ predecessors P of B OUT(P); OUT(B) = f B (IN(B)); }

14 Iterative Algorithm (Backward) uSame thing --- just: 1.Swap IN and OUT everywhere. 2.Replace entry by exit.

15 What Does the Iterative Algorithm Do? uMFP (maximal fixedpoint ) = result of iterative algorithm. uMOP = meet over all paths from entry to a given point, of the transfer function along that path applied to v ENTRY. uIDEAL = ideal solution = meet over all executable paths from entry to a point.

16 Transfer Function of a Path f1f1 f2f2 f n-1 B... f n-1 (...f 2 (f 1 (v ENTRY ))...)

17 Maximum Fixedpoint uFixedpoint = solution to the equations used in iteration: IN(B) = ∧ predecessors P of B OUT(P); OUT(B) = f B (IN(B));  Maximum = any other solution is ≤ the result of the iterative algorithm (MFP).

18 MOP and IDEAL uAll solutions are really meets of the result of starting with v ENTRY and following some set of paths to the point in question. uIf we don’t include at least the IDEAL paths, we have an error. uBut try not to include too many more. wLess “ignorance,” but we “know too much.”

19 MOP Versus IDEAL --- (1)  At each block B, MOP[B] ≤ IDEAL[B].  I.e., the meet over many paths is ≤ the meet over a subset.  Example: x ∧ y ∧ z ≤ x ∧ y because x ∧ y ∧ z ∧ x ∧ y = x ∧ y ∧ z.  Intuition: Anything not ≤ IDEAL is not safe, because there is some executable path whose effect is not accounted for.

20 MOP Versus IDEAL --- (2)  Conversely: any solution that is ≤ IDEAL accounts for all executable paths (and maybe more paths), and is therefore conservative (safe), even if not accurate.

21 MFP Versus MOP --- (1)  Is MFP ≤ MOP?  If so, then since MOP ≤ IDEAL, we have MFP ≤ IDEAL, and therefore MFP is safe. uYes, but … requires two assumptions about the framework: 1.“Monotonicity.” 2.Finite height (no infinite chains... < x 2 < x 1 < x).

22 MFP Versus MOP --- (2) uIntuition: If we computed the MOP directly, we would compose functions along all paths, then take a big meet. uBut the MFP (iterative algorithm) alternates compositions and meets arbitrarily.

23 Monotonicity  A framework is monotone if the functions respect ≤. That is:  If x ≤ y, then f(x) ≤ f(y).  Equivalently: f(x ∧ y) ≤ f(x) ∧ f(y). uIntuition: it is conservative to take a meet before completing the composition of functions.

24 Good News! uThe frameworks we’ve studied so far are all monotone. wEasy proof for functions in Gen-Kill form. uAnd they have finite height. wOnly a finite number of defs, variables, etc. in any program.

25 Two Paths to B That Meet Early ENTRY B Since f(x ∧ y) ≤ f(x) ∧ f(y), it is as if we added nonexistent paths. f OUT = x OUT = y IN = x ∧ y OUT = f(x ∧ y) In MFP, Values x and y get combined too soon. f(x) f(y) MOP considers paths independently and and combines at the last possible moment. OUT = f(x) ∧ f(y)

26 Distributive Frameworks uStrictly stronger than monotonicity is the distributivity condition: f(x ∧ y) = f(x) ∧ f(y)

27 Even More Good News! uAll the Gen-Kill frameworks are distributive. uIf a framework is distributive, then combining paths early doesn’t hurt. wMOP = MFP. wThat is, the iterative algorithm computes a solution that takes into account all and only the physical paths.