Iterative Dataflow Problems Taken largely from notes of Alex Aiken (UC Berkeley) and Martin Rinard (MIT) Dataflow information used in optimization Several.

Slides:



Advertisements
Similar presentations
CSCI 115 Chapter 6 Order Relations and Structures.
Advertisements

Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Lecture 11: Code Optimization CS 540 George Mason University.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
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.
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.
CS 536 Spring Global Optimizations Lecture 23.
Discrete Mathematics Lecture 4 Harper Langston New York University.
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.
FSM Decomposition using Partitions on States 290N: The Unknown Component Problem Lecture 24.
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.
Administrative stuff Office hours: After class on Tuesday.
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.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
Orderings and Bounds Parallel FSM Decomposition Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 10 Update and modified by Marek.
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.
Partial Orderings: Selected Exercises
Lattice and Boolean Algebra
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
Prof. Aiken CS 294 Lecture 11 Program Analysis. Prof. Aiken CS 294 Lecture 12 The Purpose of this Course How are the following related? –Program analysis.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Partially Ordered Sets (POSets)
Sets, POSets, and Lattice © Marcelo d’Amorim 2010.
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
11.1 Boolean Functions. Boolean Algebra An algebra is a set with one or more operations defined on it. A boolean algebra has three main operations, and,
Abstract Interpretation (Cousot, Cousot 1977) also known as Data-Flow Analysis.
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.
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
CS 267: Automated Verification Lecture 3: Fixpoints and Temporal Properties Instructor: Tevfik Bultan.
CS 614: Theory and Construction of Compilers Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Sets and Subsets Set A set is a collection of well-defined objects (elements/members). The elements of the set are said to belong to (or be contained in)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Data Flow Analysis Foundations Guo, Yao Part of the slides are adapted from.
8.4 Use Scientific Notation Algebra. Scientific Notation Numbers such as 1,000,000, 153,000 and are written in standard form. Another way to write.
Compiler Principles Fall Compiler Principles Lecture 11: Loop Optimizations Roman Manevich Ben-Gurion University.
Set Theory Concepts Set – A collection of “elements” (objects, members) denoted by upper case letters A, B, etc. elements are lower case brackets are used.
CSCI 115 Course Review.
Advanced Digital Designs Jung H. Kim. Chapter 1. Sets, Relations, and Lattices.
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.
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.
Dataflow Analysis CS What I s Dataflow Analysis? Static analysis reasoning about flow of data in program Different kinds of data: constants, variables,
Compiler Principles Fall Compiler Principles Lecture 9: Dataflow & Optimizations 2 Roman Manevich Ben-Gurion University of the Negev.
Infinite sets We say that a set A is infinite if a proper subset B exists of A such that there is a bijection It is easy to see that no set with a finite.
DFA foundations Simone Campanoni
Partial Orderings: Selected Exercises
Fixpoints and Reachability
Data Flow Analysis Suman Jana
Iterative Dataflow Problems
Simone Campanoni DFA foundations Simone Campanoni
LATTICES AND BOOLEAN ALGEBRA
University Of Virginia
Concurrent Models of Computation
Sungho Kang Yonsei University
Fall Compiler Principles Lecture 10: Global Optimizations
Data Flow Analysis Compiler Design
Lecture 20: Dataflow Analysis Frameworks 11 Mar 02
Field.
Background material.
Background material.
Live Variables – Basic Block
Presentation transcript:

Iterative Dataflow Problems Taken largely from notes of Alex Aiken (UC Berkeley) and Martin Rinard (MIT) Dataflow information used in optimization Several different problems fit into a common framework

Notation s is a statement succ(s) = { successor statements of s } pred(s) = { predecessor statements of s } write(s) = { variables written by s } read(s) = { variables read by s }

Liveness Analysis For each program point p, which of the variables defined at that point are used on some execution path? if y > a + b a := a + 1 x := a + b y := a * b x := a + b Optimization: If a variable is not live, no need to keep it in a register. x is not live here

Dataflow Equations

Live Variables: Schematic May analysis: property holds on some path Backwards analysis: from outputs to inputs Transfer function:

Available Expressions For each program point p, which expressions must have already been computed, and not later modified, on all paths to p. if y > a + b a := a + 1 x := a + b y := a * b x := a + b Optimization: Where available, expressions need not be recomputed. a+b is available here

Example if y > a + b a := a + 1 x := a + b y := a * b x := a + ba+ba+b, a*ba+b, a*b, y > a+ba+b a+b, y > a+b

Example if y > a + b a := a + 1 x := a + b y := a * b x := a + bx,a,bx,y,a,by,a,b x,y,a,ba,bx

