CMPUT 680 - Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic H: SSA for Predicated Code José Nelson Amaral

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.
Topic G: Static Single-Assignment Form José Nelson Amaral
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
1 Authors: Vugranam C. Sreedhar, Roy Dz-Ching Ju, David M. Gilles and Vatsa Santhanam Reader: Pushpinder Kaur Chouhan Translating Out of Static Single.
Course Outline Traditional Static Program Analysis Software Testing
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.
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic 5: Peep Hole Optimization José Nelson Amaral
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.
SSA.
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
Program Representations. Representing programs Goals.
Preliminary Transformations Chapter 4 of Allen and Kennedy Harel Paz.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
1 Data flow analysis Goal : collect information about how a procedure manipulates its data This information is used in various optimizations For example,
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 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.
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.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Computing SSA Emery Berger University.
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic G: Static Single- Assignment Form José Nelson Amaral
2015/6/24\course\cpeg421-10F\Topic1-b.ppt1 Topic 1b: Flow Analysis Some slides come from Prof. J. N. Amaral
1 CS 201 Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding.
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.
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.
Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
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.
What’s in an optimizing compiler?
Predicated Static Single Assignment (PSSA) Presented by AbdulAziz Al-Shammari
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Building SSA Form, III 1COMP 512, Rice University This lecture presents the problems inherent in out- of-SSA translation and some ways to solve them. Copyright.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Static Single Assignment John Cavazos.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.
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.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
Examples of SSA based optimizers: Global Value Numbering.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Introduction to Optimization
Code Optimization.
Static Single Assignment
Princeton University Spring 2016
Introduction to Optimization
CS 201 Compiler Construction
Topic 4: Flow Analysis Some slides come from Prof. J. N. Amaral
Compiler Code Optimizations
Optimizations using SSA
Interval Partitioning of a Flow Graph
Introduction to Optimization
Optimizing Compilers CISC 673 Spring 2011 Static Single Assignment II
8 Code Generation Topics A simple code generator algorithm
SSA-based Optimizations
EECS 583 – Class 9 Classic and ILP Optimization
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic H: SSA for Predicated Code José Nelson Amaral

CMPUT Compiler Design and Optimization2 Reading Material Stoutchinin, A., Ferriere, F. de, “Efficient Static Assignment Form for Predication,” 34th Annual International Symposium on Microarchitecture, Dec. 2001, Austin, TX, pp

CMPUT Compiler Design and Optimization3 Motivation There are efficient algorithms based on SSA for: - constant propagation - partial redundancy elimination - induction variable recognition - etc Traditionally compilers apply the following steps: 1. Convert to SSA 2. Apply common optimizations 3. Convert out of SSA 4. Perform If-conversion 5. Do non-SSA optimization of if-converted code.

CMPUT Compiler Design and Optimization4 Problem In conventional SSA, the code transformation is: b = rand() b>a? b = qb = b+3 f = b*2 b1 = rand() b1>a? b2 = qb3 = b1+3 b4=  (b2,b3) f = b4*2

CMPUT Compiler Design and Optimization5 Problem (cont.) After if conversion we have: b = rand() b>a? b = qb = b+3 f = b*2 b = rand() p1, p2 = b>a? p1: b = q p2: b = b+3 f = b*2

CMPUT Compiler Design and Optimization6 Problem (cont.) b1 = rand() p1, p2 = b1>a? p1: b2 = q b3 = ?? p2: b4 = b3+3 b5 = ?? f = b5*2 How to account for the multiple values produced for a variable in the same control path under SSA?

CMPUT Compiler Design and Optimization7  -SSA Stoutchinin defines the  -SSA, a simple extension of the  -SSA. In  -SSA the operands of a  -function indicate which predicated definition reaches a given point in the program.

CMPUT Compiler Design and Optimization8 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true

CMPUT Compiler Design and Optimization9 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true What is the value for this use of x?

CMPUT Compiler Design and Optimization10 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true What is the value for this use of x? Depends on the values of g1 and g2. How do you represent this dependence in  -SSA? You can’t.

