CS553 Colorado State University =============================================== Static Single Assignment (SSA) =============================================== 10/20/09 -------------------- Data dependences (Slide 5) -> How have we seen data dependences represented in this class so far? -DAG for instruction scheduling -implicitly as liveness -reaching definitions, for a use look at reaching definitions that may define the same var -induction variable tuples, a derived induction variable depends directly or transitively on a basic induction variable -------------------- Role of SSA (Slide 5) - diagram on slide shows how SSA is used in GCC - RTL stands for Register Transfer Language, which is a 3-address-code-like IR -------------------- SSA vs. UD and DU chains (slides 15-16) -> What is the SSA for given loops? SSA is more constrained, so it is a bit harder to manipulate. On the other hand, the side effects of changes to any particular variable are more limited and more evident. --------------------- Where do we place phi functions? (slide 18) -> What is a possible approach for determining phi placement due to the basic rule? -> What is its complexity? --------------------- Approaches to placing Phi functions (slides 19-20) With "minimal" approach, the rule doesn't say anything about v being used after the merge, so might put in more phi functions than necessary Briggs and Pruned attempt to deal with that. Briggs does it with a fast approximation. Pruned takes more analysis. Briggs Minimal: Consider temporary variables that are given the same name. They might have lifetimes that are local to a given block, in which case there’s no need to merge their values. --------------------- Machinery placing Phi functions (slides 21) Recall that the straightforward approach for determining placement based on the basic rule is too complex. --------------------------- Dominance Frontier Example (slide 22) -> do logic for showing that nodes 5 and 12 are in DF(5) Q: Why do we care about the DF? What does it have to do with Phi functions? A: Whenever a node x defines a variable a, then any node z in DF(x) needs a Phi Function for a. In SSA form, since each use has exactly one def, defs have to dominate uses, or else the use is possible undefined. Hence, each node in the DF needs a Phi function --------------------------- Dominance Frontier Example II (slide 23) Again, the plan is to put a phi function in each DF(n) for the variable being defined in node n. Additionally, a phi node becomes a new definition --------------------------- SSA exercise (slide 24) Example to build intuition about dominance frontiers. Note that DF({8,9}) is the union of the dominance frontiers for nodes 8 and 9. It is NOT the dominance frontier for both nodes 8 and 9 together. --------------------------- Dominance Frontiers Revisited (slide 25) It is important to remember that phi functions count as definitions to the variable for which it is merging values. --------------------------- Dominance Frontiers and SSA So to place phi functions we need to compute DF(n) for each node n in the control-flow graph. To calculate DF(n) for each node, we can start from the dominance tree ... ------------------- Calculating DF from dominator tree (slide 28) => write example on the board => have students describe dominator tree s1 | s2 | s3 | s4 | s5 | \ s6 s7 Do a bottom-up traversal of the dominator tree DF_local[s7] = null DF[s7] = null // no children in dominator tree DF_up[s7] = null DF_local[s6] = s5 DF[s6] = s5 DF_up[s6] = s5 // s5 not strictly dominated by itself => Make a chart Node DF_local DF DF_up s7 null null null s6 s5 s5 s5 s5 null s5 null s4 null null null ... Put in phi statements, just needed in s5 ------------------- Algorithm for Inserting Phi Functions (slide 29) Algorithm essentially creates iterated dominance frontier and places phi functions at the same time. ------------------- Variable Renaming (slide 31) Also going to use the dominance tree for variable renaming. ------------------- Variable Renaming (cont) (slide 32) - when in node 1, the value on top of the stack was the most recent definition of a particular variable and therefore should be the one used - when in node 2, a variable use is either the version on top of the stack from node 1, or a more recent version in the current node => draw a diamond CFG, note that if side nodes define a variable, then there will be a phi assignment at the top of the merge node and that define will dominate any use => draw the following up on the board to do variable renaming on example Counters: a, b, c, r Stacks: a, b, c, r -------------------- Variable Renaming algorithm - recall that children refer to children in the dominator tree and successor refers to a successor in the CFG => add visited to Counters and Stacks data structures Rename(entry) visited[entry] = true no statements one successor in CFG, but that guy doesn't have a phi function Rename(s1) visited[s1] = true call GenName(a) 0 = Counters[a] Stacks[a].push(i) Counters[a]++ replace a with a_0 on successor, but no phi function Rename(s2) replace a with a_0 call GenName(b) replace b with b_0 ... Rename(s3) just show result of alg, c0 = fread Rename(s4) c1 = c0 + 1 for successors in CFG put c1 in first phi slot Rename(s5) c2 = (c1, ) if (c2 > a) Rename(s6) c3 = c2 + 1 for successors in CFG put c3 in second phi slot No children in dominator tree Pop c3 off Stacks[c] Rename(s7) r_0 = a_0 + b_0 ------------------------ Transformation from SSA Form (slide 34) example: no problem with a0, b0, and r0 for c, push c2 = c1 at end of s4 push c2 = c3 at end of s6 does copy prop help get rid of some of the extra c variables? NO -------------------- mstrout@cs.colostate.edu, 10/15/09