Week 5
Week 5
Week-5
A Graph-Based Model
Control Dependence Graph
A Control Dependence Representation
A Control Dependence Representation
A Control Dependence Representation
A Graph Representation of Behavior
Calculating Control Dependencies
Calculating Control Dependencies
Calculating Control Dependencies
Definition of Dominance
Dominator
• Pre-dominators in a rooted, directed graph can be used to make this intuitive
notion of “controlling decision” precise.
• Node M dominates node N, if every path from the root to N passes through M.
A node will typically have many dominators, but except for the root, there is
a unique immediate dominator of node N which is closest to N on any
path from the root, and which is in turn dominated by all the other
dominators of N.
Because each node (except the root) has a unique immediate dominator, the
immediate dominator relation forms a tree.
• Post-dominators are calculated in the reverse of the control flow graph, using a
special “exit” node as the root.
An Example of Dominators
Example
Every path starting from the root node to node
10 reaches through nodes 2, 4, 5, and 1. Thus,
these nodes are pre-dominators of node 10.
Static Slice: because they are computed as the solution to a static analysis problem
(without considering the program’s input)
• Control Dependence:
Node n2 is control dependent on node n1 ≠ n2 if
• there exists a control flow path P= n1….n2 where n2 post dominates any node
in P (excluding n1), and
• N2 does not post dominate n1
Post dependences
n1\n2 1 2 3 4 5 6 7 8 9 10
1 x x x x x x
2 x x x x x
3 x x x x
4 x x x
5 x x
6 x x x x x
7 x x x x
8 x x x
9 x
10
Computing Slices
Given:
• PDG
• Slicing Criterion (n, V) where n is statement and V is a set of variables
defined or used at n
1. var n = readInput();
2. var i =1; 1 2 4 10
3 5 9
3. var sum= 0;
4. var prod=1;
5. while (i<=n){
6. sum=sum + i;
7. prod= prod*i;
6 7 8
8. i= i+1;}
9. print(sum); Slice (9, {sum})
10. print(prod);
{n |reachable(n,9)}
{1,2,3,5,6,8,9}
Class Activity
1. var x=1;
2. var y=2;
3. If (x<y){
4. y=x;}
5. Var z= x;
2. Anti-Dependent
y is anti-dependent on x, x δa y iff y defines a variable that is an input
variable to x. This is also called a write after read (WAR) dependence.
3. Output-Dependent
y is output-dependent on x, x δo y iff y defines a variable that is an output
variable for x. This is also called a write after write (WAW) dependence.
Example