SlideShare uma empresa Scribd logo
1 de 21
Contents
 Binding & Binding Times
 Definition
 Possible Binding Times
 Memory Allocation
 Important Tasks of Memory Allocation Possible Binding Times
 Types of Memory Allocation
 Memory allocation in block structured language
 Dynamic Pointer & Static Pointer
 Activation Records(AR)
 Code Optimization
 What is Code Optimization?
 Techniques of Code Optimization
BINDING & BINDING TIMES
Definition:-
 Binding :
A binding is the association of an attribute of a program entity with a value.
 Binding Times:
The binding time is a time at which a binding is actually performed.
Possible Binding Times:-
1. Language Definition Time
e.g.: bind operator symbol to operations
2. Language Implementation Time
e.g.: bind floating point type to a representation
3. Compilation time of program
e.g.: bind a variable to a type in C or Java
4. Execution Init time of procedure proc
e.g.: bind a static variable to a memory cell
5. Execution time of procedure proc
e.g.: bind a non-static variable to a memory cell
MEMORY ALLOCATION
Important Tasks of Memory Allocation:-
1. To determine amount of memory is required to represent the value of data item
2. Use an appropriate memory allocation model to implement lifetimes and scopes
of data item
3. Determine appropriate memory mapping to access the values in non- scaler
data item.
e.g. values in an array
Types of Memory Allocation:-
1. Static Binding
 Memory is allocated to a variable before the execution of program begins.
 Static memory allocation is typically performed during compilation.
 No memory allocation and de-allocation is performed during execution time.
 Thus, variables remain permanently allocated.
2. Dynamic Binding
 Memory binding are established and destroyed during the execution of a program.
 Memory allocation and de-allocation is performed during execution time.
Memory allocation in block structured language:-
Ex:
A
{
statements
- --- -- --- --
}
• The block is a sequence of statements containing local data and declarations
which are enclosed with delimiters.
• Following are rules used to determine scope of variable:
1) Variable X is accessed within the block B1 if it can be accessed by any
statement situated in block B1.
2) Variable X is accessed by any statement in block B2 and block B2 is situated in
block B1.
Dynamic Pointer & Static Pointer:-
1. Dynamic pointer points to activation record that called (invoked) the new
activation record. It is used for returning from the procedure to the calling
procedure.
2. Static pointer points to the activation record that is global to the current activation
record (i.e., points to the activation record of the procedure containing the
declaration of this procedure).
Activation Records(AR):-
 The execution of a procedure is called its activation.
 An activation record contains all the necessary information required to call a
procedure.
CODE OPTIMIZATION
Definition:-
 Code Optimization is a technique which tries to improve the code by eliminating
unnecessary code lines arranging the statements in such a sequence that speed up
the program execution without wasting the resources.
Advantages :-
 Executes Faster
 Efficient Memory Usage
 Yields better performance
Techniques
Strength
Reduction
Compile Time
Evaluation
Dead Code
Elimination
Dead Code
Elimination
Common
Sub-expression
Evaluation
Constant
Folding
Constant
Propagation
(I) Compile Time Evaluation
i. Constant Folding
• It refers to a technique of evaluating the expressions whose operands are known to be a
constant at compile time itself
• Example : length = (22/7) * d
ii. Constant Propagation
• In constant propagation, if a variable is assigned a constant value, then subsequent use
of that variable can be replaced by a constant as long as no interuening assignment has
changed the value of the variable
• Ex: If r=5 & pi=3.14
& area=pi*r*r
=> 3.14*r*r
(II) Common Sub-Expression Elimination
• The common sub-expression is an expression appearing repeatedly in the code which is
computed previously. This technique replaces redundant expression each time it is
encountered.
• Ex:
T1 = 4 * I T1 = 4 * I
T2 = a[T1] T2 = a[T1]
T3 = 4 * j T3 = 4 * j
T4 = 4 * I T5 = n
T5 = n T6 = b[T1] + T5
T6 = b[T4] + T5
Before Optimization After Optimization
(III) Code Movement
 It is a technique of moving a block of code outside a loop if it wen’t have any difference if it
is executed outside or inside the loop.
 Ex:
x=y+z;
for ( int i=0; i<n; i++)
{ for ( int i=0; i<n; i++)
x=y+z; {
a[i]=6*i; a[i]=6*i;
} }
Before Optimization After Optimization
(IV)Dead Code Elimination
 Dead Code Elimination includes eliminating those code statements which are either never
executed or unreachable or if executed their output is never used.
 Ex:
i=0 i=0
if( i == 1)
{
a=x+5;
}
Before Optimization After Optimization
(V) Strength Reduction
 It is the replacement of expressions that are expensive with cheaper and simple ones.
 Ex:
B=A*2 B=A+A
Before Optimization After Optimization
Thank You..

Mais conteúdo relacionado

Mais procurados

Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
Computer organiztion4
Computer organiztion4Computer organiztion4
Computer organiztion4
Umang Gupta
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
sheetal singh
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 

Mais procurados (20)

Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Computer organiztion4
Computer organiztion4Computer organiztion4
Computer organiztion4
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Control Unit Design
Control Unit DesignControl Unit Design
Control Unit Design
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation process
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Compiler design
Compiler designCompiler design
Compiler design
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Primality
PrimalityPrimality
Primality
 

Destaque

Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
Sonali Parab
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
Varun Mahajan
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 

Destaque (18)

Embedded C
Embedded CEmbedded C
Embedded C
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Arm processor
Arm processorArm processor
Arm processor
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
Arm developement
Arm developementArm developement
Arm developement
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Iot
IotIot
Iot
 

