Dataflow Solutions SSA SSA Construction SSA-based analysis
CO444H
Ben Livshits
1
CO444H SSA SSA Construction SSA-based analysis Ben Livshits 1 - - PowerPoint PPT Presentation
Dataflow Solutions CO444H SSA SSA Construction SSA-based analysis Ben Livshits 1 Refresher: Reaching Definitions Direction D = forward. Domain V = set of all sets of definitions in the flow graph. = union. Functions F =
Dataflow Solutions SSA SSA Construction SSA-based analysis
1
2
graph.
f(x) = (x - KILL) ∪ GEN, where KILL and GEN are sets of definitions (members of V).
May Must Forward Reaching definitions Available expressions Backward Live variables Very busy expressions
3
4
5
paths from entry to a point
point, of the transfer function along that path applied to vENTRY
running the iterative algorithm from last lecture
6
f1 f2 fn-1 B . . . fn-1( . . .f2(f1(vENTRY)). . .)
7
in iteration: IN(B) = ∧ predecessors P of B OUT(P); OUT(B) = fB(IN(B));
Maximum = any
≤ the result of the iterative algorithm (MFP)
8
9
starting with vENTRY and following some set of paths to the point in question
have an error – we are not conservative
precise
10
subset.
there is some executable path whose effect is not accounted for.
11
12
and therefore MFP is safe.
about the framework:
1. “Monotonicity” 2. Finite height (no infinite chains . . . < x2 < x1 < x within the lattice)
13
would compose functions along all paths, then take a big meet
compositions and meets somewhat arbitrarily
precision
14
(call it f) respects ≤.
completing the composition of functions.
15
monotone:
example
given program
16
ENTRY B
Since f(x ∧ y) ≤ f(x) ∧ f(y), we might have lost some precision because of the early meet
f OUT = x OUT = y IN = x∧y OUT = f(x∧y) In MFP, Values x and y get combined too soon. f(x) f(y) MOP considers paths independently and and combines at the last possible moment. OUT = f(x) ∧ f(y)
17
distributivity condition: f(x ∧ y) = f(x) ∧ f(y)
= (x - KILL) ∪ GEN, where KILL and GEN are sets of definitions (members of V) (x – (K1 U K2)) U (G1UG2) = (x-K1) U G1 U (x-K2) U G2
18
early doesn’t hurt.
takes into account all and only the physical paths.
19
SSA Representation SSA Construction Analysis based on SSA
20
merge, a Ф function is introduced, with a new definition of the variable
21
a = = a+5 a = = a+5 a = = a+5
Multiple reaching definitions
22
a1= = a1+5 a2= = a2+5 a3= a4= Ф(a1,a3) = a4+5 Single reaching definition
23
from the corresponding predecessor
knowing from which path the definition is coming from
24
1. If
Z, and
2. Each mention of V has been replaced by a mention of Vi 3. V and the corresponding Vi have the same value.
25
SSA Representation SSA Construction
Step 1: Place Ф statements Step 2: Rename all variables
Converting out of SSA
26
a = … a = Ф(a ,a) a = Ф(a ,a)
Place minimal number of Ф functions
27
28
a1= a1+5 a4 = a4+5 a2= a3= Ф(a1,a2) a3+5
iterated dominance frontier
29
30
dominates Y
31
START a b c d END START CFG DT
32
START a b c d END START a CFG DT
33
START a b c d END START a b c CFG DT
34
START a b c d END START a d b c CFG DT
35
START a b c d END START a d END b c CFG DT
36
nodes Y such that
37
START a b c d END START a d END b c CFG DT DF(c) = ? DF(a) = ?
38
START a b c d END START a d END b c CFG DT DF(c) = {d} DF(a) = ?
39
START a b c d END START a d END b c CFG DT DF(c) = {d} DF(a) = {END}
40
following sets
nodes that X doesn’t strictly dominate
previous slide
that IDOM(Z) doesn’t strictly dominate Y}
see previous slide
41
START a b c d END
DF(SET) is the union of DF(X), where X є SET.
42
two distinct nodes in SET and converge at Z
43
44
avrgDF), where
O(n2).
S a b c E d
45
a = … a = Ф(a ,a) a = Ф(a ,a) Place Ф at Iterative Dominance Frontiers
46
program and Ф functions, using dominator tree and renaming stack to keep track of the current names.
47
tree
48
a1= a1+5 a = a+5 a= a= Ф(a1,a) a+5 TOS Rename expr
49
SSA?.. f(17) function f(int x){ x = x +1; return x; }
50
SSA Representation SSA Construction Analysis based on SSA
51
Constant and Copy Propagation in SSA
52
a0=1 x1=a0+5 a2 =x1+4 x2=a2+5 a1=6 a3= Ф(a0,a1) x4=a3+5 a4= Ф(a2,a3) x3
=Ф(x2,x4)
6 10 15 1,6 6,11
10,1,6 15,11
inputs in the program and where they flow
Can it overrun buf?
53
54
a0=tainted x1=a0+5 a2 =x1+4 x2=a2+5 a3= Ф(a0,a1) x4=a3+5 a4= Ф(a2,a3) x3
=Ф(x2,x4)
a1=tainted