SlideShare a Scribd company logo
Compiler in System Programming/Code Optimization techniques in System Programming(Peephole Optimization)
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.
Compiler in System Programming/Code Optimization techniques in System Programming(Peephole Optimization)
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..
Ad

More Related Content

Viewers also liked (19)

Embedded C
Embedded CEmbedded C
Embedded C
Emertxe Information Technologies Pvt Ltd
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
Emertxe Information Technologies Pvt Ltd
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
Arm processor
Arm processorArm processor
Arm processor
SHREEHARI WADAWADAGI
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
Emertxe Information Technologies Pvt Ltd
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
Abhijeet kapse
 
Arm developement
Arm developementArm developement
Arm developement
hirokiht
 
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#)
Adair Dingle
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
Anurag Tomar
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
Sonali Parab
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
adil raja
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
sato262
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
Anurag Tomar
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
Varun Mahajan
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
Mohamed Abdallah
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
Abhijeet kapse
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
Dhaval Kaneria
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 
Iot
IotIot
Iot
Ankit Anand
 

Similar to Compiler in System Programming/Code Optimization techniques in System Programming(Peephole Optimization) (20)

Code optmize.pptx which is related to coding
Code optmize.pptx which is related to codingCode optmize.pptx which is related to coding
Code optmize.pptx which is related to coding
vamami6395
 
C- language Lecture 6
C- language Lecture 6C- language Lecture 6
C- language Lecture 6
Hatem Abd El-Salam
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
KishoreRedla
 
Library management system
Library management systemLibrary management system
Library management system
SHARDA SHARAN
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdf
Himanshu883663
 
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENTUNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
KavithaNagendran1
 
different Storage classse in c programmings.pptx
different Storage classse in c programmings.pptxdifferent Storage classse in c programmings.pptx
different Storage classse in c programmings.pptx
vidhyapm2
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
Mukesh Tekwani
 
Code optimization
Code optimizationCode optimization
Code optimization
veena venugopal
 
Code optimization
Code optimizationCode optimization
Code optimization
veena venugopal
 
Netlist to GDSII flow new.pptx physical design full info
Netlist to GDSII flow new.pptx physical design full infoNetlist to GDSII flow new.pptx physical design full info
Netlist to GDSII flow new.pptx physical design full info
sivasuryam0000
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
LakshyaChauhan21
 
basics of optimizations presentation s
basics  of  optimizations presentation sbasics  of  optimizations presentation s
basics of optimizations presentation s
AnkitKumarSharma26
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
kinish kumar
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Ajeet Kumar
 
Storage class
Storage classStorage class
Storage class
Kalaikumar Thangapandi
 
SPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization partSPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization part
NiramayKolalle
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
praveenaprakasam
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
mohammedahmed539376
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
estoredesignerclothi
 
Code optmize.pptx which is related to coding
Code optmize.pptx which is related to codingCode optmize.pptx which is related to coding
Code optmize.pptx which is related to coding
vamami6395
 
Library management system
Library management systemLibrary management system
Library management system
SHARDA SHARAN
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdf
Himanshu883663
 
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENTUNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
KavithaNagendran1
 
different Storage classse in c programmings.pptx
different Storage classse in c programmings.pptxdifferent Storage classse in c programmings.pptx
different Storage classse in c programmings.pptx
vidhyapm2
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
Mukesh Tekwani
 
Netlist to GDSII flow new.pptx physical design full info
Netlist to GDSII flow new.pptx physical design full infoNetlist to GDSII flow new.pptx physical design full info
Netlist to GDSII flow new.pptx physical design full info
sivasuryam0000
 
basics of optimizations presentation s
basics  of  optimizations presentation sbasics  of  optimizations presentation s
basics of optimizations presentation s
AnkitKumarSharma26
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
kinish kumar
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Ajeet Kumar
 
SPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization partSPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization part
NiramayKolalle
 
Ad

More from Janki Shah (9)

Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
Janki Shah
 
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
Janki Shah
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
Janki Shah
 
Addressing in Computer Networks
Addressing in Computer NetworksAddressing in Computer Networks
Addressing in Computer Networks
Janki Shah
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
Janki Shah
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
Janki Shah
 
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++
Janki Shah
 
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
Janki Shah
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
Janki Shah
 
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
Janki Shah
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
Janki Shah
 
Addressing in Computer Networks
Addressing in Computer NetworksAddressing in Computer Networks
Addressing in Computer Networks
Janki Shah
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
Janki Shah
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
Janki Shah
 
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++
Janki Shah
 
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
Janki Shah
 
Ad

Recently uploaded (20)

Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Compiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptxCompiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptx
RushaliDeshmukh2
 
W1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptxW1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptx
muhhxx51
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
ISO 9001 quality management systemPPT.pptx
ISO 9001 quality management systemPPT.pptxISO 9001 quality management systemPPT.pptx
ISO 9001 quality management systemPPT.pptx
mesfin608
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Compiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptxCompiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptx
RushaliDeshmukh2
 
W1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptxW1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptx
muhhxx51
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
ISO 9001 quality management systemPPT.pptx
ISO 9001 quality management systemPPT.pptxISO 9001 quality management systemPPT.pptx
ISO 9001 quality management systemPPT.pptx
mesfin608
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 

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

  • 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.
  • 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

Editor's Notes

  • #2: 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.