Dominator Tree First BB is the root node, each node

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
- 1 - Dominator Tree BB0 BB1 BB2BB3 BB4 BB6 BB7 BB5 BB0 BB1 BB2BB3 BB4 BB6 BB5 BB7 BBDOM0 10,1 20,1,2 30,1,3 BBDOM 40,1,3,4 50,1,3,5 60,1,3,6 70,1,7 Dom.
SSA.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
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)
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
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.
1 Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing.
Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes.
Binary Tree Applications Chapter Trees Parse Trees What is parsing? Originally from language study The breaking up of sentences into component.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Preorder Traversal with a Stack Push the root onto the stack. While the stack is not empty n pop the stack and visit it.
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Static Single Assignment.
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.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Generating SSA Form (mostly from Morgan). Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the.
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
Building SSA Form (A mildly abridged account) For the full story, see the lecture notes for COMP 512 (lecture 8) and.
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
Computer Science 313 – Advanced Programming Topics.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
EECS 583 – Class 8 Classic Optimization University of Michigan October 3, 2011.
Building SSA Form, I 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at.
Dominators and CFGs Taken largely from University of Delaware Compiler Notes.
Loops Simone Campanoni
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Trees Chapter 15.
Fundamentals of Programming II Introduction to Trees
CS 201 Compiler Construction
Static Single Assignment
© Seth Copen Goldstein & Todd C. Mowry
Section 8.1 Trees.
Building SSA Form (A mildly abridged account)
Efficiently Computing SSA
i206: Lecture 13: Recursion, continued Trees
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Princeton University Spring 2016
CS 201 Compiler Construction
More Graph Algorithms.
Factored Use-Def Chains and Static Single Assignment Forms
Taken largely from University of Delaware Compiler Notes
Building SSA Form COMP 512 Rice University Houston, Texas Fall 2003
ITEC 2620M Introduction to Data Structures
CSC D70: Compiler Optimization Static Single Assignment (SSA)
Static Single Assignment Form (SSA)
EECS 583 – Class 8 Classic Optimization
Optimizations using SSA
EECS 583 – Class 7 Static Single Assignment Form
Static Single Assignment
Optimizing Compilers CISC 673 Spring 2011 Static Single Assignment II
EECS 583 – Class 8 Finish SSA, Start on Classic Optimization
EECS 583 – Class 4 If-conversion
EECS 583 – Class 7 Static Single Assignment Form
Computer Science 2 More Trees.
Compiler Construction
Taken largely from University of Delaware Compiler Notes
CSC D70: Compiler Optimization Static Single Assignment (SSA)
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

Dominator Tree First BB is the root node, each node dominates all of its descendants BB DOM 0 0 1 0,1 2 0,1,2 3 0,1,3 BB DOM 4 0,1,3,4 5 0,1,3,5 6 0,1,3,6 7 0,1,7 BB0 BB1 BB0 BB2 BB3 BB1 BB2 BB3 BB4 BB5 BB4 BB5 BB6 BB6 BB7 BB7 Dom tree

Computing Dominance Frontiers BB0 BB0 BB DF 0 - 1 - 2 7 3 7 4 6 5 6 6 7 7 1 BB1 BB1 BB2 BB3 BB2 BB3 BB4 BB5 BB6 BB4 BB5 BB6 BB7 BB7 For each join point X in the CFG For each predecessor of X in the CFG Run up to the IDOM(X) in the dominator tree, adding X to DF(N) for each N between X and IDOM(X)‏

Class Problem Draw the dominator tree, calculate the dominance frontier for each BB BB0 BB1 BB2 BB3 BB4 BB5

Phi Node Insertion Algorithm Compute dominance frontiers Find global names (aka virtual registers)‏ Global if name live on entry to some block For each name, build a list of blocks that define it Insert Phi nodes For each global name n For each BB b in which n is defined For each BB d in b’s dominance frontier Insert a Phi node for n in d Add d to n’s list of defining BBs

Phi Node Insertion - Example BB DF 0 - 1 - 2 7 3 7 4 6 5 6 6 7 7 1 a is defined in 0,1,3 need Phi in 7 then a is defined in 7 need Phi in 1 b is defined in 0, 2, 6 then b is defined in 7 c is defined in 0,1,2,5 need Phi in 6,7 then c is defined in 7 d is defined in 2,3,4 then d is defined in 7 i is defined in BB7 need Phi in BB1 a = b = c = i = a = Phi(a,a)‏ b = Phi(b,b)‏ c = Phi(c,c)‏ d = Phi(d,d)‏ i = Phi(i,i)‏ BB0 BB1 a = c = BB2 b = c = d = BB3 a = d = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a,a)‏ b = Phi(b,b)‏ c = Phi(c,c)‏ d = Phi(d,d)‏

Class Problem Insert the Phi nodes BB0 BB1 BB2 BB3 BB4 BB5 a = b = b =

SSA Step 2 – Renaming Variables Use an array of stacks, one stack per global variable (VR)‏ Algorithm sketch For each BB b in a preorder traversal of the dominator tree Generate unique names for each Phi node Rewrite each operation in the BB Uses of global name: current name from stack Defs of global name: create and push new name Fill in Phi node parameters of successor blocks Recurse on b’s children in the dominator tree <on exit from b> pop names generated in b from stacks

