We can express this in dataflow equations using gen and kill sets, where the sets are now sets of expressions.
|
|
- Irma Watson
- 6 years ago
- Views:
Transcription
1 Available expressions Suppose we want to do common-subexpression elimination; that is, given a program that computes x y more than once, can we eliminate one of the duplicate computations? To find places where such optimizations are possible, the notion of available expressions is helpful. An expression x y is available at a node n in the flow graph if, on every path from the entry node of the graph to node n, x y is computed at least once and there are no definitions of x or y since the most recent occurrence of x y on that path. We can express this in dataflow equations using gen and kill sets, where the sets are now sets of expressions. Gen : Any node that computes x y generates {x y}. Kill : any definition of x or y kills {x y}. Table 8 summarizes the generate and kill effects. 1. t b + c generates the expression b + c, but b b + c does not generate b + c After b + c there is a subsequent definition of b. gen[s] = {b c} kill[s] 2. A store instruction (M[a] b) might modify any memory location, so it kills any fetch expression (M[x]). If we were sure that a x, we could be less conservative, and say that M[a] b does not kill M[x]. This is called alias analysis; Given gen and kill, we compute in and out almost as for reaching definitions, except that we compute the intersection of the out sets of the predecessors instead of a union. This reflects the fact that an expression is available only if it is computed on every path into the node. 14
2 Statement s gen[s] kill[s] t b c {b c} kill[s] expressions containing t t M[b] {M[b]} kill[s] expressions containing t M[a] b {} expressions of the form M[x] if a > b goto L 1 else goto L 2 {} {} goto L {} {} L : {} {} f(a 1,..., a n ) {} expressions of the form M[x] t f(a 1,..., a n ) {} expressions containing t, and expressions of the form M[x] Figure 8: Table: Gen and kill for available expressions. in[n] = out[p] p pred[n] out[n] = gen[n] (in[n] kill[n]) if n is not the start node To solve the dataflow equations by iteration, 1. we define the in set of the start node as empty, and 2. initialize all other sets to full (the set of all expressions), not empty. The intersection operator makes sets smaller, not bigger as the union operator does in the computation of reaching definitions. This algorithm then finds the greatest fixed point of the equations. in[ start node ] { } for each n other than the start node in[n] { all expressions }; out[n] { all expressions } repeat for each n in [n] in[n]; out [n] out[n] in[n] p pred[n] out[p] out[n] gen[n] (in[n] kill[n]) until in [n] = in[n] and out [n] = out[n] for all n 15
3 1 : x a + b 2 : if c > d goto L 1 3 : a p 4 : y a + b 5 : goto L 2 6 : L 1 : if e < f goto L 1 7 : L 2 : z a + b 1 : t a + b 1 : x t 2 : if c > d goto L 1 3 : a p 4 : t a + b 4 : y t 5 : goto L 2 6 : L 1 : if e < f goto L 1 7 : L 2 : z t Figure 9: Program We will take Program 9 as an example; Init Iter. 1 Iter. 2 n gen[n] kill[n] in[n] out[n] in[n] out[n] in[n] out[n] 1 a+b a+b a+b a+b 2 a+b a+b a+b a+b a+b a+b 3 a+b a+b a+b a+b a+b 4 a+b a+b a+b a+b a+b 5 a+b a+b a+b a+b a+b a+b 6 a+b a+b a+b a+b a+b a+b 7 a+b a+b a+b a+b a+b a+b a+b As a result, we can eliminate a + b at statement 7 by replacing it with temporary t introduced for statements 1 and 4. 16
4 Statement s gen[s] kill[s] t b c {b, c} {t} t M[b] {b} {t} M[a] b {a, b} {} if a > b goto L 1 else goto L 2 {a, b} {} goto L {} {} L : {} {} f(a 1,..., a n ) {a 1,..., a n } {} t f(a 1,..., a n ) {a 1,..., a n } {t} Liveness analysis Figure 10: Table: Gen and kill for liveness analysis. Two temporaries a and b can fit into the same register, if a and b are never in use at the same time. We say a variable is live if it holds a value that may be needed in the future. this analysis is called liveness analysis. Defs and uses of variable x Defs : assignments to variable/temporary x. Uses : assignments with occurrences of variable x on the right-hand sides of the assignments. A variable is live on an edge if there is a directed path from that edge to a use of the variable that does not go through any def. Gen and kill are defined as shown by Figure 10. Gen : any use of a variable generates liveness. Kill : any definition kills liveness. The equations for in and out are similar to the ones for reaching definition, but backward because liveness is a backward dataflow analysis: in[n] = gen[n] (out[n] kill[n]) out[n] = in[s] s succ[n] 17
5 To solve the dataflow equations by iteration, for each n in[n] { }; out[n] { } repeat for each n in [n] in[n]; out [n] out[n] out[n] s succ[n] in[s] in[n] gen[n] (out[n] kill[n]) until in [n] = in[n] and out [n] = out[n] for all n We will take Program 7 as an example. Iter. 1 Iter. 2 Iter. 3 n gen[n] kill[n] in[n] out[n] in[n] out[n] in[n] out[n] 1 a a a a 2 c a c,a a c,a a c,a 3 c,a c,a c,a c,a c,a c,a c,a 4 c c c c,a c,a c,a c,a 5 c,a c,a c,a c,a 6 c,a a c,a c,a c,a 7 c As a result, we can remove statements 6 and 7, because their results are never used. 18
6 2.4 Transformations using dataflow analysis Using the results of dataflow analysis, the optimizing compiler can improve the program in several ways. Common-subexpression elimination Given a flow-graph statement s : t x y, where the expression x y is available at s, the computation within s can be eliminated. Elimination steps of s: 1. Choose a new temporary w, and rewrite n with the same expression as s as follows: n : w x y n : v w 2. Finally, modify statement s to be s : t w We will rely on copy propagation to remove some or all of the extra assignment quadruples. Constant propagation Suppose that 1. we have a statement d : t c where c is a constant, and 2. another statement n that uses t, such as n : y t x. We know that t is constant in n if d reaches n, and no other definitions of t reach n. We can rewrite n as y c x. 19
7 Copy propagation This is like constant propagation, but instead of a constant c, we have a variable z. Suppose that 1. we have a statement d : t z, and 2. another statement n that uses t, such as n : y t x. If d reaches n, and no other definition of t reaches n, and there is no definition of z on any path from d to n (including a path that goes through n one or more times), then we can rewrite n as n : y z x. Copy propagation may enable the recognition of other optimizations such as common-subexpression elimination. Ex. in the program a y + z u y c u + z the two +-expressions are not recognized as common subexpressions until after the copy propagation of u y is performed. Dead-code elimination If there is a quadruple s : a b c or s : a M[x], such that a is not live-out of s, then the quadruple can be deleted. In some cases, applying dead-code elimination to a statement is not allowed because of its implicit side effects. Ex. if the computer is configured to raise an exception on an arithmetic overflow or divide by zero, then deletion of an exception-causing instruction will change the result of the computation. The optimizer should never make a change that changes program behavior. 20
We can express this in dataflow equations using gen and kill sets, where the sets are now sets of expressions.
Available expressions Suppose we want to do common-subexpression elimination; that is, given a program that computes x y more than once, can we eliminate one of the duplicate computations? To find places
More informationCompiler Design. Fall Data-Flow Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz
Compiler Design Fall 2015 Data-Flow Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292 pedro@isi.edu
More informationRegister allocation. Register allocation: ffl have value in a register when used. ffl limited resources. ffl changes instruction choices
Register allocation IR instruction selection register allocation machine code errors Register allocation: have value in a register when used limited resources changes instruction choices can move loads
More informationData Flow Information. already computed
Data Flow Information Determine if Determine if a constant in loop modifies Determine if expression already computed Determine if not used later in program Data Flow Equations Local Information: Gen(B):
More informationMIT Introduction to Dataflow Analysis. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Introduction to Dataflow Analysis Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Dataflow Analysis Used to determine properties of program that involve multiple
More informationLecture 21 CIS 341: COMPILERS
Lecture 21 CIS 341: COMPILERS Announcements HW6: Analysis & Optimizations Alias analysis, constant propagation, dead code elimination, register allocation Available Soon Due: Wednesday, April 25 th Zdancewic
More informationDataflow analysis (ctd.)
Dataflow analysis (ctd.) Available expressions Determine which expressions have already been evaluated at each point. A expression x+y is available at point p if every path from the entry to p evaluates
More informationData Flow Analysis. CSCE Lecture 9-02/15/2018
Data Flow Analysis CSCE 747 - Lecture 9-02/15/2018 Data Flow Another view - program statements compute and transform data So, look at how that data is passed through the program. Reason about data dependence
More informationRegister allocation. CS Compiler Design. Liveness analysis. Register allocation. Liveness analysis and Register allocation. V.
Register allocation CS3300 - Compiler Design Liveness analysis and Register allocation V. Krishna Nandivada IIT Madras Copyright c 2014 by Antony L. Hosking. Permission to make digital or hard copies of
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 informationFoundations of Dataflow Analysis
Foundations of Dataflow Analysis 15-745 Optimizing Compilers Spring 2006 Peter Lee Ingredients of a dataflow analysis direction: forward or backward flow/transfer function combining ( meet ) operator dataflow
More informationData Flow Analysis. Suman Jana. Adopted From U Penn CIS 570: Modern Programming Language Implementa=on (Autumn 2006)
Data Flow Analysis Suman Jana Adopted From U Penn CIS 570: Modern Programming Language Implementa=on (Autumn 2006) Data flow analysis Derives informa=on about the dynamic behavior of a program by only
More informationCS202 Compiler Construction
CS202 Compiler Construction April 17, 2003 CS 202-33 1 Today: more optimizations Loop optimizations: induction variables New DF analysis: available expressions Common subexpression elimination Copy propogation
More informationData Flow Analysis. Program Analysis
Program Analysis https://www.cse.iitb.ac.in/~karkare/cs618/ Data Flow Analysis Amey Karkare Dept of Computer Science and Engg IIT Kanpur Visiting IIT Bombay karkare@cse.iitk.ac.in karkare@cse.iitb.ac.in
More informationCS553 Lecture Generalizing Data-flow Analysis 3
Generalizing Data-flow Analysis Announcements Project 2 writeup is available Read Stephenson paper Last Time Control-flow analysis Today C-Breeze Introduction Other types of data-flow analysis Reaching
More informationCompilation 2013 Liveness Analysis
Compilation 2013 Liveness Analysis Erik Ernst Aarhus University For good complexity management, we have used an unbounded number of registers (temporaries) To save resources, many of them can be merged
More informationProgram Optimizations using Data-Flow Analysis
Program Optimizations using Data-Flow Analysis!Last time! Lattice theoretic framework for data-flow analysis!today! Dead-code elimination! Common sub-expression elimination (CSE)! Copy propagation! Constant
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 informationDependence and Data Flow Models. (c) 2007 Mauro Pezzè & Michal Young Ch 6, slide 1
Dependence and Data Flow Models (c) 2007 Mauro Pezzè & Michal Young Ch 6, slide 1 Why Data Flow Models? Models from Chapter 5 emphasized control Control flow graph, call graph, finite state machines We
More informationCompiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7
Compiler Optimizations Chapter 8, Section 8.5 Chapter 9, Section 9.1.7 2 Local vs. Global Optimizations Local: inside a single basic block Simple forms of common subexpression elimination, dead code elimination,
More informationDependence and Data Flow Models. (c) 2007 Mauro Pezzè & Michal Young Ch 6, slide 1
Dependence and Data Flow Models (c) 2007 Mauro Pezzè & Michal Young Ch 6, slide 1 Why Data Flow Models? Models from Chapter 5 emphasized control Control flow graph, call graph, finite state machines We
More informationData-flow Analysis - Part 2
- Part 2 Department of Computer Science Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Data-flow analysis These are techniques that derive information about the flow of data
More informationData-flow Analysis. Y.N. Srikant. Department of Computer Science and Automation Indian Institute of Science Bangalore
Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Data-flow analysis These are techniques that derive information about the flow
More informationCOSE312: Compilers. Lecture 20 Data-Flow Analysis (2)
COSE312: Compilers Lecture 20 Data-Flow Analysis (2) Hakjoo Oh 2017 Spring Hakjoo Oh COSE312 2017 Spring, Lecture 20 June 6, 2017 1 / 18 Final Exam 6/19 (Mon), 15:30 16:45 (in class) Do not be late. Coverage:
More informationCS202 Compiler Construction
S202 ompiler onstruction pril 15, 2003 S 202-32 1 ssignment 11 (last programming assignment) Loop optimizations S 202-32 today 2 ssignment 11 Final (necessary) step in compilation! Implement register allocation
More informationProgramming Language Processor Theory
Programming Language Processor Theory Munehiro Takimoto Course Descriptions Method of Evaluation: made through your technical reports Purposes: understanding various theories and implementations of modern
More informationCompiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7
Compiler Optimizations Chapter 8, Section 8.5 Chapter 9, Section 9.1.7 2 Local vs. Global Optimizations Local: inside a single basic block Simple forms of common subexpression elimination, dead code elimination,
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 informationWhy Global Dataflow Analysis?
Why Global Dataflow Analysis? Answer key questions at compile-time about the flow of values and other program properties over control-flow paths Compiler fundamentals What defs. of x reach a given use
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 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 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 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 informationLecture 4 Introduction to Data Flow Analysis
Lecture 4 Introduction to Data Flow Analysis I. Structure of data flow analysis II. Example 1: Reaching definition analysis III. Example 2: Liveness analysis IV. Generalization What is Data Flow Analysis?
More informationLecture 6 Foundations of Data Flow Analysis
Review: Reaching Definitions 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:
More information20b -Advanced-DFA. J. L. Peterson, "Petri Nets," Computing Surveys, 9 (3), September 1977, pp
State Propagation Reading assignment J. L. Peterson, "Petri Nets," Computing Surveys, 9 (3), September 1977, pp. 223-252. Sections 1-4 For reference only M. Pezzè, R. N. Taylor and M. Young, Graph Models
More informationPage # 20b -Advanced-DFA. Reading assignment. State Propagation. GEN and KILL sets. Data Flow Analysis
b -Advanced-DFA Reading assignment J. L. Peterson, "Petri Nets," Computing Surveys, 9 (3), September 977, pp. 3-5. Sections -4 State Propagation For reference only M. Pezzè, R. N. Taylor and M. Young,
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 informationWhy Data Flow Models? Dependence and Data Flow Models. Learning objectives. Def-Use Pairs (1) Models from Chapter 5 emphasized control
Why Data Flow Models? Dependence and Data Flow Models Models from Chapter 5 emphasized control Control flow graph, call graph, finite state machines We also need to reason about dependence Where does this
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 informationLecture 2. Introduction to Data Flow Analysis
Lecture 2 Introduction to Data Flow Analysis I II III Example: Reaching definition analysis Example: Liveness Analysis A General Framework (Theory in next lecture) Reading: Chapter 9.2 Advanced Compilers
More informationAn example of optimization in LLVM. Compiler construction Step 1: Naive translation to LLVM. Step 2: Translating to SSA form (opt -mem2reg)
Compiler construction 2014 An example of optimization in LLVM Lecture 8 More on code optimization SSA form Constant propagation Common subexpression elimination Loop optimizations int f () { int i, j,
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 informationCode optimization. Have we achieved optimal code? Impossible to answer! We make improvements to the code. Aim: faster code and/or less space
Code optimization Have we achieved optimal code? Impossible to answer! We make improvements to the code Aim: faster code and/or less space Types of optimization machine-independent In source code or internal
More informationCSCE 548 Building Secure Software Data Flow Analysis
CSCE 548 Building Secure Software Data Flow Analysis Professor Lisa Luo Spring 2018 Previous Class Why we need reverse engineering? Tools for reverse engineering Debugger Disassembler System monitoring
More informationCompiler Optimization and Code Generation
Compiler Optimization and Code Generation Professor: Sc.D., Professor Vazgen Melikyan 1 Course Overview Introduction: Overview of Optimizations 1 lecture Intermediate-Code Generation 2 lectures Machine-Independent
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 informationCIS 341 Final Examination 4 May 2017
CIS 341 Final Examination 4 May 2017 1 /14 2 /15 3 /12 4 /14 5 /34 6 /21 7 /10 Total /120 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 14 pages
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 informationIntroduction. Data-flow Analysis by Iteration. CSc 553. Principles of Compilation. 28 : Optimization III
CSc 553 Principles of Compilation 28 : Optimization III Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg Computing Data-Flow Info.
More informationPlan for Today. Concepts. Next Time. Some slides are from Calvin Lin s grad compiler slides. CS553 Lecture 2 Optimizations and LLVM 1
Plan for Today Quiz 2 How to automate the process of performance optimization LLVM: Intro to Intermediate Representation Loops as iteration spaces Data-flow Analysis Intro Control-flow graph terminology
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 informationCS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis
CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 5 out Due Tuesday Nov 13 (14 days) Project 6 out Due
More informationExample of Global Data-Flow Analysis
Example of Global Data-Flow Analysis Reaching Definitions We will illustrate global data-flow analysis with the computation of reaching definition for a very simple and structured programming language.
More informationStatic Detection of Access Anomalies in Ada95
Static Detection of Access Anomalies in Ada95 Bernd Burgstaller, University of Sydney Johann Blieberger, Vienna University of Technology Robert Mittermayr, ARC Seibersdorf research GmbH Static Detection
More informationCalvin Lin The University of Texas at Austin
Loop Invariant Code Motion Last Time SSA Today Loop invariant code motion Reuse optimization Next Time More reuse optimization Common subexpression elimination Partial redundancy elimination February 23,
More informationDependence and Data Flow Models
Chapter 6 Dependence and Data Flow Models The control flow graph and state machine models introduced in the previous chapter capture one aspect of the dependencies among parts of a program. They explicitly
More informationData-Flow Analysis Foundations
CS 301 Spring 2016 Meetings April 11 Data-Flow Foundations Plan Source Program Lexical Syntax Semantic Intermediate Code Generation Machine- Independent Optimization Code Generation Target Program This
More informationCalvin Lin The University of Texas at Austin
Loop Invariant Code Motion Last Time Loop invariant code motion Value numbering Today Finish value numbering More reuse optimization Common subession elimination Partial redundancy elimination Next Time
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 informationRegister allocation. Register allocation: ffl have value in a register when used. ffl limited resources. ffl changes instruction choices
Register allocation IR instruction selection register allocation machine code errors Register allocation: have value in a register when used limited resources changes instruction choices can move loads
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 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 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 informationLecture Notes: Dataflow Analysis Examples
Lecture Notes: Dataflow Analysis Examples 15-819O: Program Analysis Jonathan Aldrich jonathan.aldrich@cs.cmu.edu Lecture 3 1 Constant Propagation While zero analysis was useful for simply tracking whether
More informationLiveness Analysis and Register Allocation. Xiao Jia May 3 rd, 2013
Liveness Analysis and Register Allocation Xiao Jia May 3 rd, 2013 1 Outline Control flow graph Liveness analysis Graph coloring Linear scan 2 Basic Block The code in a basic block has: one entry point,
More informationcompile-time reasoning about the run-time ow represent facts about run-time behavior represent eect of executing each basic block
Data-ow analysis Data-ow analysis compile-time reasoning about the run-time ow of values in the program represent facts about run-time behavior represent eect of executing each basic block propagate facts
More informationMore Dataflow Analysis
More Dataflow Analysis Steps to building analysis Step 1: Choose lattice Step 2: Choose direction of dataflow (forward or backward) Step 3: Create transfer function Step 4: Choose confluence operator (i.e.,
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 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 informationCompiler construction in4303 answers
Compiler construction in4303 answers Koen Langendoen Delft University of Technology The Netherlands Compiler construction in4303 lecture 1 Introduction Lexical analysis by hand Chapter 1 2.15 AST exercise
More informationLoops. Lather, Rinse, Repeat. CS4410: Spring 2013
Loops or Lather, Rinse, Repeat CS4410: Spring 2013 Program Loops Reading: Appel Ch. 18 Loop = a computation repeatedly executed until a terminating condition is reached High-level loop constructs: While
More informationCompiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 10 Lecture No. # 16 Machine-Independent Optimizations Welcome to the
More informationLiveness Analysis and Register Allocation
Liveness Analysis and Register Allocation Leonidas Fegaras CSE 5317/4305 L10: Liveness Analysis and Register Allocation 1 Liveness Analysis So far we assumed that we have a very large number of temporary
More informationLecture Notes on Common Subexpression Elimination
Lecture Notes on Common Subexpression Elimination 15-411: Compiler Design Frank Pfenning Lecture 18 October 29, 2015 1 Introduction Copy propagation allows us to have optimizations with this form: l :
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 informationProgram Static Analysis. Overview
Program Static Analysis Overview Program static analysis Abstract interpretation Data flow analysis Intra-procedural Inter-procedural 2 1 What is static analysis? The analysis to understand computer software
More informationLecture Notes on Dataflow Analysis
Lecture Notes on Dataflow Analysis 15-411: Compiler Design Frank Pfenning Lecture 5 September 9, 2008 1 Introduction In this lecture we first extend liveness analysis to handle memory references and then
More informationGlobal Optimizations
Global Optimizations Avi Hayoun, Ben Eyal and Lior Zur-Lotan January 9, 2017 Contents 1 Global Optimizations 1 1.1 Basic Blocks and Control-Flow graphs.......................... 1 1.1.1 Control-Flow Graph
More informationInduction Variable Identification (cont)
Loop Invariant Code Motion Last Time Uses of SSA: reaching constants, dead-code elimination, induction variable identification Today Finish up induction variable identification Loop invariant code motion
More informationCode Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University
Code Generation Frédéric Haziza Department of Computer Systems Uppsala University Spring 2008 Operating Systems Process Management Memory Management Storage Management Compilers Compiling
More informationWhen we eliminated global CSE's we introduced copy statements of the form A:=B. There are many
Copy Propagation When we eliminated global CSE's we introduced copy statements of the form A:=B. There are many other sources for copy statements, such as the original source code and the intermediate
More informationName: CIS 341 Final Examination 10 December 2008
Name: CIS 341 Final Examination 10 December 2008 1 /8 2 /12 3 /18 4 /18 5 /14 Total /70 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 11 pages
More informationWhat Compilers Can and Cannot Do. Saman Amarasinghe Fall 2009
What Compilers Can and Cannot Do Saman Amarasinghe Fall 009 Optimization Continuum Many examples across the compilation pipeline Static Dynamic Program Compiler Linker Loader Runtime System Optimization
More informationDepartment of Computer Sciences CS502. Purdue University is an Equal Opportunity/Equal Access institution.
Reaching Definition Analysis CS502 The most fundamental dataflow information concerns the definition (or generation) and the use of values. When an operation modifies a variable at program point p, we
More informationMidterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 21, 2016
Name: Midterm 2 CMSC 430 Introduction to Compilers Fall 2016 November 21, 2016 Instructions This exam contains 7 pages, including this one. Make sure you have all the pages. Write your name on the top
More informationRegister allocation. instruction selection. machine code. register allocation. errors
Register allocation IR instruction selection register allocation machine code errors Register allocation: have value in a register when used limited resources changes instruction choices can move loads
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 informationProgram analysis for determining opportunities for optimization: 2. analysis: dataow Organization 1. What kind of optimizations are useful? lattice al
Scalar Optimization 1 Program analysis for determining opportunities for optimization: 2. analysis: dataow Organization 1. What kind of optimizations are useful? lattice algebra solving equations on lattices
More information4/24/18. Overview. Program Static Analysis. Has anyone done static analysis? What is static analysis? Why static analysis?
Overview Program Static Analysis Program static analysis Abstract interpretation Static analysis techniques 2 What is static analysis? The analysis to understand computer software without executing programs
More informationMidterm 2. CMSC 430 Introduction to Compilers Spring Instructions Total 100. Name: April 18, 2012
Name: Midterm 2 CMSC 430 Introduction to Compilers Spring 2012 April 18, 2012 Instructions This exam contains 10 pages, including this one. Make sure you have all the pages. Write your name on the top
More informationCSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...
CSE 401 Final Exam March 14, 2017 Happy π Day! (3/14) Name This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,.... Please wait to turn the page until everyone has their
More informationGlobal Optimizations
Global Optimizations Avi Hayoun, Hodai Goldman and Lior Zur-Lotan January 31, 2016 Contents 1 Global Optimizations Global optimizations and analyses are performed in the context of a whole, single function
More informationChapter 10. Improving the Runtime Type Checker Type-Flow Analysis
122 Chapter 10 Improving the Runtime Type Checker The runtime overhead of the unoptimized RTC is quite high, because it instruments every use of a memory location in the program and tags every user-defined
More informationCIS 341 Final Examination 30 April 2013
CIS 341 Final Examination 30 April 2013 1 /40 2 /30 3 /30 4 /20 Total /120 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 12 pages in this exam.
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 informationThis test is not formatted for your answers. Submit your answers via to:
Page 1 of 7 Computer Science 320: Final Examination May 17, 2017 You have as much time as you like before the Monday May 22 nd 3:00PM ET deadline to answer the following questions. For partial credit,
More informationFlow Propagation Algorithm
SOMA Flow Propagation Algorithm Univ.Prof. Dr. Franz Wotawa, Birgit Hofer Institut für Softwaretechnologie {wotawa, hofer}@ist.tugraz.at Institute for Software Technology Agenda Flow Propagation Algorithm
More informationCSE Section 10 - Dataflow and Single Static Assignment - Solutions
CSE 401 - Section 10 - Dataflow and Single Static Assignment - Solutions 1. Dataflow Review For each of the following optimizations, list the dataflow analysis that would be most directly applicable. You
More informationCSE 501 Midterm Exam: Sketch of Some Plausible Solutions Winter 1997
1) [10 pts] On homework 1, I asked about dead assignment elimination and gave the following sample solution: 8. Give an algorithm for dead assignment elimination that exploits def/use chains to work faster
More information