Generating SSA Form (mostly from Morgan). Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the.

Slides:



Advertisements
Similar presentations
Topic G: Static Single-Assignment Form José Nelson Amaral
Advertisements

SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
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.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
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.
Static Single Assignment (SSA) Form Jaeho Shin :00 ROPAS Weekly Show & Tell.
SSA.
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.
Computer Science 313 – Advanced Programming Topics.
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
Stanford University CS243 Winter 2006 Wei Li 1 SSA.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Static Single Assignment John Cavazos.
Program Representations. Representing programs Goals.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Advanced Compiler Design – Assignment 1 SSA Construction & Destruction Michael Fäs (Original Slides by Luca Della Toffola)
Example in SSA X := Y op Z in out F X := Y op Z (in) = in [ { X ! Y op Z } X :=  (Y,Z) in 0 out F X :=   (in 0, in 1 ) = (in 0 Å in 1 ) [ { X ! E |
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Course project presentations No midterm project presentation Instead of classes, next week I’ll meet with each group individually, 30 mins each Two time.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
CS745: SSA© Seth Copen Goldstein & Todd C. Mowry Static Single Assignment.
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 Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing.
CMPUT Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic G: Static Single- Assignment Form José Nelson Amaral
CS 201 Compiler Construction
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.
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.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Precision Going back to constant prop, in what cases would we lose precision?
CSE P501 – Compiler Construction
Dominators, control-dependence and SSA form. Organization Dominator relation of CFGs –postdominator relation Dominator tree Computing dominator relation.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
Interference Graphs for Programs in Static Single Information Form are Interval Graphs Philip Brisk Processor Architecture Laboratory (LAP) EPFL Lausanne,
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.
Building SSA Form (A mildly abridged account) For the full story, see the lecture notes for COMP 512 (lecture 8) and.
Program Representations. Representing programs Goals.
Final Code Generation and Code Optimization.
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
Cleaning up the CFG Eliminating useless nodes & edges This lecture describes the algorithm Clean, presented in Chapter 10 of EaC2e. The algorithm is due.
Computer Science 313 – Advanced Programming Topics.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Building SSA Form, I 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at.
Optimizing The Optimizer: Improving Data Flow Analysis in Soot Michael Batchelder 4 / 6 / 2005 A COMP-621 Class Project.
CS 201 Compiler Construction
Efficiently Computing SSA
Dataflow Testing G. Rothermel.
CS 201 Compiler Construction
Factored Use-Def Chains and Static Single Assignment Forms
Building SSA Form COMP 512 Rice University Houston, Texas Fall 2003
CS 201 Compiler Construction
Static Single Assignment Form (SSA)
Optimizations using SSA
Dominator Tree First BB is the root node, each node
Final Code Generation and Code Optimization
EECS 583 – Class 7 Static Single Assignment Form
Static Single Assignment
Optimizing Compilers CISC 673 Spring 2011 Static Single Assignment II
EECS 583 – Class 7 Static Single Assignment Form
Building SSA Harry Xu CS 142 (b) 04/22/2018.
Control dependence Intuitive idea: Example:
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:

Generating SSA Form (mostly from Morgan)

Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the same precision as bit-vector CFG-based dataflow analysis –but is asymptotically faster since it permits the exploitation of sparsity SSA has two distinct features –factored def-use chains –renaming –you do not have to perform renaming to get advantage of SSA for many dataflow problems

Summary of dependences Dependence –Data-dependence: relation between nodes Flow- or read-after-write (RAW) Anti- or write-after-read (WAR) Output- or write-after-write (WAW) –Control-dependence: relation between nodes and edges (of CFG)

Postdominators Given a CFG G, node b postdominates node a each path (a … END) contains b. b pdom a => b postdominates a Postdominance is dominance in “reverse CFG” (reverse direction of all CFG edges). Immediate Postdominator (ipdom) of B is the parent of B in the postdominator tree.

Dominance Frontier (from Morgan p. 75) “Just beyond” nodes dominated by block Dominance Frontier DF(B), set of blocks C –B dominates predecessor of C, but –B == C, OR, B does not dominate C Used to find “merge” points for  -nodes

Dominance frontier Dominance frontier of node w –Node u is in dominance frontier of node w if w dominates a CFG predecessor v of u, but does not strictly dominate u Dominance frontier = control dependence in reverse graph!

FindDominanceFrontier (B:Block) (from Morgan p. 76) foreach C  children(B) do FindDominanceFrontier(C) endfor DF(B) = Ø foreach X  SUCC(B) do if idom(X)  B then add X to DF(B) endif endfor foreach C  children(B) do foreach X  DF(C) do if idom(X)  B then add X to DF(B) endif endfor Succ(B) is a CFG successor of B children(B) are dominator tree children of B.

Iterated Dominance Frontier (from Morgan p. 171) Input: Set of blocks, S Ouput: The set DF + (S) Worklist = Ø DF + = Ø foreach B  S do DF + (S) = DF + (S)  {B} Worklist = Worklist  {B} endfor while Worklist  Ø remove B from Worklist foreach C  DF(B) do if C  DF + (S) then DF + (S) = DF + (S)  {C} Worklist = Worklist  {C} endif endfor endwhile

Algorithm to Insert  -nodes 1 Morgan, p. 172 foreach T  Variables do S = (B | B contains definition of T)  {Entry} Compute DF + (S) foreach B  DF + (S) n = |pred(B)| Insert an n-operand  -node, T =  (T i, …, T i+n-1 ) in B endfor

Algorithm to Insert  -nodes 2 Morgan, p. 173 foreach T  Variables do if T  Globals then S = (B | B contains definition of T)  {Entry} Compute DF + (S) foreach B  DF + (S) n = |pred(B)| Insert an n-operand  -node, T =  (T i, …, T i+n-1 ) in B endfor endif endfor

Algorithm for Minimum  -nodes 3 Morgan, p. 173 foreach T  Variables do if T  Globals then S = (B | B contains definition of T)  {Entry} Compute DF + (S) foreach B  DF + (S) if T  LiveIn(B) n = |pred(B)| Insert an n-operand  -node, T =  (T i, …, T i+n-1 ) in B endif endfor endif endfor

Renaming Variables After inserting  -nodes Match each use with the “new” name for definition Requires walk of the Dominator Tree –Each def of V, in block B, gets new “name” V i –V => V i for all blocks dominated by B See handout for algorithm, page 175 of Morgan for details

Computing SSA form Cytron et al algorithm –compute DF relation (see slides on computing control-dependence relation) –find irreflexive transitive closure of DF relation for set of assignments for each variable Computing full DF relation –Cytron et al algorithm takes O(|V| +|DF|) time –|DF| can be quadratic in size of CFG Faster algorithms –O(|V|+|E|) time per variable: see Bilardi and Pingali

What’s Next? So, we’ve converted CFG to SSA form Coming Attractions –Optimizations on SSA –Converting SSA back to CFG