Download presentation
Presentation is loading. Please wait.
Published byCameron Flowers Modified over 9 years ago
1
Machine-Independent Optimizations Ⅳ CS308 Compiler Theory1
2
Loops in Flow Graphs Loops are important because programs spend most of their time executing them Optimizations that improve the performance of loops can have a significant impact. CS308 Compiler Theory2
3
Dominators Say node d of a flow graph dominates node n, written d dom n, if every path from the entry node of the flow graph to n goes through d. Every node dominates itself. Which nodes are dominated by each node? CS308 Compiler Theory3
4
Dominator Tree The entry node is the root Each node d dominates only its descendants in the tree. CS308 Compiler Theory4
5
Finding Dominators CS308 Compiler Theory5
6
Depth-First Ordering The route of the search in a depth-first search forms a depth-first spanning tree (DFST). CS308 Compiler Theory6
7
Depth-First Ordering CS308 Compiler Theory7
8
Edges in a Depth-First Spanning Tree Advancing edges: going from a node m to a proper descendant of m in the tree Retreating edges: going from a node m to an ancestor of m in the tree (possibly to m itself). Cross edges: edges m n such that neither m nor n is an ancestor of the other in the DFST CS308 Compiler Theory8
9
Back Edges and Reducibility A back edge is an edge a b whose head b dominates its tail a. For any flow graph, every back edge is retreating, but not every retreating edge is a back edge. A flow graph is said to be reducible if all its retreating edges in any depth-first spanning tree are also back edges. CS308 Compiler Theory9
10
Depth of a Flow Graph Given a depth-first spanning tree for the graph, the depth is the largest number of retreating edges on any cycle-free path. CS308 Compiler Theory10 10 7 4 3 Depth=3
11
Natural Loops A natural loop is defined by two essential properties. 1. It must have a single-entry node, called the header. This entry node dominates all nodes in the loop, or it would not be the sole entry to the loop. 2. There must be a back edge that enters the loop header. Otherwise, it is not possible for the flow of control to return to the header directly from the "loop" ; i.e., there really is no loop. CS308 Compiler Theory11
12
Finding Natural Loops CS308 Compiler Theory12
13
Finding Natural Loops CS308 Compiler Theory13
14
Test yourself Exercise 9.6.1 CS308 Compiler Theory14
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.