Renaming – Example (Initial State)‏ b = c = i = a = Phi(a,a)‏ b = Phi(b,b)‏ c = Phi(c,c)‏ d = Phi(d,d)‏ i = Phi(i,i)‏ BB0 BB1 a = c = var: a b c d i ctr: 0 0 0 0 0 stk: a0 b0 c0 d0 i0 BB2 b = c = d = BB3 a = d = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a,a)‏ b = Phi(b,b)‏ c = Phi(c,c)‏ d = Phi(d,d)‏

Renaming – Example (After BB0)‏ c0 = i0 = a = Phi(a0,a)‏ b = Phi(b0,b)‏ c = Phi(c0,c)‏ d = Phi(d0,d)‏ i = Phi(i0,i)‏ BB0 BB1 a = c = var: a b c d i ctr: 1 1 1 1 1 stk: a0 b0 c0 d0 i0 BB2 b = c = d = BB3 a = d = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a,a)‏ b = Phi(b,b)‏ c = Phi(c,c)‏ d = Phi(d,d)‏

Renaming – Example (After BB1)‏ c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 3 2 3 2 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 c2 BB2 b = c = d = BB3 a = d = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a,a)‏ b = Phi(b,b)‏ c = Phi(c,c)‏ d = Phi(d,d)‏

Renaming – Example (After BB2)‏ c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 3 3 4 3 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 b2 c2 d2 c3 BB2 b2 = c3 = d2 = BB3 a = d = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a2,a)‏ b = Phi(b2,b)‏ c = Phi(c3,c)‏ d = Phi(d2,d)‏

Renaming – Example (Before BB3)‏ This just updates the stack to remove the stuff from the left path out of BB1 a0 = b0 = c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 3 3 4 3 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 c2 BB2 b2 = c3 = d2 = BB3 a = d = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a2,a)‏ b = Phi(b2,b)‏ c = Phi(c3,c)‏ d = Phi(d2,d)‏

Renaming – Example (After BB3)‏ c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 4 3 4 4 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 c2 d3 a3 BB2 b2 = c3 = d2 = BB3 a3 = d3 = BB4 d = BB5 c = c = Phi(c,c)‏ d = Phi(d,d)‏ BB6 b = BB7 i = a = Phi(a2,a)‏ b = Phi(b2,b)‏ c = Phi(c3,c)‏ d = Phi(d2,d)‏

Renaming – Example (After BB4)‏ c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 4 3 4 5 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 c2 d3 a3 d4 BB2 b2 = c3 = d2 = BB3 a3 = d3 = BB4 d4 = BB5 c = c = Phi(c2,c)‏ d = Phi(d4,d)‏ BB6 b = BB7 i = a = Phi(a2,a)‏ b = Phi(b2,b)‏ c = Phi(c3,c)‏ d = Phi(d2,d)‏

Renaming – Example (After BB5)‏ c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 4 3 5 5 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 c2 d3 a3 c4 BB2 b2 = c3 = d2 = BB3 a3 = d3 = BB4 d4 = BB5 c4 = c = Phi(c2,c4)‏ d = Phi(d4,d3)‏ BB6 b = BB7 i = a = Phi(a2,a)‏ b = Phi(b2,b)‏ c = Phi(c3,c)‏ d = Phi(d2,d)‏

Renaming – Example (After BB6)‏ c0 = i0 = a1 = Phi(a0,a)‏ b1 = Phi(b0,b)‏ c1 = Phi(c0,c)‏ d1 = Phi(d0,d)‏ i1 = Phi(i0,i)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 4 4 6 6 2 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 b3 c2 d3 a3 c5 d5 BB2 b2 = c3 = d2 = BB3 a3 = d3 = BB4 d4 = BB5 c4 = c5 = Phi(c2,c4)‏ d5 = Phi(d4,d3)‏ BB6 b3 = BB7 i = a = Phi(a2,a3)‏ b = Phi(b2,b3)‏ c = Phi(c3,c5)‏ d = Phi(d2,d5)‏

Renaming – Example (After BB7)‏ c0 = i0 = a1 = Phi(a0,a4)‏ b1 = Phi(b0,b4)‏ c1 = Phi(c0,c6)‏ d1 = Phi(d0,d6)‏ i1 = Phi(i0,i2)‏ BB0 BB1 a2 = c2 = var: a b c d i ctr: 5 5 7 7 3 stk: a0 b0 c0 d0 i0 a1 b1 c1 d1 i1 a2 b4 c2 d6 i2 a4 c6 BB2 b2 = c3 = d2 = BB3 a3 = d3 = BB4 d4 = BB5 c4 = c5 = Phi(c2,c4)‏ d5 = Phi(d4,d3)‏ BB6 b3 = BB7 i2 = a4 = Phi(a2,a3)‏ b4 = Phi(b2,b3)‏ c6 = Phi(c3,c5)‏ d6 = Phi(d2,d5)‏ Fin!

Class Problem Rename the variables so this code is in SSA form BB0 BB1