Reading: Chapter 9.3. Carnegie Mellon

Similar documents
CSC D70: Compiler Optimization Dataflow-2 and Loops

Dataflow Analysis - 2. Monotone Dataflow Frameworks

Goal. Partially-ordered set. Game plan 2/2/2013. Solving fixpoint equations

The Meet-Over-All-Paths Solution to Data-Flow Problems

Dataflow Analysis. Chapter 9, Section 9.2, 9.3, 9.4

We define a dataflow framework. A dataflow framework consists of:

Dataflow Analysis. Dragon book, Chapter 9, Section 9.2, 9.3, 9.4

Generalizing Data-flow Analysis

Spring Based on Partee, ter Meulen, & Wall (1993), Mathematical Methods in Linguistics

Data-Flow Analysis. Compiler Design CSE 504. Preliminaries

MIT Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

An Introduction to the Theory of Lattice

CMSC 631 Program Analysis and Understanding. Spring Data Flow Analysis

Chapter 9: Relations Relations

Monotone Data Flow Analysis Framework

Axioms of Kleene Algebra

Lecture 1: Lattice(I)

Class Notes on Poset Theory Johan G. Belinfante Revised 1995 May 21

COSE312: Compilers. Lecture 14 Semantic Analysis (4)

Data flow analysis. DataFlow analysis

Dataflow analysis. Theory and Applications. cs6463 1

CS 6110 Lecture 21 The Fixed-Point Theorem 8 March 2013 Lecturer: Andrew Myers. 1 Complete partial orders (CPOs) 2 Least fixed points of functions

Two Approaches to Interprocedural Data Flow Analysis

AAA616: Program Analysis. Lecture 3 Denotational Semantics

Introduction to Kleene Algebras

Completeness of Star-Continuity

Diskrete Mathematik Solution 6

Axioms for the Real Number System

a + b = b + a and a b = b a. (a + b) + c = a + (b + c) and (a b) c = a (b c). a (b + c) = a b + a c and (a + b) c = a c + b c.

Properties of the Integers

Introduction to Abstract Interpretation. ECE 584 Sayan Mitra Lecture 18

CS411 Notes 3 Induction and Recursion

Discrete Mathematics Review

Lecture Notes 1 Basic Concepts of Mathematics MATH 352

Kleene Algebra and Arden s Theorem. Anshul Kumar Inzemamul Haque

Data Cleaning and Query Answering with Matching Dependencies and Matching Functions

(Pre-)Algebras for Linguistics

CMSC 631 Program Analysis and Understanding Fall Abstract Interpretation

MAD 3105 PRACTICE TEST 2 SOLUTIONS

What is SSA? each assignment to a variable is given a unique name all of the uses reached by that assignment are renamed

Lecture 2: A crash course in Real Analysis

Today s Topics. Methods of proof Relationships to logical equivalences. Important definitions Relationships to sets, relations Special functions

MAT 570 REAL ANALYSIS LECTURE NOTES. Contents. 1. Sets Functions Countability Axiom of choice Equivalence relations 9

Axioms for Set Theory

That is, there is an element

Gerwin Klein, June Andronick, Ramana Kumar S2/2016

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

Lecture Notes: Selected Topics in Discrete Structures. Ulf Nilsson

A should be R-closed: R(A) A. We would like this to hold because we would like every element that the rules say should be in A to actually be in A.

1 The Local-to-Global Lemma

Lecture 11: Data Flow Analysis III

Mathematics Review for Business PhD Students

CS Lecture 3. More Bayesian Networks

Practice Exam 1 CIS/CSE 607, Spring 2009

Appendix A. Definitions for Ordered Sets. The appendices contain all the formal definitions, propositions and proofs for

