Topic 5a Partial Redundancy Elimination and SSA Form

Slides:



Advertisements
Similar presentations
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
Advertisements

School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
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.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
SSA.
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Partial Redundancy Elimination.
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.
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.
Lazy Code Motion Comp 512 Spring 2011
05 May Lazy Code Motion in an SSA World A CS 526 Course Project Patrick Meredith Steven Lauterburg 05 May 2006.
Partial Redundancy Elimination & Lazy Code Motion
Lazy Code Motion C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
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,
University of Houston Extending Global Optimizations in the OpenUH Compiler for OpenMP Open64 Workshop, CGO ‘08.
Loop Invariant Code Motion — classical approaches — 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
TM Pro64™: Performance Compilers For IA-64™ Jim Dehnert Principal Engineer 5 June 2000.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Cpeg421-08S/final-review1 Course Review Tom St. John.
1 Data flow analysis Goal : –collect information about how a procedure manipulates its data This information is used in various optimizations –For example,
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
1 CS 201 Compiler Construction Lecture 8 Code Optimizations: Partial Dead Code Elimination.
CS 201 Compiler Construction
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic H: SSA for Predicated Code José Nelson Amaral
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Improving Code Generation Honors Compilers April 16 th 2002.
Static Single Assignment Form (SSA)
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
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.
Eliminating Memory References Joshua Dunfield Alina Oprea.
1 CS 201 Compiler Construction Data Flow Analysis.
Computer Science & Engineering, Indian Institute of Technology, Bombay Code optimization by partial redundancy elimination using Eliminatability paths.
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Code Optimization Overview and Examples
Introduction to Optimization
Lecture 5 Partial Redundancy Elimination
Static Single Assignment
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
Introduction to Optimization
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
Intermediate Code Generation
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.
Topic 4: Flow Analysis Some slides come from Prof. J. N. Amaral
Advanced Compiler Techniques
Static Single Assignment Form (SSA)
Topic-4a Dataflow Analysis 2019/2/22 \course\cpeg421-08s\Topic4-a.ppt.
Introduction to Optimization
Static Single Assignment
Reference These slides, with minor modification and some deletion, come from U. of Delaware – and the web, of course. 4/4/2019 CPEG421-05S/Topic5.
Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Reference These slides, with minor modification and some deletion, come from U. of Delaware – and the web, of course. 4/17/2019 CPEG421-05S/Topic5.
Lecture 17: Register Allocation via Graph Colouring
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
The SGI Pro64 Compiler Infrastructure
Prof. Dhananjay M Dhamdhere
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

Topic 5a Partial Redundancy Elimination and SSA Form 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

References Robert Kennedy, Sun Chan, Shin-ming Liu, Raymond Lo, Pend Tu, Fred Chow. Partial redundancy elimination in SSA Form. ACM Trans. On Programming Languages and Systems, 21(3), May 1999: 627-676. Drechsler K. and Stadel M. A variation of Knoop, Ruthing, and Steffen’s lazy code motion. SIGPLAN Notices, 28(5), May, 1993: 29-38. Keith Cooper, Linda Torczon. Engineering a compiler. 2004 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Partial Redundancy Elimination (PRE) SSAPRE (a short summary) Outline Partial Redundancy Elimination (PRE) SSAPRE (a short summary) 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

