Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jeffrey D. Ullman Stanford University Flow Graph Theory.

Similar presentations


Presentation on theme: "Jeffrey D. Ullman Stanford University Flow Graph Theory."— Presentation transcript:

1 Jeffrey D. Ullman Stanford University Flow Graph Theory

2 2 1. Proper ordering of nodes of a flow graph speeds up the iterative algorithms: “depth-first ordering.” 2. “Normal” flow graphs have a surprising property --- “reducibility” --- that simplifies several matters. 3. Outcome: few iterations “normally” needed.

3 3  Start at entry.  If you can follow an edge to an unvisited node, do so.  If not, backtrack to your parent (node from which you were visited).  Constructs a Depth-First Spanning Tree:  Root = entry.  Tree edges are the edges along which we first visit the node at the head.

4 4 1 5 3 4 2

5 5  The reverse of the order in which a DFS retreats from the nodes.  Alternatively, reverse of postorder traversal of the tree.

6 6 1 3 5 2 4

7 7 1. Tree edges. 2. Forward edges (node to proper descendant). 3. Retreating edges (node to ancestor).  Includes a self-loop. 4. Cross edges (between two nodes, neither of which is an ancestor of the other.

8 8  Of these edges, only retreating edges go from high to low in DF order.  Example of proof: You must retreat from the head of a tree edge before you can retreat from its tail.  Also surprising: all cross edges go right to left in the DFST.  Assuming we add children of any node from the left.

9 9 1 3 5 2 4 Retreating Forward Cross

10 10 1. “Normal” flow graphs are “reducible.” 2. “Dominators” needed to explain reducibility. 3. In reducible flow graphs, loops have single entry points, and retreating edges are independent of the DFST chosen (and called “back” edges). 4. Leads to relationship between DF order and efficient iterative algorithm.

11 11  Node d dominates node n if every path from the entry to n goes through d.  Text has a forward-intersection iterative algorithm for finding dominators.  Quick observations: 1.Every node dominates itself. 2.The entry dominates every node.

12 12 1 3 5 2 4 {1,5} {1,4} {1,2,3} {1,2} {1}

13 13  The test of a while loop dominates all blocks in the loop body.  The test of an if-then-else dominates all blocks in either branch.

14 14  An edge is a back edge if its head dominates its tail.  Theorem: Every back edge is a retreating edge in every DFST of every flow graph.  Converse almost always true, but not always. Back edge Head reached before tail in any DFST Search must reach the tail before retreating from the head, so tail is a descendant of the head Note: We assume all nodes are reachable from the entry, or else they can be deleted from the flow graph.

15 15 1 3 5 2 4 {1,5} {1,4} {1,2,3} {1,2} {1}

16 16  A flow graph is reducible if every retreating edge in any DFST for that flow graph is a back edge.  Testing reducibility: Remove all back edges from the flow graph and check that the result is acyclic.  Hint why it works: All cycles must include some retreating edge in every DFST.  In particular, the edge that enters the first node of the cycle that is visited.

17 17 Depth-first search reaches here first Search must reach these nodes before leaving the cycle So this is a retreating edge

18 18 1 3 5 2 4

19 19 1 3 5 2 4 Remaining graph is acyclic.

20 20  Folk theorem: All flow graphs in practice are reducible.  Fact: If you use only while-loops, for-loops, repeat-loops, if-then(-else), break, and continue, then your flow graph is reducible.

21 21 A CB In any DFST, one of these edges will be a retreating edge. A B C A B C But no heads dominate their tails, so deleting back edges leaves the cycle.

22 22 1. Proper ordering of nodes during iterative algorithm assures number of passes limited by the number of “nested” back edges. 2. Depth of nested loops upper-bounds the number of nested back edges.

23 23  Suppose that for a RD analysis, we visit nodes during each iteration in DF order.  The fact that a definition d reaches a block will propagate in one pass along any increasing sequence of blocks.  When d arrives at the tail of a retreating edge, it is too late to propagate d from OUT to IN.  The IN at the head has already been computed for that round.

24 24 1 3 5 2 4 d d d d d d d d d d Definition d is Gen’d by node 2 not killed anywhere. The first pass The second pass

25 25  The depth of a flow graph with a given DFST and DF-order is the greatest number of retreating edges along any acyclic path.  For RD, if we use DF order to visit nodes, we converge in depth+2 passes.  Depth+1 passes to follow that number of increasing segments.  1 more pass to realize we converged.

26 26 increasing retreating increasing retreating Pass 1 Pass 2 Pass 3

27 27  AE also works in depth+2 passes.  Unavailability propagates along retreat-free node sequences in one pass.  So does LV if we use reverse of DF order.  A use propagates backward along paths that do not use a retreating edge in one pass.

28 28  The depth+2 bound works for any monotone framework, as long as information only needs to propagate along acyclic paths.  Example: if a definition reaches a point, it does so along an acyclic path.

29 29  Normal control-flow constructs produce reducible flow graphs with the number of back edges at most the nesting depth of loops.  Nesting depth tends to be small.

30 30 3 nested while- loops; depth = 3. 3 nested repeat- loops; depth = 1

31 31  The natural loop of a back edge a->b is b plus the set of nodes that can reach a without going through b.  Theorem: two natural loops are either disjoint, identical, or one is contained (nested) within the other.  Thus, for reducible flow graphs, the nesting structure of loops is well defined.

32 32 1 3 5 2 4 Natural loop of 3 -> 2 Natural loop of 5 -> 1


Download ppt "Jeffrey D. Ullman Stanford University Flow Graph Theory."

Similar presentations


Ads by Google