Program Dependence Graph
Program Dependence Graph
entry entry
Z > 1 B1 Z > 1 B1
X=1 X = 2 B4 X=1 X = 2 B4
B2 Z>2 B2 Z>2
Z=X–3 Z=X–3
B3 Y = X + 1 B5 X=4 B3 Y = X + 1 B5 X=4
B6 Z = X + 7 B6 Z = X + 7
exit exit
Data-Dependence Graph
entry entry
Z > 1 B1 Z > 1 B1
X=1 X = 2 B4 X=1 X = 2 B4
B2 Z>2 X B2 Z>2
X
X
Z=X–3 Z=X–3
B3 Y = X + 1 B5 X=4 B3 Y = X + 1 B5 X=4
X
B6 Z = X + 7 B6 Z = X + 7
exit exit
Data-Dependence Graph
entry entry
Z
Z
Z > 1 B1 Z > 1 B1
Z Y
X=1 X = 2 B4 X=1 X = 2 B4
B2 Z>2 X B2 Z>2
X
X X
Z=X–3 Z=X–3
B3 Y = X + 1 B5 X=4 B3 Y = X + 1 B5 X=4
X X
Y B6 Z = X + 7 B6 Z = X + 7
Z
exit exit
Control-Dependence Analysis
Intuition
• A statement S1 is
control dependent on a entry
statement S2 if the
outcome of S2 directly
determines whether S1 Z > 1 B1
may not be reached T F
• What are the control
dependences for each X=1 X = 2 B4
statement in the CFG on B2 Z > 2 F
the right?
T Z=X–3
B3 Y = X + 1 B5 X = 4
B6 Z = X + 7
exit
Control-Dependence Analysis
Intuition
• A statement S1 is
control dependent on a entry
statement S2 if the
outcome of S2 directly
determines whether S1 Z > 1 B1
may not be reached T F
• What are the control
dependences for each X=1 X = 2 B4
statement in the CFG on B2 Z > 2 F
the right?
• entry, B1, exit – T Z=X–3
entering code B3 Y = X + 1 B5 X = 4
• B2 – B1T
• B3 – B2T
• B4 – B1F
B6 Z = X + 7
• B5 – B2F, B1F
• B6 – B2F, B1F
exit
Control-Dependence Analysis
Definition
Let G be a CFG, with X and entry
Y nodes in G. Y is
control-dependent on
edge (u->v) if
Z > 1 B1
1. Y post-dominates v and T F
2. If Y != u, then Y does
not post-dominate u X=1 X = 2 B4
B2 Z > 2 F
T Z=X–3
B3 Y = X + 1 B5 X = 4
B6 Z = X + 7
exit
Computing CD Using FOW
Augment the CFG
by adding a node AugCFG En
Ex
Computing CD Using FOW
Construct the
postdominator AugCFG En
Ex
Computing CD Using FOW
Construct the
postdominator Pdom Ex
Tree
tree for AugCFG
Start 2 3 6 1
5 En
4
Computing CD Using FOW
Consider set S of edges (m, n)
in AugCFG such that n does
not postdominate m AugCFG En
For AugCFG S consists of:
T 1
T F
Pdom 2 4
Ex
Start F
Tree T
3 5
Start 2 3 6 1 F
5 En 6
4 Ex
Computing CD Using FOW
Consider set S of edges (m, n)
in AugCFG such that n does
not postdominate m AugCFG En
For AugCFG S consists of:
• (Start, En) T 1
• (1,2) T F
• (1,4) 2 4
• (2,3) Start F
• (2,5)
T
3 5
F
Ex
Computing CD Using FOW
Consider, for each edge
(A,B) in S, those
nodes in the Pdom Pdom Ex
tree from B to least Tree
common ancestor L
of A and B Start 2 3 6 1
• Including L if L is A
• Excluding L if L is not A 5 En
4
Computing CD Using FOW
Consider, for each edge
(A,B) in S, those
nodes in the Pdom Pdom Ex
tree from B to least Tree
common ancestor L
of A and B Start 2 3 6 1
• Including L if L is A
• Excluding L if L is not A 5 En
Edge L Nodes
Start, En 4
1, 2
1, 4
2, 3
2, 5
Computing CD Using FOW
Consider, for each edge
(A,B) in S, those
nodes in the Pdom Pdom Ex
tree from B to least Tree
common ancestor L
of A and B Start 2 3 6 1
• Including L if L is A
• Excluding L if L is not A 5 En
Edge L Nodes
Start, En Ex En, 1 4
1, 2 Ex 2
1, 4 Ex 4, 5, 6
2, 3 Ex 3 All identified nodes are
2, 5 Ex 5, 6 control dependent on A
Computing CD Using FOW
Consider, for each edge
(A,B) in S, those
nodes in the Pdom Pdom Ex
tree from B to least Tree
common ancestor L
of A and B Start 2 3 6 1
• Including L if L is A
• Excluding L if L is not A 5 En
Edge L Nodes CD on
Start, En Ex En, 1 Start, T 4
1, 2 Ex 2 1, T
1, 4 Ex 4, 5, 6 1, F
2, 3 Ex 3 2, T All identified nodes are
2, 5 Ex 5, 6 2, F control dependent on A
Computing CD Using FOW
Given (A,B), how can
you find the set of
nodes control Pdom Ex
dependent on A Tree
easily?
Start 2 3 6 1
Why is the set we obtain
correct?
5 En
Edge L Nodes CD on
Start, En Ex En, 1 Start, T 4
1, 2 Ex 2 1, T
1, 4 Ex 4, 5, 6 1, F
2, 3 Ex 3 2, T
2, 5 Ex 5, 6 2, F
Computing CD Using FOW