Computer Science 313 – Advanced Programming Topics.

Slides:



Advertisements
Similar presentations
A Survey of Program Slicing Techniques A Survey of Program Slicing Techniques Sections 3.1,3.6 Swathy Shankar
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.
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.
Stanford University CS243 Winter 2006 Wei Li 1 Register Allocation.
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
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.
Program Representations. Representing programs Goals.
Advanced Compiler Design – Assignment 1 SSA Construction & Destruction Michael Fäs (Original Slides by Luca Della Toffola)
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:
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.
Chair of Software Engineering Fundamentals of Program Analysis Dr. Manuel Oriol.
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.
Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes.
Another example p := &x; *p := 5 y := x + 1;. Another example p := &x; *p := 5 y := x + 1; x := 5; *p := 3 y := x + 1; ???
CS 201 Compiler Construction
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.
Class canceled next Tuesday. Recap: Components of IR Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements.
Projects. Dataflow analysis Dataflow analysis: what is it? A common framework for expressing algorithms that compute information about a program Why.
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.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
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?
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
CSE P501 – Compiler Construction
1 A Static Analysis Approach for Automatically Generating Test Cases for Web Applications Presented by: Beverly Leung Fahim Rahman.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
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.
Generating SSA Form (mostly from Morgan). Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the.
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
Hy-C A Compiler Retargetable for Single-Chip Heterogeneous Multiprocessors Philip Sweany 8/27/2010.
Introduction to SSA Data-flow Analysis Revisited – Static Single Assignment (SSA) Form Liberally Borrowed from U. Delaware and Cooper and Torczon Text.
Computer Science 313 – Advanced Programming Topics.
1 Iterative Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program.
Loops Simone Campanoni
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Dataflow analysis.
Static Single Assignment
Efficiently Computing SSA
Topic 10: Dataflow Analysis
Factored Use-Def Chains and Static Single Assignment Forms
CS 201 Compiler Construction
CSC D70: Compiler Optimization Static Single Assignment (SSA)
Static Single Assignment Form (SSA)
Optimizations using SSA
Control Flow Analysis (Chapter 7)
Dominator Tree First BB is the root node, each node
Data Flow Analysis Compiler Design
EECS 583 – Class 7 Static Single Assignment Form
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.
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.
EECS 583 – Class 7 Static Single Assignment Form
Building SSA Harry Xu CS 142 (b) 04/22/2018.
Control dependence Intuitive idea: Example:
CSC D70: Compiler Optimization Static Single Assignment (SSA)
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

Computer Science 313 – Advanced Programming Topics

Static Single Assignment  Ignores local variables programmer wrote  Programmers are stupid  Creates lots of variables on its own  Each variable is assigned exactly once (def)  Variable use tied to definition at the assignment

Examples of SSA Form a = 2; b = a + 1; a = 3; b = a + 1; a 1 = 2; b 1 = a 1 + 1; a 2 = 3; b 2 = a 2 + 1; if (…) { a = 2; } else { a = 3; } b = a + 1; if (…) { a 1 = 2; } else { a 2 = 3; } a 3 = Φ(a 1, a 2 ); b = a 3 + 1;

Control Flow Graph  Common technique showing program structure  Visualizes different ways method can be run  Also referred to as the flow of a program’s control  Basic blocks are vertices in this graph  Basic block is code that must be executed together  Edges represent transfer of flow between blocks  Normally result from start & end of loops or branches

Example of a CFG a 1 = 2; b 1 = a 1 + 1; a 2 = 3; b 2 = a 2 + 1; if (b 2 > 20) { System.out.println(“Woot”); } else { System.err.print(“Doh”); foo(a 2 ); } b 3 = a 2 + b 2

Example of a CFG a 1 = 2; b 1 = a 1 + 1; a 2 = 3; b 2 = a 2 + 1; if (b 2 > 20) System.err.print(“Woot”); System.err.print(“Doh”); foo(a 2 ); T F b 3 = a 2 + b 2 ;

Ф Functions Are Fun!  SSA could have problem with basic blocks  What happens when variable defined in if & else  Uses Ф function to merge variable definitions  Ф function has one input per merged block  Variables have exactly one definition with function  Function does not really exist  Keeps value from the basic block executed  Keeps books properly balanced

Examples of SSA Form a 1 = 2; b 1 = a 1 + 1; a 2 = 3; b 2 = a 2 + 1; if (b 2 > 20) b 3 = 21 foo(a 2 ); T F b 4 = Ф (b 3, b 2 ); b 5 = a 2 + b 4 ;

Dominators  X dominates Y if and only if X on all paths from method start to Y  Used to help convert code to SSA form  Excuse for explaining –trix suffix  Domination both reflexive & transitive  dom(Y) defines dominators of Y  Set of definitions which reach a given block  Will create need to add Ф for Y using dom(Y)

Dominator Tree Example START a b c d END START CFG DT

Dominator Tree Example START a b c d END START CFG DT a

Dominator Tree Example START a b c d END START CFG DT a b c

Dominator Tree Example START a b c d END START CFG DT a b c d

Dominator Tree Example START a b c d END START CFG DT a b c d END

Next Step for SSA Form  Dominance frontier for node X in CFG  Defines set of nodes such that each node Y in set  X dominates predecessor of Y, but  X does not dominate Y and X != Y

DF Computation  Algorithm to compute dominance frontier for (Vertex b : CFG.vertices()) if ( CFG.countInEdges( b ) ≥ 2) for (Vertex p : CFG.adjacentVertices( b )) runner  p while ( runner != dominatorTree. parent (b)) // Add b to runner ’s dominance frontier runner  dominatorTree. parent (b)

DF Example START a b c d END START a d END b c CFG DT DF(c) = ?

DF Example START a b c d END START a d END b c CFG DT DF(c) = {d} c dominates c, but not d

DF(a) = {END} a dominates b,c,&d, but not END DF Example START a b c d END START a d END b c CFG DT DF(c) = {d}

DF Computation  Algorithm to compute dominance frontier for (Vertex b : CFG.vertices()) if ( CFG.countInEdges( b ) ≥ 2) for (Vertex p : CFG.adacentVertices( b )) runner  p while ( runner != dominatorTree. parent (b)) // Add b to runner ’s dominance frontier runner  dominatorTree. parent (b)

Placing Φ Nodes  If basic block, x, defines variable named a  Need Φ function for a at start of all blocks where  Block is in x ’s dominance frontier –or–  In dominance frontier of block in x ’s dominance frontier  Repeat algorithm however long as needed  Must be computed iteratively

For Next Class  Lab #6 available on Angel  Will start to look at how SSA can be used