Control-dependence Analysis 2 Control-dependence Analysis 1. - - PDF document

control dependence analysis
SMART_READER_LITE
LIVE PREVIEW

Control-dependence Analysis 2 Control-dependence Analysis 1. - - PDF document

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 1 Control-dependence Analysis 2


slide-1
SLIDE 1

1

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

2

Control-dependence Analysis

slide-2
SLIDE 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

A statement S1 is control dependent on a statement S2 if the outcome of S2 determines whether S1 is reached in the CFG What are the control dependences for each statement in the CFG at right?

B2 – B1T B3 – B2T entry, B1, exit – entering code B4 – B1F B5 – B2F, B1F B6 – B2F, B1F

entry Z > 1 X = 1 Z > 2 Y = X + 1 X = 2 Z = X – 3 X = 4 Z = X + 7 exit

B1 B3 B2 B6 B5 B4 T F F T CFG

slide-3
SLIDE 3

Introduction

Intuition

A statement S1 is control dependent on a statement S2 if the outcome of S2 determines whether S1 is reached in the CFG What are the control dependences for each statement in the CFG at right?

entry, B1, exit – entering code B2 – B1T B3 – B2T B4 – B1F B5 – B2F, B1F B6 – B2F, B1F

entry Z > 1 X = 1 Z > 2 Y = X + 1 X = 2 Z = X – 3 X = 4 Z = X + 7 exit

B1 B3 B2 B6 B5 B4 T F F T CFG

Introduction

entry Z > 1 X = 1 Z > 2 Y = X + 1 X = 2 Z = X – 3 X = 4 Z = X + 7 exit

B1 B3 B2 B6 B5 B4 T F F T

Definition (formal) 1. Let G be a CFG, with X and Y nodes in G. Y is control- dependent on X iff

1. There exists a directed path P from X to Y with any Z in P (excluding X and Y) postdominated by Y and 2. X is not postdominated by Y

Definition (informal)

There are two edges out of Y

  • traversing one edge always

leads to X,

  • traversing the other edge the
  • ther may not lead to X

CFG

slide-4
SLIDE 4

Introduction

entry Z > 1 X = 1 Z > 2 Y = X + 1 X = 2 Z = X – 3 X = 4 Z = X + 7 exit

B1 B3 B2 B6 B5 B4 T F F T

Definition (formal) 1. Let G be a CFG, with X and Y nodes in G. Y is control- dependent on X iff

1. There exists a directed path P from X to Y with any Z in P (excluding X and Y) postdominated by Y and 2. X is not postdominated by Y

Definition (informal)

There are two edges out of X

  • traversing one edge always

leads to Y,

  • traversing the other edge the
  • ther may not lead to Y

CFG

Computing Control-dependence Using FOW

  • 1. Augment the CFG by

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

En 1 2 3 4 5 6 Ex

T F T F CFG

slide-5
SLIDE 5

Computing Control-dependence Using FOW

  • 1. Augment the CFG by

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

En 1 2 3 4 5 6 Ex

Start T F T F T F AugCFG

Computing Control-dependence Using FOW

  • 2. Construct the

postdominator tree for AugCFG

En 1 2 3 4 5 6 Ex

Start T F T F T F AugCFG

slide-6
SLIDE 6

Computing Control-dependence Using FOW

  • 2. Construct the

postdominator tree for AugCFG

En 4 5 Ex 1 2 3 6 Start

Pdom Tree

Computing Control-dependence Using FOW

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

Pdom Tree

slide-7
SLIDE 7

Computing Control-dependence Using FOW

  • 5. Consider each edge

(A,B) in S, those nodes in the Pdom tree from B to least common ancestor L of A and B

  • Including L if L is A
  • Excluding L if L is not A

En 4 5 Ex 1 2 3 6 Start

Pdom Tree

Computing Control-dependence Using FOW

En 4 5 Ex 1 2 3 6 Start

Pdom Tree

2, 3 2, 5 1, 4 1, 2 Start, En CD on Nodes L Edge

slide-8
SLIDE 8

Computing Control-dependence Using FOW

En 4 5 Ex 1 2 3 6 Start

Pdom Tree

2, T 3 Ex 2, 3 2, F 5, 6 Ex 2, 5 1, F 4, 5, 6 Ex 1, 4 1, T 2 Ex 1, 2 Start, T En, 1 Ex Start, En CD on Nodes L Edge

Computing Control-dependence Using FOW

  • 6. Create control-

dependence graph

2, T 3 Ex 2, 3 2, F 5, 6 Ex 2, 5 1, F 4, 5, 6 Ex 1, 4 1, T 2 Ex 1, 2 Start, T En, 1 Ex Start, En CD on Nodes L Edge

En 6 5 1 2 3 4 Start

T F T T T F F F F

slide-9
SLIDE 9

Computing Control-dependence Using FOW

  • 7. Add region nodes to

CDG

En 6 5 1 2 3 4 Start

T T

R1 R2 R3

F F

R4

T

R5

Computing Control-dependence Using FOW

  • 7. Add region nodes to

CDG

  • 8. Create new regions if

necessary

En 6 5 1 2 3 4 Start

T T

R1 R2 R3

F F

R4

T

R5 En 6 5 1 2 3 4 Start

T

R1 R2 R3

F F

R4

T

R5

T

R6

slide-10
SLIDE 10

Computing Control-dependence Using FOW

  • 7. Merge region nodes if

possible

  • 8. Create new regions if

necessary

En 6 5 1 2 3 4 Start

T

R1 R2 R3

F F

R4

T

R5

T

R6 En 6 5 1 2 3 4 Start

T

R1 R2 R3

F F

R4

T T

R6

Program-dependence Graph

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

slide-11
SLIDE 11

Create PDG for Program

En 6 5 1 2 3 4 Start

T F T T T F F F F

22 22

Program-dependence Graph

1 2 3 4 5 6 7 8 Ex En Completed in class

slide-12
SLIDE 12

Program-dependence Graph

1. A = 1 2. B = 2 3. C = A + B 4. D = C - A

  • 5. D = B * D

8. B = A + B 9. E = C - A

  • 10. A = B * D
  • 11. B = A - D

6. D = A + B 7. E = E + 1

B1 B2 B3 B4 B5 B6 T F T Completed in class F