Machine-Independent Optimizations Ⅱ CS308 Compiler Theory1.

Slides:



Advertisements
Similar presentations
Symbolic Analysis. Symbolic analysis tracks the values of variables in programs symbolically as expressions of input variables and other variables, which.
Advertisements

Partial Derivatives Definitions : Function of n Independent Variables: Suppose D is a set of n-tuples of real numbers (x 1, x 2, x 3, …, x n ). A real-valued.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
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.
Compilation (Semester A, 2013/14) Lecture 12: Abstract Interpretation Noam Rinetzky Slides credit: Roman Manevich, Mooly Sagiv and Eran Yahav.
Foundations of Data-Flow Analysis. Basic Questions Under what circumstances is the iterative algorithm used in the data-flow analysis correct? How precise.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
1 Constant Propagation A More Complex Semilattice A Nondistributive Framework.
CS 536 Spring Global Optimizations Lecture 23.
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.
Abstract Interpretation Part I Mooly Sagiv Textbook: Chapter 4.
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.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
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.
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.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis: Data-flow frameworks –Classic.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Λλ 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.
Abstract Interpretation (Cousot, Cousot 1977) also known as Data-Flow Analysis.
1 CS 201 Compiler Construction 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
Compiler Construction Lecture 16 Data-Flow Analysis.
Universidad Nacional de ColombiaUniversidad Nacional de Colombia Facultad de IngenieríaFacultad de Ingeniería Departamento de Sistemas- 2002Departamento.
CS 614: Theory and Construction of Compilers Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
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.
Section 10.5 Let X be any random variable with (finite) mean  and (finite) variance  2. We shall assume X is a continuous type random variable with p.d.f.
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.
DFA foundations Simone Campanoni
Fall Compiler Principles Lecture 7: Dataflow & Optimizations 2
Copyright © Cengage Learning. All rights reserved.
Simone Campanoni DFA foundations Simone Campanoni
Copyright © Cengage Learning. All rights reserved.
Global optimizations.
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.
7.2 Area Between Two Curves
CS 201 Compiler Construction
Warm Up Simplify. Assume all variables are positive.
Sungho Kang Yonsei University
Fall Compiler Principles Lecture 10: Global Optimizations
Fall Compiler Principles Lecture 10: Loop Optimizations
Data Flow Analysis Compiler Design
Lecture 20: Dataflow Analysis Frameworks 11 Mar 02
Composition OF Functions.
2.6 Operations on Functions
Composition OF Functions.
3.5 Operations on Functions
Presentation transcript:

Machine-Independent Optimizations Ⅱ CS308 Compiler Theory1

Foundations of Data-Flow Analysis CS308 Compiler Theory2

Semilattices CS308 Compiler Theory3

Semilattices The partial order for a semilattice (V, ∧ ) for all x and y in V, Greatest low bound of domain elements x and y is an element g such that The meet of x and y, g=x ∧ y, is their only greatest lower bound CS308 Compiler Theory4

Semilattices Lattice Diagrams for 3 definitions The set of data-flow values is the power set of the definitions, which contains 2 n elements if there are n definitions in the program. CS308 Compiler Theory5

Product Lattices for only one definition d, the lattice would have two element: {} and {d} Suppose (A, ∧ A ) and (B, ∧ B ) are lattices, the product lattice is: CS308 Compiler Theory6

Transfer Functions Closed under composition –For any two functions f and g in F, h(x)=g(f(x)) is in F Monotone frameworks –A data-flow framework (D, F, V, ∧ ) is monotone if for all x and y in V and f in F, x<=y implies f(x)<=f(y) Distributive frameworks –f(x ∧ y) = f(x) ∧ f(y) for all x and y in V and f in F. CS308 Compiler Theory7

The Iterative Algorithm for General Frameworks CS308 Compiler Theory8

The Iterative Algorithm for General Frameworks CS308 Compiler Theory9

Constant Propagation The set of data-flow values is a product lattice The lattice for a single variable consists of the following: –All constants appropriate for the type of the variable –The value NAC, which stands for not-a-constant. –The value UNDEF, which stands for undefined. CS308 Compiler Theory10 The semilattice for a typical integer- valued variable The semilattice of data-flow values is simply the product of the semilattices like the Figure.

Constant Propagation CS308 Compiler Theory11

Constant Propagation As long as there exists a path that defines a variable reaching a program point, the variable will not have an UNDEF value. If all the definitions reaching a program point have the same constant value, the variable is considered a constant even though it may not be defined along some program path. CS308 Compiler Theory12

Constant Propagation CS308 Compiler Theory13 The values of x are 10 and UNDEF at the exit of B2 and B3, respectively. UNDEF ∧ 10=10 The value of x is 10 on entry to B4. x in B5 can be replaced with10 What about B1-B3-B4-B5? Choosing 10 as the value of x cannot be worse than allowing x to assume random value.