1 CS 201 Compiler Construction Lecture 10 SSA-Based Sparse Conditional Constant Propagation.

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
Overview Structural Testing Introduction – General Concepts
1 SSA review Each definition has a unique name Each use refers to a single definition The compiler inserts  -functions at points where different control.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
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.
1 CS 201 Compiler Construction Machine Code Generation.
SSA.
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
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 Constant Propagation for Loops with Factored Use-Def Chains Reporter : Lai, Yen-Chang.
SSA-Based Constant Propagation, SCP, SCCP, & the Issue of Combining Optimizations 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon,
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
Semi-Sparse Flow-Sensitive Pointer Analysis Ben Hardekopf Calvin Lin The University of Texas at Austin POPL ’09 Simplified by Eric Villasenor.
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
Early Global Program Optimizations Chapter Mooly Sagiv.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
1 CS 201 Compiler Construction Lecture 10 SSA-Based Sparse Conditional Constant Propagation.
1 CS 201 Compiler Construction Lecture 12 Global Register Allocation.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Data Flow Analysis Compiler Design Nov. 3, 2005.
From last time: reaching definitions For each use of a variable, determine what assignments could have set the value being read from the variable Information.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
CS 201 Compiler Construction
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.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
1 CS 201 Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
1 CS 201 Compiler Construction Lecture 9 Static Single Assignment Form.
From last time: reaching definitions For each use of a variable, determine what assignments could have set the value being read from the variable Information.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Constant Propagation. The constant propagation framework is different from all the data-flow problems discussed so far, in that It has an unbounded set.
Precision Going back to constant prop, in what cases would we lose precision?
1 CS 201 Compiler Construction 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.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
Using SSA Dead Code Elimination & Constant Propagation C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
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.
Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.
CS 614: Theory and Construction of Compilers Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
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.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Data Flow Analysis II AModel Checking and Abstract Interpretation Feb. 2, 2011.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Yet More Data flow analysis John Cavazos.
Definition-Use Chains
Efficiently Computing SSA
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.
CS 201 Compiler Construction
Dataflow analysis.
CS 201 Compiler Construction
CS 201 Compiler Construction
Static Single Assignment Form (SSA)
Optimizations using SSA
Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Relational Operators.
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Objectives Identify advantages (and disadvantages ?) of optimizing in SSA form Given a CFG in SSA form, perform Global Constant Propagation Dead code elimination.
Objectives Identify advantages (and disadvantages ?) of optimizing in SSA form Given a CFG in SSA form, perform Global Constant Propagation Dead code elimination.
Presentation transcript:

1 CS 201 Compiler Construction Lecture 10 SSA-Based Sparse Conditional Constant Propagation

Conditional Constant Propagation SSA-based algorithm is faster than the previous algorithm that was presented earlier. Basic Idea: Use SSA-edges for faster propagation of constants from definitions to uses. 2

Contd.. Handling Executable vs Non-Executable Edges - At ϕ -functions non- executable operands have lattice value of top-undef- - This allows conditional constant propagation. - Process nodes only when they are known to be executable. - Non-executable SSA edges will transmit 3

Contd.. When can we process a SSA edge ? - When we know the destination of the edge is executable. - Destination statement is executable when at least one of the incoming control flow edge is executable. Justification: In SSA form ecah use receives value from only one definition. Thus, no matter how we get to the use it will get the value from the same SSA-edge. 4

Contd.. Maintain two worklists: FlowWorkList (for control flow edges) SSAWorkList (for SSA edges) 1.Initialize: FlowWorkList  Edges leaving the entry node. SSAWorkList  {} ExecutableFlag(FlowEdge)  False Lattice cells initialized to UNDEF or top 2. Halt execution when both worklists are empty. Execution may proceed by processing edges from either worklist. 5

Contd.. Maintain two worklists: FlowWorkList (for control flow edges) SSAWorkList (for SSA edges) 1.Initialize: FlowWorkList  Edges leaving the entry node. SSAWorkList  {} ExecutableFlag(FlowEdge)  False Lattice cells initialized to UNDEF or top 2. Halt execution when both worklists are empty. Execution may proceed by processing edges from either worklist. 6

Contd.. 3. if e is CFG-edge from FlowWorkList then if ExecutableFlag(e)=false then ExecutableFlag(e) = true Perform Visit ϕ for all ϕ -nodes at destination node. if only one incoming CFG-edges is TRUE then this this is the first visit to the node then Perform VisitExpression at the node if the node contains one outgoing CFGedge then add the edge to FlowWorkList 7

Contd.. 4. if e is SSA-edge from SSAWorkList then if destination of e is a ϕ -node then Perform Visit ϕ elseif destination of e is an expression then examine ExecutableFlags for the CFG edges reaching that node and if any one flag is true then perform VisitExpression. 8

Contd.. Visit ϕ For each operand in the ϕ -node examine the ExecutableFlag of the corresponding CFG-edge and set the operand’s lattice value as follows: CFG-edge executable  lattice value same as lattice value at the definition edge of the SSA-edge. CFG-edge non-executable  lattice value is UNDEF or top. Compute the lattice value of the variable on the left hand side. 9

Contd.. VisitExpression Evaluate lattice value of the expression using lattice values of operands from places where they were defined. If lattice value changes then if expression is part of an assignment statement then add SSA-edge starting from left hand side to SSAWorkList elseif expression is conditional/predicate then based upon the result add appropriate CFG-edges to the FlowWorkList: TRUE  true edge; FALSE  false edge; and bottom  both edges. 10

Def-Use Edges vs SSA-edges We cannot take advantage of non-executable edges if def-use edges are used for propagation. Why? Because def-use chains include def-use edges formed through non- executable edges. 11 executable

Def-Use Edges vs SSA-edges Algorithm based upon Def-Use chains will be less efficient. SSA-based algorithm: Time spent is proportional to number of SSA-edges. Number of SSA-edges per variable is O(N) where N is the number of statements. Therefore time complexity is O(NxV) where V is the number of variables. Def-Use based algorithm: There can be O(N) definitions and uses of one variable. Thus, number of def-use edges is and hence the time complexity is O(N 2 xV). 12