For Example: User level quicksort program Three address code.

Slides:



Advertisements
Similar presentations
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
Advertisements

P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
The University of Adelaide, School of Computer Science
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
Code optimization: –A transformation to a program to make it run faster and/or take up less space –Optimization should be safe, preserve the meaning of.
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
10/6: Lecture Topics Procedure call Calling conventions The stack
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Procedure Calls Prof. Sirer CS 316 Cornell University.
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Code Generation Mooly Sagiv html:// Chapter 4.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Feedback: Keep, Quit, Start
Peephole Optimization Final pass over generated code: examine a few consecutive instructions: 2 to 4 See if an obvious replacement is possible: store/load.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
Previous finals up on the web page use them as practice problems look at them early.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
Chapter 9: Subprogram Control
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.
Schedule Midterm out tomorrow, due by next Monday Final during finals week Project updates next week.
From last class. The above is Click’s solution (PLDI 95)
Procedure Optimizations and Interprocedural Analysis Chapter 15, 19 Mooly Sagiv.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Runtime Environments Compiler Construction Chapter 7.
Interprocedural Optimizations CS 671 April 8, 2008.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014.
Basic Semantics Associating meaning with language entities.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
COMP3190: Principle of Programming Languages
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
V 1.01 Arrays and Pointers in C A pointer variable is a variable that contains the address of another variable. An array is a collection of like elements,
CSC 8505 Compiler Construction Runtime Environments.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
Procedures and Functions Procedures and Functions – subprograms – are named fragments of program they can be called from numerous places  within a main.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Computer Architecture & Operations I
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization Overview and Examples
Computer structure: Procedure Calls
Mooly Sagiv html://
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
Introduction to Compilers Tim Teitelbaum
Procedures (Functions)
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Optimizing Transformations Hal Perkins Autumn 2011
Stack Frame Linkage.
The University of Adelaide, School of Computer Science
Subroutines – parameter passing
Optimizing Transformations Hal Perkins Winter 2008
Computer Organization and Design Assembly & Compilation
Procedures and Calling Conventions
8 Code Generation Topics A simple code generator algorithm
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Intermediate Code Generation
Compiler Construction
Runtime Environments What is in the memory?.
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Compilers Jakub Yaghob
Procedures and Macros.
Presentation transcript:

For Example: User level quicksort program Three address code

Flow graph

For Block B5

For Block B5

MOV a, R0 ADD b, R0 MOV c, R1 SUB d, R1 MOV R0, t1 MOV e, R0 For Example: (a+b)+(e+(c-d)) t1: = a+b t2:= c-d t3:=e+t2 t4=t1+t3 Instruction order as: MOV a, R0 ADD b, R0 MOV c, R1 SUB d, R1 MOV R0, t1 MOV e, R0 ADD R0, R1 MOV t1, R0 ADD R1, R0 MOV R0,t4

If, we change the above instructions order as: t2:= c-d t3:=e+t2 t1: = a+b t4=t1+t3 Now we get the improved cost as MOV c, R0 SUB d, R0 MOV e, R1 ADD R0, R1 MOV a, R0 ADD b, R0 ADD R1, R0 MOV R0,t4

Inter-Procedural Optimization In this technique, we are used all kinds of optimization techniques to improve the performance of the program. a) Tail call & tail recursion elimination Transformation that applies to calls Reduce procedure-call overhead and enable additional optimizations A call from procedure f() to procedure g() is a tail call if the only thing f() does, after g() returns to it, is itself return The call is tail recursive if f() and g() are the same b) In-lining Replaces calls to procedures with copies of their bodies Converts calls from opaque (not transparent) objects to local code Exposes the “effects” of the called procedure Extends the compilation region Language support: the inline attribute But the compiler can decide per call-site, rather than per -procedure

d) Link Time or Compile Time c) Leaf routine optimization A procedure that is a leaf in the call graph. It calls no other procedures. Simplifies the way parameters are passed to a leaf routine. Removes much of the procedure calling and return. Depends on the calling convention and temporary storage requirements. d) Link Time or Compile Time Mainly extensions to graph coloring. Involves interprocedural live variable analysis. Tries to minimize save/restore overheads. Procedures in different sub-trees of the call graph can share registers.

e) Aggregation of global references Link-time optimization. Collect global data into an area that can be referenced by short offsets. Avoids need to calculate “high order” bits. Reserve global pointer (gp) register during compilation. Extension: Sort the global objects smallest to largest to maximize the number of objects accessible by the global pointer.