Available Expressions Again

Available Expressions: Schematic Must analysis: property holds on all paths Forwards analysis: from inputs to outputs Transfer function:

Very Busy Expressions An expression e is very busy at program point p if every path from p must evaluate e before any variable in e is redefined Optimization: hoisting expressions A must-analysis A backwards analysis

Reaching Definitions For a program point p, which assignments made on paths reaching p have not been overwritten Connects definitions with uses –use-def chains A may-analysis A forwards analysis

One Cut at the Dataflow Design Space MayMust ForwardsReaching definitions Available expressions BackwardsLive variablesVery busy expressions

The Literature Vast literature of dataflow analyses 90+% can be described by –Forwards or backwards –May or must Some oddballs, but not many –Bidirectional analyses

Terminology Must vs. May Forwards vs. Backwards Flow-sensitive vs. Flow-insensitive Lattice Theory --- look at the mathematical definition

Partial Orders Set P Partial order  such that  x,y,z  P –x  x (reflexive) –x  y and y  x implies x  y (asymmetric) –x  y and y  z implies x  z(transitive)

Upper Bounds If S  P then –x  P is an upper bound of S if  y  S, y  x –x  P is the least upper bound of S if x is an upper bound of S, and x  y for all upper bounds y of S –  - join, least upper bound, lub, supremum, sup  S is the least upper bound of S x  y is the least upper bound of {x,y}

Lower Bounds If S  P then –x  P is a lower bound of S if y  S, x  y –x  P is the greatest lower bound of S if x is a lower bound of S, and y  x for all lower bounds y of S –  - meet, greatest lower bound, glb, infimum, inf  S is the greatest lower bound of S x  y is the greatest lower bound of {x,y}

Covering x  y if x  y and x  y x is covered by y (y covers x) if –x  y, and –x  z  y implies x  z Conceptually, y covers x if there are no elements between x and y

Example P = { 000, 001, 010, 011, 100, 101, 110, 111} (standard boolean lattice, also called hypercube) x  y if (x bitwise and y) = x Hasse Diagram If y covers x Line from y to x y above x in diagram

Lattices If x  y and x  y exist for all x,y  P, then P is a lattice. If  S and  S exist for all S  P, then P is a complete lattice. All finite lattices are complete Example of a lattice that is not complete –Integers I –For any x, y  I, x  y = max(x,y), x  y = min(x,y) –But  I and  I do not exist –I  { ,  } is a complete lattice

Top and Bottom Greatest element of P (if it exists) is top Least element of P (if it exists) is bottom (  )

Connection Between , , and  The following 3 properties are equivalent: –x  y –x  y  y –x  y  x Will (well, we could, anyway) prove: –x  y implies x  y  y and x  y  x –x  y  y implies x  y –x  y  x implies x  y Then by transitivity, can obtain –x  y  y implies x  y  x –x  y  x implies x  y  y

Connecting Lemma Proofs Proof of x  y  y implies x  y –y is an upper bound of {x,y} implies x  y Proof of x  y  x implies x  y –x is a lower bound of {x,y} implies x  y

Lattices as Algebraic Structures Have defined  and  in terms of  Will now define  in terms of  and  –Start with  and  as arbitrary algebraic operations that satisfy associative, commutative, idempotence, and absorption laws –Will define  using  and  –Will show that  is a partial order

Algebraic Properties of Lattices Assume arbitrary operations  and  such that –(x  y)  z  x  (y  z)(associativity of  ) –(x  y)  z  x  (y  z)(associativity of  ) –x  y  y  x(commutativity of  ) –x  y  y  x(commutativity of  ) –x  x  x(idempotence of  ) –x  x  x(idempotence of  ) –x  (x  y)  x(absorption of  over  ) –x  (x  y)  x(absorption of  over  )

Connection Between  and  x  y  y if and only if x  y  x Proof of x  y  y implies x = x  y x = x  (x  y) (by absorption) = x  y(by assumption) Proof of x  y  x implies y = x  y y = y  (y  x)(by absorption) = y  (x  y)(by commutativity) = y  x (by assumption) = x  y (by commutativity)

Chains A set S is a chain if  x,y  S, y  x or x  y P has no infinite chains if every chain in P is finite P satisfies the ascending chain condition if for all sequences x 1  x 2  …there exists n such that x n = x n+1 = …

Application to Dataflow Analysis Dataflow information will be lattice values –Transfer functions operate on lattice values –Solution algorithm will generate increasing sequence of values at each program point –Ascending chain condition will ensure termination Will use  to combine values at control-flow join points