Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Similar presentations


Presentation on theme: "CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones."— Presentation transcript:

1 CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones

2 Lecture 15©2003 Joel Jones2 Overview Control Flow Analysis Basic Blocks Types of Analyses Control Flow Graphs Interval Analysis Control Flow Graphs Representation and Formation Traversals and Edges Finding Loops Reading for Next Time

3 Lecture 15©2003 Joel Jones3 Control Flow Analysis Control flow analysis is the discovery of the hierarchical flow of control within a procedure Used in concert with data flow analysis in performing optimizations

4 Lecture 15©2003 Joel Jones4 Basic Blocks All forms of control flow analysis begin with basic blocks Basic blocks are formed from a linear form of IR, such as MIR A basic block consists of a sequence of instructions that can be entered only at the beginning and exited only at the end

5 Lecture 15©2003 Joel Jones5 Example of Basic Block Formation Pair Up: Find the Basic Blocks receive m (val) f0 <- 0 f1 <- 1 if m <= 1 goto L3 i <- 2 L1: if i <= m goto L2 return f2 L2: f2 <- f0 + f1 f1 <- f2 i <- i + 1 goto L1 L3: return m

6 Lecture 15©2003 Joel Jones6 Control Flow Graphs A control flow graph (CFG) is a rooted, directed graph The nodes of a CFG are basic blocks plus two distinguished nodes, the entry and exit nodes The edges of a CFG correspond to the flow of control from one basic block (BB) the the next Additionally, an edge is placed between the entry node and the first node of the procedure Also, edges are placed from each final BB (BBs with no successors) to the exit

7 Lecture 15©2003 Joel Jones7 Control Flow Graphs (cont.) Pair Up: Draw the Control Flow Graph receive m (val) f0 <- 0 f1 <- 1 if m <= 1 goto L3 i <- 2 L1: if i <= m goto L2 return f2 L2: f2 <- f0 + f1 f1 <- f2 i <- i + 1 goto L1 L3: return m

8 Lecture 15©2003 Joel Jones8 Code for Graphs, CFGs, and Graph Traversals See handouts

9 Lecture 15©2003 Joel Jones9 Definitions Dominance – a relation between nodes m dom n iff every path from the start node to n must include m Natural loop – a strongly connected component where there is an edge m  n where n dominates m

10 Lecture 15©2003 Joel Jones10 Definitions (cont.) Immediate Dominance – for a ≠ b, a idom b iff a dom b and there does not exist a node c such that c ≠ a and c ≠ b for which a dom c and c dom b Post domiance, p postdominates i, p pdom i if every possible path from i to exit includes p, i.e. i dom p in the flowgraph with edges reversed and exit and entry interchanged Strongly connected component (SCC) – a subgraph where every node is reachable from every other node

11 Lecture 15©2003 Joel Jones11 Examples of SCCs, Dominance Figure 7.27a, 7.28

12 Lecture 15©2003 Joel Jones12 Readings for Next Time Section 7.7 of Muchnick Sections 8–8.1 of the textbook


Download ppt "CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones."

Similar presentations


Ads by Google