8 Optimisation. 8.1 Introduction to Optimisation
|
|
- Linette Meghan Nash
- 6 years ago
- Views:
Transcription
1 8 8.1 Introduction to 8.1 Introduction refers to compiler strategies which result in generated object code which is more efficient, either in terms of speed or memory use. can be performed in two locations: 1. During Code Generation: s can be applied during code generation. This includes: a) during mapping the parse tree to intermediate code b) s applied to the intermediate code itself c) s applied during the mapping of intermediate code to assembler. 2. After Code Generation: an independent process can take the generated assembler code as input and modify it to perform better. 2 1
2 8.1 Introduction Machine-dependent vs. Machine-independent s Some of these optimisations are specific to the object code being generated (machine-dependent) Other optimisations have consequence for all target systems (machine-independent) 1. During Code Generation: a) during mapping the parse tree to intermediate code b) s applied to the intermediate code itself c) s applied during the mapping of intermediate code to assembler. 2. After Code Generation: opimisations applied directly on the generated object code. machine-independent machine-dependent Introduction Machine-independent optimisations Some common machine-independent optimisations: Partial execution of code within the compiler, instead of delaying execution to the object program. (e.g., constant folding : x= 5*4*x Redundant Code Elimination: Elimination of code where equivalent code has been executed previously. Change order of some instructions, to produce more efficient code. Increasing efficiency of loops: including: where calculations made in the loop are not affected by the loop, moving the calculations outside the loop. Dead-code elimination: where code cannot be reached, it is eliminated from the target code. 4 2
3 8.1 Introduction Machine-dependent optimisations Some common machine-dependent optimisations: Special Instructions: most target languages include instructions which are special to that architecture, and using these instructions can be more efficient. Minimising the number of registers used: in machines with few registers. For instance, the code could be simplified to use a single register. Rearrangement of code: some architectures are more efficient when the operations are executed in a certain order. Modifying the code to benefit from that order Introduction and other Compiler Tasks can interfer with other goals of the compiler: Programmers often trace program execution as a means of locating errors. But optimisation means that the instructions actually executed may not correspond to any one statement of the original source code And some source code statements may occur in a different sequence. Some source code statements may disappear completely. 6 3
4 8 8.2 Machine-Independent Execution at compile time Execution at compile time: Constant Folding It is sometimes possible that part of the code can be executed off-line, and thus the compiler can perform the calculations, and only include the result in the generated code. Nearly always, this is restricted to arithmetical expressions and type conversion For instance, Constant Folding: operations involving constants: Example: a = 8 / 2 * b The compiler can perform the calculation of 8/2 and generate instead the code for a = 4 * b Example: a = 8 * b / 2 The compiler could reorder operations to see this is equivalent to a = 8 / 2 * b and perform the above optimisation. 8 4
5 Execution at compile time The prior example (a = 4 * b / 8) might generate assembler like: MOV EAX, [b] IDIV EAX, 2 MOV [a], EAX 9 Execution at compile time: Constant Propagation Constant propagation is the process of substituting the values of known constants in expressions at compile time. The compiler can keep track of the current value of variables at each point. Where the variable contains a constant value at a given point, the compiler can generate code containing the constant rather than the variable. E.g., a = 5; x = a * 4 => a= 5; X = 5 * 4 Constant folding might apply in such cases, e.g., b = 5 a = b * 6 => MOV, a,
6 Execution at compile time: Constant Propagation In order to perform such optimisations, the compiler needs to keep track of the values held in identifiers at each step. This can done via the symbol table, or a data structure maintained for this purpose. In the following we will assume we have a list T which holds identifier-value pairs, such as (a, 3). T defines the set of identifiers with known values at the current state of processing. We will assume here that intermediate code in the form of quadruples is generated, although similar methods can be used for other forms of intermediate code. 11 Constant Folding and Propagation: Algorithm We assume each quad has the form: (opr, OP1, OP2, RES) For each quadruple in the intermediate representation in turn: 1. Substitute constant value for OP1 if possible. 2. Substitute constant value for OP2 if possible. 3. Remove RES from T if present 4. If OP1 and OP2 are constants: 1. Delete the quadruple 2. Place (Res, OP1 opr OP2) in T 5. If opr is a unary operator, and OP1 is constant, 1. Delete the quadruple 2. Place (Res, opr OP1) in T 6. If opr is := and OP1 is a constant, place (RES, OP1) in T 12 6
7 Step 1: Constant Propagation on OP1 If OP 1 is an identifier, and (OP 1, V 1 ) is in T: replace OP 1 with V 1 Example: (:=, 5,, a) => (:=, 5,, a) (+, a, b, t1) (+, 5, b, t1) 13 Step 2: Constant Propagation on OP2 If OP 2 is an identifier, and (OP 2, V 2 ) is in T: replace OP 2 with V 2 Example: (:=, 5,, a) => (:=, 5,, a) (+, b, a, t1) (+, b, 5, t1) 14 7
8 Step 3: Clearning stored value of RES If the quad has a specified value for RES (e.g., most operators except for jump statements) THEN the execution of the quadruple will change the value of RES. We should thus remove the old value associated with RES from T. The next step MAY store a new value for RES in T 15 Step 4: Constant Folding: binary operators By now, if OP1 or OP2 were variables holding constants, they would have been replaced by the constants. if OP 1 and OP 2 are both constants: Eliminate the quadruple. Calculate v = OP 1 op OP 2 Add (RES, v) to T Example: (*, 5, 3, t1) => - but place (t1, 15) in T 16 8
9 Step 4 Cont.: Constant Folding error in calculation If the calculatation in the prior slide produced an error (e.g., div. by zero) It might be the case that this quad won t be reached in a given execution of the final program. For this reason, the compiler does not issue an error and quit. Rather, it issues a warning. And leaves the quadruple as it was. Example: (/, 5, 0, t1) => (/, 5, 0, t1) 17 Step 5: Constant Folding: unary operators By now, if OP1 was a variables holding a constant, it would have been replaced by the constant in step 1. if OP 1 is a constant: Eliminate the quadruple. Calculate v = opr OP 1 Add (RES, v) to T Example: (_, 5, t1) => - but place (t1, -5) in T 18 9
10 Step 6: Assignment Statement If operator is := and OP1 is a constant, then we need to register the value of RES Place (RES, OP1) in T Example: (:=, 5,, x) => Place (x, 5) in T 19 Exercise Assume the following code and corresponding quadruples int i; float f; i=2+3; i=4; f=i+2.5; (+, 2, 3, T1) (:=, T1,, i) (:=, T3,, f) Apply the above steps to simplify the code * ITOF: Convert int to float 20 10
11 Exercise solution (+, 2, 3, T1) (:=, T1,, i) (:=, T3,, f) T = {} 1. (+, 2, 3, T1) step 4 applies no error in calc. delete quad T = {(T1,5)} (:=, T1,, i) (:=, T3,, f) 21 Exercise solution (+, 2, 3, T1) (:=, T1,, i) (=, T3,, f) T = {(T1,5)} 2. (:=, T1,, i) step 1 applies quad becomes (:=, 5,, i) step 6 applies T = {(i,5) (T1,5)} (:=, 5,, i) (:=, T3,, f) 22 11
12 Exercise solution (+, 2, 3, T1) (:=, T1,, i) (=, T3,, f) T = {(i,5) (T1,5)} 3. step 3 applies T = {(T1,5)} step 6 applies T = {(i,4) (T1,5)} (:=, 5,, i) (:=, T3,, f) 23 Exercise solution (+, 2, 3, T1) (:=, T1,, i) (=, T3,, f) T = {(i,4) (T1,5)} 4. (ITOF, i,, T2) step 1 applies (ITOF, 4,, T2) step 5 applies delete quad place (T2, 4.0) in T (:=, 5,, i) (:=, T3,, f) 24 12
13 Exercise solution (+, 2, 3, T1) (:=, T1,, i) (=, T3,, f) T = {(T2,4.0)(i,4)(T1,5)} 5. (+, T2, 2.5, T3) step 1 applies (+, 4.0, 2.5, T3) step 4 applies delete quad place (T3, 6.5) in T (:=, 5,, i) (:=, T3,, f) 25 Exercise solution (+, 2, 3, T1) (:=, T1,, i) (:=, T3,, f) T = {(T3,6.5)(T2,4.0)(i,4)(T1,5)} 6. (:=, T3,, f) step 1 applies (:=, 6.5,, f) step 6 applies place (f, 6.5) in T (:=, 5,, i) (:=, 6.5,, f) 26 13
14 Execution at compile time: Nonsequential Execution The preceding discussion assumed that flow of control in the program passes from one quadruple to the next throughout the quadruple list However, loops, if statements, etc. can result in jump operators in the quadruples. With conditional and nonconditional jumps, we cannot be sure that any one statement always follows the one before it in the quad list. 27 Execution at compile time: Nonsequential Execution The solution here is to apply the optimisation only to sequences of quads where we can verify sequential operation. Simple approach is to organise the quads in terms of a directed graph, where: Each node is a quadruple An arc is drawn between each quadruple and the quadruples which could possibly be the next The next quad can be found: Non-jump statements: the next quad is always that which is next in the list. Nonconditional jump: the next is that at the end of the jump. Conditional jump, both the previous apply
15 Execution at compile time: Nonsequential Execution 1 (:=, 0,, i) ; initialisation 2 (<, i, 5, t1) ; condition 3 (jfalse, t1,, 8) 4-5 <body of loop> 6 (+, i, 1, i) ; Iteration 7 (jump_to,,, 2) Execution at compile time: Nonsequential Execution From this graph, we can locate sequences of quads where each quad has only one incoming arc (one point from which control can flow. The previous optimisations can be performed on these sequences T must be cleared at the start of each sequence Sequences: (1), (2,3), (4, 5, 6, 7) (8) 30 15
16 Nonsequential Execution: more intelligent applications Note that more intelligent compilers could avoid clearing T in some cases, e.g., After a conditional branch, each branch could take a copy of T and continue processing When the graph branches then rejoins (e.g. as in the quadruples for an if statement),the values in T could be maintained after the re-joining except for those values affected DURING the separation
8 Optimisation. 8.2 Machine-Independent Optimisation
8 8.2 Machine-Independent 8.2.2 Eliminating Redundant Instructions The aim of this optimisation is to identify instructions that do not need to be performed, and eliminating them. This can be done at the
More information8 Optimisation. 8.2 Machine-Independent Optimisation
8 8.2 Machine-Independent 8.2.4 Replacing binary with Unary operations Replacing binary with Unary operators The following operations do not produce redundant quads: a=c-d; 1. (-, c, d, t1) b=d-c; => 2.
More informationLesson 7: Code optimisation. Compilers. Code optimisation. Code optimisation. Kinds of optimisations. Introductory concepts
Compilers Lesson 7: Code optimisation Third year Spring term Alfonso Ortega: alfonso.ortega@uam.es Enrique Alfonseca: Enrique.Alfonseca@uam.es Code optimisation Introductory concepts This process can be
More informationComp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation
Comp 204: Computer Systems and Their Implementation Lecture 22: Code Generation and Optimisation 1 Today Code generation Three address code Code optimisation Techniques Classification of optimisations
More informationProgramming Language Implementation
A Practical Introduction to Programming Language Implementation 2014: Week 12 Optimisation College of Information Science and Engineering Ritsumeikan University 1 review of last week s topics why primitives
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 informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationUndergraduate Compilers in a Day
Question of the Day Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution
More informationCOMPILER CONSTRUCTION (Intermediate Code: three address, control flow)
COMPILER CONSTRUCTION (Intermediate Code: three address, control flow) Prof. K R Chowdhary Email: kr.chowdhary@jietjodhpur.ac.in Campus Director, JIET, Jodhpur Thursday 18 th October, 2018 kr chowdhary
More information9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement
Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationOverview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1
CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity
More informationIntermediate Representations
Intermediate Representations A variety of intermediate representations are used in compilers Most common intermediate representations are: Abstract Syntax Tree Directed Acyclic Graph (DAG) Three-Address
More informationExpression Evaluation and Control Flow. Outline
Expression Evaluation and Control Flow In Text: Chapter 6 Outline Notation Operator Evaluation Order Operand Evaluation Order Overloaded operators Type conversions Short-circuit evaluation of conditions
More informationUnder the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world.
Under the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world. Supercharge your PS3 game code Part 1: Compiler internals.
More informationAnnouncements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop
Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00
More informationTorben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer
Torben./Egidius Mogensen Introduction to Compiler Design ^ Springer Contents 1 Lexical Analysis 1 1.1 Regular Expressions 2 1.1.1 Shorthands 4 1.1.2 Examples 5 1.2 Nondeterministic Finite Automata 6 1.3
More informationSEQUENCING AND SCHEDULING ACTIVITIES
SEQUENCING AND SCHEDULING ACTIVITIES SEQUENCING AND SCHEDULING ACTIVITIES Throughout a project, we will require a schedule that clearly indicates when each of the project s activities is planned to occur
More informationCS 403 Compiler Construction Lecture 10 Code Optimization [Based on Chapter 8.5, 9.1 of Aho2]
CS 403 Compiler Construction Lecture 10 Code Optimization [Based on Chapter 8.5, 9.1 of Aho2] 1 his Lecture 2 1 Remember: Phases of a Compiler his lecture: Code Optimization means floating point 3 What
More informationProf. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan
Language Processing Systems Prof. Mohamed Hamada Software ngineering Lab. The University of Aizu Japan Intermediate/Code Generation Source language Scanner (lexical analysis) tokens Parser (syntax analysis)
More informationPrinciples of Computer Science
Principles of Computer Science Lecture 2 Dr. Horia V. Corcalciuc Horia Hulubei National Institute for R&D in Physics and Nuclear Engineering (IFIN-HH) January 27, 2016 Loops: do-while do-while loops do
More informationIntermediate Code & Local Optimizations. Lecture 20
Intermediate Code & Local Optimizations Lecture 20 Lecture Outline Intermediate code Local optimizations Next time: global optimizations 2 Code Generation Summary We have discussed Runtime organization
More informationCS153: Compilers Lecture 15: Local Optimization
CS153: Compilers Lecture 15: Local Optimization Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 4 out Due Thursday Oct 25 (2 days) Project 5 out Due Tuesday Nov 13 (21 days)
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 informationCompiler construction in4303 lecture 9
Compiler construction in4303 lecture 9 Code generation Chapter 4.2.5, 4.2.7, 4.2.11 4.3 Overview Code generation for basic blocks instruction selection:[burs] register allocation: graph coloring instruction
More informationLECTURE 17. Expressions and Assignment
LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)
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 informationtokens parser 1. postfix notation, 2. graphical representation (such as syntax tree or dag), 3. three address code
Intermediate generation source program lexical analyzer tokens parser parse tree generation intermediate language The intermediate language can be one of the following: 1. postfix notation, 2. graphical
More informationLecture Outline. Intermediate code Intermediate Code & Local Optimizations. Local optimizations. Lecture 14. Next time: global optimizations
Lecture Outline Intermediate code Intermediate Code & Local Optimizations Lecture 14 Local optimizations Next time: global optimizations Prof. Aiken CS 143 Lecture 14 1 Prof. Aiken CS 143 Lecture 14 2
More informationCompiler Optimization
Compiler Optimization The compiler translates programs written in a high-level language to assembly language code Assembly language code is translated to object code by an assembler Object code modules
More informationIntermediate Representations
Compiler Design 1 Intermediate Representations Compiler Design 2 Front End & Back End The portion of the compiler that does scanning, parsing and static semantic analysis is called the front-end. The translation
More informationMotivation. Both human- and computer-generated programs sometimes contain data-flow anomalies.
Motivation Both human- and computer-generated programs sometimes contain data-flow anomalies. These anomalies result in the program being worse, in some sense, than it was intended to be. Data-flow analysis
More informationIntroduction to Machine-Independent Optimizations - 6
Introduction to Machine-Independent Optimizations - 6 Machine-Independent Optimization Algorithms Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course
More informationCOMPUTER ORGANIZATION & ARCHITECTURE
COMPUTER ORGANIZATION & ARCHITECTURE Instructions Sets Architecture Lesson 5a 1 What are Instruction Sets The complete collection of instructions that are understood by a CPU Can be considered as a functional
More informationCredits and Disclaimers
Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 2 nd Edition by Bryant and O'Hallaron
More informationBuilding a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano
Building a Runnable Program and Code Improvement Dario Marasco, Greg Klepic, Tess DiStefano Building a Runnable Program Review Front end code Source code analysis Syntax tree Back end code Target code
More informationCPS104 Recitation: Assembly Programming
CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in
More informationMulti-dimensional Arrays
Multi-dimensional Arrays IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula) A 2D array is a 1D array of 1D arrays Java uses arrays of pointers to arrays for >1D
More informationIntermediate Representations
Most of the material in this lecture comes from Chapter 5 of EaC2 Intermediate Representations Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP
More informationProject 5: Extensions to the MiniJava Compiler
Project 5: Extensions to the MiniJava Compiler Due: Friday, March 7, 12:30 pm. In this assignment you will make two required extensions to the target code generator. You will also make an extension to
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 informationProgramming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee
1 0 1 0 Foundation Topics 1 0 Chapter 1 - Introduction to Programming 1 1 Systems Development Life Cycle N/A N/A N/A N/A N/A N/A 1-8 12-13 1 2 Bloodshed Dev-C++ 5 Compiler/IDE N/A N/A N/A N/A N/A N/A N/A
More informationIntermediate Code & Local Optimizations
Lecture Outline Intermediate Code & Local Optimizations Intermediate code Local optimizations Compiler Design I (2011) 2 Code Generation Summary We have so far discussed Runtime organization Simple stack
More informationRunning class Timing on Java HotSpot VM, 1
Compiler construction 2009 Lecture 3. A first look at optimization: Peephole optimization. A simple example A Java class public class A { public static int f (int x) { int r = 3; int s = r + 5; return
More informationAdding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit
Part 5 Adding Binary Integers Arithmetic Logic Unit = Adding Binary Integers Adding Base Numbers Computer's add binary numbers the same way that we do with decimal Columns are aligned, added, and "'s"
More informationPower Estimation of UVA CS754 CMP Architecture
Introduction Power Estimation of UVA CS754 CMP Architecture Mateja Putic mateja@virginia.edu Early power analysis has become an essential part of determining the feasibility of microprocessor design. As
More informationSemantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis?
Semantic analysis and intermediate representations Which methods / formalisms are used in the various phases during the analysis? The task of this phase is to check the "static semantics" and generate
More information55:132/22C:160, HPCA Spring 2011
55:132/22C:160, HPCA Spring 2011 Second Lecture Slide Set Instruction Set Architecture Instruction Set Architecture ISA, the boundary between software and hardware Specifies the logical machine that is
More informationRAID 0 (non-redundant) RAID Types 4/25/2011
Exam 3 Review COMP375 Topics I/O controllers chapter 7 Disk performance section 6.3-6.4 RAID section 6.2 Pipelining section 12.4 Superscalar chapter 14 RISC chapter 13 Parallel Processors chapter 18 Security
More informationCSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.
1. (10 points) Write a regular ression or regular ressions that generate the following sets of strings. (a) (5 points) All strings containing a s, b s, and c s with at least one a and at least one b. [abc]*a[abc]*b[abc]*
More informationAbout the Authors... iii Introduction... xvii. Chapter 1: System Software... 1
Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...
More informationSemantic actions for expressions
Semantic actions for expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate representations
More informationIntermediate Representations
Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end
More informationComputer Science II (20082) Week 1: Review and Inheritance
Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax
More informationCOMPILER DESIGN - CODE OPTIMIZATION
COMPILER DESIGN - CODE OPTIMIZATION http://www.tutorialspoint.com/compiler_design/compiler_design_code_optimization.htm Copyright tutorialspoint.com Optimization is a program transformation technique,
More informationCSE 401/M501 Compilers
CSE 401/M501 Compilers Intermediate Representations Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 G-1 Agenda Survey of Intermediate Representations Graphical Concrete/Abstract Syntax Trees (ASTs)
More informationIntroduction to Code Optimization. Lecture 36: Local Optimization. Basic Blocks. Basic-Block Example
Lecture 36: Local Optimization [Adapted from notes by R. Bodik and G. Necula] Introduction to Code Optimization Code optimization is the usual term, but is grossly misnamed, since code produced by optimizers
More information3. You are writing code for a business application by using C#. You write the following statement to declare an array:
Lesson 1: Introduction to Programming 1. You need to gain a better understanding of the solution before writing the program. You decide to develop an algorithm that lists all necessary steps to perform
More informationCS143 - Written Assignment 4 Reference Solutions
CS143 - Written Assignment 4 Reference Solutions 1. Consider the following program in Cool, representing a slightly over-engineered implementation which calculates the factorial of 3 using an operator
More informationAgenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1
Agenda CSE P 501 Compilers Instruction Selection Hal Perkins Autumn 2005 Compiler back-end organization Low-level intermediate representations Trees Linear Instruction selection algorithms Tree pattern
More informationInstruction Sets: Characteristics and Functions Addressing Modes
Instruction Sets: Characteristics and Functions Addressing Modes Chapters 10 and 11, William Stallings Computer Organization and Architecture 7 th Edition What is an Instruction Set? The complete collection
More informationCS415 Compilers. Intermediate Represeation & Code Generation
CS415 Compilers Intermediate Represeation & Code Generation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review - Types of Intermediate Representations
More informationQuadsim Version 2.1 Student Manual
Boston University OpenBU Computer Science http://open.bu.edu CAS: Computer Science: Technical Reports 1993-02-21 Quadsim Version 2.1 Student Manual Shaban, Marwan Boston University Computer Science Department
More informationCSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow
CSE 452: Programming Languages Expressions and Control Flow Outline of Today s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and
More informationAS/A Level Computing Syllabus 2011
AS/A Level Computing Syllabus 2011 Section 3 - System Software Mechanisms - - Machine Architecture - - Database Theory - - Programming Paradigms - Chapter 3.3 Computer Architectures & Fetch-Execute Cycle
More informationWhat is Superscalar? CSCI 4717 Computer Architecture. Why the drive toward Superscalar? What is Superscalar? (continued) In class exercise
CSCI 4717/5717 Computer Architecture Topic: Instruction Level Parallelism Reading: Stallings, Chapter 14 What is Superscalar? A machine designed to improve the performance of the execution of scalar instructions.
More informationCopyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies
More informationSummary: Direct Code Generation
Summary: Direct Code Generation 1 Direct Code Generation Code generation involves the generation of the target representation (object code) from the annotated parse tree (or Abstract Syntactic Tree, AST)
More informationCredits and Disclaimers
Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 3 nd Edition by Bryant and O'Hallaron
More informationVector and Parallel Processors. Amdahl's Law
Vector and Parallel Processors. Vector processors are processors which have special hardware for performing operations on vectors: generally, this takes the form of a deep pipeline specialized for this
More informationCS356 Unit 12a. Logic Circuits. Combinational Logic Gates BASIC HW. Processor Hardware Organization Pipelining
2a. 2a.2 CS356 Unit 2a Processor Hardware Organization Pipelining BASIC HW Logic Circuits 2a.3 Combinational Logic Gates 2a.4 logic Performs a specific function (mapping of input combinations to desired
More informationCompiler construction 2009
Compiler construction 2009 Lecture 3 JVM and optimization. A first look at optimization: Peephole optimization. A simple example A Java class public class A { public static int f (int x) { int r = 3; int
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 informationA simple syntax-directed
Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
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 informationParsing and Pattern Recognition
Topics in IT 1 Parsing and Pattern Recognition Week 10 Lexical analysis College of Information Science and Engineering Ritsumeikan University 1 this week mid-term evaluation review lexical analysis its
More informationIntermediate representations IR #1: CPS/L 3. Code example. Advanced Compiler Construction Michel Schinz
Intermediate representations Intermediate representations Advanced Compiler Construction Michel Schinz 2016 03 03 The term intermediate representation (IR) or intermediate language designates the data-structure(s)
More informationImplementing Algorithms in MIPS Assembly
1 / 18 Implementing Algorithms in MIPS Assembly (Part 1) January 28 30, 2013 2 / 18 Outline Effective documentation Arithmetic and logical expressions Compositionality Sequentializing complex expressions
More informationMachine-Independent Optimizations
Chapter 9 Machine-Independent Optimizations High-level language constructs can introduce substantial run-time overhead if we naively translate each construct independently into machine code. This chapter
More informationIntermediate Representa.on
IR Intermediate Representa.on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Intermediate Representation Language Specific Language + Machine Independent Machine Dependent
More informationIn Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.
Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability.
More informationDynamic Translation for EPIC Architectures
Dynamic Translation for EPIC Architectures David R. Ditzel Chief Architect for Hybrid Computing, VP IAG Intel Corporation Presentation for 8 th Workshop on EPIC Architectures April 24, 2010 1 Dynamic Translation
More informationChapter 3. Section 3.10 Type of Expressions and Automatic Conversion. CS 50 Hathairat Rattanasook
Chapter 3 Section 3.10 Type of Expressions and Automatic Conversion CS 50 Hathairat Rattanasook Types of Expressions and Automatic Conversions In C, every expression has an associated type. Operators and
More informationLecture 2: Variables & Assignments
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 2: Variables & Assignments (Sections 2.1-2.3,2.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,
More informationCOMP455: COMPILER AND LANGUAGE DESIGN. Dr. Alaa Aljanaby University of Nizwa Spring 2013
COMP455: COMPILER AND LANGUAGE DESIGN Dr. Alaa Aljanaby University of Nizwa Spring 2013 Chapter 1: Introduction Compilers draw together all of the theory and techniques that you ve learned about in most
More informationCS 432 Fall Mike Lam, Professor. Code Generation
CS 432 Fall 2015 Mike Lam, Professor Code Generation 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 00
More informationCommunicating with People (2.8)
Communicating with People (2.8) For communication Use characters and strings Characters 8-bit (one byte) data for ASCII lb $t0, 0($sp) ; load byte Load a byte from memory, placing it in the rightmost 8-bits
More informationCS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II
CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II Example: Simple variables Handout written by Julie Zelenski and Nick Parlante A variable is a location in memory. When a variable
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 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 informationLecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines
Lecture Outline Code Generation Lecture 30 (based on slides by R. Bodik) Stack machines The MIPS assembly language The x86 assembly language A simple source language Stack-machine implementation of the
More informationCOMPILER CONSTRUCTION Seminar 03 TDDB
COMPILER CONSTRUCTION Seminar 03 TDDB44 2016 Martin Sjölund (martin.sjolund@liu.se) Mahder Gebremedhin (mahder.gebremedhin@liu.se) Department of Computer and Information Science Linköping University LABS
More informationIntroduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands
Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires
More informationMore Programming Constructs -- Introduction
More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and
More informationComputer Architecture and Organization
6-1 Chapter 6 - Languages and the Machine Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 6 Languages and the Machine 6-2 Chapter 6 - Languages and the Machine Chapter
More information1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.
Code No: R05320502 Set No. 1 1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. 2. Construct predictive parsing
More informationCompilers. Compiler Construction Tutorial The Front-end
Compilers Compiler Construction Tutorial The Front-end Salahaddin University College of Engineering Software Engineering Department 2011-2012 Amanj Sherwany http://www.amanj.me/wiki/doku.php?id=teaching:su:compilers
More informationCompiler Construction SMD163. Understanding Optimization: Optimization is not Magic: Goals of Optimization: Lecture 11: Introduction to optimization
Compiler Construction SMD163 Understanding Optimization: Lecture 11: Introduction to optimization Viktor Leijon & Peter Jonsson with slides by Johan Nordlander Contains material generously provided by
More informationWhere we are. Instruction selection. Abstract Assembly. CS 4120 Introduction to Compilers
Where we are CS 420 Introduction to Compilers Andrew Myers Cornell University Lecture 8: Instruction Selection 5 Oct 20 Intermediate code Canonical intermediate code Abstract assembly code Assembly code
More information