1 CS 201 Compiler Construction Lecture 4 Data Flow Framework.

Slides:



Advertisements
Similar presentations
Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
Advertisements

Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
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.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
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.
CSE 231 : Advanced Compilers Building Program Analyzers.
CSE 231 : Advanced Compilers Building Program Analyzers.
Worklist algorithm Initialize all d i to the empty set Store all nodes onto a worklist while worklist is not empty: –remove node n from worklist –apply.
Course project presentations No midterm project presentation Instead of classes, next week I’ll meet with each group individually, 30 mins each Two time.
From last time: Lattices A lattice is a tuple (S, v, ?, >, t, u ) such that: –(S, v ) is a poset – 8 a 2 S. ? v a – 8 a 2 S. a v > –Every two elements.
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.
Loop invariant detection using SSA An expression is invariant in a loop L iff: (base cases) –it’s a constant –it’s a variable use, all of whose single.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
Administrative stuff Office hours: After class on Tuesday.
1 CS 201 Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding.
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.
San Diego October 4-7, 2006 Over 1,000 women in computing Events for undergraduates considering careers and graduate school Events for graduate students.
Recap: Reaching defns algorithm From last time: reaching defns worklist algo We want to avoid using structure of the domain outside of the flow functions.
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.
Lattice and Boolean Algebra
Data Flow Analysis Compiler Design Nov. 8, 2005.
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.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Claus Brabrand, ITU, Denmark DATA-FLOW ANALYSISMar 25, 2009 Static Analysis: Data-Flow Analysis II Claus Brabrand IT University of Copenhagen (
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.
Functions.
1 Region-Based Data Flow Analysis. 2 Loops Loops in programs deserve special treatment Because programs spend most of their time executing loops, improving.
Precision Going back to constant prop, in what cases would we lose precision?
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.
Global Redundancy Elimination: Computing Available Expressions Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Data-Flow Analysis (Chapter 8). Outline What is Data-Flow Analysis? Structure of an optimizing compiler An example: Reaching Definitions Basic Concepts:
CS 614: Theory and Construction of Compilers Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Formalization of DFA using lattices. Recall worklist algorithm let m: map from edge to computed value at edge let worklist: work list of nodes for each.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Data Flow Analysis Foundations Guo, Yao Part of the slides are adapted from.
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.
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.
Lub and glb Given a poset (S, · ), and two elements a 2 S and b 2 S, then the: –least upper bound (lub) is an element c such that a · c, b · c, and 8 d.
DFA foundations Simone Campanoni
Fall Compiler Principles Lecture 7: Dataflow & Optimizations 2
Simone Campanoni DFA foundations Simone Campanoni
CSC D70: Compiler Optimization Dataflow-2 and Loops
Global optimizations.
Another example: constant prop
Fall Compiler Principles Lecture 10: Global Optimizations
Data Flow Analysis Compiler Design
Lecture 20: Dataflow Analysis Frameworks 11 Mar 02
Dataflow Analysis: Dataflow Frameworks
Formalization of DFA using lattices
Formalization of DFA using lattices
Formalization of DFA using lattices
Formalization of DFA using lattices
Presentation transcript:

1 CS 201 Compiler Construction Lecture 4 Data Flow Framework

2 The various problems considered have things in common: –Transfer functions –Confluence Operator –Direction of Propagation These problems can be treated in a unified way  data flow framework is an algebraic structure used to encode and solve data flow problems.

3 Monotone Data Flow Framework Components of the framework: 1.Information Set: L 2.Effect of joining paths: ∧ (meet operator) 3.Effect of basic blocks: f n (monotone transfer func.) 4.Iterative Solution: can be shown to terminate (L, ∧ ) is a semilattice st ∨ a,b,c εL 1. a ∧ a = a (idempotent) 2. a ∧ b = b ∧ a (commutative) 3. a ∧ (b ∧ c) = (a ∧ b) ∧ c (assocative) Bottom Element st ∨ a ε L, a ∧ = Top Element Τ st ∨ a ε L, a ∧ Τ = a If top & bottom elements exist, they are unique.

Contd.. Relation ≤ is a partial order on L a ≤ b ≅ a ∧ b = a Can similarly define, ≥ relations A semilattice is bounded iff ∨ a εL there exists a constant c a st length of chain beginning at a is at most c a. 4 Max c a

5 Monotonic Functions Effect of each basic block is modeled by a transfer function f: L  L. Function f must be monotonic. A total function f: L  L is monotonic iff ∨ a,b ε L f(a ∧ b) ≤ f(a) ∧ f(b) Distributive function: f(a ∧ b) = f(a) ∧ f(b) For monotonic functions: a ≤ b => f(a) ≤ f(b)

6 Contd.. For monotonic functions: a ≤ b => f(a) ≤ f(b) Proof: f(a ∧ b) ≤ f(a) ∧ f(b) Defn. of Monotonicity f(a ∧ b) ∧ f(a) ∧ f(b) = f(a ∧ b) Defn. of ≤:(a ∧ b=a) f(a) ∧ f(a) ∧ f(b)= f(a) Given a ≤ b: a ∧ b = a f(a) ∧ f(b) = f(a) f(a) ∧ f(a) = f(a) idempotence f(a) ≤ f(b) Defn. of ≤

7 Fixpoint A fixpoint of a monotonic function f: L  L is a value a ε L such that f(a) = a Τ > f (Τ) > f ( f (Τ) ) > f ( f ( f (Τ) ) ) …….. There exists t such that f ( f t (Τ) ) = f t (Τ) f t (Τ) is the greatest fixpoint of f.

8 Monotone Function Space A monotone function space for a semilattice is a set F of monotonic functions which: 1.Contains the identity function (id) -- basic blocks may not modify information 2.Is closed under function composition -- to model the effects of paths 3.For each a ε L, there exists fεF st f( ) = a -- to model gen functions A distributive function space is a monotone function space in which all functions are distributive.

9 A Monotone Data Flow System A monotone data flow system is a tuple 1.(L, ∧ ) is a bounded semilattice with Τ & 2.F is the monotone function space 3.G = (N, E, s) is the program flow graph 4.FM: N  F is a total function that associates a function from F with each basic block.

10 Meet Over All Paths Solution Meet over all paths solution (MOP) of a data flow system – MOP: N  L MOP(s) = NULL (NULL is the element in L which represents “no information”) F f π is composition of functions from nodes along path π excluding node n. n 1  n 2  n 3  ….  n k-1  n k  fn k o fn k-1 o….o fn 2 o fn 1

11 MOP Solution Finding MOP solution is undecidable, i.e. there does not exist a general algorithm that computes MOP solution for all monotone data flow systems. Let X: N  L denote a total function that associates nodes with lattice elements. X is conservative or safe iff ∨ n εN, X(n) ≤ MOP(n) Iterative algorithm computes conservative approximation of MOP. For distributive data flow systems, it computes solution that is identical to MOP solution.

12 Iterative Algorithm

13 Reaching Definitions

14 Contd…

15 Dominators

16 Constant Propagation f (X)={(a,2),(b,3),(c,5)}f (Y)={(a,3),(b,2),(c,5)} f (X) ∧ f (Y) = {(a,not-const), (b, not-const), (c,5)} X ∧ Y = {(a,not-const),(b,not-const),(c,undef)} f (X ∧ Y) = {(a,not-const),(b,not-const),(c,not-const)} f (X ∧ Y) ≤ f(X) ∧ f(Y)