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

Similar documents
Example (cont.): Control Flow Graph. 2. Interval analysis (recursive) 3. Structural analysis (recursive)

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

Control Flow Analysis & Def-Use. Hwansoo Han

Control-Flow Analysis

Control Flow Analysis

Lecture 8: Induction Variable Optimizations

Challenges in the back end. CS Compiler Design. Basic blocks. Compiler analysis

Control Flow Analysis

Lecture 2: Control Flow Analysis

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

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

CONTROL FLOW ANALYSIS. The slides adapted from Vikram Adve

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

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

Control flow and loop detection. TDT4205 Lecture 29

Introduction to Machine-Independent Optimizations - 4

Intermediate representation

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

An Overview of GCC Architecture (source: wikipedia) Control-Flow Analysis and Loop Detection

Topic 9: Control Flow

Motivation for B-Trees

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Optimizations. Optimization Safety. Optimization Safety CS412/CS413. Introduction to Compilers Tim Teitelbaum

Graph Algorithms Using Depth First Search

Fundamentals of Data Structure

Lecture 9: Loop Invariant Computation and Code Motion

Intermediate Representations. Reading & Topics. Intermediate Representations CS2210

Lecture 3: Graphs and flows

CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion

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

Department of Computer Science and Technology

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

Goals of Program Optimization (1 of 2)

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

Directed Graphs (II) Hwansoo Han

Compiler Construction 2009/2010 SSA Static Single Assignment Form

Graph: representation and traversal

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

LECTURE 17 GRAPH TRAVERSALS

CS24 Week 8 Lecture 1

Control Flow Analysis. Reading & Topics. Optimization Overview CS2210. Muchnick: chapter 7

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1


CS301 - Data Structures Glossary By

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

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

LECTURE 11 TREE TRAVERSALS

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

Graph. Vertex. edge. Directed Graph. Undirected Graph

Lecture 23 CIS 341: COMPILERS

Data Structure. IBPS SO (IT- Officer) Exam 2017

CSE P 501 Compilers. Loops Hal Perkins Spring UW CSE P 501 Spring 2018 U-1

EECS 583 Class 2 Control Flow Analysis LLVM Introduction

An Introduction to Trees

Design and Analysis of Algorithms

Module 16: Data Flow Analysis in Presence of Procedure Calls Lecture 32: Iteration. The Lecture Contains: Iteration Space.

Compiler Construction 2010/2011 Loop Optimizations

CS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.

CS DATA STRUCTURES AND ALGORITHMS

Advanced Set Representation Methods

XML Query Processing. Announcements (March 31) Overview. CPS 216 Advanced Database Systems. Course project milestone 2 due today

Elementary Graph Algorithms CSE 6331

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Graph Biconnectivity

CS577 Modern Language Processors. Spring 2018 Lecture Optimization

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1

Compiler Construction 2016/2017 Loop Optimizations

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Graph Representations and Traversal

W4231: Analysis of Algorithms

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

Unweighted Graphs & Algorithms

Graph Algorithms. Imran Rashid. Jan 16, University of Washington

Konigsberg Bridge Problem

An O (mlogn)-time Algorithm for the Maximal Planar Subgraph Problem

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Announcements. HW3 is graded. Average is 81%

Announcements (March 31) XML Query Processing. Overview. Navigational processing in Lore. Navigational plans in Lore

Graph Algorithms. Definition

Algorithms for Finding Dominators in Directed Graphs

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

The tree data structure. Trees COL 106. Amit Kumar Shweta Agrawal. Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo

Range Reporting. Range reporting problem 1D range reporting Range trees 2D range reporting Range trees Predecessor in nested sets kd trees

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

Contents of Lecture 2

Regions and Other Concepts

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

A Practical Interprocedural Dominance Algorithm

[ DATA STRUCTURES ] Fig. (1) : A Tree

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

Strongly connected components

LECTURE 18. Control Flow

Graphs: basic concepts and algorithms

Transcription:

The Lecture Contains: Algorithm to Find Dominators Loop Detection Algorithm to Detect Loops Extended Basic Block Pre-Header Loops With Common eaders Reducible Flow Graphs Node Splitting Interval Analysis Intervals Interval Partition Interval Graphs Control Tree file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_1.htm[6/14/2012 12:08:58 PM]

Algorithm to Find Dominators D(n0) := {n0}; for n in N-{n0} do D(n) := N; while changes to any D(n) occur do for n in N-{n0} do D(n) := {n} n D(p); Loop Detection Search for a back-edge such that a b is an edge and b dom a. Given a back edge a b Find set of nodes that can reach node a without going through node b And node b These nodes form a natural loop with b as header. Given back edge a b natural loop is a sub graph which contains a, b and all the nodes which can reach a without passing through b file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_2.htm[6/14/2012 12:08:58 PM]

