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
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 entry � A statement S1 is control CFG dependent on a statement S2 if the outcome of S2 B1 determines whether S1 is Z > 1 T reached in the CFG F � What are the control B4 X = 1 X = 2 dependences for each B2 statement in the CFG at right? Z > 2 F � B2 – B1T T � B3 – B2T Z = X – 3 � entry, B1, exit – entering B3 B5 Y = X + 1 X = 4 code � B4 – B1F � B5 – B2F, B1F B6 Z = X + 7 � B6 – B2F, B1F exit
Introduction Intuition entry CFG � A statement S1 is control dependent on a statement S2 if the outcome of S2 B1 determines whether S1 is Z > 1 T reached in the CFG F � What are the control B4 X = 1 X = 2 dependences for each B2 statement in the CFG at right? Z > 2 F � entry, B1, exit – entering T code Z = X – 3 � B2 – B1T B3 B5 Y = X + 1 X = 4 � B3 – B2T � B4 – B1F � B5 – B2F, B1F B6 Z = X + 7 � B6 – B2F, B1F exit Introduction Definition (formal) entry 1. Let G be a CFG, with X and Y CFG nodes in G. Y is control- dependent on X iff B1 1. There exists a directed path Z > 1 T P from X to Y with any Z in P F (excluding X and Y) postdominated by Y and B4 X = 1 X = 2 2. X is not postdominated by Y B2 Z > 2 F Definition (informal) T Z = X – 3 There are two edges out of Y B3 B5 Y = X + 1 X = 4 � traversing one edge always leads to X, � traversing the other edge the B6 other may not lead to X Z = X + 7 exit
Introduction Definition (formal) entry 1. Let G be a CFG, with X and Y CFG nodes in G. Y is control- dependent on X iff B1 1. There exists a directed path Z > 1 T P from X to Y with any Z in P F (excluding X and Y) postdominated by Y and B4 X = 1 X = 2 2. X is not postdominated by Y B2 Z > 2 F Definition (informal) T Z = X – 3 There are two edges out of X B3 B5 Y = X + 1 X = 4 � traversing one edge always leads to Y, � traversing the other edge the B6 other may not lead to Y Z = X + 7 exit Computing Control-dependence Using FOW 1. Augment the CFG by En CFG adding a node Start with edge (Start, entry) 1 labeled “T” and edge T F (Start, exit) labeled “F”; 2 call this AugCFG 4 F T 3 5 6 Ex
Computing Control-dependence Using FOW 1. Augment the CFG by En AugCFG adding a node Start with edge (Start, entry) T 1 labeled “T” and edge T F (Start, exit) labeled “F”; 2 call this AugCFG 4 Start F T 3 5 F 6 Ex Computing Control-dependence Using FOW 2. Construct the En AugCFG postdominator tree for AugCFG T 1 T F 2 4 Start F T 3 5 F 6 Ex
Computing Control-dependence Using FOW 2. Construct the Pdom Ex postdominator tree for Tree AugCFG 2 3 6 1 Start En 5 4 Computing Control-dependence Using FOW 3. Consider edges in AugCFG Pdom that are labeled (i.e., those 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), En 5 (2,5) (i.e., those edges (A,B) 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 Pdom Ex (A,B) in S, those nodes Tree in the Pdom tree from B to least common 2 3 6 1 Start ancestor L of A and B � Including L if L is A En 5 � Excluding L if L is not A 4 Computing Control-dependence Using FOW Pdom Ex Edge L Nodes CD on Tree Start, En 2 3 6 1 Start 1, 2 En 1, 4 5 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 2 3 6 1 Start 1, 2 Ex 2 1, T En 1, 4 Ex 4, 5, 6 1, F 5 2, 3 Ex 3 2, T 4 2, 5 Ex 5, 6 2, F Computing Control-dependence Using FOW 6. Create control- dependence graph Edge L Nodes CD on 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 F 2 F T F 2, 5 Ex 5, 6 2, F F 3 6 5 4
Computing Control-dependence Using FOW 7. Add region nodes to CDG Start T R1 1 En T F R3 R2 6 5 4 2 F T R4 R5 3 Computing Control-dependence Using FOW 7. Add region nodes to 8. Create new regions if CDG necessary Start Start T T R1 R1 1 En 1 En T F T F R3 R2 R2 R3 6 5 4 2 4 R6 2 F T 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 necessary Start Start T T R1 R1 1 En 1 En T F T F R2 R3 R2 R3 4 4 F R6 2 R6 2 T T F R4 5 R4 R5 5 6 6 3 3 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
Create PDG for Program Start T T En 1 T F F 2 F T F F 3 6 5 4 Program-dependence Graph Completed in class En 1 2 3 4 5 6 8 7 Ex 22 22
Program-dependence Graph 1. A = 1 B1 Completed in class 2. B = 2 B2 3. C = A + B 4. D = C - A 5. D = B * D B3 B5 T F 8. B = A + B 6. D = A + B 9. E = C - A 7. E = E + 1 F T B4 10. A = B * D B6 11. B = A - D
Recommend
More recommend