Dataflow Analysis Lecture 2. Simple Constant Propagation. A sample program int fib10(void) {

The integers. Chapter 3

Bernhard Nebel, Julien Hué, and Stefan Wölfl. June 27 & July 2/4, 2012

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

WORKSHEET MATH 215, FALL 15, WHYTE. We begin our course with the natural numbers:

Introduction to data-flow analysis. Data-flow analysis. Control-flow graphs. Data-flow analysis. Example: liveness. Requirements

Model Checking & Program Analysis

MATH 202B - Problem Set 5

MATH 13 SAMPLE FINAL EXAM SOLUTIONS

Homework 5. Solutions

Complete Induction and the Well- Ordering Principle

September 14. Fall Software Foundations CIS 500

Introduction to generalized topological spaces

1. (B) The union of sets A and B is the set whose elements belong to at least one of A

Automata and Languages

Well-Ordering Principle. Axiom: Every nonempty subset of Z + has a least element. That is, if S Z + and S, then S has a smallest element.

0 Sets and Induction. Sets

Chapter 2. Unification. Foundations of Logic Programming

Notes on Abstract Interpretation

Introduction to Axiomatic Semantics

Semantics and Verification of Software

Data Flow Analysis. Lecture 6 ECS 240. ECS 240 Data Flow Analysis 1

2MA105 Algebraic Structures I

Design of Distributed Systems Melinda Tóth, Zoltán Horváth

Introduction. Chapter 1

Discrete Mathematics. 2. Relations

Worksheet on Relations

Lecture 4. Algebra, continued Section 2: Lattices and Boolean algebras

REVIEW FOR THIRD 3200 MIDTERM

Dataflow Analysis. A sample program int fib10(void) { int n = 10; int older = 0; int old = 1; Simple Constant Propagation

A Tutorial on Program Analysis

1 Lattices and Tarski s Theorem

CS422 - Programming Language Design

Discrete Fixpoint Approximation Methods in Program Static Analysis

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

Exam Practice Problems

Concrete Domains. Gilles Kahn INRIA Sophia Antipolis Gordon D. Plotkin University of Edinburgh

Logical Connectives and Quantifiers

(b). Identify all basic blocks in your three address code. B1: 1; B2: 2; B3: 3,4,5,6; B4: 7,8,9; B5: 10; B6: 11; B7: 12,13,14; B8: 15;

Lecture 7: Relations

Lecture 24 Nov. 20, 2014

Exercises 1 - Solutions

06 Recursive Definition and Inductive Proof

Size-Change Termination and Transition Invariants

Lecture 2. Econ August 11

Transcription:

I II Lecture 3 Foundation of Data Flow Analysis Semi-lattice (set of values, meet operator) Transfer functions III Correctness, precision and convergence IV Meaning of Data Flow Solution Reading: Chapter 9.3

I. Purpose of a Framework Purpose 1 Prove properties of entire family of problems once and for all Will the program converge? What does the solution to the set of equations mean? Purpose 2: Aid in software engineering: re-use code CS243: Foundation of Data Flow 2

The Data-Flow Framework Data-flow problems (F, V, ) are defined by A semi-lattice domain of values V meet operator : V x V à V A family of transfer functions F: V à V CS243: Foundation of Data Flow 3

Semi-lattice: Structure of the Domain of Values A semi-lattice S = <a set of values V, a meet operator > Properties of the meet operator idempotent: x x = x commutative: x y = y x associative: x (y z) = (x y) z Examples of meet operators? Non-examples? CS243: Foundation of Data Flow 4

Example of a Semi-Lattice Diagram (V, ) : V = {x such that x {d 1,d 2,d 3 }}, = U {} (T) {d 1 } {d 2 } {d 3 } {d 1,d 2 } {d 1,d 3 } {d 2,d 3 } {d 1,d 2,d 3 } ( ) x y = first common descendant of x & y A meet semi-lattice is bounded if there exists a top element T, such that x T = x for all x. A bottom element exists, if x = for all x. important CS243: Foundation of Data Flow 5

Meet Semi-Lattices vs Partially Ordered Sets A meet-semilattice is a partially ordered set which has a meet (or greatest lower bound) for any nonempty finite subset. {} (T) {d 1 } {d 2 } {d 3 } {d 1,d 2 } {d 1,d 3 } {d 2,d 3 } {d 1,d 2,d 3 } ( ) Greatest lower bound: x y = First common descendant of x & y Largest: top element T, if x T = x for all x. Smallest: bottom element, if x = for all x. CS243: Foundation of Data Flow 6

A Meet Operator Defines a Partial Order Partial order of a meet semi-lattice : x y if and only if x y = x path y x (x y = x) ( x y ) {} (T) Meet operator: U Partial order : {d 1 } {d 2 } {d 3 } {d 1,d 2 } {d 1,d 3 } {d 2,d 3 } {d 1,d 2,d 3 } ( ) Properties of meet operator guarantee that is a partial order Reflexive: x x Antisymmetric: if x y and y x then x = y Transitive: if x y and y z then x z CS243: Foundation of Data Flow 7

Drawing a Semi-Lattice Diagram (x < y) (x y) (x y) A semi-lattice diagram: Set of nodes: set of values Set of edges {(y, x): x < y and z s.t. (x < z) (z < y)} CS243: Foundation of Data Flow 8

Summary Three ways to define a semi-lattice: Set of values + meet operator idempotent: x x = x commutative: x y = y x associative: x (y z) = (x y) z Set of values + partial order with a greatest lower bound for any nonempty subset Reflexive: x x Antisymmetric: if x y and y x then x = y Transitive: if x y and y z then x z A semi-lattice diagram CS243: Foundation of Data Flow 9

Another Example Semi-lattice V = {x such that x {d 1, d 2, d 3 }} = {d 1,d 2,d 3 } (T) {d 1,d 2 } {d 1,d 3 } {d 2,d 3 } {d 1 } {d 2 } {d 3 } {} ( ) is CS243: Foundation of Data Flow 10

One Element at a Time A semi-lattice for data flow problems can get quite large: 2 n elements for n var/definition A useful technique: define semi-lattice for 1 element product of semi-lattices for all elements Example: Union of definitions For each element def1 def2 {} {} def1 x def2 {},{} {d 1 } {d 2 } {d 1 },{} {},{d 2 } <x 1, x 2 > <y 1, y 2 > iff x 1 y 1 and x 2 y 2 {d 1 },{d 2 } CS243: Foundation of Data Flow 11

Descending Chain Definition The height of a lattice is the largest number of > relations that will fit in a descending chain. x 0 > x 1 > Height of values in reaching definitions? Important property: finite descending chains CS243: Foundation of Data Flow 12

II. Transfer Functions A family of transfer functions F Basic Properties f : V à V Has an identity function f such that f(x) = x, for all x. Closed under composition if f 1,f 2 F, f 1 f 2 F CS243: Foundation of Data Flow 13

Monotonicity: 2 Equivalent Definitions A framework (F, V, ) is monotone iff x y implies f(x) f(y) Equivalently, a framework (F, V, ) is monotone iff f(x y) f(x) f(y), meet inputs, then apply f apply f individually to inputs, then meet results CS243: Foundation of Data Flow 14

Example Reaching definitions: f(x) = Gen U (x - Kill), = U Definition 1: Let x 1 x 2, f(x 1 ): Gen U (x 1 - Kill) f(x 2 ): Gen U (x 2 - Kill) Definition 2: f(x 1 x 2 ) = (Gen U ((x 1 U x 2 ) - Kill)) f(x 1 ) f(x 2 ) = (Gen U (x 1 - Kill) ) U (Gen U (x 2 - Kill) ) CS243: Foundation of Data Flow 15

Distributivity A framework (F, V, ) is distributive if and only if f(x y)= f(x) f(y), meet input, then apply f is equal to apply the transfer function individually then merge result CS243: Foundation of Data Flow 16

Important Note Monotone framework does not mean that f(x) x e.g. Reaching definition for two definitions in program suppose: f: Gen = {d 1 } ; Kill = {d 2 } CS243: Foundation of Data Flow 17

III. Properties of Iterative Algorithm Given: and monotone data flow framework Finite descending chain Converges Initialization of interior points to T Maximum Fixed Point (MFP) solution of equations CS243: Foundation of Data Flow 18

Behavior of iterative algorithm (intuitive) For each IN/OUT of an interior program point: Invariant: new value old value in any step Start with T (largest value) Proof by induction 1st transfer function or meet operator: new value old value (T) Meet operation: Assume new inputs old inputs, new output old output Transfer function (in a monotone framework) Assume new inputs old inputs, new output old output Algorithm iterates until equations are satisfied Values do not come down unless some constraints drive them down. Therefore, finds the largest solution that satisfies the equations CS243: Foundation of Data Flow 19

IV. What Does the Solution Mean? IDEAL data flow solution Let f 1,..., f m : F, f i is the transfer function for node i f p = f nk f n1, p is a path through nodes n 1,..., n k f p = identify function, if p is an empty path For each node n: f pi (boundary value), for all possibly executed paths p i reaching n Example false if sqr(y) >= 0 true x = 0 x = 1 Determining all possibly executed paths is undecidable CS243: Foundation of Data Flow 20

Err in the conservative direction Meet-Over-Paths MOP Meet-Over-Paths MOP Assume every edge is traversed For each node n: MOP(n) = f pi (boundary value), for all paths p i reaching n Compare MOP with IDEAL MOP includes more paths than IDEAL MOP = IDEAL Result(Unexecuted-Paths) MOP IDEAL MOP is a smaller solution, more conservative, safe MOP IDEAL Goal: as close to MOP from below as possible CS243: Foundation of Data Flow 21

Solving Data Flow Equations What is the difference between MOP and MFP of data flow equations? F 1 F 2 F 3 Therefore FP MFP MOP IDEAL FP, MFP, MOP are safe If framework is distributive, FP MFP = MOP IDEAL CS243: Foundation of Data Flow 22

Summary A data flow framework Semi-lattice set of values (top) meet operator finite descending chains? Transfer functions summarizes each basic block boundary conditions Properties of data flow framework: Monotone framework and finite descending chains iterative algorithm converges finds maximum fixed point (MFP) FP MFP MOP IDEAL Distributive framework FP MFP = MOP IDEAL CS243: Foundation of Data Flow 23