Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.

Slides:



Advertisements
Similar presentations
Compiler Construction
Advertisements

Simple Graph Warmup. Cycles in Simple Graphs A cycle in a simple graph is a sequence of vertices v 0, …, v n for some n>0, where v 0, ….v n-1 are distinct,
1 Induction Variables Region-Based Analysis Meet and Closure of Transfer Functions Affine Functions of Reference Variables.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Path Analysis Why path analysis for test case design?
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.
1 CS 201 Compiler Construction Machine Code Generation.
SSA.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Loop invariant code removal CS 480. Our sample calculation for i := 1 to n for j := 1 to m c [i, j] := 0 for k := 1 to p c[i, j] := c[i, j] + a[i, k]
Dominators and CFGs Taken largely from University of Delaware Compiler Notes \course\cpeg421-05s\Topic2.ppt.
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
1 Introduction to Data Flow Analysis. 2 Data Flow Analysis Construct representations for the structure of flow-of-data of programs based on the structure.
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
CMPUT Compiler Design and Optimization
More Dataflow Analysis CS153: Compilers Greg Morrisett.
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.
Lecture 23 Basic Blocks Topics Code Generation Readings: 9 April 17, 2006 CSCE 531 Compiler Construction.
Code Generation Professor Yihjia Tsai Tamkang University.
1 CS 201 Compiler Construction Lecture 1 Introduction.
Lecture 6 Program Flow Analysis Forrest Brewer Ryan Kastner Jose Amaral.
2015/6/24\course\cpeg421-10F\Topic1-b.ppt1 Topic 1b: Flow Analysis Some slides come from Prof. J. N. Amaral
1 Chapter 15 Introduction to Planning. 2 Chapter 15 Contents l Planning as Search l Situation Calculus l The Frame Problem l Means-Ends Analysis l The.
Lecture 25 Generating Code for Basic Blocks Topics Code Generation Readings: April 19, 2006 CSCE 531 Compiler Construction.
Projects. Dataflow analysis Dataflow analysis: what is it? A common framework for expressing algorithms that compute information about a program Why.
Data Flow Analysis Compiler Design Nov. 8, 2005.
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 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
1.2 Introduction to Graphing Equations. An equation in two variables, say x and y is a statement in which two expressions involving these variables are.
1 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph.
1 Chapter 15 Introduction to Planning. 2 Chapter 15 Contents l Planning as Search l Situation Calculus l The Frame Problem l Means-Ends Analysis l The.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Compilers Modern Compiler Design
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
Control Flow Analysis Compiler Baojian Hua
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
High-level optimization Jakub Yaghob
Integration Testing This is the step after the individual pieces of code or modules (programs) are tested. A set of programs do not exist in vacuum. They.
Dataflow analysis.
Data Flow Testing.
More Graph Algorithms.
Measuring Internal product attributes:Structure
Control Flow Analysis CS 4501 Baishakhi Ray.
Sequence Pair Representation
Network Flow 2016/04/12.
CS 201 Compiler Construction
TARGET CODE GENERATION
Topic 4: Flow Analysis Some slides come from Prof. J. N. Amaral
Different Levels of Testing
Solution to problem 4. a) Control flow graph art Start k = i + 2 * j
Graphs.
Control Flow Analysis (Chapter 7)
Interval Partitioning of a Flow Graph

Graphs By Rajanikanth B.
Program Flow.
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Taken largely from University of Delaware Compiler Notes
Analysis of engineering system by means of graph representation
Line Graphs.
Heaps Chapter 6 Section 6.9.
CS 201 Compiler Construction
Presentation transcript:

Control Flow Analysis

Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control within a procedure Call graphs represent the structure of flow- of-control between procedures

Control Flow Graphs Nodes in the graph are basic blocks A basic block is a sequence of consecutive statements in which control can only enter at the beginning and leave at the end There is an edge from a basic block b 1 to a basic block b 2 if control can flow from the end of b 1 to the beginning of b 2 ; we say b 1 is a predecessor of b 2 and b 2 is a successor of b 1

An Example (1)prod := 0 (2)i := 1 (3)t1 := 4 * i (4)t2 := a[t1] (5)t3 := 4 * i (6)t4 := b[t3] (7)t5 := t2 * t4 (8)t6 := prod + t5 (9)prod := t6 (10)t7 := i + 1 (11)i := t7 (12)if i <= 20 goto (3)

Construction of Basic Blocks Determine the set of leaders –the first statement is a leader –the target of a jump is a leader –any statement immediately following a jump is a leader For each leader, its basic block consists of the leader and all statements up to but not including the next leader or the end of the program

Representation of Basic Blocks Each basic block is represented by a record consisting of –a count of the number of statements –a pointer to the leader –a list of predecessors –a list of successors

An Example (1)prod := 0 (2)i := 1 (3)t1 := 4 * i (4)t2 := a[t1] (5)t3 := 4 * i (6)t4 := b[t3] (7)t5 := t2 * t4 (8)t6 := prod + t5 (9)prod := t6 (10)t7 := i + 1 (11)i := t7 (12)if i <= 20 goto (3)

Call Graphs Nodes in the graphs are procedures There is an edge from a procedure p 1 to a procedure p 2 if p 2 is called within p 1 ; we say p 1 is a predecessor of p 2 and p 2 is a successor of p 1

An Example procedure main( ) one( ) end procedure one( ) two( ) end procedure two( ) one( ) end main one two