Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 313 – Advanced Programming Topics.

Similar presentations


Presentation on theme: "Computer Science 313 – Advanced Programming Topics."— Presentation transcript:

1 Computer Science 313 – Advanced Programming Topics

2 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

3 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;

4 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

5 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

6 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 ;

7 Ф 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

8 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 ;

9 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)

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

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

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

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

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

15 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

16 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)

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

18 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

19 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}

20 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)

21 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

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


Download ppt "Computer Science 313 – Advanced Programming Topics."

Similar presentations


Ads by Google