Semelhante a Compiler in System Programming/Code Optimization techniques in System Programming(Peephole Optimization)

Semelhante a Compiler in System Programming/Code Optimization techniques in System Programming(Peephole Optimization) (20)

C- language Lecture 6
C- language Lecture 6C- language Lecture 6
C- language Lecture 6
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
Library management system
Library management systemLibrary management system
Library management system
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdf
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Storage class
Storage classStorage class
Storage class
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programming
 
Storage classes, linkage & memory management
Storage classes, linkage & memory managementStorage classes, linkage & memory management
Storage classes, linkage & memory management
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 

Mais de Janki Shah

Mais de Janki Shah (9)

Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical MethodsGauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Addressing in Computer Networks
Addressing in Computer NetworksAddressing in Computer Networks
Addressing in Computer Networks
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Sorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmSorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of Algorithm
 

Último

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Último (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 

Compiler in System Programming/Code Optimization techniques in System Programming(Peephole Optimization)

  • 1.
  • 2. Contents  Binding & Binding Times  Definition  Possible Binding Times  Memory Allocation  Important Tasks of Memory Allocation Possible Binding Times  Types of Memory Allocation  Memory allocation in block structured language  Dynamic Pointer & Static Pointer  Activation Records(AR)  Code Optimization  What is Code Optimization?  Techniques of Code Optimization
  • 4. Definition:-  Binding : A binding is the association of an attribute of a program entity with a value.  Binding Times: The binding time is a time at which a binding is actually performed.
  • 5. Possible Binding Times:- 1. Language Definition Time e.g.: bind operator symbol to operations 2. Language Implementation Time e.g.: bind floating point type to a representation 3. Compilation time of program e.g.: bind a variable to a type in C or Java 4. Execution Init time of procedure proc e.g.: bind a static variable to a memory cell 5. Execution time of procedure proc e.g.: bind a non-static variable to a memory cell
  • 7. Important Tasks of Memory Allocation:- 1. To determine amount of memory is required to represent the value of data item 2. Use an appropriate memory allocation model to implement lifetimes and scopes of data item 3. Determine appropriate memory mapping to access the values in non- scaler data item. e.g. values in an array
  • 8. Types of Memory Allocation:- 1. Static Binding  Memory is allocated to a variable before the execution of program begins.  Static memory allocation is typically performed during compilation.  No memory allocation and de-allocation is performed during execution time.  Thus, variables remain permanently allocated. 2. Dynamic Binding  Memory binding are established and destroyed during the execution of a program.  Memory allocation and de-allocation is performed during execution time.
  • 9. Memory allocation in block structured language:- Ex: A { statements - --- -- --- -- } • The block is a sequence of statements containing local data and declarations which are enclosed with delimiters. • Following are rules used to determine scope of variable: 1) Variable X is accessed within the block B1 if it can be accessed by any statement situated in block B1. 2) Variable X is accessed by any statement in block B2 and block B2 is situated in block B1.
  • 10.
  • 11. Dynamic Pointer & Static Pointer:- 1. Dynamic pointer points to activation record that called (invoked) the new activation record. It is used for returning from the procedure to the calling procedure. 2. Static pointer points to the activation record that is global to the current activation record (i.e., points to the activation record of the procedure containing the declaration of this procedure).
  • 12. Activation Records(AR):-  The execution of a procedure is called its activation.  An activation record contains all the necessary information required to call a procedure.
  • 14. Definition:-  Code Optimization is a technique which tries to improve the code by eliminating unnecessary code lines arranging the statements in such a sequence that speed up the program execution without wasting the resources. Advantages :-  Executes Faster  Efficient Memory Usage  Yields better performance
  • 15. Techniques Strength Reduction Compile Time Evaluation Dead Code Elimination Dead Code Elimination Common Sub-expression Evaluation Constant Folding Constant Propagation
  • 16. (I) Compile Time Evaluation i. Constant Folding • It refers to a technique of evaluating the expressions whose operands are known to be a constant at compile time itself • Example : length = (22/7) * d ii. Constant Propagation • In constant propagation, if a variable is assigned a constant value, then subsequent use of that variable can be replaced by a constant as long as no interuening assignment has changed the value of the variable • Ex: If r=5 & pi=3.14 & area=pi*r*r => 3.14*r*r
  • 17. (II) Common Sub-Expression Elimination • The common sub-expression is an expression appearing repeatedly in the code which is computed previously. This technique replaces redundant expression each time it is encountered. • Ex: T1 = 4 * I T1 = 4 * I T2 = a[T1] T2 = a[T1] T3 = 4 * j T3 = 4 * j T4 = 4 * I T5 = n T5 = n T6 = b[T1] + T5 T6 = b[T4] + T5 Before Optimization After Optimization
  • 18. (III) Code Movement  It is a technique of moving a block of code outside a loop if it wen’t have any difference if it is executed outside or inside the loop.  Ex: x=y+z; for ( int i=0; i<n; i++) { for ( int i=0; i<n; i++) x=y+z; { a[i]=6*i; a[i]=6*i; } } Before Optimization After Optimization
  • 19. (IV)Dead Code Elimination  Dead Code Elimination includes eliminating those code statements which are either never executed or unreachable or if executed their output is never used.  Ex: i=0 i=0 if( i == 1) { a=x+5; } Before Optimization After Optimization
  • 20. (V) Strength Reduction  It is the replacement of expressions that are expensive with cheaper and simple ones.  Ex: B=A*2 B=A+A Before Optimization After Optimization

Notas do Editor

  1. NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.