TARGET CODE -Next Usage

Slides:



Advertisements
Similar presentations
Target Code Generation
Advertisements

Register Usage Keep as many values in registers as possible Register assignment Register allocation Popular techniques – Local vs. global – Graph coloring.
Lecture 11: Code Optimization CS 540 George Mason University.
Compiler Construction Sohail Aslam Lecture ExampleExample a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2.
1 CS 201 Compiler Construction Machine Code Generation.
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
A simple register allocation optimization scheme.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Lecture 26 Epilogue: Or Everything else you Wanted to Know about Compilers (more accurately Everything else I wanted you to Know) Topics Getreg – Error.
Lecture 12 – Code Generation Eran Yahav 1 Reference: Dragon 8. MCD
Lecture 11 – Code Generation Eran Yahav 1 Reference: Dragon 8. MCD
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Lecture 23 Basic Blocks Topics Code Generation Readings: 9 April 17, 2006 CSCE 531 Compiler Construction.
Code Generation Professor Yihjia Tsai Tamkang University.
Introduction to Kernel
Lecture 25 Generating Code for Basic Blocks Topics Code Generation Readings: April 19, 2006 CSCE 531 Compiler Construction.
Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into.
Improving Code Generation Honors Compilers April 16 th 2002.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
1 Code Generation Part II Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
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.
Lecture by: Prof. Pooja Vaishnav.  Language Processor implementations are highly influenced by the kind of storage structure used for program variables.
Chapter 7 Object Code Generation. Chapter 7 -- Object Code Generation2  Statements in 3AC are simple enough that it is usually no great problem to map.
Compilers Modern Compiler Design
Topic #9: Target Code EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
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 Analysis and Optimization Pat Morin COMP 3002.
Compilation (Semester A, 2013/14)
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Introduction to Kernel
Compiler Design (40-414) Main Text Book:
Chapter 2 Memory and process management
Computer Science 210 Computer Organization
Computer architecture and computer organization
Chapter 11 Instruction Sets
Assembly Language Ms. V.Anitha AP/CSE SCT
Optimization Code Optimization ©SoftMoore Consulting.
Compiler Construction
The fetch-execute cycle
Computer Science 210 Computer Organization
Code Generation Part I Chapter 9
Programming Languages (CS 550) Mini Language Compiler
Code Generation.
8086 Registers Module M14.2 Sections 9.2, 10.1.
Unit IV Code Generation
Instruction Scheduling Hal Perkins Winter 2008
Code Generation Part I Chapter 8 (1st ed. Ch.9)
The University of Adelaide, School of Computer Science
CS 201 Compiler Construction
Code Generation Part I Chapter 9
Advanced Computer Architecture
Lecture 16: Register Allocation
8 Code Generation Topics A simple code generator algorithm
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Compiler Construction
Code Generation Part II
Target Code Generation
TARGET CODE GENERATION
Computer Organization and Assembly Language
Instruction Scheduling Hal Perkins Autumn 2011
Programming Languages (CS 360) Mini Language Compiler
Run-time environments
Live Variables – Basic Block
8/23/
Code Optimization.
Presentation transcript:

TARGET CODE -Next Usage Rajat Sethi 04CS3022 TARGET CODE -Next Usage

Topics to be covered Next Use Information Code Generation Computation using Backward Scan Code Generation Register and Address Descriptor Algorithm getreg() function Example

Next Usage This technique is employed in dead code optimization. The instructions with no ‘next use’ are removed from the block. If the name in a register is no longer needed, then the register can be assigned to some other name. We collect next-use information about names in a basic block. Note that we consider only the variables in the same block.

Backward Scan: statement i : x := y op z STEP 1: Attach to statement i, attribute information of next use of x, y and z. STEP 2: In symbol table, set x to “no next use” and “not live” STEP 3: In symbol table set the next uses of y and z to I and also to “live” NOTE : The orders of Step 2 and Step 3 should not be interchanged because x may be y or z. e.g.:- x := x+1

Register & Address Descriptors Register Descriptor: It keeps track of what is in each register. It is consulted whenever a new register is needed. E.g.: R0 contains t, y, z. Address Descriptor: It keeps tract of the location(s) where the current value of the name can be found at the runtime. The location might be register, stack or memory location.

Code Generation Algorithm STEP 1 Find space L to store value of x using function getreg(). For Y, see whether it is stored in L. If yes, perform op Z,L Else perform mov Y,L; op Z,L Generate : op Z,L Update address descriptor of X. If X stored in any other register, remove it. If the current values of Y and Z have no next use then free the registers. STEP 2 STEP 3 STEP 4

Function getreg(); STEP 1: If the name y is in a register , that holds the value of no other names (in other words no other names point to the same register as y does), and y is not live and has no next use after the execution of y = x op z, then :- return L. Update the address descriptor of y , so that y is no longer in L. STEP 2: Failing (1), return an empty register for L if it exists. STEP 3: Failing (2), if x has a next use in the block, or if op requires a register then :- find an occupied register R. MOV(R,M) if value of R is not in proper M. If R holds value of many variables, generate a MOV for each of the variables. STEP 4: Failing (3), select the memory location of x as L.

Example: Statements Code Generated Register Descriptor Address t = a-b d=(a-b) + (a-c) + (a-c) Statements Code Generated Register Descriptor Address t = a-b MOV a, R0 SUB b, R0 R0 -> t t -> R0 u= a-c MOV a, R1 SUB c, R1 R1 -> u u -> R1 v= t+u ADD R1,R0 R0 -> v v -> R0 d= v+u MOV R0,d R0 -> d d -> R0

THANK YOU