More on Loop Optimization Data Flow Analysis CS 480.

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

CSC 4181 Compiler Construction Code Generation & Optimization.
SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
Course Outline Traditional Static Program Analysis Software Testing
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.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Loops or Lather, Rinse, Repeat… CS153: Compilers Greg Morrisett.
19 Classic Examples of Local and Global Code Optimizations Local Constant folding Constant combining Strength reduction.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Jeffrey D. Ullman Stanford University. 2  A never-published Stanford technical report by Fran Allen in  Fran won the Turing award in  Flow.
Graph-Coloring Register Allocation CS153: Compilers Greg Morrisett.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
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.
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 Lecture 7 Code Optimizations: Partial Redundancy Elimination.
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.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
More Dataflow Analysis CS153: Compilers Greg Morrisett.
CS 536 Spring Global Optimizations Lecture 23.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
Reduction in Strength CS 480. Our sample calculation for i := 1 to n for j := 1 to m c [i, j] := 0 for k := 1 to p c[i, j] := c[i, j] + a[i, k] * b[k,
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
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.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
Intermediate Code. Local Optimizations
Improving Code Generation Honors Compilers April 16 th 2002.
Prof. Fateman CS164 Lecture 211 Local Optimizations Lecture 21.
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.
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.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Compiler Code Optimizations. Introduction Introduction Optimized codeOptimized code Executes faster Executes faster efficient memory usage efficient memory.
1 CS 201 Compiler Construction Data Flow Analysis.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
MIT Introduction to Program Analysis and Optimization Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Jeffrey D. Ullman Stanford University. 2 boolean x = true; while (x) {... // no change to x }  Doesn’t terminate.  Proof: only assignment to x is at.
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 and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
Optimization Simone Campanoni
Code Optimization Overview and Examples
Code Optimization.
Data Flow Analysis Suman Jana
Static Single Assignment
Basic Block Optimizations
Fall Compiler Principles Lecture 8: Loop Optimizations
Topic 10: Dataflow Analysis
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.
Compiler Code Optimizations
Code Optimization Overview and Examples Control Flow Graph
Fall Compiler Principles Lecture 10: Loop Optimizations
Live Variables – Basic Block
Basic Block Optimizations
Code Optimization.
Presentation transcript:

More on Loop Optimization Data Flow Analysis CS 480

Make a broader goal for loop optimization General idea: – Link every assignment of a variable to the set of all places it might possibly be used – Link every use of a variable to the set of all places it might possibly have been assigned In general, a use might have several assignments, and an assign will almost always have many uses

How to do this Fundamental equation For each node: out = (in – kill) union gen Out: variables (and values) that flow out of a node In: variables (and values) that flow in to a node Kill: variables killed by a node Gen : variables (and values) generated by a node

Note that kill definition slightly different For common subscripts kill was defined as “possibly altered” For this we need to define kill as “possibly survive” X = 12 *p = 42 … If (x < b) // could use of x come from assign?

Apply equations repeatedly Apply equations to each node in the graph until nothing changes Will certainly need to do this repeated times x = 3 while (x < a) // link use of x to assignment if (b > 0) x = x + b else x = x - b

Once we have this information, what can we do with it? What is a variable that is used but never assigned to? What is a variable that is set but never used?

What about this one? max = 142 …. // lots of code, none of which changes max If (a < (max – 1)) …. // called constant propagation

Dead code elimination Can possibly discover, at compile time, that a whole section of code cannot possibly ever be executed. Think that no good programmer would ever do this?

How many people have done this? Debug = false … If (debug) { … } … Why generate code that is not executed?

Copy Propagation After X = y X and y are aliases of each other until one or the other is reassigned. Can look for common subexpressions that might not be obvious Z = (x + 42) * w G = (y + 42) * w

From previous lectures Loop invariant code (expressions with no set inside of loop) Induction variables and the resulting reduction in strength

Common subexpressions that span nodes Previously we only looked at common subexpressions within a single node What about expressions that span nodes – called available expressions A[x + 42] = 17 // subscript is common If (b < 39) a [ x + 42 ] = 18 // can be saved and reused

Or can be distributed out Or, common subexpressions can be moved back to a previous common node – called busy expressions if (a < 12) b[x + 32] = 17 Else b[x + 32] = 49 // can move subscript before if

Live-dead analysis When registers are used to hold variables (more next week) need to know when a variable is no longer being used, and can free up the register Called “live-dead analysis”

New one – polymorphism elimination Var w : window …. W = new textWindow(); …. w.draw(); // if we can ensure that w is a textwindow can probably generate faster code

Bottom line Data flow analysis, matching every variable set and every variable use, is one of the most powerful tools in the optimizer writers set of tricks