Example (cont.): Control Flow Graph. 2. Interval analysis (recursive) 3. Structural analysis (recursive)
|
|
- Malcolm Lambert
- 5 years ago
- Views:
Transcription
1 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 1 C.Kessler,IDA,Linköpings Universitet, Control Flow Analysis [ASU1e 10.4] [ALSU2e 9.6] [Muchnick 7] necessary to enable global optimizations beyond basic blocks basis for data-flow analysis reconstruction of if-then-else, loops from MIR, from unstructured source code or from target code! loops: candidates for loop transformations, software pipelining! if-then-else: candidates for predication identify basic blocks of a routine construct its flow graph / basic block graph 1. Dominator-based analysis (iterative) 2. Interval analysis (recursive) 3. Structural analysis (recursive) DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 3 C.Kessler,IDA,Linköpings Universitet, Example (cont.): Control Flow Graph // MIR 1 receive m 1 receive m // read arg value 2 f0 = 0 3 f1 = 1 4 if m<=1 goto L3 5 i = 2 6 L1: if i<=m goto L2 8 L2: f2 = f0 + f1 9 f0 = f1 10 f1 = f2 11 i = i goto L1 13 L3: return f2 12 return m f0 = 0 f1 = 1 m <= 1? 5 6 i = 2 i <= m? f2 = f0+f1 f0 = f1 f1 = f2 i = i + 1 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 2 C.Kessler,IDA,Linköpings Universitet, Control Flow Analysis Running Example // Fibonacci - Iterative alg. unsigned int fib ( unsigned int m ) { unsigned int f0 = 0, f1 = 1, f2, i; if (m <= 1) return m; else { for (i=2; i<=m; i++) { f2 = f0 + f1; f0 = f1; f1 = f2; } return f2; } } // MIR, flattened 1 receive m // read arg value 2 f0 = 0 3 f1 = 1 4 if m<=1 goto L3 5 i = 2 6 L1: if i<=m goto L2 8 L2: f2 = f0 + f1 9 f0 = f1 10 f1 = f2 11 i = i goto L1 13 L3: return f2 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 4 C.Kessler,IDA,Linköpings Universitet, Detecting basic blocks basic block (BB) = max. sequence of consecutive statements (IR or target level) that can be entered by program control only via the first one and left only via the last one. first instruction ( leader ) of a BB: either + point of a procedure, or + branch target, or + instruction immediately following a branch or return! call instructions need not delimit the basic block (ok for most cases, but not for e.g. instruction scheduling)! exception-based control transfer not considered here
2 successor BB s of a BB b: Succ(b) = fn 2 : (b n) 2 Eg predecessor BB s of a BB b: Pred(b) = fn 2 : (n b) 2 Eg DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 5 C.Kessler,IDA,Linköpings Universitet, Basic-block graph erminology: in [Muchnick 97] called control-flow graph CFG, whereas our CFG (statement level) is there called a flowchart rooted, directed graph = G E) ( nodes = basic blocks + + edges = control flow edges from CFG/flowchart (there connecting BB s to the leaders of their successor BBs) + enter! initial basic block + final basic blocks (no succ.)! DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 7 C.Kessler,IDA,Linköpings Universitet, Example (cont.): CFG + Basic Blocks! Basic Block Graph 1 receive m 2 f0 = 0 12 return m 3 4 f1 = 1 m <= 1? 5 i = 2 6 i <= m? 8 f2 = f0+f1 9 f0 = f1 10 f1 = f2 11 i = i + 1 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 6 C.Kessler,IDA,Linköpings Universitet, Example (cont.): CFG! Basic Block Leaders 1 receive m 1 receive m 2 f0 = 0 2 f0 = 0 3 f1 = 1 3 f1 = 1 12 return m 4 m <= 1? 5 i = 2 12 return m 4 m <= 1? 5 i = 2 6 i <= m? 6 i <= m? 8 f2 = f0+f1 8 f2 = f0+f1 9 f0 = f1 9 f0 = f1 10 f1 = f2 10 f1 = f2 11 i = i i = i + 1 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 8 C.Kessler,IDA,Linköpings Universitet, Extended basic blocks, regions Extended basic block (EBB) = max. sequence of instructions beginning with a leader that contains no join nodes other than (maybe) its first node! single, multiple s, tree-like internal control flow! EBB also known as treegion EBB s are useful for some optimizations e.g. instruction scheduling Algorithm for computing the EBB s of a CFG: see e.g. [Muchnick 7.1] Region = strongly connected subgraph (SCC) of the CFG with a single
3 ! Find uniform treatment for program loops DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 9 C.Kessler,IDA,Linköpings Universitet, Example (cont.): Extended Basic Blocks DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 11 C.Kessler,IDA,Linköpings Universitet, Graph-theoretic concepts of control-flow analysis (1) depth-first search (dfs): recursively explore descendants of a node before any of its siblings (as far as not yet visited) dfs-number: order in which dfs enters nodes tree edges: edges followed by dfs via recursive calls dfs-tree: ( nodes, tree edges ) non-tree edges classified as forward edges F back edges B cross edges C not unique! depends on ordering of descendants see also DFS-slides on course homepage DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 10 C.Kessler,IDA,Linköpings Universitet, Finding Loops Programs spend most of the execution time in loops.! Optimizations that exploit the loop structure are important loop unrolling, loop parallelization, software pipelining,... Loops may be expressed in programs by different constructs (while, for, goto,..., compiler-converted tail-recursion) Use a general approach based on graph-theoretic properties of CFG. DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 12 C.Kessler,IDA,Linköpings Universitet, Example: DFS-tree, edge classification B C 3 4 F B 7 3 B C 5 C 7 B 8 5 4
4 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 13 C.Kessler,IDA,Linköpings Universitet, Graph-theoretic concepts of control-flow analysis (2) preorder traversal of a digraph G = ( E): at each node b 2 process b before its descendants (not unique; in dfsnum-order) postorder traversal at each node b 2 process b after its descendants DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 15 C.Kessler,IDA,Linköpings Universitet, Dominance intuition (1) Imagine a source of light going into the node, nodes are transparent and edges are optical fibers Lamp Place an opaque barrier at node v! nodes dominated by v get dark (Adapted from a nice presentation by J. Amaral 2003) DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 14 C.Kessler,IDA,Linköpings Universitet, Dominance, immediate dominance, strict dominance Given: flow graph G = ( E), nodes d i p b 2 d dominates b (d dom b) if every possible execution path! b includes d dom is reflexive, transitive, antisymmetric! partial order on i immediately dominates b (i idom b) if i dom b and there is no c 2, i 6= c 6= b, withi dom c and c dom b idom(b) is unique for each b 2! (i)dominator tree, rooted at strict dominance d sdom b if d dom b and d 6= b DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 16 C.Kessler,IDA,Linköpings Universitet, Dominance intuition (2) he node dominates all nodes: Lamp
5 Domin(r) frg; Domin(n) 8n 2 ;frg Domin(p) p2pred(n) DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 17 C.Kessler,IDA,Linköpings Universitet, Dominance intuition (3) ode dominates,,, : Lamp DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 19 C.Kessler,IDA,Linköpings Universitet, Postdominance p postdominates b (p pdom b) if every possible execution path b! includes p p pdom b () b dom p in the reversed flow graph DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 18 C.Kessler,IDA,Linköpings Universitet, Dominance intuition (4) ode only dominates itself: Lamp DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 20 C.Kessler,IDA,Linköpings Universitet, Computing the dominators of a node a dom b iff (1) a = b, or 9 (2) unique immediate predecessor of b, namely a, Pred(b) = i.e. fag, or (3) for all 2 Pred(b) c 6= c a and a dom c. Algorithm 1: change true; while ( change ) change false for all n 2 ;frg // in dfsnum order D fng[ if D 6= Domin(n) return Domin c1 c2 Domin(n) D; change true a... b
6 mp(n) Domin(n) ; fng mp(n) mp(n) ;ftg idom(n) the b 2mp(n) time O(elogn) or O(e α(e n)) DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 21 C.Kessler,IDA,Linköpings Universitet, Example: Computing dominators node i Domin(i), init. Domin(i), iter. 1 iter fg fg change=true... f,,,,,, g, g f, change=true... f,,,,,, g, f, g,... f,,,,,, g, f, g,... f,,,,,, g, f,, g,... f,,,,,, g, f,,,g,... f,,,,,, g, f,,,g,... f,,,,,, g, f, g,... DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 23 C.Kessler,IDA,Linköpings Universitet, Example: Computing immediate dominators node i init. mp(i)=domin(i) fig mp(i), iter. 1 fg fg fg fg f, g fg f, g fg f,, g fg f,,, g fg f,,, g fg f, g fg Dominator tree: DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 22 C.Kessler,IDA,Linköpings Universitet, Extension for computing immediate dominators... compute Domin... for each n 2 for each n 2 ;frg // in dfsnum order // if a s in mp(n) has a dominator t 6= s, removet from mp(n) for each s 2 mp(n) for each 2 mp(n) ;fsg t if 2 mp(s) t then for each n 2 ;frg // in dfsnum order otal time: O(n 2 e) if sets are represented by bitvectors DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 24 C.Kessler,IDA,Linköpings Universitet, Computing dominators Algorithm 2 [Lengauer/arjan 79] based on depth first search and path compression (see e.g. [Muchnick pp ])
7 Algorithm: Compute the loop node set for a given loop back edge (m n)! Easier to place new instructions immediately before the loop DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 25 C.Kessler,IDA,Linköpings Universitet, Loops and Strongly Connected Components We call a (backward, B) edge (m n) a loop back edge if n dom m. Remark: ot every B edge is a loop back edge! atural loop of a loop back (m n) edge = subgraph of n and all nodes v from which m can be reached without passing through n n is the loop header. n B v m a w a b b C c v B c d B d e e F c does not dominate d ) not a natural loop (2 points) DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 27 C.Kessler,IDA,Linköpings Universitet, Identifying the natural loop of a loop back edge Start by marking m and n as loop nodes. Backwards from m, (df)search predecessors v, stopping recursive backward search at already found loop nodes. w n? Can t exist because n dom m B v v m DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 26 C.Kessler,IDA,Linköpings Universitet, Example (cont.): atural Loop n m DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 28 C.Kessler,IDA,Linköpings Universitet, Loop header, preheader For technical reasons, add a pre-header (initially empty) if the header has more than 2 predecessors: header pre header B header B
8 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 29 C.Kessler,IDA,Linköpings Universitet, Properties of atural Loops wo natural loops with different headers are either disjoint or one is nested in the other. Each natural loop is a SCC. Background: Strongly connected component (SCC) = subgraph S = (S E S), S, ES E, where every node in VS is reachable in S from every other node in VS via edges in ES. SCC s can be computed with arjan s algorithm (extension of dfs) in time O(jV j + jej) [arjan 72] Several loops sharing a common header node is a pathological special case that must be treated ad hoc. See e.g. Muchnick 7.4 for more details. DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 31 C.Kessler,IDA,Linköpings Universitet, Reducibility of flow graphs A flow-graph is reducible if all B edges in any DFS tree are loop back edges. Intuitively:... if there are no jumps into the middles of loops (e.g., goto s). b b c d e f c d c e f Reducible flow graphs are well-structured (loops properly nested). Irreducible flow graphs are rare and can be made reducible by replicating nodes. DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 30 C.Kessler,IDA,Linköpings Universitet, Properties of atural Loops (cont.) ASCCS V is maximal if every SCC containing S is just S itself. Example: S1 = f g is a maximal SCC. S2 = fg is a SCC but not a maximal SCC. DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 32 C.Kessler,IDA,Linköpings Universitet, Interval analysis Divide flowgraph into regions (e.g., loops in CFA) Repeatedly collapse a region to an abstract node! abstract flowgraph nested regions (control tree)! Hierarchical folding structure allows for faster / simpler data flow analysis Simplest variant: 1-2 Analysis [Ullman 73] 1: a 2: a ry to fold entire flow graph into a single node Works only for very restricted flow graphs
9 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 33 C.Kessler,IDA,Linköpings Universitet, Analysis Example 1: a 2: a Example: a a 2: 1: 2: b b a b a b a 1-2 control tree DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 35 C.Kessler,IDA,Linköpings Universitet, Structural analysis Some regions and transformations self loop: a a if then: Bn a if then else: a a... stmt block: while loop: DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 34 C.Kessler,IDA,Linköpings Universitet, Structural Analysis is a special case of interval analysis: CFG folding follows the hierarchical structure of the program! folding transformations for loops, if-then-else, switch, etc. Every region has 1 point Works only for well-structured programs Extensions to handle arbitrary flowgraphs (define a new region / transf. for otherwise irreducible constructs) + Equations etc. for dataflow analysis can be pre-formulated for each construct! faster DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 36 C.Kessler,IDA,Linköpings Universitet, Example (cont.): Structural analysis procedure R9 R9 R8 R7 n m R8 R7 Region Hierarchy ree Remark: If only loop-based regions are of interest, the hierarchy flattens accordingly (R8 and R9 merged with top level).
10 DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 37 C.Kessler,IDA,Linköpings Universitet, Computing a bottom-up order of regions of a reducible flow graph Input: A reducible flow graph G Output: A bottom-up ordered list R of loop-based regions of G 1. R f :::g = all leaf regions, i.e., all single blocks in G, in any order 2. repeat Choose a natural loop L such that, if there are any natural loops L 0 contained within L, then the (body and loop) regions for these L 0 were already added to R. R.add( the region consisting of the body of L ) // body of L = L without the back edges to the header of L R.add ( the loop region for L ) until all natural loops have been considered 3. If the entire flow graph is not itself a natural loop, R.add( the region consisting of the entire flow graph ). DDC86 Compiler Optimizations and Code Generation Control Flow Analysis. Page 38 C.Kessler,IDA,Linköpings Universitet, Summary: Control-Flow Analysis Basic blocks, extended basic blocks Loop detection Dominator-based CFA Interval-based CFA Structural analysis
Challenges in the back end. CS Compiler Design. Basic blocks. Compiler analysis
Challenges in the back end CS3300 - Compiler Design Basic Blocks and CFG V. Krishna Nandivada IIT Madras The input to the backend (What?). The target program instruction set, constraints, relocatable or
More informationControl-Flow Analysis
Control-Flow Analysis Dragon book [Ch. 8, Section 8.4; Ch. 9, Section 9.6] Compilers: Principles, Techniques, and Tools, 2 nd ed. by Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jerey D. Ullman on reserve
More informationStatements or Basic Blocks (Maximal sequence of code with branching only allowed at end) Possible transfer of control
Control Flow Graphs Nodes Edges Statements or asic locks (Maximal sequence of code with branching only allowed at end) Possible transfer of control Example: if P then S1 else S2 S3 S1 P S3 S2 CFG P predecessor
More informationModule 14: Approaches to Control Flow Analysis Lecture 27: Algorithm and Interval. The Lecture Contains: Algorithm to Find Dominators.
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
More informationCONTROL FLOW ANALYSIS. The slides adapted from Vikram Adve
CONTROL FLOW ANALYSIS The slides adapted from Vikram Adve Flow Graphs Flow Graph: A triple G=(N,A,s), where (N,A) is a (finite) directed graph, s N is a designated initial node, and there is a path from
More informationControl Flow Analysis
COMP 6 Program Analysis and Transformations These slides have been adapted from http://cs.gmu.edu/~white/cs60/slides/cs60--0.ppt by Professor Liz White. How to represent the structure of the program? Based
More informationAn Overview of GCC Architecture (source: wikipedia) Control-Flow Analysis and Loop Detection
An Overview of GCC Architecture (source: wikipedia) CS553 Lecture Control-Flow, Dominators, Loop Detection, and SSA Control-Flow Analysis and Loop Detection Last time Lattice-theoretic framework for data-flow
More informationGoals of Program Optimization (1 of 2)
Goals of Program Optimization (1 of 2) Goal: Improve program performance within some constraints Ask Three Key Questions for Every Optimization 1. Is it legal? 2. Is it profitable? 3. Is it compile-time
More informationIntermediate Representations. Reading & Topics. Intermediate Representations CS2210
Intermediate Representations CS2210 Lecture 11 Reading & Topics Muchnick: chapter 6 Topics today: Intermediate representations Automatic code generation with pattern matching Optimization Overview Control
More informationControl Flow Analysis. Reading & Topics. Optimization Overview CS2210. Muchnick: chapter 7
Control Flow Analysis CS2210 Lecture 11 Reading & Topics Muchnick: chapter 7 Optimization Overview Control Flow Analysis Maybe start data flow analysis Optimization Overview Two step process Analyze program
More informationIntermediate representation
Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing HIR semantic analysis HIR intermediate code gen.
More informationCompiler Structure. Data Flow Analysis. Control-Flow Graph. Available Expressions. Data Flow Facts
Compiler Structure Source Code Abstract Syntax Tree Control Flow Graph Object Code CMSC 631 Program Analysis and Understanding Fall 2003 Data Flow Analysis Source code parsed to produce AST AST transformed
More informationControl Flow Analysis
Control Flow Analysis Last time Undergraduate compilers in a day Today Assignment 0 due Control-flow analysis Building basic blocks Building control-flow graphs Loops January 28, 2015 Control Flow Analysis
More informationLecture 2: Control Flow Analysis
COM S/CPRE 513 x: Foundations and Applications of Program Analysis Spring 2018 Instructor: Wei Le Lecture 2: Control Flow Analysis 2.1 What is Control Flow Analysis Given program source code, control flow
More informationReview; questions Basic Analyses (2) Assign (see Schedule for links)
Class 2 Review; questions Basic Analyses (2) Assign (see Schedule for links) Representation and Analysis of Software (Sections -5) Additional reading: depth-first presentation, data-flow analysis, etc.
More informationProgram Analysis. Readings
Program Analysis Class #2 Readings he Program Dependence Graph and Its Use in Optimization Program slicing A Survey of Program Slicing echniques Dragon book Program Analysis Data-low Analysis (wrap up)
More informationLecture 8: Induction Variable Optimizations
Lecture 8: Induction Variable Optimizations I. Finding loops II. III. Overview of Induction Variable Optimizations Further details ALSU 9.1.8, 9.6, 9.8.1 Phillip B. Gibbons 15-745: Induction Variables
More informationCompiler Construction 2016/2017 Loop Optimizations
Compiler Construction 2016/2017 Loop Optimizations Peter Thiemann January 16, 2017 Outline 1 Loops 2 Dominators 3 Loop-Invariant Computations 4 Induction Variables 5 Array-Bounds Checks 6 Loop Unrolling
More informationA Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013
A Bad Name Optimization is the process by which we turn a program into a better one, for some definition of better. CS 2210: Optimization This is impossible in the general case. For instance, a fully optimizing
More informationData Flow Analysis. Agenda CS738: Advanced Compiler Optimizations. 3-address Code Format. Assumptions
Agenda CS738: Advanced Compiler Optimizations Data Flow Analysis Amey Karkare karkare@cse.iitk.ac.in http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur Static analysis and compile-time
More informationEECS 583 Class 2 Control Flow Analysis LLVM Introduction
EECS 583 Class 2 Control Flow Analysis LLVM Introduction University of Michigan September 8, 2014 - 1 - Announcements & Reading Material HW 1 out today, due Friday, Sept 22 (2 wks)» This homework is not
More informationControl Flow Analysis & Def-Use. Hwansoo Han
Control Flow Analysis & Def-Use Hwansoo Han Control Flow Graph What is CFG? Represents program structure for internal use of compilers Used in various program analyses Generated from AST or a sequential
More informationLecture 4. More on Data Flow: Constant Propagation, Speed, Loops
Lecture 4 More on Data Flow: Constant Propagation, Speed, Loops I. Constant Propagation II. Efficiency of Data Flow Analysis III. Algorithm to find loops Reading: Chapter 9.4, 9.6 CS243: Constants, Speed,
More informationECE 5775 High-Level Digital Design Automation Fall More CFG Static Single Assignment
ECE 5775 High-Level Digital Design Automation Fall 2018 More CFG Static Single Assignment Announcements HW 1 due next Monday (9/17) Lab 2 will be released tonight (due 9/24) Instructor OH cancelled this
More informationControl flow and loop detection. TDT4205 Lecture 29
1 Control flow and loop detection TDT4205 Lecture 29 2 Where we are We have a handful of different analysis instances None of them are optimizations, in and of themselves The objective now is to Show how
More informationCompiler Construction 2010/2011 Loop Optimizations
Compiler Construction 2010/2011 Loop Optimizations Peter Thiemann January 25, 2011 Outline 1 Loop Optimizations 2 Dominators 3 Loop-Invariant Computations 4 Induction Variables 5 Array-Bounds Checks 6
More informationTopic I (d): Static Single Assignment Form (SSA)
Topic I (d): Static Single Assignment Form (SSA) 621-10F/Topic-1d-SSA 1 Reading List Slides: Topic Ix Other readings as assigned in class 621-10F/Topic-1d-SSA 2 ABET Outcome Ability to apply knowledge
More informationContents of Lecture 2
Contents of Lecture Dominance relation An inefficient and simple algorithm to compute dominance Immediate dominators Dominator tree Jonas Skeppstedt (js@cs.lth.se) Lecture / Definition of Dominance Consider
More informationCS 432 Fall Mike Lam, Professor. Data-Flow Analysis
CS 432 Fall 2018 Mike Lam, Professor Data-Flow Analysis Compilers "Back end" Source code Tokens Syntax tree Machine code char data[20]; int main() { float x = 42.0; return 7; } 7f 45 4c 46 01 01 01 00
More informationControl Flow Graphs. (From Matthew S. Hetch. Flow Analysis of Computer Programs. North Holland ).
Control Flow Graphs (From Matthew S. Hetch. Flow Analysis of Computer Programs. North Holland. 1977. ). 38 Control Flow Graphs We will now discuss flow graphs. These are used for global optimizations (as
More informationGraph Algorithms Using Depth First Search
Graph Algorithms Using Depth First Search Analysis of Algorithms Week 8, Lecture 1 Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Graph Algorithms Using Depth
More informationIntroduction to Machine-Independent Optimizations - 4
Introduction to Machine-Independent Optimizations - 4 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of
More informationOptimizations. Optimization Safety. Optimization Safety CS412/CS413. Introduction to Compilers Tim Teitelbaum
Optimizations CS412/CS413 Introduction to Compilers im eitelbaum Lecture 24: s 24 Mar 08 Code transformations to improve program Mainly: improve execution time Also: reduce program size Can be done at
More informationGraphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes
Graphs Graphs A graph is a data structure consisting of nodes (or vertices) and edges An edge is a connection between two nodes A D B E C Nodes: A, B, C, D, E Edges: (A, B), (A, D), (D, E), (E, C) Nodes
More informationCompiler Optimisation
Compiler Optimisation 4 Dataflow Analysis Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Introduction This lecture:
More informationCS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers
CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers These notes are not yet complete. 1 Interprocedural analysis Some analyses are not sufficiently
More informationEECS 583 Class 3 More on loops, Region Formation
EECS 583 Class 3 More on loops, Region Formation University of Michigan September 19, 2016 Announcements & Reading Material HW1 is out Get busy on it!» Course servers are ready to go Today s class» Trace
More informationAlgorithms for Finding Dominators in Directed Graphs
Department of Computer Science Aarhus University Master s Thesis Algorithms for Finding Dominators in Directed Graphs Author: Henrik Knakkegaard Christensen 20082178 Supervisor: Gerth Støling Brodal January
More informationCompiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz
Compiler Design Fall 2015 Control-Flow Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292
More informationInstruction Scheduling Beyond Basic Blocks Extended Basic Blocks, Superblock Cloning, & Traces, with a quick introduction to Dominators.
Instruction Scheduling Beyond Basic Blocks Extended Basic Blocks, Superblock Cloning, & Traces, with a quick introduction to Dominators Comp 412 COMP 412 FALL 2016 source code IR Front End Optimizer Back
More informationCompiler Construction 2009/2010 SSA Static Single Assignment Form
Compiler Construction 2009/2010 SSA Static Single Assignment Form Peter Thiemann March 15, 2010 Outline 1 Static Single-Assignment Form 2 Converting to SSA Form 3 Optimization Algorithms Using SSA 4 Dependencies
More informationData Structures and Algorithms in Compiler Optimization. Comp314 Lecture Dave Peixotto
Data Structures and Algorithms in Compiler Optimization Comp314 Lecture Dave Peixotto 1 What is a compiler Compilers translate between program representations Interpreters evaluate their input to produce
More informationTopic 9: Control Flow
Topic 9: Control Flow COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 The Front End The Back End (Intel-HP codename for Itanium ; uses compiler to identify parallelism)
More informationLecture 9: Loop Invariant Computation and Code Motion
Lecture 9: Loop Invariant Computation and Code Motion I. Loop-invariant computation II. III. Algorithm for code motion Partial redundancy elimination ALSU 9.5-9.5.2 Phillip B. Gibbons 15-745: Loop Invariance
More informationAlgorithms: Lecture 10. Chalmers University of Technology
Algorithms: Lecture 10 Chalmers University of Technology Today s Topics Basic Definitions Path, Cycle, Tree, Connectivity, etc. Graph Traversal Depth First Search Breadth First Search Testing Bipartatiness
More informationCFG (Control flow graph)
CFG (Control flow graph) Class B T12 오지은 200814189 신승우 201011340 이종선 200811448 Introduction to CFG Algorithm to construct Control Flow Graph Statement of Purpose Q & A Introduction to CFG Algorithm to
More informationIntermediate Representation (IR)
Intermediate Representation (IR) Components and Design Goals for an IR IR encodes all knowledge the compiler has derived about source program. Simple compiler structure source code More typical compiler
More informationSuccessor/Predecessor Rules in Binary Trees
Successor/Predecessor Rules in inary Trees Thomas. nastasio July 7, 2003 Introduction inary tree traversals are commonly made in one of three patterns, inorder, preorder, and postorder. These traversals
More informationLecture 3 Local Optimizations, Intro to SSA
Lecture 3 Local Optimizations, Intro to SSA I. Basic blocks & Flow graphs II. Abstraction 1: DAG III. Abstraction 2: Value numbering IV. Intro to SSA ALSU 8.4-8.5, 6.2.4 Phillip B. Gibbons 15-745: Local
More informationControl flow graphs and loop optimizations. Thursday, October 24, 13
Control flow graphs and loop optimizations Agenda Building control flow graphs Low level loop optimizations Code motion Strength reduction Unrolling High level loop optimizations Loop fusion Loop interchange
More informationTrees. CSE 373 Data Structures
Trees CSE 373 Data Structures Readings Reading Chapter 7 Trees 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical relationships File directories
More informationCS301 - Data Structures Glossary By
CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm
More informationCSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s
CSCE 750, Fall 2002 Notes 6 Page 1 10 Graph Algorithms (These notes follow the development in Cormen, Leiserson, and Rivest.) 10.1 Definitions ffl graph, directed graph (digraph), nodes, edges, subgraph
More informationTREES. Trees - Introduction
TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)
More informationLecture 23 CIS 341: COMPILERS
Lecture 23 CIS 341: COMPILERS Announcements HW6: Analysis & Optimizations Alias analysis, constant propagation, dead code elimination, register allocation Due: Wednesday, April 25 th Zdancewic CIS 341:
More informationfast code (preserve flow of data)
Instruction scheduling: The engineer s view The problem Given a code fragment for some target machine and the latencies for each individual instruction, reorder the instructions to minimize execution time
More informationTrees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.
Trees Q: Why study trees? : Many advance DTs are implemented using tree-based data structures. Recursive Definition of (Rooted) Tree: Let T be a set with n 0 elements. (i) If n = 0, T is an empty tree,
More informationCSE P 501 Compilers. SSA Hal Perkins Spring UW CSE P 501 Spring 2018 V-1
CSE P 0 Compilers SSA Hal Perkins Spring 0 UW CSE P 0 Spring 0 V- Agenda Overview of SSA IR Constructing SSA graphs Sample of SSA-based optimizations Converting back from SSA form Sources: Appel ch., also
More informationLoops! while a.runs() loop { while b.runs() loop c.foo() pool; b.reset(); } pool
Loops Loops! while a.runs() loop { while b.runs() loop c.foo() pool; b.reset(); } pool Not a Loop! if a.iseven() then { Even: b.foo(); goto Odd; } else { Odd: b.bar(); goto Even; } Optimizing Loops Most
More informationDDS Dynamic Search Trees
DDS Dynamic Search Trees 1 Data structures l A data structure models some abstract object. It implements a number of operations on this object, which usually can be classified into l creation and deletion
More informationTrees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology
Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path
More informationMiddle End. Code Improvement (or Optimization) Analyzes IR and rewrites (or transforms) IR Primary goal is to reduce running time of the compiled code
Traditional Three-pass Compiler Source Code Front End IR Middle End IR Back End Machine code Errors Code Improvement (or Optimization) Analyzes IR and rewrites (or transforms) IR Primary goal is to reduce
More informationData Structure - Binary Tree 1 -
Data Structure - Binary Tree 1 - Hanyang University Jong-Il Park Basic Tree Concepts Logical structures Chap. 2~4 Chap. 5 Chap. 6 Linear list Tree Graph Linear structures Non-linear structures Linear Lists
More informationCS577 Modern Language Processors. Spring 2018 Lecture Optimization
CS577 Modern Language Processors Spring 2018 Lecture Optimization 1 GENERATING BETTER CODE What does a conventional compiler do to improve quality of generated code? Eliminate redundant computation Move
More informationCSE P 501 Compilers. Loops Hal Perkins Spring UW CSE P 501 Spring 2018 U-1
CSE P 501 Compilers Loops Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 U-1 Agenda Loop optimizations Dominators discovering loops Loop invariant calculations Loop transformations A quick look at some
More informationData Flow Analysis. Daqing Hou
Data Flow Analysis Daqing Hou Outline Basic blocks and control flow graph An example: reaching definitions Characteristics of DFA (Data Flow Analysis) Daqing Hou, Spring 2008 2 Example 100 unsigned int
More informationCSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion Prof. Gennady Pekhimenko University of Toronto Winter 2018 The content of this lecture is adapted from the lectures of Todd Mowry and Phillip
More informationUNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,
More informationClass 6. Review; questions Assign (see Schedule for links) Slicing overview (cont d) Problem Set 3: due 9/8/09. Program Slicing
Class 6 Review; questions Assign (see Schedule for links) Slicing overview (cont d) Problem Set 3: due 9/8/09 1 Program Slicing 2 1 Program Slicing 1. Slicing overview 2. Types of slices, levels of slices
More informationData Flow Analysis and Computation of SSA
Compiler Design 1 Data Flow Analysis and Computation of SSA Compiler Design 2 Definitions A basic block is the longest sequence of three-address codes with the following properties. The control flows to
More informationV Advanced Data Structures
V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,
More informationA main goal is to achieve a better performance. Code Optimization. Chapter 9
1 A main goal is to achieve a better performance Code Optimization Chapter 9 2 A main goal is to achieve a better performance source Code Front End Intermediate Code Code Gen target Code user Machineindependent
More informationLecture 6 Foundations of Data Flow Analysis
Lecture 6 Foundations of Data Flow Analysis I. Meet operator II. Transfer functions III. Correctness, Precision, Convergence IV. Efficiency ALSU 9.3 Phillip B. Gibbons 15-745: Foundations of Data Flow
More informationSSA Construction. Daniel Grund & Sebastian Hack. CC Winter Term 09/10. Saarland University
SSA Construction Daniel Grund & Sebastian Hack Saarland University CC Winter Term 09/10 Outline Overview Intermediate Representations Why? How? IR Concepts Static Single Assignment Form Introduction Theory
More informationData Structure. IBPS SO (IT- Officer) Exam 2017
Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data
More informationProgram Representations. Xiangyu Zhang
Program Representations Xiangyu Zhang Why Program Representations Initial representations Source code (across languages). Binaries (across machines and platforms). Source code / binaries + test cases.
More informationLecture Notes on Decompilation
Lecture Notes on Decompilation 15411: Compiler Design Maxime Serrano Lecture 20 October 31, 2013 1 Introduction In this lecture, we consider the problem of doing compilation backwards - that is, transforming
More informationCSE 230 Intermediate Programming in C and C++ Binary Tree
CSE 230 Intermediate Programming in C and C++ Binary Tree Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu Introduction to Tree Tree is a non-linear data structure
More informationTree Structures. A hierarchical data structure whose point of entry is the root node
Binary Trees 1 Tree Structures A tree is A hierarchical data structure whose point of entry is the root node This structure can be partitioned into disjoint subsets These subsets are themselves trees and
More informationFlow Graph Theory. Depth-First Ordering Efficiency of Iterative Algorithms Reducible Flow Graphs
Flow Graph Theory Depth-First Ordering Efficiency of Iterative Algorithms Reducible Flow Graphs 1 Roadmap Proper ordering of nodes of a flow graph speeds up the iterative algorithms: depth-first ordering.
More informationLecture Notes on Loop Optimizations
Lecture Notes on Loop Optimizations 15-411: Compiler Design Frank Pfenning Lecture 17 October 22, 2013 1 Introduction Optimizing loops is particularly important in compilation, since loops (and in particular
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationV Advanced Data Structures
V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,
More informationDataflow Analysis. Xiaokang Qiu Purdue University. October 17, 2018 ECE 468
Dataflow Analysis Xiaokang Qiu Purdue University ECE 468 October 17, 2018 Program optimizations So far we have talked about different kinds of optimizations Peephole optimizations Local common sub-expression
More informationAlgorithms and Data Structures
Algorithms and Data Structures Graphs 3: Finding Connected Components Marius Kloft Content of this Lecture Finding Connected Components in Undirected Graphs Finding Strongly Connected Components in Directed
More informationA PDG-Based Tool and Its Use in Analyzing Program Control Dependences *
Published in the proceedings of: International Conference on Parallel Architectures and Compilation echniques (PAC) Montreal, Canada, August 23-26, 1994, 157-168 A PDG-Based ool and Its Use in Analyzing
More informationDecompilation of Binary Programs & Structuring Decompiled Graphs
Decompilation of Binary Programs & Structuring Decompiled Graphs Ximing Yu May 3, 2011 1 Introduction A decompiler, or reverse compiler, is a program that attempts to perform the inverse process of the
More informationGraph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1
Graph Algorithms Chapter 22 CPTR 430 Algorithms Graph Algorithms Why Study Graph Algorithms? Mathematical graphs seem to be relatively specialized and abstract Why spend so much time and effort on algorithms
More informationCompiler Optimisation
Compiler Optimisation 3 Dataflow Analysis Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Introduction Optimisations
More informationLecture Compiler Backend
Lecture 19-23 Compiler Backend Jianwen Zhu Electrical and Computer Engineering University of Toronto Jianwen Zhu 2009 - P. 1 Backend Tasks Instruction selection Map virtual instructions To machine instructions
More informationGlobal Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization
Lecture Outline Global Optimization Global flow analysis Global constant propagation Liveness analysis Compiler Design I (2011) 2 Local Optimization Recall the simple basic-block optimizations Constant
More informationAlgorithms and Data Structures
Algorithms and Data Structures Strongly Connected Components Ulf Leser Content of this Lecture Graph Traversals Strongly Connected Components Ulf Leser: Algorithms and Data Structures, Summer Semester
More informationGarbage Collection: recycling unused memory
Outline backtracking garbage collection trees binary search trees tree traversal binary search tree algorithms: add, remove, traverse binary node class 1 Backtracking finding a path through a maze is an
More informationDirected Graphs (II) Hwansoo Han
Directed Graphs (II) Hwansoo Han Traversals of Directed Graphs To solve many problems dealing with digraphs, we need to visit vertexes and arcs in a systematic way Depth-first search (DFS) A generalization
More informationCompiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler
Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis Synthesis of output program (back-end) Intermediate Code Generation Optimization Before and after generating machine
More informationELEC 876: Software Reengineering
ELEC 876: Software Reengineering () Dr. Ying Zou Department of Electrical & Computer Engineering Queen s University Compiler and Interpreter Compiler Source Code Object Compile Execute Code Results data
More informationGraph Algorithms: Chapters Part 1: Introductory graph concepts
UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum
More informationSSI Properties Revisited
SSI Properties Revisited 21 BENOIT BOISSINOT, ENS-Lyon PHILIP BRISK, University of California, Riverside ALAIN DARTE, CNRS FABRICE RASTELLO, Inria The static single information (SSI) form is an extension
More informationCompiler Optimization Techniques
Compiler Optimization Techniques Department of Computer Science, Faculty of ICT February 5, 2014 Introduction Code optimisations usually involve the replacement (transformation) of code from one sequence
More informationCompilers. Optimization. Yannis Smaragdakis, U. Athens
Compilers Optimization Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) What we already saw Lowering From language-level l l constructs t to machine-level l constructs t At this point
More information