1 Constant Propagation A More Complex Semilattice A Nondistributive Framework.

Slides:



Advertisements
Similar presentations
Completeness and Expressiveness
Advertisements

Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
1 Induction Variables Region-Based Analysis Meet and Closure of Transfer Functions Affine Functions of Reference Variables.
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.
1 More NP-Complete Problems NP-Hard Problems Tautology Problem Node Cover Knapsack.
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.
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 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
Conversion of CFG to PDA Conversion of PDA to CFG
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
The Pumping Lemma for CFL’s
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.
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.
Abstract Interpretation Part I Mooly Sagiv Textbook: Chapter 4.
Data Flow Analysis Compiler Design Nov. 8, 2005.
1 Decidability Turing Machines Coded as Binary Strings Diagonalizing over Turing Machines Problems as Languages Undecidable Problems.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs, Data-flow Analysis Data-flow Frameworks --- today’s.
1 Semantics of Datalog With Negation Local Stratification Stable Models Well-Founded Models.
1 Data-Flow Frameworks Lattice-Theoretic Formulation Meet-Over-Paths Solution Monotonicity/Distributivity.
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.
Tutorial 10 Iterative Methods and Matrix Norms. 2 In an iterative process, the k+1 step is defined via: Iterative processes Eigenvector decomposition.
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.
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.
Claus Brabrand, UFPE, Brazil Aug 09, 2010DATA-FLOW ANALYSIS Claus Brabrand ((( ))) Associate Professor, Ph.D. ((( Programming, Logic, and.
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 Data-Flow Analysis Proving Little Theorems Data-Flow Equations Major Examples.
Example x := read() v := a + b x := x + 1 w := x + 1 a := w v := a + b z := x + 1 t := a + b.
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.
Machine-Independent Optimizations Ⅱ CS308 Compiler Theory1.
Compiler Construction Lecture 16 Data-Flow Analysis.
Chapter 2 Mathematical preliminaries 2.1 Set, Relation and Functions 2.2 Proof Methods 2.3 Logarithms 2.4 Floor and Ceiling Functions 2.5 Factorial and.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Global Redundancy Elimination: Computing Available Expressions Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
CS 267: Automated Verification Lecture 3: Fixpoints and Temporal Properties Instructor: Tevfik Bultan.
A Logic of Partially Satisfied Constraints Nic Wilson Cork Constraint Computation Centre Computer Science, UCC.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Chapter 5 Constraint Satisfaction Problems
Compiler Principles Fall Compiler Principles Lecture 11: Loop Optimizations Roman Manevich Ben-Gurion University.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
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.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Iterative Dataflow Problems Taken largely from notes of Alex Aiken (UC Berkeley) and Martin Rinard (MIT) Dataflow information used in optimization Several.
Optimization Simone Campanoni
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Yet More Data flow analysis John Cavazos.
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
Theory of Computational Complexity Probability and Computing Chapter Hikaru Inada Iwama and Ito lab M1.
Fall Compiler Principles Lecture 7: Dataflow & Optimizations 2
Simone Campanoni DFA foundations Simone Campanoni
CSC D70: Compiler Optimization Dataflow-2 and Loops
Global optimizations.
Infiniteness Test The Pumping Lemma Nonregular Languages
Another example: constant prop
Program Analysis and Verification
Fall Compiler Principles Lecture 10: Global Optimizations
Data Flow Analysis Compiler Design
Lecture 20: Dataflow Analysis Frameworks 11 Mar 02
Presentation transcript:

1 Constant Propagation A More Complex Semilattice A Nondistributive Framework

2 The Point uInstead of doing constant folding by RD’s, we can maintain information about what constant, if any, a variable has at each point. uAn interesting example of a DF framework not of the gen-kill type. uA simple version of static type analysis.

3 Domain of Values uThe set of values propagated is the set of mappings from variables to values of their type.  Example: [x → 5, s → “cat”, y → UNDEF, z → NAC] wUNDEF = “We don’t yet know anything.” wNAC = “Not a constant” = we know too much for any constant to satisfy.”

4 The Semilattice uA product lattice, one component for each variable. uEach component lattice consists of: 1.UNDEF (the top element). 2.NAC (the bottom element). 3.All values from a type, e.g., integers, strings.

5 Picture UNDEF … NAC … …

6 The Meet Operation  The diagram represents ≤. That is: 1.Any constant ≤ UNDEF. 2.NAC ≤ any constant. uEquivalently, for any constants x and y: 1.UNDEF ∧ x = x. 2.NAC ∧ x = NAC. 3.NAC ∧ UNDEF = NAC. 4.x ∧ x = x but x ∧ y = NAC if x ≠ y.

7 The Product Lattice uCall each of the lattices just described a diamond lattice. uThe lattices we use are products of diamond lattices. uFor the product D 1 *D 2 *…*D n, the values are [v 1, v 2,…, v n ], where each v i is in D i.

8 Meet in Product Lattices  [v 1, v 2,…, v n ] ∧ [w 1, w 2,…, w n ] = [v 1 ∧ w 1, v 2 ∧ w 2,…, v n ∧ w n ] = componentwise meet.  In terms of ≤ : [v 1, v 2,…, v n ] ≤ [w 1, w 2,…, w n ] if and only if v i ≤ w i for all i.

9 Intuitive Meaning 1.If variable x is mapped to UNDEF (i.e., in the product-lattice value, the component for x is UNDEF), then we do not know anything about x. 2.If x is mapped to constant c, then we only know of paths where x has value c. 3.If x is mapped to NAC, we know about paths where x has different values.

10 Product-Lattice Values as Mappings uThink of a lattice element as a mapping from variables to values {UNDEF, NAC, constants}. uLattice element is m, and m(x) is the value to which m maps variable x.

11 Transfer Functions --- (1) uTransfer functions map lattice elements to lattice elements.  Suppose m is the variable->constant mapping just before a statement x = y+z.  Let f(m) = m’ be the transfer function associated with x = y+z.

12 Transfer Functions --- (2) uIf m(y) = c and m(z) = d, then m’(x) = c+d. uIf m(y) = NAC or m(z) = NAC, then m’(x) = NAC. uOtherwise, if m(y) = UNDEF or m(z) = UNDEF, then m’(x) = UNDEF. um’(w) = m(w) for all w other than x.

13 Transfer Functions --- (3) uSimilar rules for other types of statements (see text). uFor a block, compose the transfer functions of the individual statements.

14 Iterative Algorithm uIt’s a plain-ol’ Forward iteration, with the meet and transfer functions as given. uThe framework is monotone and has bounded depth, so it converges to a safe solution.

15 Finite Depth uThe value of any IN or OUT can only decrease. wVerify from transfer functions (monotonicity). uValues are finite-length vectors, and each component can only decrease twice. wFrom UNDEF to a constant to NAC. uIf no IN or OUT decreases in any component in a round, we stop.

16 Monotonicity --- (1)  Need to show m ≤ n implies f(m) ≤ f(n). uShow for function f associated with a single statement. uComposition of monotone functions is monotone. uThat’s enough to show monotonicity for all possible transfer functions.

17 Monotonicity --- (2)  One case: let f be the function associated with x = y+z.  One subcase: m(y) = c; m(z) = d; n(y) = c; n(z) = UNDEF; m(w) = n(w) otherwise. Thus, m ≤ n. uThen (f(m))(x) = c+d and (f(n))(x) = UNDEF.  Thus (f(m))(w) ≤ (f(n))(w) for all w.

18 Nondistributivity uFirst example of a framework that is not distributive. uThus, iterative solution is not the MOP. uWe’ll show an example where MFP appears to include impossible paths.

19 Example: Nondistributivity x = 3 y = 2 x = 2 y = 3 z = x+y x->UNDEF y->UNDEF x->2 y->3 x->3 y->2 x->NAC y->NAC z->NAC Iterative solution finds z is “not a constant.”

20 Example: Nondistributivity --- (2) x = 3 y = 2 x = 2 y = 3 z = x+y x->UNDEF y->UNDEF x->2 y->3 z->5 x->3 y->2 z->5 MOP has z = 5.

21 Example: Nondistributivity --- (3) uWe observe that MFP differs from the MOP solution. uThat proves the framework is not distributive. wBecause every distributive framework has MFP = MOP.