Download presentation
Presentation is loading. Please wait.
Published byLambert Howard Modified over 9 years ago
1
Generating SSA Form (mostly from Morgan)
2
Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the same precision as bit-vector CFG-based dataflow analysis –but is asymptotically faster since it permits the exploitation of sparsity SSA has two distinct features –factored def-use chains –renaming –you do not have to perform renaming to get advantage of SSA for many dataflow problems
3
Summary of dependences Dependence –Data-dependence: relation between nodes Flow- or read-after-write (RAW) Anti- or write-after-read (WAR) Output- or write-after-write (WAW) –Control-dependence: relation between nodes and edges (of CFG)
4
Postdominators Given a CFG G, node b postdominates node a each path (a … END) contains b. b pdom a => b postdominates a Postdominance is dominance in “reverse CFG” (reverse direction of all CFG edges). Immediate Postdominator (ipdom) of B is the parent of B in the postdominator tree.
5
Dominance Frontier (from Morgan p. 75) “Just beyond” nodes dominated by block Dominance Frontier DF(B), set of blocks C –B dominates predecessor of C, but –B == C, OR, B does not dominate C Used to find “merge” points for -nodes
6
Dominance frontier Dominance frontier of node w –Node u is in dominance frontier of node w if w dominates a CFG predecessor v of u, but does not strictly dominate u Dominance frontier = control dependence in reverse graph!
7
FindDominanceFrontier (B:Block) (from Morgan p. 76) foreach C children(B) do FindDominanceFrontier(C) endfor DF(B) = Ø foreach X SUCC(B) do if idom(X) B then add X to DF(B) endif endfor foreach C children(B) do foreach X DF(C) do if idom(X) B then add X to DF(B) endif endfor Succ(B) is a CFG successor of B children(B) are dominator tree children of B.
8
Iterated Dominance Frontier (from Morgan p. 171) Input: Set of blocks, S Ouput: The set DF + (S) Worklist = Ø DF + = Ø foreach B S do DF + (S) = DF + (S) {B} Worklist = Worklist {B} endfor while Worklist Ø remove B from Worklist foreach C DF(B) do if C DF + (S) then DF + (S) = DF + (S) {C} Worklist = Worklist {C} endif endfor endwhile
9
Algorithm to Insert -nodes 1 Morgan, p. 172 foreach T Variables do S = (B | B contains definition of T) {Entry} Compute DF + (S) foreach B DF + (S) n = |pred(B)| Insert an n-operand -node, T = (T i, …, T i+n-1 ) in B endfor
10
Algorithm to Insert -nodes 2 Morgan, p. 173 foreach T Variables do if T Globals then S = (B | B contains definition of T) {Entry} Compute DF + (S) foreach B DF + (S) n = |pred(B)| Insert an n-operand -node, T = (T i, …, T i+n-1 ) in B endfor endif endfor
11
Algorithm for Minimum -nodes 3 Morgan, p. 173 foreach T Variables do if T Globals then S = (B | B contains definition of T) {Entry} Compute DF + (S) foreach B DF + (S) if T LiveIn(B) n = |pred(B)| Insert an n-operand -node, T = (T i, …, T i+n-1 ) in B endif endfor endif endfor
12
Renaming Variables After inserting -nodes Match each use with the “new” name for definition Requires walk of the Dominator Tree –Each def of V, in block B, gets new “name” V i –V => V i for all blocks dominated by B See handout for algorithm, page 175 of Morgan for details
13
Computing SSA form Cytron et al algorithm –compute DF relation (see slides on computing control-dependence relation) –find irreflexive transitive closure of DF relation for set of assignments for each variable Computing full DF relation –Cytron et al algorithm takes O(|V| +|DF|) time –|DF| can be quadratic in size of CFG Faster algorithms –O(|V|+|E|) time per variable: see Bilardi and Pingali
14
What’s Next? So, we’ve converted CFG to SSA form Coming Attractions –Optimizations on SSA –Converting SSA back to CFG
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.