



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: PROG ANLYS&UNDERSTANDING; Subject: Computer Science; University: University of Maryland; Term: Fall 2004;
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Static Single Assignment Form and Dominators CMSC 631 – Program Analysis and Understanding Fall 2004 CMSC 631, Fall 2004 2
■ (^) There are a lot of facts and ■ (^) There are a lot of program points? ■ potentially takes a lot of space/time
CMSC 631, Fall 2004 3
x := 3 y := a + b z := 2 * y w := y + z a > b y := a - b y := y * 10 w := w + y z := w + x CMSC 631, Fall 2004 4
■ (^) Only propagate facts about x where they’re needed
■ (^) Each variable is defined (assigned to) exactly once ■ But may be used multiple times
■ (^) No intervening statements use/define variable ■ (^) Safe to propagate only along SSA edges
x 1 := 3 y 1 := a 1 + b 1 z 1 := 2 * y 1 w 2 := y 1 + z 1 a 1 > b 1 y 2 := a 1 - b 1 y 3 := y 2 * 10 w 3 := w 1 + y 3 z 1 := w? + x 1
■ (^) Intuitively, takes meet of arguments ■ (^) At code generation time, need to eliminate Φ nodes
x 1 := 3 y 1 := a 1 + b 1 z 1 := 2 * y 1 w 2 := y 1 + z 1 a 1 > b 1 y 2 := a 1 - b 1 y 3 := y 2 * 10 w 3 := w 1 + y 3 w 4 := !(w 2 , w 3 ) z 1 := w 4 + x 1
CMSC 631, Fall 2004 7
■ C(n) := top
■ (^) Remove an edge (x, y) from the worklist ■ (^) C(y) := C(y) meet C(x) ■ Add SSA edges from y if C(y) changed
CMSC 631, Fall 2004 8
■ (^) Propagate facts along def-use chains
CMSC 631, Fall 2004 9
a := 1 a := 2 a := 3 b := a c := a d := a Def-Use Chains a 1 := 1 a 2 := 2 a 3 := 3 b 1 := a 4 c 1 := a 4 d 1 := a 4 a 4 := !(a 1 , a 2 , a 3 ) SSA Form
CMSC 631, Fall 2004 10
■ (^) But what if some branches are never taken in practice?
■ Fits in neatly with SSA form
■ Advantage of nodes: may be fewer of them ■ (^) Advantage of edges: can trace differences on multiple paths to same node
■ (^) Some may not be because they’re on not-taken branch ■ (^) Initially, assume no edges taken ■ (^) At joins, don’t propagate information from not-taken in-edges
■ We need proof that a pessimistic fact holds ■ We’re computing a greatest fixpoint
CMSC 631, Fall 2004 19
■ (^) Two non-null CFG paths that both define v ■ Such that both paths start at two distinct nodes and end at Z
v := 3 v := 4 Z CMSC 631, Fall 2004 20
Dominated by X X Dominance Frontier of X X P Y CMSC 631, Fall 2004 21
■ (^) There exists a path from X to Exit through Y such that Y is the first node not strictly dominated by X
■ (^) Y is the first node where a path from X to Exit and a path from Entry to Exit (not going through X) meet
■ (^) X dominates a predecessor of Y ■ (^) X does not strictly dominate Y
CMSC 631, Fall 2004 22
1 2 3 4 5 6 7 Entry Exit
■ DFlocal(X) = {Y succ(X) | X> Y}
■ (^) Then there is a U pred(Y) such that X≥U, X>Y ■ If^ U=X,^ then^ U^ DFlocal(X) = {Y^ succ(X) | X>^ Y} ■ Otherwise U≠X
X/U Y X Z U Y
CMSC 631, Fall 2004 25
■ (^) DF(X) = succ(X) - sdom(X)
CMSC 631, Fall 2004 26
■ DF(X) = succ(X) ■ (^) For each Z such that idom(Z) = X do
CMSC 631, Fall 2004 27
CMSC 631, Fall 2004 28
■ Recall, those are all the places where the definition of v in S and some other definition of v may meet
■ (^) v := Φ(v, ..., v)
■ DFi+1 = DF(S^ DFi)
Entry 1 : x := 3 2 3 5 : x := 4 6 9 11 4 7 8 10 Exit = need Φ function 1 2 3 4 5 6 9 7 8 10 11
■ (^) At definition of v, push new # for v onto the stack ■ (^) When leaving node with definition of v, pop stack ■ Intuitively: Works because there’s a Φ function, hence a new definition of v, just beyond region dominated by definition
■ (^) Linear in size of CFG with Φ functions
CMSC 631, Fall 2004 37
■ MustMod(S) = variables always modified by S ■ (^) MayMod(S) = variables sometimes modified by S
■ writes to MayMod(S) ■ (^) reads MayUse(S) (MayMod(S) - MustMod(S))
CMSC 631, Fall 2004 38
X A B C
■ I.e., if X is executed, then Y is always executed ■
■ There is a path^ X→Z 1 →···→Zn→Y^ such that^ Y postdominates all Zi and ■ (^) Y does not postdominate X ■ (^) I.e.,there is some path from X on which Y is always executed, and there is some path on which Y is not executed
■ There is a path^ X←Z 1 ←···←Zn←Y^ where