Basic Analysis 4
Basic Analysis 4
Control-dependence Analysis
2
Control-dependence Analysis
Introduction
Intuition
y A statement S1 is control CFG entry
dependent on a statement S2
if the outcome of S2
determines whether S1 is Z > 1 B1
reached in the CFG T F
y What are the control
dependences for each X=1 X = 2 B4
statement in the CFG at right? B2 Z > 2 F
y B2 – B1T
y B3 – B2T T Z=X–3
y entry, B1, exit – entering B3 Y = X + 1 B5 X = 4
code
y B4 – B1F
y B5 – B2F, B1F
y B6 – B2F, B1F
B6 Z = X + 7
exit
Introduction
Intuition
y A statement S1 is control CFG entry
dependent on a statement S2
if the outcome of S2
determines whether S1 is Z > 1 B1
reached in the CFG T F
y What are the control
dependences for each X=1 X = 2 B4
statement in the CFG at right? B2 Z > 2 F
y entry, B1, exit – entering
code T Z=X–3
y B2 – B1T
B3 Y = X + 1 B5 X = 4
y B3 – B2T
y B4 – B1F
y B5 – B2F, B1F
y B6 – B2F, B1F
B6 Z = X + 7
exit
Introduction
Definition (formal)
1. Let G be a CFG, with X and Y CFG entry
nodes in G. Y is control-
dependent on X iff
1. There exists a directed path Z > 1 B1
P from X to Y with any Z in P T F
(excluding X and Y)
postdominated by Y and X=1 X = 2 B4
2. X is not postdominated by Y B2 Z > 2 F
Definition (informal) T Z=X–3
There are two edges out of Y
y traversing one edge always
B3 Y = X + 1 B5 X = 4
leads to X,
y traversing the other edge the
other may not lead to X B6 Z = X + 7
exit
Introduction
Definition (formal)
1. Let G be a CFG, with X and Y CFG entry
nodes in G. Y is control-
dependent on X iff
1. There exists a directed path Z > 1 B1
P from X to Y with any Z in P T F
(excluding X and Y)
postdominated by Y and X=1 X = 2 B4
2. X is not postdominated by Y B2 Z > 2 F
Definition (informal) T Z=X–3
There are two edges out of X
y traversing one edge always
B3 Y = X + 1 B5 X = 4
leads to Y,
y traversing the other edge the
other may not lead to Y B6 Z = X + 7
exit
Ex
Computing Control-dependence Using
FOW
3 5
F
Ex
2. Construct the
AugCFG En
postdominator tree for
AugCFG
T 1
T F
2 4
Start T F
3 5
F
Ex
Computing Control-dependence Using
FOW
2. Construct the
postdominator tree for Pdom Ex
AugCFG Tree
Start 2 3 6 1
5 En
Pdom Ex
Edge L Nodes CD on Tree
Start, En
Start 2 3 6 1
1, 2
1, 4 5 En
2, 3
4
2, 5
Computing Control-dependence Using
FOW
Pdom Ex
Edge L Nodes CD on Tree
Start, En Ex En, 1 Start, T
Start 2 3 6 1
1, 2 Ex 2 1, T
1, 4 Ex 4, 5, 6 1, F 5 En
2, 3 Ex 3 2, T
4
2, 5 Ex 5, 6 2, F
6. Create control-
Edge L Nodes CD on dependence graph
Start, En Ex En, 1 Start, T
T
Start
T
1, 2 Ex 2 1, T
En 1
1, 4 Ex 4, 5, 6 1, F T
F
2, 3 Ex 3 2, T 2 F
T F
F
2, 5 Ex 5, 6 2, F
3 F 6 5 4
Computing Control-dependence Using
FOW
En 1
T F
R2 R3
2 6 5 4
T F
R4 R5
2 6 5 4 4
T F 2 R6
T F
R4 R5 R4 R5 5
6
3 3
Computing Control-dependence Using
FOW
En 1 En 1
T F T F
R2 R3 R2 R3
2 F R6 4 R6 4
T
2
T F
R4 5 R4 R5 5
6 6
3 3
Program-dependence Graph
T
Start
T
En 1
T
F
2 F F
T F
3 F 6 5 4
Program-dependence Graph
En Completed in class
1
2 3
4 5
6
8
7
Ex
22
Program-dependence Graph
1. A=1
B1 2. B=2 Completed in class
B2 3. C=A+B
4. D=C-A
5. D = B * D B3
T B5
F
6. D=A+B 8. B=A+B
7. E=E+1 9. E=C-A
F
T
B4
10. A = B * D
B6 11. B = A - D