Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 201 Compiler Construction

Similar presentations


Presentation on theme: "CS 201 Compiler Construction"— Presentation transcript:

1 CS 201 Compiler Construction
Static Single Assignment Form

2 Program Representations
Why develop Advanced Program Representations? To develop faster algorithms To develop more powerful algorithms Superior representation for Data Flow Static Single Assignment Form (SSA Form) superior to def-use chains Superior representation for Control Flow Control Dependence Graph superior to control flow graph

3 SSA-Form A program in SSA-form satisfies the following two properties:
A use of a variable is reached by exactly one definition of that variable. The program is augmented with ϕ–nodes that distinguish values of variables transmitted on distinct incoming control flow edges.

4 Example K11 L11 Repeat K2ϕ(K1,K5) L2ϕ(L1,L6) if (P) then if (Q) then L32 else L43 L5ϕ(L3,L4) K3K2+1 else K4K2+2 K5ϕ(K3,K4) L6ϕ(L2,L5) Until (T) K  1 L  1 Repeat if (P) then if (Q) then L2 else L3 KK+1 else KK+2 Until (T)

5 SSA-Form Observations:
SSA-form has def-use information embedded in it. Given a use, we know where the definition comes from. SSA-form is more compact representation of def-use chains. Def-use chains: #defs x #uses – O(n2) SSA-form: 2 x #defs or #uses – O(n)

6 Constructing SSA-Form
Step 1: Introduce functions at certain points in the program -- v  ϕ (v,v,….) where number of operands equals number of control predecessors and ith operand corresponds to ith predecessor. v  .. w  .. w  ϕ(w,w) v  w+1 v  .. w  .. v  w+1

7 Contd.. Step 2: Each variable v is given several new names v1, v2, …. Such that every name appears exactly once on the left hand side of an assignment. v1 .. w1 .. w2 .. w3  ϕ(w1,w2) v2  w3+1

8 Step 1: Introducing ϕ-functions
Node Z needs a ϕ-function for variable V if Z is the first node common to two non-null paths that originate at two different nodes each containing: an assignment to V; or a ϕ-function for V. v  .. v  ϕ(v,v)

9 Step 1 Contd.. Definition: X strictly dominates Y ≅ X dominates Y & X != Y. Definition: Immediate dominator of a node is its closest strict dominator. Notation: X = idom(Y). Definition: Dominance Frontier DF(X) = {Y: there exists P ε pred(Y) such that X dominates P & X does not strictly dominate Y} ϕ-functions are placed at nodes in DF nodes of nodes with assignments.

10 Step 1 Contd.. X Y X Y X Y X X P X Y P P ε pred(Y) Y Y ε DF(X)
Strict Domination Does Not Strictly Domination Dominate X Y > > X Y > X Y X P Y X P > P ε pred(Y) X Y Y ε DF(X)

11 Step 1 Contd.. Observation: if Y εDF(X) then there may or may not be a direct edge from X to Y. X Y X Y

12 Step 1 Contd.. Computing Dominance Frontier: for each Y εsucc(X) do
if idom(Y) != X then DF(X) = DF(X) U {Y} for each Z εChildren(X) in the dominator tree do for each Y εDF(Z) do Compute bottom-up order According to dominator tree X Y dominator tree X Y Z ~ X Y Z ~

13 Step 1 Contd.. 2 1 7 3 4 5 8 6 9 1 2 3 4 5 6 7 8 9 Dominator Tree 2, 9
11 12 10 2, 9 Step 1 Contd.. 1 2 3 4 5 6 7 8 9 10 11 12 Dominator Tree

14 Step 1 Contd.. Dominance Frontier of a Set of Nodes S DF(S) = DF(X) Iterated Dominance Frontier DF+(S): DF1 = DF(S) DFi+1 = DF(S U DFi) S – set of nodes which assign to variable V DF+(S) – set of nodes including those where ϕ-functions must be placed.

15 Step 2: Rename the Variables
Step 2: For each variable v rename its left hand side occurrences as v1, v2, …. Perform reaching definition analysis to identify names to use in the right hand side occurrences of v.

16 Static Single Assignment
Sample Problem Static Single Assignment

17 SSA Form


Download ppt "CS 201 Compiler Construction"

Similar presentations


Ads by Google