Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes.

Similar presentations


Presentation on theme: "Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes."— Presentation transcript:

1 Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes

2 Assignments Reminders –project #3 is Now due Friday, June 8, 2007 at 5:00 PM In order to get the course graded, there will be no extensions –Final exam will be Tuesday June 12, 3:30pm to 5:20 pm Normal place FAB 150

3 Grading Project 1 Grading of Project 1 I ran 11 tests, where I observed the output of your code, looking for key values. This was worth 56 points I ran 22 coverage tests, where I was trying to cause your code to cause an error. These were worth 44 points. I added the two scores. I have included the transcript of the first 11 tests, each test tells what I was looking for, and then prints out the code you generated.

4 Static Single Assignment The SSA form of a program combines elements of both data-flow and control flow into a single analysis. Every variable is assigned only once, so the scope or reach of an assignment is the whole program. We do this by renaming (or numbering) every variable to the left of an assignment, then renaming uses appropriately We also need to add phi functions, that combine the mulitple possible values of (of the original variables before renaming) that reach each basic block. This is best seen by example:

5 Example x <- … y <- … while (x <100) x <- x+1 y <- y +x x 0 <- … y 0 <- … if (x 0 >= 100) goto next loop: x 1 <-  (x 0,x 2 ) y 1 <-  (y 0,y 2 ) x 2 <- x 1 + 1 y 2 <- y 1 + x 2 if (x 2 <= 100) goto loop next: x 3 <-  (x 0,x 2 ) y 3 <-  (y 0,y 2 ) each  (x i ) chooses exactly one if the x i corresponding to the actual flow of control. we split the loop into two tests because in the test (x<100) the x could refer to either x 0 or x 2

6 Building SSA Algorithm –Walk over the code, for each assignment renumber the variables. –Do this basic-block by basic block, in a depth first manner. –Inside each block, keep a counter, k, and walk from top to bottom. when we reach x := e produce x k := e renamed To rename, replace all x’s with x k, until the next assignment. –For each basic block, add an n-way phi function if there n-predecessors to the block.

7 Example for 1 Basic Block x <- 0 x <- x + 3 y <- x – 5 z <- x-y x 0 <- 0 x 1 <- x 0 + 3 y <- x – 5 z <- x-y next counter = 0 next counter = 1 x 0 <- 0 x 1 <- x 0 + 3 y 2 <- x 1 – 5 z <- x - y next counter = 2 x 0 <- 0 x 1 <- x 0 + 3 y 2 <- x 1 – 5 z 3 <- x 1 - y 2 next counter = 3

8 Adding phi nodes loop: x 1 <-  (x 0,x 2 ) y 1 <-  (y 0,y 2 ) x 2 <- x 1 + 1 y 2 <- y 1 + x 2 if x 2 <= 100) goto loop x 0 <- … y 0 <- … if x 0 >= 100 goto next next: x3 <-  (x0,x2) y3 <-  (y0,y2) Note that both the second and third BB have two flow paths, so they get phi functions with two inputs

9 Problems This algorithm works But it tends to add too many phi nodes. Why? Because we add phi-nodes with n-inputs to the beginning of each basic block. We add one for each variable used in the block. But, not every path redefines every variable in the block. So we tend to have too many phi-nodes. We need an analysis that determines which paths define which variables.

10 Dominators In a control flow graph –(node i) `dominates` (node j) –if every path to j must also go through i This is useful in many optimizations such as SSA construction B0B0 B1B1 B2B2 B3B3 B4B4 B5B5 B6B6 B7B7

11 Computing Dominators We can compute dominators by using dataflow equations. Dom(n) = {n}  ( ∩ m  preds(n) Dom(m) ) This computes the complete set of blocks that dominates each block.

12 B0B0 B1B1 B2B2 B3B3 B4B4 B5B5 B6B6 B7B7 preds(0) = {} preds(1) = {0,7} preds(2) = {1} preds(3) = {1} preds(4) = {3} preds(5) ={3} preds(6) ={4,5} preds(7) = {6,2} Dom(n) = {n}  ( ∩m  preds(n) Dom(m) ) Dom(0) = {0} Dom(1) = {1} Dom(2) = {2} Dom(3) = {3} Dom(4) = {4} Dom(5) ={5} Dom(6) ={6} Dom(7) = {7} Dom(0) = {0} Dom(1) = {1,0} Dom(2) = {2,1,0} Dom(3) = {3,1,0} Dom(4) = {4,3,1,0} Dom(5) ={5,3,1,0} Dom(6) ={6,3,1,0} Dom(7) = {7,1,0}

13 Dominance Frontiers The dominance frontier of a node n, the DF(n). DF(n) includes the first nodes m i reachable from n that are not dominated by n. I.e. there is another path through the graph that could reach each m i, that does not flow through node n B0B0 B1B1 B2B2 B3B3 B4B4 B5B5 B6B6 B7B7

14 Domnance Frontier info to & phi nodes When inserting phi functions in SSA form. A definition of x ( x <- … ) in block B, forces a phi function at the start of every node in the DF(B) Blocks reachable from B, but not in the DF(B) have no other realizable paths, so phi functions are unnecessary. B0B0 B1B1 B2B2 B3B3 B4B4 B5B5 B6B6 B7B7


Download ppt "Lecture #17, June 5, 2007 Static Single Assignment phi nodes Dominators Dominance Frontiers Dominance Frontiers when inserting phi nodes."

Similar presentations


Ads by Google