Flow Graph Theory. Depth-First Ordering Efficiency of Iterative Algorithms Reducible Flow Graphs

Similar documents
Acknowledgement. Flow Graph Theory. Depth First Search. Speeding up DFA 8/16/2016

Lecture 4. More on Data Flow: Constant Propagation, Speed, Loops

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Lecture 8: Induction Variable Optimizations

Loops! while a.runs() loop { while b.runs() loop c.foo() pool; b.reset(); } pool

Control Flow Analysis

Module 14: Approaches to Control Flow Analysis Lecture 27: Algorithm and Interval. The Lecture Contains: Algorithm to Find Dominators.

Graph Algorithms Using Depth First Search

Control Flow Graphs. (From Matthew S. Hetch. Flow Analysis of Computer Programs. North Holland ).

Statements or Basic Blocks (Maximal sequence of code with branching only allowed at end) Possible transfer of control

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

Searching in Graphs (cut points)

Why Global Dataflow Analysis?

Compiler Structure. Data Flow Analysis. Control-Flow Graph. Available Expressions. Data Flow Facts

Directed Graphs (II) Hwansoo Han

Control-Flow Analysis

(Refer Slide Time: 05:25)

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

When we eliminated global CSE's we introduced copy statements of the form A:=B. There are many

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Lecture 2: Control Flow Analysis


Contents of Lecture 2

Trees. Arash Rafiey. 20 October, 2015

Undirected Graphs. Hwansoo Han

Applications of BDF and DFS

Binary Trees

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz

Info 2950, Lecture 16

Lecture 3: Graphs and flows

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

Graphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes

COS 423 Lecture14. Robert E. Tarjan 2011

CSE 417 Branch & Bound (pt 4) Branch & Bound

Priority Queues, Binary Heaps, and Heapsort

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Efficient memory-bounded search methods

CSE 21 Mathematics for Algorithm and System Analysis

March 20/2003 Jayakanth Srinivasan,

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Graph Algorithms. Definition

Structures and Strategies For Space State Search

CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion

(Refer Slide Time: 06:01)

Control flow and loop detection. TDT4205 Lecture 29

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

LECTURE 26 PRIM S ALGORITHM

Graph Representation

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Review; questions Basic Analyses (2) Assign (see Schedule for links)

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

Backtracking. Chapter 5

Motivation for B-Trees

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

An Algorithm for Enumerating all Directed Spanning Trees in a Directed Graph

Introduction to Machine-Independent Optimizations - 4

LECTURE 11 TREE TRAVERSALS

Compiler Construction 2009/2010 SSA Static Single Assignment Form

MAL 376: Graph Algorithms I Semester Lecture 1: July 24

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Artificial Intelligence

Algorithmic Aspects of Communication Networks

22.3 Depth First Search

Assignment No 2 (Group B)

Copyright 2000, Kevin Wayne 1

Data Structures Lesson 9

Foundations of Discrete Mathematics

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Introduction and Overview

Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

Algorithms: Lecture 10. Chalmers University of Technology

Spring 2007 Midterm Exam

Binary Trees, Binary Search Trees

Recitation 9. Prelim Review

Part IV. Common Reduction Targets

For a printable form of this assignment: assignment3.pdf. Assignment 3: Binary trees

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

Search means finding a path or traversal between a start node and one of a set of goal nodes. Search is a study of states and their transitions.

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim:

An algorithm for Performance Analysis of Single-Source Acyclic graphs

Module 5 Graph Algorithms

CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers

Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?

Brute Force: Selection Sort

Data Structures Question Bank Multiple Choice

Lecture 9: Loop Invariant Computation and Code Motion

Trees. Truong Tuan Anh CSE-HCMUT

CSE 638: Advanced Algorithms. Lectures 10 & 11 ( Parallel Connected Components )

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

CS 280 Problem Set 10 Solutions Due May 3, Part A

Figure 1. A breadth-first traversal.

COSC 2011 Section N. Trees: Terminology and Basic Properties

Transcription:

Flow Graph Theory Depth-First Ordering Efficiency of Iterative Algorithms Reducible Flow Graphs 1

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

Depth-First Search 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). 3

Depth-First Spanning Tree Root = entry. Tree edges are the edges along which we first visit the node at the head. 4

Example: DFST 1 2 4 3 5 5

Depth-First Node Order The reverse of the order in which a DFS retreats from the nodes. Alternatively, reverse of postorder traversal of the tree. 6

Example: DF Order 1 4 2 5 3 7

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

A Little Magic Of these edges, only retreating edges go from high to low in DF order. Most surprising: all cross edges go right to left in the DFST. Assuming we add children of any node from the left. 9

Example: Non-Tree Edges Retreating 1 Forward 4 2 5 3 Cross 10

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

Dominators 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

Example: Dominators 1 {1} 4 {1,4} 2 {1,2} 5 {1,5} 3 {1,2,3} 13

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

Back Edges 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. 15

Example: Back Edges 1 {1} 4 {1,4} 2 {1,2} 5 {1,5} 3 {1,2,3} 16

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

Example: Remove Back Edges 1 4 2 5 3 18

Example: Remove Back Edges 1 4 2 5 3 Remaining graph is acyclic. 19

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

Example: Nonreducible Graph A A A B B C C C In any DFST, one of these edges will be a retreating edge. B 21

Why Care About Back/Retreating Edges? 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. 22

DF Order and Retreating Edges 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 along a retreating edge, it is too late to propagate d from OUT to IN. 23

Example: DF Order d 1 d 4 d d 2 d d d d 5 3 d d 24

Depth of a Flow Graph The depth of a flow graph 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. 25

Example: Depth = 2 increasing retreating increasing retreating increasing 26

Similarly... 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. 27

In General... 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. 28

Why Depth+2 is Good 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. 29

Example: Nested Loops 3 nested whileloops; depth = 3. 3 nested repeatloops; depth = 1 30

Natural Loops 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 nested. 31

Example: Natural Loops 1 4 2 5 3 Natural loop of 5 -> 1 Natural loop of 3 -> 2 32