Docsity

Flow Graph Theory - Advanced Compiling Techniques - Lecture Slides, Slides of Compilers

Partial preview of the text

Download Flow Graph Theory - Advanced Compiling Techniques - Lecture Slides and more Slides Compilers in PDF only on Docsity!

Flow Graph Theory

Depth-First Ordering

Efficiency of Iterative Algorithms

Reducible Flow Graphs

Roadmap

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

Depth-First Spanning Tree

  • Root = entry.
  • Tree edges are the edges along which we first visit the node at the head.

Example: DFST

5

1

3 5

2 4

Example: DF Order

7

1

5 3

4 2

Four Kinds of Edges

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

Example: Non-Tree Edges

10

1

5 3

4 2

Retreating Forward

Cross

Roadmap

  • “Normal” flow graphs are “reducible.”
  • “Dominators” needed to explain reducibility.
  • In reducible flow graphs, loops are well defined, retreating edges are unique (and called “back” edges).
  • Leads to relationship between DF order and efficient iterative algorithm.

Example: Dominators

13

1

5 3

4 2

{1,5}

{1,4}

{1,2,3}

{1,2}

{1}

Common Dominator Cases

  • 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.

Example: Back Edges

16

1

5 3

4 2

{1,5}

{1,4}

{1,2,3}

{1,2}

{1}

Reducible Flow Graphs

  • A flow graph is reducible if every retreating edge in any DFST for that flow graph is a back edge.
  • Testing reducibility: Take any DFST for the flow graph, remove the back edges, and check that the result is acyclic.

Example: Remove Back Edges

19

1

5 3

4 2

Remaining graph is acyclic.

Why Reducibility?

  • 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.