Lecture notes 20210609 SSA 3
Review
1 --> 2
2 --> 3, 11
3 --> 4, 8
4 --> 5
5 --> 6
6 --> 5, 7
7 --> 2
8 --> 9
9 --> 6, 10
10 --> 8
2 --> 3, 11
3 --> 4, 8
4 --> 5
5 --> 6
6 --> 5, 7
7 --> 2
8 --> 9
9 --> 6, 10
10 --> 8
Desctructing SSA form
- (1) For each variable v
- (1.1) Let phiweb(v) be the singleton set containing v
- (2) For each PHI-command a0 = PHI(a1, a2, ..., an)
- (2.1) For i in 1, 2, 3, ..., n
- (2.1.1) Union phiweb(a0) and phiweb(ai)
Making nonconventional SSA form conventional
CFG:
1 --> 2, 3
2 --> 4
3 --> 4
Original Instructions:
1:
a <-- ...
tmp <-- a
2:
a <- a
3:
a <- a + 1
4:
... <- a
... <- tmp
Conventional SSA:
1:
a1 <-- ...
tmp <-- a1
2:
a2 <- a1
3:
a3 <- a1 + 1
4:
a4 <- PHI (a2, a3)
... <- a4
... <- tmp
Transformed SSA:
1:
a1 <-- ...
2:
3:
a3 <- a1 + 1
4:
a4 <- PHI (a1, a3)
... <- a4
... <- a1
1 --> 2, 3
2 --> 4
3 --> 4
Original Instructions:
1:
a <-- ...
tmp <-- a
2:
a <- a
3:
a <- a + 1
4:
... <- a
... <- tmp
Conventional SSA:
1:
a1 <-- ...
tmp <-- a1
2:
a2 <- a1
3:
a3 <- a1 + 1
4:
a4 <- PHI (a2, a3)
... <- a4
... <- tmp
Transformed SSA:
1:
a1 <-- ...
2:
3:
a3 <- a1 + 1
4:
a4 <- PHI (a1, a3)
... <- a4
... <- a1
After adding new variables:
1:
a1 <-- ...
2:
a1' <- a1
3:
a3 <- a1 + 1
a3' <- a3
4:
a4 <- PHI (a1', a3')
... <- a4
... <- a1
1:
a1 <-- ...
2:
a1' <- a1
3:
a3 <- a1 + 1
a3' <- a3
4:
a4 <- PHI (a1', a3')
... <- a4
... <- a1
Partial redundancy elimination
CFG:
1 --> 2, 3
2 --> 4
3 --> 4
Instructions (before optimization):
2: ... <-- a + b
4: ... <-- a + b
Instructions (after optimization):
2: ... <-- a + b
3: ... <-- a + b
1 --> 2, 3
2 --> 4
3 --> 4
Instructions (before optimization):
2: ... <-- a + b
4: ... <-- a + b
Instructions (after optimization):
2: ... <-- a + b
3: ... <-- a + b
CFG:
1 --> 2
2 --> 2, 3
Instructions (before optimization):
2: ... <-- a + b
Instructions (after optimization):
1: ... <-- a + b
1 --> 2
2 --> 2, 3
Instructions (before optimization):
2: ... <-- a + b
Instructions (after optimization):
1: ... <-- a + b
Example 1:
Annotating the expression:
2: ... <-- a + b [h]
4: h <-- PHI (h, h)
... <-- a + b [h]
Inserting expressions:
2: ... <-- a + b [h]
3: ... <-- a + b [h]
4: h <-- PHI (h, h)
... <-- a + b [h]
deleting expressions:
2: ... <-- a + b [h]
3: ... <-- a + b [h]
4: h <-- PHI (h, h)
Annotating the expression:
2: ... <-- a + b [h]
4: h <-- PHI (h, h)
... <-- a + b [h]
Inserting expressions:
2: ... <-- a + b [h]
3: ... <-- a + b [h]
4: h <-- PHI (h, h)
... <-- a + b [h]
deleting expressions:
2: ... <-- a + b [h]
3: ... <-- a + b [h]
4: h <-- PHI (h, h)
Example 2:
Annotating the expression:
2: h <-- PHI (h, h)
... <-- a + b [h]
Inserting expressions:
1: ... <-- a + b [h]
2: h <-- PHI (h, h)
... <-- a + b [h]
deleting expressions:
1: ... <-- a + b [h]
2: h <-- PHI (h, h)
Annotating the expression:
2: h <-- PHI (h, h)
... <-- a + b [h]
Inserting expressions:
1: ... <-- a + b [h]
2: h <-- PHI (h, h)
... <-- a + b [h]
deleting expressions:
1: ... <-- a + b [h]
2: h <-- PHI (h, h)
(* 2021-06-09 07:55 *)