U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.

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

Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
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.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
SSA.
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-
Jeffrey D. Ullman Stanford University. 2  Generalizes: 1.Moving loop-invariant computations outside the loop. 2.Eliminating common subexpressions. 3.True.
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.
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.
1 Partial Redundancy Elimination Finding the Right Place to Evaluate Expressions Four Necessary Data-Flow Problems.
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.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 More data flow analysis Emery Berger.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Lecture 2 Emery Berger University of.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
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.
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.
Loop invariant detection using SSA An expression is invariant in a loop L iff: (base cases) –it’s a constant –it’s a variable use, all of whose single.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Class canceled next Tuesday. Recap: Components of IR Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Data flow analysis Emery Berger University.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
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.
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.
Global Common Subexpression Elimination with Data-flow Analysis Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Computer Science & Engineering, Indian Institute of Technology, Bombay Code optimization by partial redundancy elimination using Eliminatability paths.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Introduction to Optimization, II Value Numbering & Larger Scopes Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Advanced Compilers CMPSCI 710 Spring 2004 Lecture 1 Emery Berger University of Massachusetts,
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Static Single Assignment John Cavazos.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Dominators, etc. Emery Berger University.
12/5/2002© 2002 Hal Perkins & UW CSER-1 CSE 582 – Compilers Data-flow Analysis Hal Perkins Autumn 2002.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science John Cavazos J Eliot B Moss Architecture and Language Implementation Lab University.
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.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Lecture 5 Partial Redundancy Elimination
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
Topic 10: Dataflow Analysis
Code Generation Part III
Advanced Compiler Techniques
Code Generation Part III
Static Single Assignment Form (SSA)
Topic 5a Partial Redundancy Elimination and SSA Form
Data Flow Analysis Compiler Design
Static Single Assignment
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
Prof. Dhananjay M Dhamdhere
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710 Spring 2003 Partial Redundancy Elimination

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 2 Topics Last time Common subexpression elimination Value numbering Global CSE This time Partial redundancy elimination

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 3 Partial Redundancy Partial redundancy: Expression computed more than once on some path through control-flow graph Partial-redundancy elimination (PRE): Minimizes partial redundancies Inserts and deletes computations (adds temps)  Each path contains no more (usually fewer) occurrences of any computation than before Dominates global CSE & loop-invariant code motion

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 4 PRE Example

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 5 PRE: Problem Critical edge prevents redundancy elimination Connects node with two or more successors to one with two or more predecessors Why is it a problem?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 6 PRE: Solution Split critical edges! Insert empty basic blocks Allows PRE to continue

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 7 Big Example: Critical Edges

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 8 Big Example: Critical Edges Removed

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 9 PRE Dataflow Equations First formulation [Morel & Renvoise 79] bidirectional dataflow analysis Ugly This version [Knoop et al. 92] Based on “lazy code motion” Places computations as late as possible Same reductions as classic algorithm Minimizes register pressure Most complex dataflow problem we’ve ever seen…

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 10 Step 1: Local Transparency Expression’s value is locally transparent in a basic block if No assignments to variables that occur in expression Set of locally transparent expressions: TRANSloc(i) Note: Ignore expressions in branches

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 11 Local Transparency TransLoc – no assignments to variables in expression

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 12 Step 2: Locally Anticipatable Expression is locally anticipatable in basic block if There is computation of expression in block Moving to beginning of block has no effect No uses of expression nor assignments of variable in block ahead of computation Set of locally anticipatable expressions: ANTloc(i)

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 13 Locally Anticipatable ANTloc – computes expr, can move to front

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 14 Step 3: Globally Anticipatable Expression’s value globally anticipatable on entry to basic block if Every path from that point includes computation of expression Expression yields same value all along path Set of globally anticipatable expressions: ANTin(i)

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 15 Globally Anticipatable Expressions: Dataflow Equations ANTout(exit) =  ANTin(i) = ANTloc(i) [ (TRANSloc(i) Å ANTout(i)) ANTout(i) = Å j 2 Succ(i) ANTin(j) What’s the analysis direction?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 16 Globally Anticipatable ANTout(exit) =  ANTin(i) = ANTloc(i) [ (TRANSloc(i) Å ANTout(i)) ANTout(i) = Å j 2 Succ(i) ANTin(j)

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 17 Step 4: Earliest Expressions Expression is earliest at entrance to block if No block from entry to block both: Evaluates expression and Produces same value as at entrance to block Defined in terms of local transparency and globally anticipatable expressions EARLin(i) = [ j 2 Pred(i) EARLout(j) EARLout(i) = inv(TRANSloc(i)) [ (inv(ANTin(i)) Å EARLin(i)) Initialize EARLin(entry) = U exp

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 18 Early Expressions EARLin(i) = [ j 2 Pred(i) EARLout(j) EARLout(i) = inv(TRANSloc(i)) [ (inv(ANTin(i) Å EARLin(i))

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 19 PRE Transformation We’ll cut to the chase: Latest, Isolated expressions Use earliest, globally anticipatable OPT(i) = latest but not isolated = LATEin(i) Å inv(ISOLout(i)) REDN(i) = used but not optimal = ANTloc(i) Å inv(LATEin(i) [ ISOLout(i)) Insert fresh temporaries for OPT expressions, replace uses in REDN

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 20 OPT, REDN, PRE OPT(B1) = a+1 OPT(B2, B3a) = x*y REDN(B1) = a+1 REDN(B2, B4, B7) = x*y

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 21 Conclusion PRE Subsumes global CSE & loop-invariant code motion Complex (but unidirectional) dataflow analysis problem Can only reduce number of computations and register pressure Next time Register allocation: ACDI ch.16, pp