CMPUT Compiler Design and Optimization11 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true x2 =  (x0, x1) 1: g1?x3 = 2 x4 =  (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 = ?? 4: = x6 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead x0 =x1 =

CMPUT Compiler Design and Optimization12 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true x2 =  (x0, x1) 1: g1?x3 = 2 x4 =  (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead x0 =x1 = The original values are used, not the ones generated by  -functions.

CMPUT Compiler Design and Optimization13 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true x2 =  (x0, x1) 1: g1?x3 = 2 x4 =  (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = ?? 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 =

CMPUT Compiler Design and Optimization14 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g?  operation is active when g is true g!  operation is active when g’s complement is true x2 =  (x0, x1) 1: g1?x3 = 2 x4 =  (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 =  (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 =

CMPUT Compiler Design and Optimization15 Example: Optimizations x2 =  (x0, x1) 1: g1?x3 = 2 x4 =  (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 =  (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 = x2 =  (x0, x1) 1: g1?x3 = 2 x4 =  (x2, x3) x10 =  (x3) 2: g1? = x10 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 =  (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 = X4 is only used if the assignment to x3 happens.

CMPUT Compiler Design and Optimization16 Example: Optimizations x2 =  (x0, x1) 1: g1?x3 = 2 x10 =  (x3) 2: g1? = x10 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 =  (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 = x2 =  (x0, x1) 1: g1?x3 = 2 x10 =  (x3) 2: g1? = x10 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 =  (x2, x3, x5, x7, x8) x11 =  (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = G5 = g3|g4, thus x9 is only used if either x7 or x8 are defined.

CMPUT Compiler Design and Optimization17 Example: Optimizations x2 =  (x0, x1) 1: g1?x3 = 2 x10 =  (x3) 2: g1? = x10 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 =  (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = x2 =  (x0, x1) 1: g1?x3 = 2 x10 =  (x3) 2: g1? = x3 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 =  (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 =

CMPUT Compiler Design and Optimization18 Example: Optimizations x2 =  (x0, x1) 1: g1?x3 = 2 2: g1? = x3 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 =  (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = x2 =  (x0, x1) 1: g1?x3 = 2 2: g1? = x3 3: g2?x5 = z x6 =  (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 =  (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = Assuming that g1 + g2 = 1

CMPUT Compiler Design and Optimization19 Example: Optimizations 1: g1?x3 = 2 2: g1? = x3 3: g2?x3 = z 4: = x3 5: g3?x7 = v 6: g4?x7 = w 7:g5 = g3 | g4 8: g5? = x7 x3 and x7 are dead x0 =x1 = x2 =  (x0, x1) 1: g1?x3 = 2 2: g1? = x3 3: g2?x5 = z x6 =  (x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 =  (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = Translating out of SSA.

CMPUT Compiler Design and Optimization20  -Functions Only the first operand of a  -function can correspond to a non-predicated (eg. a  -function) or an unconditional assignment.  -function operands that are defined by another  -function are inlined into the operand list. This inlining allows for the de-serialization of the  -functions, and for the reordering of predicate code.

CMPUT Compiler Design and Optimization21  -Functions Given a  -function  (x 1, x 2, …, x k ), the operands x 1, x 2, … x k are defined in a single control flow path, and their order from left to right is the program order of the assignments to these variables. The value of  (x 1, x 2, …, x k ) is the value of the operand whose assignment is executed the last at runtime.

CMPUT Compiler Design and Optimization22 Placement of  -Functions The introduction of  -functions does not affect the semantics of  -functions. Thus in a predicated code, the  -functions are inserted first to take care of the predicated assignments and then the usual SSA renaming with  -functions takes place. The  -functions can be placed during the Cytron-Ferrante  placement algorithm.

CMPUT Compiler Design and Optimization23  -Congruence Two variables x and y are congruent to each other, if (i) they are referenced in the same  -function; or (ii) there exist a variable z such that x is congruent to z and z is congruent to y. When translating out of  -SSA, all the variables in a  -congruent class can be replaced by a single temporary name.

CMPUT Compiler Design and Optimization24  -Congruence Order Given two variables x and y, x precedes y in congruence order, x  c y, if: (i) x is an argument in a  -function that defines y, or (ii) the definitions of x and y may be active at the same execution, and (a) x precedes y in the argument list of some  -function, or (b) there is a variable z such that (1) x precedes z for some  -function, and (2) z precedes y in (the same or another)  - function.

CMPUT Compiler Design and Optimization25  -Congruence Order The  -Congruence Order defines a partial order on the statements that define variables. This partial order must be maintained when translating out of  -SSA in order to preserve the correct semantic of the program.