0% found this document useful (0 votes)
0 views12 pages

Basic Analysis 4

Uploaded by

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

Basic Analysis 4

Uploaded by

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

Class 4

• Basic Analyses (4)


• Assign (see Schedule for links)
• Readings
• Control/program-dependence analysis
• Static single assignment and control dependence
• Problem Set 2: due 9/1/09

Control-dependence Analysis

2
Control-dependence Analysis

1. Introduction (motivation, overview)


2. Computation of control-dependence using
FOW
3. Computation of control-dependence using
dominance frontiers (later)

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

Computing Control-dependence Using


FOW

1. Augment the CFG by


CFG En
adding a node Start with
edge (Start, entry)
labeled “T” and edge 1
T F
(Start, exit) labeled “F”;
call this AugCFG 2 4
F
T
3 5

Ex
Computing Control-dependence Using
FOW

1. Augment the CFG by


AugCFG En
adding a node Start with
edge (Start, entry)
labeled “T” and edge T 1
T F
(Start, exit) labeled “F”;
call this AugCFG 2 4
Start T F

3 5
F

Ex

Computing Control-dependence Using


FOW

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

Computing Control-dependence Using


FOW
3. Consider edges in AugCFG
that are labeled (i.e., those Pdom Ex
nodes on which another node Tree
might be control dependent);
call this set S 2 3 6 1
Start
4. For AugCFG S consists of
(Start, En), (1,2), (1,4), (2,3),
(2,5) (i.e., those edges (A,B) 5 En
in the AugCFG for which B is
not an ancestor of A in Pdom
4
tree)
Computing Control-dependence Using
FOW

5. Consider each edge


(A,B) in S, those nodes Pdom Ex
in the Pdom tree from B Tree
to least common
Start 2 3 6 1
ancestor L of A and B
y Including L if L is A
y Excluding L if L is not A 5 En

Computing Control-dependence Using


FOW

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

Computing Control-dependence Using


FOW

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

7. Add region nodes to


CDG Start
T
R1

En 1
T F

R2 R3

2 6 5 4
T F
R4 R5

Computing Control-dependence Using


FOW

7. Add region nodes to 8. Create new regions if


CDG Start necessary
Start
T T
R1 R1
En 1 1
T F En
T F
R2 R3 R2 R3

2 6 5 4 4
T F 2 R6
T F
R4 R5 R4 R5 5
6
3 3
Computing Control-dependence Using
FOW

7. Merge region nodes if 8. Create new regions if


possible Start necessary
Start
T T
R1 R1

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

y 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
y A PDG contains nodes representing statements
in P, edges representing control dependence
between nodes, and edges representing data
dependence between nodes
Create PDG for Program

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

You might also like