KCC Compiler Infrastructure Fortran C fe90 gfec gfecc Asm file Very High WHIRL High WHIRL Middle WHIRL Low WHIRL Very Low WHIRL CGIR Source to IR (Scanner →Parser →RTL →WHIRL) VHO (Very High WHIRL Optimizer) Standalone Inliner W2C/W2F IPA (inter-procedural analysis & opt) LNO (Loop unrolling/fission/fusion/tiling/peeling etc) PREOPT (point-to analysis etc) WOPT - SSAPRE (Partial Redundancy Elimination) - VNFRE (Value numbering based full redundancy elim.) RVI-1 (Register Variable Identification) RVI-2 Some peephole opt Cflow (control flow opt) EBO (extended block opt.) PQS (predicate query system) Loop Opt (Unrolling + SWP) GCM (global code motion), HB sched (hyperblk schedule) GRA/LRA (global/local register alloc) Machine Model Front end Middle end Back end 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Important Observation An operand of a  function is regarded as occurring at the end of its corresponding predecessor block. The result of a  function is regarded as occurring at the beginning of the block that contains it. 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Partial Redundancy Elimination Is the program in SSA form before and after PRE? tx*y a t a x*y B1 tx*y B2 X*y is partially redundant here b x*y b t B3 X*y is made redundant here 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Problem Formulation for PRE For an expression, identify its partially redundant occurrences Safely insert occurrences (to new temporaries) at some points Delete the original partially (now fully) redundant occurrences. Replace them by loads from a temporary variable. 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

PRE Basics Availability: An expression, say, x*y, is available at a program point p if EVERY path from entry to p evaluates the expression before reaching p And there are no assignments to x or y after the (last) evaluation but before p (on all paths). Availability implies full redundancy. 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

PRE Basics (Cont.) Partial availability: An expression, say, x*y, is partially available at a program point p if SOME paths from entry to p evaluates the expression before reaching p And there are no assignments to x or y after the (last) such evaluation but before p. Partial availability implies partial redundancy. 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

X*y is anticipatable here PRE Basics (Cont.) Anticipatability: An expression e is anticipatable ( “down-safe”) at a program point p if it appears (without redefinition) along ALL paths from p to an exit of the program X*y is anticipatable here a x*y b x*y B3 B1 B2 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Safe Placement - Safe insertion: If an inserted computation occurs at a point where the computation is anticipated. - Unsafe insertion: means that some original path in the program did not contain this computation. May increase the execution time of the program May cause exceptions 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Safe Placement: Example x*y x*y This is called an “critical edge”. Allowable if we can insert computations on an edge. Otherwise, need split Safe Not safe 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Optimal Placement (Cont’d) Computationally optimal If no other safe placement can result in fewer occurrences of the computation along any path from entry to exit in the program. 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Optimal Placement (cont’d) Lifetime optimal Minimize the lifetimes of the introduced temporaries. Intuition: delay an expression to the latest point (Lazy Code Motion [KnoopEtal92, DrechslerStadel93]) 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Partial redundancy elimination (PRE) Outline Partial redundancy elimination (PRE) SSAPRE (a short summary) 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

SSAPRE 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

SSAPRE: Motivation Traditional data flow analysis based on bit-vectors do not interface well with SSA representation 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Traditional Partial Redundancy Elimination a x*y b x*y B1 B2 B3 Before PRE SSA form tx*y a t After PRE B1 tx*y B2 Not SSA form! b t B3 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

SSAPRE: Motivation (Cont.) Traditional PRE needs a postpass transform to turn the results into SSA form again. SSA is based on variables, not on expressions 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

SSAPRE: Motivation (Cont.) Representative occurrence Given a partially redundant occurrence E0, we define the representative occurrence for E0 as the nearest to E0 among all occurrences that dominate E0. Unique and well-defined 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

FRG (Factored Redundancy Graph) Control flow edge E Factored E E =(E, E, ) Redundancy edge Without factoring 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

FRG (Factored Redundancy Graph) t0  x*y t1  x*y t2(t0, t1 , t3)  t2 E =(E, E, ) E E Note: This is in SSA form 2019-01-10 Assume E=x*y \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Observation Every use-def edge of the temporary corresponds directly to a redundancy edge for the expression. 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

Intuition for SSAPRE Construct FRG for each expression E Refine redundant edges to form the use-def relation for each expression E’s temporary Transform the program For a definition, replace with tE For a use, replace with t Sometimes need also insert an expression 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

An Example a1 t1 a1+ b1 B1 a1 B1 t2(t4 , t1) a2(a4 , a1) exit B5 2019-01-10 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt exit