SSA
SSA Properties
● Each definition in the procedure creates a unique name.
● Each use refers to a single definition.
Construct SSA Form
● Insert phi-functions.
● Rename variables to conform the properties.
Where to Insert phi-functions
● A definition in node n forces a phi-function at join points that lie just outside
the region of the CFG that n dominates.
○ n dominate a predecessor of m
○ n does not strictly dominate m
■ m belongs DF(n)
● DF(n) contains the first node reachable from n that n does not dominate.
● DF: Dominance Frontier
Dominance
● In a flow graph with entry node e, node n dominates node m if and only if n
lies on every path from e to m.
● Annotate each node m in the CFG with a set DOM(m) that contains the
names of all nodes that dominate m
e
a
b c
d f
g
h
i
DOM(d) = {e, a, c, d}
Dominance Frontier e
a
b c
d f
g
h
i
DF(c) = {h}
Immediate Dominator
● The node in strictly dominator
that is closest to n is called n’s
immediate dominator IDOM(n)
e
a
b c
d f
g
h
i
IDOM(g) = {c}
Dominator Tree
● Node
○ Every node of the flow graph
● Edge
○ If n is in IDOM(m), then the
dominator tree has an edge
from n to m.
e
a
b c
d f
g
h
i
Dominator Tree Properties
● Given a node n in the dominator tree
○ IDOM(n) is just its parent in the tree
○ DOM(n): the nodes that lie on the path from the root of the dominator tree to n.
Placing phi-functions
● A definition of x in block b forces a phi-function at every node in DF(b)
● Global names
○ The set of names that are live across multiple blocks
● Insert phi-functions for global names and ignore any name that is not in the
set
○ semipruned SSA form
Global Names
● In each block, it looks for names with upward exposed uses, UEVAR.
● Union of all the UEVAR sets gives global names.
Globals = {}
Initialize all the Blocks sets to {}
for each block b
varkill = {}
for each operation i in b in order
assume operation i is x = y op z
if y is not in varkill
Globals = Globals + {y}
if z is not in varkill
Globals = Globals + {z}
varkill = varkill + {x}
block(x) = block(x) + {b}
Computing Dominance Frontiers
for all nodes n in the CFG
DF(n) = {}
for all nodes n in the CFG
if n has multiple predecessors
for each predecessor p of n
runner = p
while runner != IDOM(n)
DF(runner) = DF(runner) + {n}
runner = IDOM(runner)
Insert phi-functions
for each name x in Globals
worklist = blocks(x)
for each block b in worklist
for each block d in DF(b)
if d has no phi-function for x
insert phi-function for x in d
worklist = worklist + {d}

SSA - PHI-functions Placements

  • 1.
  • 2.
    SSA Properties ● Eachdefinition in the procedure creates a unique name. ● Each use refers to a single definition.
  • 3.
    Construct SSA Form ●Insert phi-functions. ● Rename variables to conform the properties.
  • 4.
    Where to Insertphi-functions ● A definition in node n forces a phi-function at join points that lie just outside the region of the CFG that n dominates. ○ n dominate a predecessor of m ○ n does not strictly dominate m ■ m belongs DF(n) ● DF(n) contains the first node reachable from n that n does not dominate. ● DF: Dominance Frontier
  • 5.
    Dominance ● In aflow graph with entry node e, node n dominates node m if and only if n lies on every path from e to m. ● Annotate each node m in the CFG with a set DOM(m) that contains the names of all nodes that dominate m
  • 6.
  • 7.
    Dominance Frontier e a bc d f g h i DF(c) = {h}
  • 8.
    Immediate Dominator ● Thenode in strictly dominator that is closest to n is called n’s immediate dominator IDOM(n) e a b c d f g h i IDOM(g) = {c}
  • 9.
    Dominator Tree ● Node ○Every node of the flow graph ● Edge ○ If n is in IDOM(m), then the dominator tree has an edge from n to m. e a b c d f g h i
  • 10.
    Dominator Tree Properties ●Given a node n in the dominator tree ○ IDOM(n) is just its parent in the tree ○ DOM(n): the nodes that lie on the path from the root of the dominator tree to n.
  • 11.
    Placing phi-functions ● Adefinition of x in block b forces a phi-function at every node in DF(b) ● Global names ○ The set of names that are live across multiple blocks ● Insert phi-functions for global names and ignore any name that is not in the set ○ semipruned SSA form
  • 12.
    Global Names ● Ineach block, it looks for names with upward exposed uses, UEVAR. ● Union of all the UEVAR sets gives global names. Globals = {} Initialize all the Blocks sets to {} for each block b varkill = {} for each operation i in b in order assume operation i is x = y op z if y is not in varkill Globals = Globals + {y} if z is not in varkill Globals = Globals + {z} varkill = varkill + {x} block(x) = block(x) + {b}
  • 13.
    Computing Dominance Frontiers forall nodes n in the CFG DF(n) = {} for all nodes n in the CFG if n has multiple predecessors for each predecessor p of n runner = p while runner != IDOM(n) DF(runner) = DF(runner) + {n} runner = IDOM(runner)
  • 14.
    Insert phi-functions for eachname x in Globals worklist = blocks(x) for each block b in worklist for each block d in DF(b) if d has no phi-function for x insert phi-function for x in d worklist = worklist + {d}