generating ssa form (mostly from morgan). why is ssa form useful? for many dataflow problems, ssa...
TRANSCRIPT
Generating SSA Form(mostly from Morgan)
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
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)
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.
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
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!
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) endifendfor
foreach C children(B) do foreach X DF(C) do if idom(X) B then add X to DF(B) endif endforendfor
Succ(B) is a CFG successor of B
children(B) are dominator tree children of B.
Iterated Dominance Frontier(from Morgan p. 171)
Input: Set of blocks, SOuput: The set DF+(S)
Worklist = ØDF+ = Øforeach B S do DF+(S) = DF+(S) {B} Worklist = Worklist {B}endforwhile Worklist Ø remove B from Worklist foreach C DF(B) do if C DF+ (S) then DF+(S) = DF+(S) {C} Worklist = Worklist {C} endif endforendwhile
Algorithm to Insert -nodes1
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 = (Ti, …, Ti+n-1) in B endforendfor
Algorithm to Insert -nodes2
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 = (Ti, …, Ti+n-1) in B endfor endifendfor
Algorithm for Minimum -nodes3
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 = (Ti, …, Ti+n-1) in B endif endfor endifendfor
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” Vi
– V => Vi for all blocks dominated by B
• See handout for algorithm, page 175 of Morgan for details
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
What’s Next?
• So, we’ve converted CFG to SSA form
• Coming Attractions– Optimizations on SSA– Converting SSA back to CFG