Professional Documents
Culture Documents
Marcus Denker
SSA
Roadmap
© Marcus Denker
2
SSA
> Definition:
© Marcus Denker
3
SSA
Why Static?
© Marcus Denker
4
SSA
Example: Sequence
Original SSA
a := b + c
a1 := b1 + c 1
b := c + 1
b2 := c1 + 1
d := b + c
d1 := b2 + c 1
a := a + 1
a2 := a1 + 1
e := a + b
e1 := a2 + b 2
© Marcus Denker
5
SSA
Example: Condition
Original
SSA
if B then
if B then
a := b
a1 := b
else
else
a := c
a2 := c
end
End
… a …
… a? …
© Marcus Denker
6
SSA
Solution: Φ-Function
Original
SSA
if B then
if B then
a := b
a1 := b
else
else
a := c
a2 := c
end
End
… a …
a3 := Φ(a1,a2)
… a3 …
© Marcus Denker
7
SSA
The Φ-Function
© Marcus Denker
8
SSA
© Marcus Denker
9
SSA
if x = y then
S1
else
S2
end
S3
© Marcus Denker
10
SSA
if B then
a1 := 1
else
a2 := 2
End
a3 := PHI(a1,a2)
… a3 …
© Marcus Denker
11
Intermediate Representation
Repeat: IR
© Oscar Nierstrasz
12
SSA
SSA as IR
© Marcus Denker
13
SSA
Transforming to SSA
© Marcus Denker
14
SSA
Minimal SSA
© Marcus Denker
15
SSA
© Marcus Denker
16
SSA
Iterated Path-Convergence
© Marcus Denker
17
SSA
Example (Simple)
© Marcus Denker
18
SSA
© Marcus Denker
20
SSA
Dominance
DominanceFrontier
and SSA Creation
Marcus Denker
21
SSA
Dominance
DominanceFrontier
and SSA Creation
?
© Marcus Denker
22
SSA
Dominance
DominanceFrontier
and SSA Creation
Intuition:
Nodes at the border of a region of dominance
© Marcus Denker
23
SSA
© Marcus Denker
24
SSA
© Marcus Denker
25
SSA
© Marcus Denker
26
SSA
Simple Example
DF(B1)=
DF(B2)=
DF(B3)=
DF(B4)=
© Marcus Denker
27
SSA
Simple Example
DF(B1)={?}
DF(B2)=
DF(B3)=
DF(B4)=
© Marcus Denker
28
SSA
Simple Example
DF(B1)={}
DF(B2)=
DF(B3)=
DF(B4)=
© Marcus Denker
29
SSA
Simple Example
DF(B1)={}
DF(B2)={?}
DF(B3)=
DF(B4)=
© Marcus Denker
30
SSA
Simple Example
DF(B1)={}
DF(B2)={B4}
DF(B3)=
DF(B4)=
© Marcus Denker
31
SSA
Simple Example
DF(B1)={}
DF(B2)={B4}
DF(B3)={B4}
DF(B4)=
© Marcus Denker
32
SSA
Simple Example
DF(B1)={}
DF(B2)={B4}
DF(B3)={B4}
DF(B4)={}
© Marcus Denker
33
SSA
Simple Example
DF(B1)={}
DF(B2)={B4}
DF(B3)={B4}
DF(B4)={}
Properties of SSA
> Examples:
— Constant propagation
— Value numbering
— Invariant code motion and removal
Next Week!
— Strength reduction
— Partial redundancy elimination
© Marcus Denker
35
SSA
© Marcus Denker
36
SSA
© Marcus Denker
37
SSA
© Marcus Denker
38
SSA
Problems
> Problems:
— Copies need to be removed
— Wrong in some cases after reordering of code
Φ-Congruence
© Marcus Denker
40
SSA
Φ-Congruence: Definitions
Φ-connected(x):
a3 = Φ(a1, a2)
a5 = Φ(a3, a4)
--> a1, a4 are connected
Φ-congruence-class:
Transitive closure of Φ-connected(x).
© Marcus Denker
41
SSA
Φ-Congruence Property
Φ-congruence property:
© Marcus Denker
42
Code Generation
Repeat: Liveness
Interference
© Marcus Denker
45
SSA
© Marcus Denker
46
SSA
© Marcus Denker
47
SSA
SSA: Literature
Books:
- SSA Chapter in Appel
Modern Compiler Impl. In Java
- Chapter 8.11 Muchnik:
Advanced Compiler Construction
SSA Creation:
Cytron et. al: Efficiently computing Static Single
Assignment Form and the Control Dependency Graph
(TOPLAS, Oct 1991)
Summary
© Marcus Denker
49
SSA
© Marcus Denker
50
SSA
© Marcus Denker
51
SSA
License
> http://creativecommons.org/licenses/by-sa/2.5/
Attribution-ShareAlike 2.5
You are free:
• to copy, distribute, display, and perform the work
• to make derivative works
• to make commercial use of the work
Attribution. You must attribute the work in the manner specified by the author or licensor.
Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting
work only under a license identical to this one.
• For any reuse or distribution, you must make clear to others the license terms of this work.
• Any of these conditions can be waived if you get permission from the copyright holder.
Your fair use and other rights are in no way affected by the above.
© Oscar Nierstrasz
52