0% found this document useful (0 votes)
8 views20 pages

Program Dependence Graph

Uploaded by

scribd.boil024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views20 pages

Program Dependence Graph

Uploaded by

scribd.boil024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Data-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

Start with edge


T
(Start, entry) T
1
F
labeled “T” and 2 4
edge (Start, exit) Start
T
F
labeled “F”; call
3 5
this AugCFG F

Ex
Computing CD Using FOW
Construct the
postdominator AugCFG En

tree for AugCFG


T 1
T F
2 4
Start F
T
3 5
F

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

Edge L Nodes CD on Create CDG


Start, En Ex En, 1 Start, T
Start
T 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 F
T F
2, 5 Ex 5, 6 2, F 3 F 6 5 4
Program-Dependence Graph
(PDG)
A program dependence graph (PDG)
for a program P is the combination
of the control-dependence graph
for P and the data-dependence
graph for P
A PDG contains nodes representing
statements in P, edges
representing control dependence
between nodes, and edges
representing data dependence
between nodes
Program-Dependence Graph
(PDG)
1. read (n) Compute the PDG for
2. if (n < 0) the
program on the left
3. n=0
4. i := 1
5. sum := 0
6. product := 1
7. while i <= n do
8. sum := sum + i
9. product := product *
i
10. i := i + 1
11. write (sum)
12. write (product)
Program-Dependence Graph
(PDG)
1. read a Compute the PDG for
2. if (a <= 0) { the
3. print a program on the left
4. return
5. }
6. i = a
7. while (i > 0) {
8. a=a+i
9. i=i-1
10. }
11. print a

You might also like