Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Some Properties of SSA Mooly Sagiv

2 Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions

3 Static Single Assignment Every variable is assigned once But in loops a variable will be assigned many times

4 An Acyclic Example x  x + 1 x  x + 2 x > 0 x  x + 3 x  x + 4 x > 0 x  x + 5 x  x + 6

5 A Cyclic Example i = 1; j = 1; k = 0 while (k < 0) { if (j < 0) { j = i; k = k + 1; } else { j = k ; k = k + 2 } return j

6 What does it buy us? Compact representation of DU chains Convert “imperative” into “functional” style Extended basic blocks Allows flow-insensitive analysis

7 How much does it cost Code size –Worst case the extra number of assignments is quadratic –For programs with while-do and if-then-else linear –In practice linear Construction of SSA

8 Open Questions Dealing with pointers When is it useful? Is it really needed? –Can we choose an appropriate data structure in the iterative data flow algorithm instead

9 Conditional Constant Propagation Conditions with constant values can be interpreted to improve precision A more precise solution is obtained “optimistically”

10 char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; main() { FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; break; case ORANGE: t3=Orange; }} printf(“%s\n”, t3 );} main() { printf(“%s\n”, “red”);} “red”

11 char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; main() { FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; break; case ORANGE: t3=Orange; }} printf(“%s\n”, t3);}

12 Iterative Data-Flow Algorithm Input: a flow graph G=(N,E,r) An init value Init A montonic function F B for every B in N Output:For every N in(N) Initializatio: in(Entry) := Init; for each node B in N-{Entry} do in(B) :=  WL := N - {Entry} Iteration: while WL != {} do Select and remove an B from WL out := F B (in(B)) For all B’ in succ(B) such that in(B’) != in(B’)  out do in(B’):= in(B’)  out WL := WL  {B’}

13 Iterative Data-Flow Algorithm Input: a flow graph G=(N,E,r) An init value Init A montonic function F B for every B in N Output:For every N in(N) Initializatio: in(Entry) := Init; for each node B in N-{Entry} do in(B) :=  WL := {Entry} Iteration: while WL != {} do Select and remove an B from WL out := F B (in(B)) For all B’ in succ(B) such that in(B’) != in(B’)  out do in(B’):= in(B’)  out WL := WL  {B’}

14 char * Red = “red”; char * Yellow = “yellow”; char * Orange = “orange”; main() { FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; break; case ORANGE: t3=Orange; }} printf(“%s\n”, t3);}

15 Conditional Constant Propagation initialize the worklist to the entry node mark all edges as not executable repeat until the worklist is empty: –select and remove a node from the worklist –if it is an assignment then mark the successor edge as executable –if it is a test then symbolically evaluate the test and mark the enabled successor edges as executable if test evaluates to true or  mark true edge executable if test evaluates to false or  mark false edge executable –update the value of all the variables at the entry and exit of this node –if there are changes then add all successors reachable from the node with edges marked executable to the worklist

16 Sparse Conditional Constant bring the program in SSA form initialize the analysis information: –all variables are mapped to  –all flow edges are marked as not executable initialize the two worklists –Flow-Worklist contains all edges of the flow graph with the entry node as source –SSA-Worklist is empty

17 repeat until both worklists are empty: –select and remove an edge from one of the worklists –if it is a flow edge then if the edge is not marked executable then –mark it executable –if the target of the edge is a  -node then call visit-  –if it is the first time the node is visited (only one incoming flow edge is marked executable) and it is a normal node then call visit-instr –if it is an SSA edge then if the target of the edge is a  -node then call visit-  if it is a normal node and at least one of the flow edges entering the node are marked executable then call visit-instr

18 visit-  : (the node is a  -node) –the assigned variable is given a value that is the join the values of the arguments with incoming edges marked executable visit-instr: (the node is a normal node) –determine the value of the expression of the node and update the variable in case of an assignment –if there are changes then if the node is an assignment then add all SSA edges with source at the target of the current edge to the SSA-worklist if the node is a test then add all relevant flow edges to the Flow- worklist and mark them executable –if test evaluates to true or  add true edge –if test evaluates to false or  : add false edge


Download ppt "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."

Similar presentations


Ads by Google