Advanced Compilers Introduction to Dataflow Analysis by Example. Fall Chungnam National Univ. Eun-Sun Cho
|
|
- Brent Raymond Rice
- 5 years ago
- Views:
Transcription
1 Advanced Compilers Introduction to Dataflow Analysis by Example Fall Chungnam National Univ. Eun-Sun Cho 1
2 Dataflow Analysis + Optimization r1 = r2 + r3 r6 = r4 r5 r6 = r2 + r3 r7 = r4 r5 r4 = 4 r6 = 8 Classical optimization examples Common subexpression elimination r2 + r3? r4 - r5? Register allocation (live range anlysis) Can virtual registers r1 and r7 be allocated in a same actual register? Control flow analysis Considering basic blocks as black boxes Concerns only branches Data flow analysis Collecting information about constructions/destructions of each data value in a program Look inside basic blocks and check each operations cf. CFA note: (virtual) registers == (user-defined or temporary) variables
3 Live Variable (Liveness) Analysis r1 = r2 + r3 r6 = r4 r5 r6 = r2 + r3 r7 = r4 r5 r4 = 4 r6 = 8 r6(=8) is dead Others are live r1,r2,r3,r4 and r5 are live r6 (=r4-r5) is dead r4 and r6(=r4-r5) are dead others are live Live variable analysis : to see (at a specific program point) if the current value of a variable is to be used in the future Conclusions : r6 = r4 r5 is useless!
4 Live Variable Analysis Algorithms Collecting following sets USE/DEF inner basic block USE = set of external variables consumed in the BB DEF = set of variables defined in the BB IN/OUT inter basic blocks IN = set of variables that are live at the entry point of a BB OUT = set of variables that are live at the exit point of a BB note) It is better to evaluate IN/OUT backward IN/OUT are defined by USE/DEF At the entry of a BB, registers except for IN had better be freed, At the exit of a BB, registers except for OUT had better be freed.
5 Compute USE/DEF Sets For Each BB (When an instruction is Equal to a BB) for each basic block X, do DEF(X) = dest : = src 1 +src 2 USE(X) = for each operation in sequential order in X, op, do for each source operand of op, src, do USE(X) += src DEF(X) += dest
6 Compute USE/DEF Sets For Each BB (In General) for each basic block X, do DEF(X) = dest : = src 1 +src 2 USE(X) = for each operation in sequential order in X, op, do for each source operand of op, src, do if (src not in DEF(X)) then USE(X) += src endif DEF(X) += dest DEF : all the LHS in the block USE : the values from outside which are used before redefined in the block
7 Example DEF/USE Calculation r1 = MEM[r2+0] r2 = r2 + 1 r3 = r1 * r4 USE = r2,r4 DEF = r1,r2,r3 USE = r1,r5 DEF = r1,r3,r7 r1 = r1 + 5 r3 = r5 r1 r7 = r3 * 2 r2 = 0 r7 = 23 r1 = 4 USE = DEF = r1,r2,r7 r8 = r7 + 5 r1 = r3 r8 r3 = r1 * 2 USE = r3,r7 DEF = r1,r3,r8
8 Compute IN/OUT Sets For All BBs initialize IN(X) to for all basic blocks X change = 1 while (change) do change = 0 for each basic block, X, do old_in = IN(X) OUT(X) = Y successor(x) IN(Y) IN(X) = USE(X) + (OUT(X) DEF(X)) if (old_in!= IN(X)) then change = 1 endif IN : live variables at the entry point of the block the variables of which values at the entry point are used in the USE(X) + the variables of which values are not updated in this block, while they are to be used in some following blocks OUT(X) DEF(X) OUT : collection of IN(Y)s from direct successor blocks Y
9 Example IN/OUT Calculation r1 = MEM[r2+0] r2 = r2 + 1 r3 = r1 * r4 USE = r2,r4 DEF = r1,r2,r3 IN = r2,r4,r5 OUT = r1,r3,r5 USE = r1,r5 DEF = r1,r3,r7 IN = r1,r5 OUT = r3,r7 r1 = r1 + 5 r3 = r5 r1 r7 = r3 * 2 r2 = 0 r7 = 23 r1 = 4 USE = DEF = r1,r2,r7 IN = r3 OUT = r3,r7 r8 = r7 + 5 r1 = r3 r8 r3 = r1 * 2 USE = r3,r7 DEF = r1,r3,r8 IN = r3,r7 OUT = liveness analysis = finding out the set of registers which retain meaningful values at a specific program point (like the entry point of a block, the exit point of a block..),
10 Reaching Definition Analysis (rdefs) 1: r1 = r2 + r3 2: r6 = r4 r5 Definition of a variable an (assignment) expression which has the variable at its lhs 5: r6 = r2 + r3 6: r7 = r4 r5 3: r4 = 4 4: r6 = 8 defs 1 and 2 reach this point defs 1, 3, 4 Definition d reaches a program point (point) p from right after d to p, there exists a path d which does not kill d reach this point Definition d is killed between two def 2 is killed by 4 program points on the path between the two points, there exist other definitions of the same variable that d defines eg) r1=r2+r3 kills all the previous definition (although they are not shown in the figure) of r1 defs 1, 3, 5, 6 reach this point defs 2, 4 are killed by 5
11 Reaching Definition Analysis - Algorithms Collecting following sets GEN/KILL inner basic block GEN = set of definitions generated in the BB KILL = set of definitions killed in the BB IN/OUT inter basic blocks IN = set of definitions reaching the BB entry OUT = set of definitions reaching the BB exit note) It is better to evaluate IN/OUT forward IN/OUT are defined by GEN/KILL
12 Compute Rdef GEN/KILL Sets For Each BB (When an instruction is Equal to a BB) for each basic block X, do GEN(X) = dest : = src 1 +src 2 KILL(X) = for each operation in sequential order in X, op, do GEN(X) += op KILL(X) = {all ops which define dest}
13 Compute Rdef GEN/KILL Sets For Each BB (In General) for each basic block X, do GEN(X) = dest : = src 1 +src 2 KILL(X) = for each operation in sequential order in X, op, do G = op K = {all ops which define dest} GEN(X) = G + (GEN(X) K) KILL(X) = K + (KILL(X) G)
14 Example Rdef GEN/KILL Calculation 1: r1 = MEM[r2+0] 2: r2 = r : r3 = r1 * r4 GEN = 1,2,3 KILL = 4,5,7,9,11,12 GEN = 4,5,6 KILL = 1,3,8,9,11,12 4: r1 = r : r3 = r5 r1 6: r7 = r3 * 2 7: r2 = 0 8: r7 = 23 9: r1 = 4 GEN = 7,8,9 KILL = 1,2,4,6,11 10: r8 = r : r1 = r3 r8 12: r3 = r1 * 2 GEN = 10,11,12 KILL = 1,3,4,5,9
15 Compute Rdef IN/OUT Sets for all BBs initialize OUT(X) = for all basic blocks X change = 1 while (change) do change = 0 for each basic block X, do old_out = OUT(X) IN(X) = Y predessor(x) OUT(Y) OUT(X) = GEN(X) + (IN(X) KILL(X)) if (old_out!= OUT(X)) then change = 1 endif IN = set of definitions reaching the entry of BB OUT = set of definitions leaving BB
16 Example Rdef IN/OUT Calculation 1: r1 = MEM[r2+0] 2: r2 = r : r3 = r1 * r4 GEN = 1,2,3 KILL = 4,5,7,9,11,12 IN = OUT = 1,2,3 GEN = 4,5,6 KILL = 1,3,8,9,11,12 IN = 1,2,3 OUT = 2,4,5,6 4: r1 = r : r3 = r5 r1 6: r7 = r3 * 2 7: r2 = 0 8: r7 = 23 9: r1 = 4 10: r8 = r : r1 = r3 r8 12: r3 = r1 * 2 GEN = 10,11,12 KILL = 1,3,4,5,9 GEN = 7,8,9 KILL = 1,2,4,6,11 IN = 1,2,3 OUT = 3,7,8,9 IN = 2,3,4,5,6,7,8,9 OUT = 2,6,7,8,10,11,12
17 Application Live Ranges in Register Allocation C from CMU Compiler Web site 17
18 r1 = r2 + r3 r6 = r4 r5 r6 = r2 + r3 r7 = r4 r5 Available Expressions r4 = 4 r6 = 8 r2+r4 is available r4-r5 is available r2+r3 is available r4- r5 is not available r2+r3 is available r4-r5 is not available Goals to reuse the values of syntactically same expressions which were evaluated before Availability Consider all the (syntactic) expressions Is an expression already evaluated? = Is this expression available? expression e is killed between two program points on the path between the two points, there exist definitions of the variable used in e: the previous value is not usable eg) r4=4 kills the expression r4-r5 in r6=r4-r5
19 Available Expression Analysis - Algorithms Collecting following sets E_GEN/E_KILL inner basic block E_GEN = set of expressions generated in the BB E_KILL = set of expressions killed in the BB IN/OUT inter basic blocks IN = set of expressions available at the BB entry OUT = set of expressions available at the BB exit note) It is better to evaluate IN/OUT forward IN/OUT are defined by E_GEN/E_KILL
20 Compute AvailExp. GEN/KILL Sets For Each BB for each basic block X, do E_GEN(X) = dest : = src 1 +src 2 E_KILL(X) = for each operation in sequential order in X, op, do if (dest is not FV of src 1 +src 2 ) G = src 1 +src 2 K = {all exprs which contains dest in FV} E_GEN(X) = G + (E_GEN(X) K) E_KILL(X) = K + (E_KILL(X) G) FV (e): set of free variables of e exprs eg.. FV(x+1) = {x} FV(2+x+y+3) = {x, y}
21 Example AvailExp. GEN/KILL Calculation r1 = MEM[r2+0] r2 = r2 + 1 r3 = r1 * r4 E_GEN = r1*r4 E_KILL = r2+1, r1+5, r5-r1, r3*2, r3-r8, E_GEN = r5-r1 r3*2 E_KILL = r1*r4, r1+5, r3-r8, r7+5 r1 = r1 + 5 r3 = r5 r1 r7 = r3 * 2 r2 = r3*2 r7 = 23 r1 = 4 E_GEN = r3*2 E_KILL =r2+1, r7+5, r1*r4, r1+5, r5-r1 r8 = r7 + 5 r1 = r3 r8 r7 = r3 * 2 E_GEN = r3-r8, r3*2 E_KILL = r1*r4, r1+5, r5-r1, r7+5
22 Compute AvailExp. IN/OUT Sets for all BBs initialize OUT(X) = U for all basic blocks X change = 1 while (change) do change = 0 for each basic block X, do old_out = OUT(X) IN(X) = Y predessor(x) OUT(Y) OUT(X) = E_GEN(X) + (IN(X) E_KILL(X)) if (old_out!= OUT(X)) then change = 1 endif IN = set of expressions available the entry of BB OUT = set of available expressions leaving BB
23 Example AvailExp. IN/OUT Calculation r1 = MEM[r2+0] r2 = r2 + 1 r3 = r1 * r4 E_GEN = r1*r4 E_KILL = r2+1, r1+5, IN = OUT = r1*r4 r5-r1, r3*2, r3-r8, E_GEN = r5-r1 r3*2 E_KILL = r1*r4, r1+5, r3-r8, r7+5 IN = r1*r4 OUT = r5-r1, r3*2 r1 = r1 + 5 r3 = r5 r1 r7 = r3 * 2 r8 = r7 + 5 r1 = r3 r8 r7 = r3 * 2 r2 = r3*2 r7 = 23 r1 = 4 E_GEN = r3*2 E_KILL = r2+1, r7+5, r1*r4, r1+5, r5-r1 IN = r1*r4 OUT = r3*2 E_GEN = r3-r8, r3*2 E_KILL = r1*r4, r1+5, r5-r1, r7+5 IN = r3*2 OUT = r3-r8, r3*2
24 Summary of Three Dataflow Problems Live Variables Reaching Definition Available Expressions Domain Sets of variables Sets of definitions Sets of expressions Direction Backwards Forwards Forwards Main Logic IN = USE + (OUT DEF) OUT = GEN + (IN KILL) OUT = GEN + (IN KILL) Transfer function F B (x) = use B (x def B ) F B (x) = gen B (x kill B ) F B (x) = e_gen B (x e_kill B ) Boundary IN(Exit) = OUT(Entry) = OUT (Entry) = Meet( ) Initialize IN(X) = OUT(X) = OUT(X) = U universe Equation in(b) = F B (out(b)) out(b) = Q Succ(B) in(q) out(b) = F B (in(b)) in(b) = Q Pred(B) out(q) out(b) = F B (in(b)) in(b) = Q Pred(B) out(q) 24
EECS 583 Class 6 Dataflow Analysis
EECS 583 Class 6 Dataflow Analysis University of Michigan September 26, 2011 Announcements & Reading Material Today s class» Compilers: Principles, Techniques, and Tools, A. Aho, R. Sethi, and J. Ullman,
More informationEECS 583 Class 6 Dataflow Analysis
EECS 583 Class 6 Dataflow Analysis University of Michigan September 24, 2012 Announcements & Reading Material Homework 1 due tonight at midnight» Remember, submit single.tgz file to andrew.eecs.umich.edu:/y/submit/uniquename_hw1.tgz
More informationEECS 583 Class 6 Dataflow Analysis
EECS 583 Class 6 Dataflow Analysis University of Michigan September 26, 2016 Announcements & Reading Material HW 1» Congratulations if you are done!» The fun continues à HW2 out Wednesday, due Oct 17th,
More informationEECS 583 Class 6 More Dataflow Analysis
EECS 583 Class 6 More Dataflow Analysis University of Michigan September 24, 2018 Announcements & Reading Material HW 1 due tonight at midnight» Hopefully you are done or very close to finishing Today
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 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 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 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 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 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 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 informationLecture 5. Partial Redundancy Elimination
Lecture 5 Partial Redundancy Elimination I. Forms of redundancy global common subexpression elimination loop invariant code motion partial redundancy II. Lazy Code Motion Algorithm Mathematical concept:
More informationLecture 10: Lazy Code Motion
Lecture : Lazy Code Motion I. Mathematical concept: a cut set II. Lazy Code Motion Algorithm Pass : Anticipated Expressions Pass 2: (Will be) Available Expressions Pass 3: Postponable Expressions Pass
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 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 informationCompiler Design Spring 2017
Compiler Design Spring 2017 8.6 Live variables Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation Live variables Foundations for several optimizations If a variable is not live,
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 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 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 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 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 information: Compiler Design. 9.6 Available expressions 9.7 Busy expressions. Thomas R. Gross. Computer Science Department ETH Zurich, Switzerland
252-210: Compiler Design 9.6 Available expressions 9.7 Busy expressions Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Available expressions An expression a+b is available at a point
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 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 informationIntro to dataflow analysis. CSE 501 Spring 15
Intro to dataflow analysis CSE 501 Spring 15 Announcements Paper commentaries Please post them 24 hours before class ApplicaBon paper presentabons Good training for conference talks! Will help go through
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 informationLive Variable Analysis. Work List Iterative Algorithm Rehashed
Putting Data Flow Analysis to Work Last Time Iterative Worklist Algorithm via Reaching Definitions Why it terminates. What it computes. Why it works. How fast it goes. Today Live Variable Analysis (backward
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 informationCMSC430 Spring 2009 Midterm 2 (Solutions)
CMSC430 Spring 2009 Midterm 2 (Solutions) Instructions You have until 4:45pm to complete the midterm. Feel free to ask questions on the midterm. One sentence answers are sufficient for the ``essay'' questions.
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 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 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 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 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 informationWe 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 informationTour of common optimizations
Tour of common optimizations Simple example foo(z) { x := 3 + 6; y := x 5 return z * y } Simple example foo(z) { x := 3 + 6; y := x 5; return z * y } x:=9; Applying Constant Folding Simple example foo(z)
More informationCode Optimization. Code Optimization
161 Code Optimization Code Optimization 162 Two steps: 1. Analysis (to uncover optimization opportunities) 2. Optimizing transformation Optimization: must be semantically correct. shall improve program
More informationIntroduction to Compiler Design: optimization and backend issues
Introduction to Compiler Design: optimization and backend issues Andy Pimentel group andy@science.uva.nl Introduction to Compiler Design A. Pimentel p. 1/127 Compilers: Organization Revisited Source Frontend
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 informationGlobal Data Flow Analysis of Syntax Tree Intermediate Code
Global Data Flow Analysis of Syntax Tree Intermediate Code A Thesis by : Supervisors: Richard McCabe BSc. Micheál O'hEigeartaigh Heather Ruskin Mervyn Barman Declaration : No portion of this work has been
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 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 informationCS 6353 Compiler Construction, Homework #3
CS 6353 Compiler Construction, Homework #3 1. Consider the following attribute grammar for code generation regarding array references. (Note that the attribute grammar is the same as the one in the notes.
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 informationA Domain-Specific Language for Generating Dataflow Analyzers
A Domain-Specific Language for Generating Dataflow Analyzers Jia Zeng Chuck Mitchell Stephen A. Edwards Columbia Univ. Microsoft Co. Columbia Univ. jia@cs.columbia.edu chuckm@microsoft.com sedwards@cs.columbia.edu
More informationDataflow Analysis 2. Data-flow Analysis. Algorithm. Example. Control flow graph (CFG)
Dataflow Analysis 2 Data-flow Analysis Algorithm 1. Find basic blocks, build CFG 2. Find propagation functions for basic blocks 3. Propagate information around CFG 4. Propagate information into basic blocks
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 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 informationWe 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 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 informationLecture Compiler Middle-End
Lecture 16-18 18 Compiler Middle-End Jianwen Zhu Electrical and Computer Engineering University of Toronto Jianwen Zhu 2009 - P. 1 What We Have Done A lot! Compiler Frontend Defining language Generating
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 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 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 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 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 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 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 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 informationCompiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code)
Compiler Theory (Intermediate Code Generation Abstract S yntax + 3 Address Code) 006 Why intermediate code? Details of the source language are confined to the frontend (analysis phase) of a compiler, while
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 Selection and Scheduling
Instruction Selection and Scheduling The Problem Writing a compiler is a lot of work Would like to reuse components whenever possible Would like to automate construction of components Front End Middle
More informationCode generation and local optimization
Code generation and local optimization Generating assembly How do we convert from three-address code to assembly? Seems easy! But easy solutions may not be the best option What we will cover: Instruction
More informationChallenges 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 informationEECS 583 Class 8 Classic Optimization
EECS 583 Class 8 Classic Optimization University of Michigan October 3, 2011 Announcements & Reading Material Homework 2» Extend LLVM LICM optimization to perform speculative LICM» Due Friday, Nov 21,
More informationCode generation and local optimization
Code generation and local optimization Generating assembly How do we convert from three-address code to assembly? Seems easy! But easy solutions may not be the best option What we will cover: Instruction
More informationCompiler Design and Construction Optimization
Compiler Design and Construction Optimization Generating Code via Macro Expansion Macroexpand each IR tuple or subtree A := B+C; D := A * C; lw $t0, B, lw $t1, C, add $t2, $t0, $t1 sw $t2, A lw $t0, A
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 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 informationCompiling Code, Procedures and Stacks
Compiling Code, Procedures and Stacks L03-1 RISC-V Recap Computational Instructions executed by ALU Register-Register: op dest, src1, src2 Register-Immediate: op dest, src1, const Control flow instructions
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 informationCode generation and optimization
Code generation and timization Generating assembly How do we convert from three-address code to assembly? Seems easy! But easy solutions may not be the best tion What we will cover: Peephole timizations
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 informationDealing with Register Hierarchies
Dealing with Register Hierarchies Matthias Braun (MatzeB) / LLVM Developers' Meeting 2016 r1;r2;r3;r4 r0;r1;r2;r3 r0,r1,r2,r3 S0 D0 S1 Q0 S2 D1 S3 r3;r4;r5 r2;r3;r4 r1;r2;r3 r2;r3 r1,r2,r3,r4 r3,r4,r5,r6
More informationIntra-procedural Data Flow Analysis Introduction
The Setting: Optimising Compilers The Essence of Program Analysis Reaching Definitions Analysis Intra-procedural Data Flow Analysis Introduction Hanne Riis Nielson and Flemming Nielson email: {riis,nielson}@immdtudk
More informationReaching Definitions and u-d Chaining M.B.Chandak
Reaching Definitions and u-d Chaining M.B.Chandak hodcs@rknec.edu Reaching Definitions A definition of any variable is killed if between two points along the path, there is a re-assignment. A definition
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 informationHomework Assignment #1 Sample Solutions
Homework Assignment # Sample Solutions Due Monday /, at the start of lecture. For the following control flow graph, for the purposes of a forward data flow analysis (such as available expressions), show
More informationPrinciples of Compiler Design
Principles of Compiler Design Code Generation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Intermediate Code Code Generation Target Program
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 informationCS 406/534 Compiler Construction Putting It All Together
CS 406/534 Compiler Construction Putting It All Together Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy
More informationInstruction-Level Parallelism (ILP)
Instruction Level Parallelism Instruction-Level Parallelism (ILP): overlap the execution of instructions to improve performance 2 approaches to exploit ILP: 1. Rely on hardware to help discover and exploit
More informationCSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1
CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on
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 informationPartial Redundancy Analysis
Partial Redundancy Analysis Partial Redundancy Analysis is a boolean-valued data flow analysis that generalizes available expression analysis. Ordinary available expression analysis tells us if an expression
More informationMIT Introduction to Program Analysis and Optimization. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Introduction to Program Analysis and Optimization Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Program Analysis Compile-time reasoning about run-time behavior
More informationInduction variable elimination
Induction variable elimination Algorithm DIV: Detection of Induction Variables Our objective here is to associate with each induction variable, j, a triple (i,c,d) where i is a basic induction variable
More informationAutomatic Determination of May/Must Set Usage in Data-Flow Analysis
Automatic Determination of May/Must Set Usage in Data-Flow Analysis Andrew Stone Colorado State University stonea@cs.colostate.edu Michelle Strout Colorado State University mstrout@cs.colostate.edu Shweta
More informationRegister Allocation. Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations
Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class
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 informationCode Placement, Code Motion
Code Placement, Code Motion Compiler Construction Course Winter Term 2009/2010 saarland university computer science 2 Why? Loop-invariant code motion Global value numbering destroys block membership Remove
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 informationThe Static Single Assignment Form:
The Static Single Assignment Form: Construction and Application to Program Optimizations - Part 3 Department of Computer Science Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design
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 informationMidterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 11, 2015
Name: Midterm 2 CMSC 430 Introduction to Compilers Fall 2015 November 11, 2015 Instructions This exam contains 8 pages, including this one. Make sure you have all the pages. Write your name on the top
More informationCompilation 2012 Static Analysis
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University Interesting Questions Is every statement reachable? Does every non-void method return a value? Will local variables definitely be
More informationAn Implementation of Lazy Code Motion for Machine SUIF
An Implementation of Lazy Code Motion for Machine SUIF Laurent Rolaz Swiss Federal Institute of Technology Processor Architecture Laboratory Lausanne 28th March 2003 1 Introduction Optimizing compiler
More informationLecture 19: Instruction Level Parallelism
Lecture 19: Instruction Level Parallelism Administrative: Homework #5 due Homework #6 handed out today Last Time: DRAM organization and implementation Today Static and Dynamic ILP Instruction windows Register
More informationCode Analysis and Optimization. Pat Morin COMP 3002
Code Analysis and Optimization Pat Morin COMP 3002 Outline Basic blocks and flow graphs Local register allocation Global register allocation Selected optimization topics 2 The Big Picture By now, we know
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 information