Copy Propagation and Common Subexpression Elimination in Titanium Johnathon Jamison David Marin CS265 S. Graham.

Slides:



Advertisements
Similar presentations
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Advertisements

Chapter Modules CSC1310 Fall Modules Modules Modules are the highest level program organization unit, usually correspond to source files and.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Computer Science 313 – Advanced Programming Topics.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Loops or Lather, Rinse, Repeat… 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.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Dataflow Analysis Introduction Guo, Yao Part of the slides are adapted from.
Program Representations. Representing programs Goals.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Partial Redundancy Elimination Guo, Yao.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
Introduction to Code Optimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
1 CS 201 Compiler Construction Lecture 12 Global Register Allocation.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Recap from last time Saw several examples of optimizations –Constant folding –Constant Prop –Copy Prop –Common Sub-expression Elim –Partial Redundancy.
CS 536 Spring Global Optimizations Lecture 23.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
Administrative info Subscribe to the class mailing list –instructions are on the class web page, click on “Course Syllabus” –if you don’t subscribe by.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
Administrative info Subscribe to the class mailing list –instructions are on the class web page, which is accessible from my home page, which is accessible.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
Another example p := &x; *p := 5 y := x + 1;. Another example p := &x; *p := 5 y := x + 1; x := 5; *p := 3 y := x + 1; ???
CS 201 Compiler Construction
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.
Class canceled next Tuesday. Recap: Components of IR Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Intermediate Code. Local Optimizations
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
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.
Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Fast, Effective Code Generation in a Just-In-Time Java Compiler Rejin P. James & Roshan C. Subudhi CSE Department USC, Columbia.
Presentation of Failure- Oblivious Computing vs. Rx OS Seminar, winter 2005 by Lauge Wullf and Jacob Munk-Stander January 4 th, 2006.
Amortized Algorithm Analysis COP3503 July 25, 2007 Andy Schwartz.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
Introduction to OOP CPS235: Introduction.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax.
Code Optimization Overview and Examples
Introduction to Optimization
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Basic Block Optimizations
Common Subexpression Elimination
For Example: User level quicksort program Three address code.
Common Subexpression Elimination
Machine-Independent Optimization
Common Subexpression Elimination and Copy Propagation in Titanium
Topic 10: Dataflow Analysis
Introduction to Optimization
Code Generation Part III
Code Generation Part III
Static Single Assignment Form (SSA)
Indirection.
Data Flow Analysis Compiler Design
Introduction to Optimization
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Live Variables – Basic Block
Basic Block Optimizations
Presentation transcript:

Copy Propagation and Common Subexpression Elimination in Titanium Johnathon Jamison David Marin CS265 S. Graham

Outline Titanium Def/Use analysis (used by CSE) Copy Propagation Common Subexpression Elimination Implementation Examples

Titanium Titanium is an extension of Java The Titanium compiler compiles Titanium code to C The C code is then compiled by the system compiler, e.g. gcc

Def/Use Given: a = … … …a… We want to link the use of a to the definition of a above.

Def/Use Every use of a variable has a list of all possible definitions associated with it Every definition of a variable has a list of all possible uses associated with it Method calls and pointer indirection are included in this analysis

Def/Use The Titanium compile has (may) def/use information available It seems this could be leveraged for Copy Propagation or CSE (rather than writing a whole new dataflow analysis)

Global Copy Propagation Given a = b; … x = a + 1; We want to replace a with b on the last line, but we need to know that a and b are unchanged Def/use analysis isn’t quite enough (why?)

Inserting Fake Defs and Uses Add fake defs and uses so that def/use analysis gives us the info we need b = b; a = b; … newfaketemp = b; x = a + 1; We can use a similar technique to enable CSE.

CSE Given: a = f * i … b = f * i We want to compute f * i only once

CSE We could do: a = f * i temp = a … b = temp But only if the value of f * i has not changed

Finding CSEs a = f * i … b = f * i The second f * i can be eliminated if the definitions of f and i that are used are exactly the same as the first –Leverage our def/use analysis! But checking for that could be onerous

Finding CSEs So, lets create some fake definitions of f and i immediately before the first f * i Then, there is one explicit definition that can be traced to for checking the previously mentioned condition

Finding CSEs f = f i = i a = f * i … b = f * i Thus, if f and i have the same definitions in both places, then the second f * i can be eliminated

Handing Global CSEs This is fine and dandy for straight line code, but what if you have: a = f * ib = f * i… c = f * i

Handing Global CSEs So, you need to see if f and i have the same definitions in all pairs of places where the common subexpression exists. I.e., does f or i have any definition that is not associated with a fake definition introduced by this analysis? If not, then an elimination can occur

Simultaneous CSEs The def/use analysis is expensive –You can not run the def use analysis for every potential CSE Thus all CSEs should be analyzed simultaneously So, extra assignments are placed everywhere in the code a CSE could be

Simultaneous CSEs When tracing definitions, those introduced definitions must be explicitly ignored Trace back from a use If it is a definition associated with a CSE we are cool If it is an introduced one, pass through If it is neither, we can not use this

Altogether Now… Insert the extra assignments For every similar expression –At every site, try to eliminate this expression Delete the assignments, so as not to interfere with anything else

Interaction with Copy Propagation Any temps introduced are placed after the calculation, so that copy propagation can remove thema = f * i temp_1 = a… b = f * ib = temp_1 temp_2 = b… c = f * ic = temp_2

CSE Tidbits Compiler temps are placed at top level, as the live range of CSEs are unknown Associativity is accounted for Only binary and unary operations are done –Can be extended

Examples

Timings – Preliminary Results CSE alone seems to have negligable effect Global copy propagation gives a few percent increase CSE on top of global copy propagation gives a couple percent more