A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION Proseminar „Programmanalyse”, Prof. Dr. Heike Wehrheim Universität Paderborn, WS 2011/2012.

Slides:



Advertisements
Similar presentations
Example of Constructing the DAG (1)t 1 := 4 * iStep (1):create node 4 and i 0 Step (2):create node Step (3):attach identifier t 1 (2)t 2 := a[t 1 ]Step.
Advertisements

Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Lecture 11: Code Optimization CS 540 George Mason University.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
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.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
C Chuen-Liang Chen, NTUCS&IE / 321 OPTIMIZATION Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University.
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
1 Introduction to Data Flow Analysis. 2 Data Flow Analysis Construct representations for the structure of flow-of-data of programs based on the structure.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Dataflow Analysis Introduction Guo, Yao Part of the slides are adapted from.
1 CS 201 Compiler Construction Data Flow Framework.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
Partial Redundancy Elimination. Partial-Redundancy Elimination Minimize the number of expression evaluations By moving around the places where an expression.
1 Data flow analysis Goal : collect information about how a procedure manipulates its data This information is used in various optimizations For example,
Early Global Program Optimizations Chapter Mooly Sagiv.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
1 Data flow analysis Goal : –collect information about how a procedure manipulates its data This information is used in various optimizations –For example,
Catching Bugs in the Web of Program Invariants Proseminar „Programmanalyse”, Prof. Dr. Heike Wehrheim Universität Paderborn, WS 2011/2012 Anton Tonkushin.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
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.
CS 201 Compiler Construction
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.
Data Flow Analysis Compiler Design Nov. 8, 2005.
1 Copy Propagation What does it mean? – Given an assignment x = y, replace later uses of x with uses of y, provided there are no intervening assignments.
Improving Code Generation Honors Compilers April 16 th 2002.
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
1 CS 201 Compiler Construction Lecture 4 Data Flow Framework.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
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. 8, 2005.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
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 Region-Based Data Flow Analysis. 2 Loops Loops in programs deserve special treatment Because programs spend most of their time executing loops, improving.
1 CS 201 Compiler Construction Data Flow Analysis.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
MIT Introduction to Program Analysis and Optimization Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Data flow analysis John Cavazos University.
Optimization Simone Campanoni
Code Optimization Data Flow Analysis. Data Flow Analysis (DFA)  General framework  Can be used for various optimization goals  Some terms  Basic block.
High-level optimization Jakub Yaghob
Data Flow Analysis Suman Jana
Lecture 5 Partial Redundancy Elimination
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
Global optimizations.
University Of Virginia
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.
CS 201 Compiler Construction
Interval Partitioning of a Flow Graph
Static Single Assignment
EECS 583 – Class 5 Dataflow Analysis
Compiler Construction
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
Optimizing Compilers CISC 673 Spring 2009 Data flow analysis
Live Variables – Basic Block
Presentation transcript:

A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION Proseminar „Programmanalyse”, Prof. Dr. Heike Wehrheim Universität Paderborn, WS 2011/2012

2 Different Data flow problems  Reaching definitions For each use of a variable, find all definitions that reach it.  Live variables For a point p and a variable v, determine whether v is live at p.  Upward exposed uses For each definition of a variable, find all uses that it reaches. Find all expressions whose value is available at some point p.  Available expressions

3 Global: Goal = to collect information at the beginning and end of each basic block Iterative: Construct data flow equations that describe how information flows through each basic block and solve them by iteratively converging on a solution. Global Iterative Data Flow Analysis

4  Components of data flow equations  Sets containing collected information  in set: information coming into the BB from outside (following flow of dats)  gen set: information generated/collected within the BB  kill set: information that, due to action within the BB, will affect what has been collected outside the BB  out set: information leaving the BB  Functions (operations on these sets)  Transfer functions describe how information changes as it flows through a basic block  Meet functions describe how information from multiple paths is combined. Global Iterative Data Flow Analysis

Constant propagation Common subexpression elimination CP and CSE 5

