Machine-Independent Optimizations Ⅳ CS308 Compiler Theory1.

Slides:



Advertisements
Similar presentations
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Advertisements

Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Jeffrey D. Ullman Stanford University. 2  A set of nodes N and edges E is a region if: 1.There is a header h in N that dominates all nodes in N. 2.If.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 More Control Flow John Cavazos University.
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
GRAPHS Lecture 18 CS2110 – Fall Graph Algorithms 2 Search –depth-first search –breadth-first search Shortest paths –Dijkstra's algorithm Minimum.
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
Breadth-First Search Seminar – Networking Algorithms CS and EE Dept. Lulea University of Technology 27 Jan Mohammad Reza Akhavan.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Jeffrey D. Ullman Stanford University Flow Graph Theory.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Lecture 2 Emery Berger University of.
Chapter 5 Trees PROPERTIES OF TREES 3 4.
Structures and Strategies for State Space Search
PSUCS322 HM 1 Languages and Compiler Design II Basic Blocks Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
ECE1724F Compiler Primer Sept. 18, 2002.
2015/6/24\course\cpeg421-10F\Topic1-b.ppt1 Topic 1b: Flow Analysis Some slides come from Prof. J. N. Amaral
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
1 Structures and Strategies for State Space Search 3 3.0Introduction 3.1Graph Theory 3.2Strategies for State Space Search 3.3Using the State Space to Represent.
Efficiency of Iterative Algorithms
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
1 Region-Based Data Flow Analysis. 2 Loops Loops in programs deserve special treatment Because programs spend most of their time executing loops, improving.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Can you connect the dots as shown without taking your pen off the page or drawing the same line twice.
Discussion #32 1/13 Discussion #32 Properties and Applications of Depth-First Search Trees.
Topological Sort (an application of DFS) CSC263 Tutorial 9.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
ENGM 732 Formalization of Network Flows Network Flow Models.
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Loops.
Announcements & Reading Material
CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Properties and Applications of Depth-First Search Trees and Forests
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
CS 3220: Compilation Techniques for Parallel Systems Spring Pitt CS
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture nine Dr. Hamdy M. Mousa.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Dominators and CFGs Taken largely from University of Delaware Compiler Notes.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Spanning Trees Alyce Brady CS 510: Computer Algorithms.
Loops Simone Campanoni
1 Traversal Algorithms  sequential polling algorithm  traversing connected networks (tree construction) complexity measures tree terminology tarry’s.
CS 201 Compiler Construction
EECS 583 – Class 2 Control Flow Analysis
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Topological Sort (an application of DFS)
CS223 Advanced Data Structures and Algorithms
CSC D70: Compiler Optimization Dataflow-2 and Loops
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
CS 201 Compiler Construction
Taken largely from University of Delaware Compiler Notes
Control Flow Analysis CS 4501 Baishakhi Ray.
Code Optimization Chapter 10
Code Optimization Chapter 9 (1st ed. Ch.10)
Optimizing Compilers CISC 673 Spring 2009 More Control Flow
Graphs Chapter 11 Objectives Upon completion you will be able to:
Topic 4: Flow Analysis Some slides come from Prof. J. N. Amaral
Search Exercise Search Tree? Solution (Breadth First Search)?
Control Flow Analysis (Chapter 7)
Topological Sort (an application of DFS)
EECS 583 – Class 2 Control Flow Analysis
Taken largely from University of Delaware Compiler Notes
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
CSC D70: Compiler Optimization Static Single Assignment (SSA)
Two – One Problem Legal Moves: Slide Rules: 1s’ move right Hop
Two – One Problem Legal Moves: Slide Rules: 1s’ move right Hop
Presentation transcript:

Machine-Independent Optimizations Ⅳ CS308 Compiler Theory1

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

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

Dominator Tree The entry node is the root Each node d dominates only its descendants in the tree. CS308 Compiler Theory4

Finding Dominators CS308 Compiler Theory5

Depth-First Ordering The route of the search in a depth-first search forms a depth-first spanning tree (DFST). CS308 Compiler Theory6

Depth-First Ordering CS308 Compiler Theory7

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

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

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

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

Finding Natural Loops CS308 Compiler Theory12

Finding Natural Loops CS308 Compiler Theory13

Test yourself Exercise CS308 Compiler Theory14