Compiler Construction Sohail Aslam Lecture 42. 2 Code Generation  The code generation problem is the task of mapping intermediate code to machine code.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

LEUCEMIA MIELOIDE AGUDA TIPO 0
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman 1-1.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
ZMQS ZMQS
SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan
Embedded Software 1. General 8051 features (excluding I/O) CPU 8 bit microcontroller The basic registers include (more discussed later) The 8-bit A (accumulator)
Chapter 4: Machine Language
ABC Technology Project
© S Haughton more than 3?
1 Code Generation The target machine Instruction selection and register allocation Basic blocks and flow graphs A simple code generator Peephole optimization.
Progam.-(6)* Write a program to Display series of Leaner, Even and odd using by LOOP command and Direct Offset address. Design by : sir Masood.
Twenty Questions Subject: Twenty Questions
Chapter 4 The Von Neumann Model
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Squares and Square Root WALK. Solve each problem REVIEW:
Energy & Green Urbanism Markku Lappalainen Aalto University.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Intermediate Representations CS 671 February 12, 2008.
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
We will resume in: 25 Minutes.
1 Unit 1 Kinematics Chapter 1 Day
1 PART 1 ILLUSTRATION OF DOCUMENTS  Brief introduction to the documents contained in the envelope  Detailed clarification of the documents content.
Topics Left Superscalar machines IA64 / EPIC architecture
Compiler Construction
©UCB CPSC 161 Lecture 3 Prof. L.N. Bhuyan
Overheads for Computers as Components 2nd ed.
1 CIS 461 Compiler Design and Construction Fall 2014 Instructor: Hugh McGuire slides derived from Tevfik Bultan, Keith Cooper, and Linda Torczon Lecture-Module.
Target Code Generation
MIPS Assembly Tutorial
THUMB Instructions: Branching and Data Processing
Target code Generation Made by – Siddharth Rakesh 11CS30036 Date – 12/11/2013.
Tutorial 2 IDE for ARM 7 board (2). Outline Introduce the Debug mode of uVision4 2.
Code Generation.
Based on Mike Feeley’s and Tamara Munzner’s original slides; Modified by George Tsiknis Parameters and Local Variables Relevant Information CPSC 213 Companion.
Compiler Construction Sohail Aslam Lecture ExampleExample a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2.
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
CS 31003: Compilers Introduction to Phases of Compiler.
Lecture 23 Basic Blocks Topics Code Generation Readings: 9 April 17, 2006 CSCE 531 Compiler Construction.
1 Code Generation. 2 Position of a Code Generator in the Compiler Model Front-End Code Optimizer Source program Symbol Table Lexical error Syntax error.
Compilers Modern Compiler Design
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
Code Generation Part I Chapter 8 (1st ed. Ch.9)
Code Generation Part I Chapter 9
Code Generation.
Computer Programming Machine and Assembly.
Code Generation Part I Chapter 8 (1st ed. Ch.9)
Code Generation Part I Chapter 9
8 Code Generation Topics A simple code generator algorithm
Presentation transcript:

Compiler Construction Sohail Aslam Lecture 42

2 Code Generation  The code generation problem is the task of mapping intermediate code to machine code.

3 Code Generation Requirements:  Correctness  Efficiency

4 Issues:Issues:  Input language: intermediate code (optimized or not)  Target: machine code, assembly language

5 Issues:Issues:  Memory management: mapping names to data objects in the run-time system.  Instruction Selection  Instruction Scheduling  Register allocation

6 Issues:Issues:  Memory management: mapping names to data objects in the run-time system.  Instruction Selection  Instruction Scheduling  Register allocation

7 Issues:Issues:  Memory management: mapping names to data objects in the run-time system.  Instruction Selection  Instruction Scheduling  Register allocation

8 Issues:Issues:  Memory management: mapping names to data objects in the run-time system.  Instruction Selection  Instruction Scheduling  Register allocation

9 Target: Assembly Language General Characteristics  Byte-addressable with 4-byte words  N general -purpose registers  Two-address instructions: op source, destination

10 Target: Assembly Language Operations: MOV source, destination ADD source, destination SUB source, destination (dest = dest – source) GOTO address CJ conditional jump

11 Addressing Modes MODEFORMADDRESSADDED COST absoluteMM1 registerRR0 indexedc(R)c + contents(R)1 indirect register*Rcontents(R)0 indirect indexed*c(R)contents(c+contents(R))1 literal#cc1 stackSP 0 indexed stackc(SP)c + contents(SP)1

12 Target: Assembly Language Instruction costs: The cost corresponds to length of instruction MOV R0,R1 ; R0 = c(R1) has cost 1 MOV R5,M ; M = c(R5) has cost 2: 1 for instruction, 1 additional for memory address

13 Simple Code Generation  Define a target code sequence for each intermediate code statement type.

14 Simple Code Generation Intermediatebecomes… a = bMOV b,a a = b[c]MOV addr(b),R0 ADD c, R0 MOV *R0,a

15 Simple Code Generation Intermediatebecomes… a = b + cMOV b,a ADD c,a a[b] = cMOV addr(a),R0 ADD b,R0 MOV c,*R0

16  Consider the C statement: a[i] = b[c[j]]; t1 := c[j] MOV addr(c), R0 ADD j, R0 MOV *R0, t1 t2 := b[t1] MOV addr(b), R0 ADD t1, R0 MOV *R0, t2 a[i] := t2 MOV address(a), R0 ADD i, R0 MOV t2, *R0  The cost of this code is 18 and we are forced to allocate space for two temporaries.

17 ProblemsProblems  Local decisions do not produce good code.  Do not take temporary variables into account

18 OptimizeOptimize  Get rid of the temporaries: MOV addr(c), R0 ADD j, R0 MOV addr(b), R1 ADD *R0, R1 MOV addr(a), R2 ADD i, R2 MOV *R1, *R2 The cost of this code is 12.

19 a[i] = b[c[j]]; t1 := c[j] MOV addr(c), R0 ADD j, R0 MOV *R0, t1 t2 := b[t1] MOV addr(b), R0 ADD t1, R0 MOV *R0, t2 a[i] := t2 MOV address(a), R0 ADD i, R0 MOV t2, *R0 The cost of this code is 18 MOV addr(c), R0 ADD j, R0 MOV addr(b), R1 ADD *R0, R1 MOV addr(a), R2 ADD i, R2 MOV *R1, *R2 The cost of this code is 12.

20 Can optimize further … MOV addr(c), R0 ADD j, R0 MOV addr(a), R2 ADD i, R2 MOV *addr(b)(R0), *R2 The cost of this code is 10.

21 Can optimize further …  What is needed is a way to generate machine code based on past and future use of the data.