Constant propagation CONSTANT PROPAGATION begin integer i,a,b,c,d,e a:=1; c:=0; … for i:=1 step 1 until 10 do begin b:=2; … d:=a+b; … e:=b+c; … c:=4;... end end entry: a:=1 c:=0 b:=2 d:=a+b e:=b+c c:=4 A B C D E F P A = ∅ P B = {(a,1)} P C = {(a,1)} P D = {(a,1),(b,2)} P E = {(a,1),(b,2),(d,3)} P F = {(a,1),(b,2),(d,3)} 6 Problem: Determining the pool of propagated constants Pool of Constants

CONSTANT PROPAGATION entry: a:=1 A c:=0 B b:=2 C d:=a+b D e:=b+c E c:=4 F 7 = {(a,1),(b,2),(c,4),(d,3),(e,2)} Formally Determining the Pool of propagated constants at node E The first approximation for the path from A to E: (A,B,C,D,E) = {(a,1),(c,0),(b,2),(d,3)} The second approximation for the path (A,B,C,D,E,F,C,D,E)

final constant pool DATA FLOW ANALYSIS ALGORITHM {(a,1),(b,2),(d,3),(e,2),(c,4)} P = {(a,1),(b,2),(d,3),(e,2),(c,4)} = {(a,1)} 8 = {(a,1),(c,0)} = {(a,1),(c,0),(b,2)} = {(a,1),(c,0),(b,2),(d,3)} = {(a,1),(c,0),(b,2),(d,3),(e,2)} no changes anymore For instance: Formally: The constant pool resulting from F entering C: THE SECOND APPROXIMATIONTHE THIRD ONE = {(a,1),(b,2)} = {(a,1),(b,2),(d,3)} = {(a,1)} …

9 DATA FLOW ANALYSIS ALGORITHM INFORMAL a.Start with an entry node P i with a given entry pool usually only one entry node Usually entry pool is empty b.Process P i and produce optimizing function c.Intersect the incoming optimization pools (for the first time assume as the first approximation) d.Considering each successor node, if the amount of optimization information is reduced, then process the successor in the same manner as the initial entry node.

DATA FLOW ANALYSIS ALGORITHM f(A, ∅ ) = {(a,1)} f(B, {(a,1)}) = {(a,1),(c,0)} f(C, f(B, f(A, ∅ ))) = {(a,1), (c,0), (b,2)} 10 f : N × P(U) P(U) f : N × P P Homomorphism: Note f(N, x) < 1 and N analyzed set of nodes U = V × C ordered pairs in any constant pool V set of variables C set of constants P(U) power set (the set of all subsets of U) So the function can be applied: “Optimizing function” f is defined

11 1: [initialize]L ← ℇ 2: [terminate?]if L= ∅ then halt 3: [select node]Let L' L, L'=(N,P i ) for some N N and P i P, L ← L- {L'} 4: [traverse?]Let P N be the current approximate pool for node N (Initially, P N = 1). If P N ≤ P i then go to step 2 5: [set pool]P N ← P N ∧ P i, L ← L {N', f(N, P N | N‘ I(N) 6: [loop]go to step 2: DATA FLOW ANALYSIS ALGORITHM

Common subexpression elimination … r:=a+b; … r+x …(a+b)+X … r:=a+b r+x (a+b)+x entry:A B C D Before A P A = ∅ Before B P B =P A = {a I b I a+b, r } Before C P C {a I b I a+b, r I x I x+r} Before D P D {a I b I a+b, r I x I x+r I (a+b)+x} (a+b)+x has the same evaluation as r+x {a I b I a+b, r I x I r+x, (a+b)+x} 12 Detect Eliminate Detect Eliminate Problem redundant expressions purpose

Optimizing function f(N,P) 13 redundant New class in P Consider computation e d:=e in N remove expression with d 1.Create e’’ for each e’ in P 2.Place e’’ in class of e’ COMMON SUBEXPRESSION ELIMINATION 1.Consider each partial computation e at node N 2.If the computation in class of P then e is redundant 3.Create new class, add all computation, which have operands equivalent to e 4.If N contains d:=e, remove from class expression with d as a sub expression

14 CONSTANT PROPOGATION & COMMON SUBEXPRESSION ELIMINATIOM Optimizing function f 2 d:=e in N New class in P … … no further processing z:=e z in P combine z & e combine z & e Add z to e otherwise

QUESTIONS? 15