Algorithm to Detect Loops stack := empty; loop := {b}; insert(a); while stack is not empty do begin pop m of the stack; for each predecessor p of m do insert(p) end; procedure insert(m); if m is not in loop then begin loop := loop {m}; push m onto stack end; Approaches to Control Flow Analysis Approach 1; Use dominators to discover loops use loops in optimization do iterative data flow analysis Approach 2: Use interval analysis analyze overall structure of the program decompose it into nested regions the nesting structure forms a control tree Approach 3: Use structural analysis speeds up dataflow analysis also called elimination method Most compilers use the first approach It is easy to implement and provides most of the information for optimization It is inferior to the other two approaches Interval based approaches are faster Interval based approach can be used in incremental analysis Structural analysis makes control flow transformations easy file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_3.htm[6/14/2012 12:08:59 PM]

Extended Basic Block Maximal sequence of instructions begining with a header and no other join nodes Single entry multiple exits block Depth first traversal contains (i) all the nodes and (ii) edges which make depth first order. This is called depth first spanning tree. Forward edges: from a node to descendent Back edges: go from node to ancestor Cross edges: connects nodes such that neither is an ancestor in dfs file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_4.htm[6/14/2012 12:08:59 PM]

Pre-Header Many optimizations require code movement from inside a loop to just before it. Pre-header is a new empty block just before header. All edges from outside to header go to pre-header A new edge goes from pre-header to header Loops With Common Headers Two loops with different headers are either disjoint or nested Two loops with the same header Not clear if they are nested Or are one loop Can not be decided without looking at the source code file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_5.htm[6/14/2012 12:08:59 PM]

A ntaural loop is a strongly connected region Each strongly connected region is not a loop Reducible Flow Graphs A graph is reducible if applying a sequence of transformations reduce it to a single node A flow graph G=(N,E) is reducible if E can be partitioned into two disjoint groups Eb and Ef such that: (N,Ef ) forms an acyclic graph in which every node can be reached from entry Eb are the backw edges, edges whose heads dominate their tails. Example of a Non Reducible Flow Graph file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_6.htm[6/14/2012 12:08:59 PM]

In a reducible graph All the loops are natural loops There are no jumps in the middle of a loop Improper regions are multiple entry strongly connected regions Programming languages do not allow irreducible flow graphs Fortran with loops of if and gotos construct irreducible flow graphs Most of the optimizations do not work for irreducible flow graphs Node splitting is a possible solution file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_7.htm[6/14/2012 12:08:59 PM]

Node Splitting Transformation used for converting non-reducible flow graphs to reducible flow graphs. If there is a node n with k predecessors: Split n into k nodes generating nodes n1, n2,..., nk The ith predecessor of n becomes the predecessors of ni All the successors of n become successors of all of the ni s Interval Analysis Divides flow graph into various regions Consolidate each region into a (abstract) node Resulting flow graph is an abstract flow graph Result of transformations produce control tree Root represents the original graph Leaf of control tree are basic blocks Internal nodes are abstract nodes Edges represent relationship between abstract nodes Intervals Each interval has a header node that dominates all the nodes in the interval. Given a flow graph with initial node n0, the interval with header n is denoted by I(n) and is defined as: N is in I(n) If all the predecessors of a node m are in I(n) then m is in I(n) No other node is in I(n) file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_8.htm[6/14/2012 12:08:59 PM]

Interval Partition Construct I(n0); while there is a node m not yet selected but with a selected predecessor do construct I(m); Construct I(n); I(n) := {n}; while there exists a node m 6= n0 all of whose predecessors are in I(n) do I(n) := I(n) {m} I(1) = 1, 2 I(3) = 3 I(4) = 4, 5, 6 I(7) = 7, 8, 9, 10 Interval Graphs From the interval graph construct a new graph I(G) Nodes of the new graph correspond to interval partitions. Initial node is the node containing initial node of G. There is an edge from node I to node J if there is some edge from element of I to the header of J. Interval partition can be repeatedly applied to the new Interval graph. file:///d /...ary,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_9.htm[6/14/2012 12:08:59 PM]

If the limit flow graph is a single node then the graph is reducible. Control Tree The result of applying a sequence of such transformations produces a control tree. It is defined as follows: The root is sn abstract graph representing the original flowgraph The leaves are individual basic blocks The internal nodes are abstract nodes representing regions of the flowgraph The edges of the tree represent the relationship between each abstract node and the regions that are its descendants file:///d /...ry,%20dr.%20sanjeev%20k%20aggrwal%20&%20dr.%20rajat%20moona/multi-core_architecture/lecture%2027/27_10.htm[6/14/2012 12:08:59 PM]