SlideShare a Scribd company logo
1 of 18
Welcome to my
Presentation
Topic : Peephole Optimization
Samrin Ahmed
ID: 011142021
CONTENTS
Functioning of Peephole Optimization & Example
Replacement Rules
Working Flow of Peephole Optimization
Introduction to Peephole Optimization
What is an Optimization
2
Conclusion
References
What is Optimization ??
 Process of transforming a piece of code to make it more efficient (either in
terms of time or space) without changing its output or side-effects.
 Tries to minimize or maximize some attributes of an executable computer
program.
Introduction to Peephole
Optimization ??
 Optimization performed over a very small set of
instructions in a segment of generated code.
 Works by recognizing sets of instructions that can be
replaced by shorter or faster sets of instructions.
 Goals:
 improve performance
 reduce code size
 reduce memory footprint
Why it’s needed ??
After compilation, the code still has some flaws
 Scheduling & allocation really are NP-Complete
 Optimizer may not implement every needed transformation
Curing the problem
 More work on scheduling and allocation
 Implement more optimizations
— or —
 Optimize after compilation
 Peephole optimization
 Link-time optimization
Working Flow of Peephole
Optimization
Replacement Rules
Common techniques applied in peephole optimization:-
 Constant folding
– Evaluate constant sub-expressions in advance.
 Strength reduction
– Replace slow operations with faster equivalents.
 Null sequences
– Delete useless operations.
 Combine operations
– Replace several operations with one equivalent.
 Algebraic laws
– Use algebraic laws to simplify or reorder instructions.
 Special case instructions
– Use instructions designed for special operand cases.
 Address mode operations
– Use address modes to simplify code.
Functioning of Peephole
Optimization
 Replacing slow instructions with faster ones
 Removing redundant code
 Removing redundant stack instructions
Functioning (Contd…)
 Replacing slow instructions with faster ones
The following Java byteCode
...
load 1
load 1
mul
...
Can be replaced by
...
load 1
dup
mul
...
Functioning (Contd…)
 Removing redundant code
 Another example is to eliminate redundant load stores.
a = b + c;
d = a + e;
is straightforwardly implemented as
MOV b, R0 # Copy b to the register
ADD c, R0 # Add c to the register, the register is now b+c
MOV R0, a # Copy the register to a
MOV a, R0 # Copy a to the register
ADD e, R0 # Add e to the register, the register is now a+e [(b+c)+e]
MOV R0, d # Copy the register to d
Functioning (Contd…)
 Removing redundant code
but can be optimized to
MOV b, R0 # Copy b to the register
ADD c, R0 # Add c to the register, which is now b+c (a)
MOV R0, a # Copy the register to a
ADD e, R0 # Add e to the register, which is now b+c+e [(a)+e]
MOV R0, d # Copy the register to d
Functioning (Contd…)
 Removing redundant stack instructions
PUSH AF
PUSH BC
PUSH DE
PUSH HL
CALL _ADDR1
POP HL
POP DE
POP BC
POP AF
PUSH AF
PUSH BC
PUSH DE
PUSH HL
CALL _ADDR2
POP HL
POP DE
POP BC
POP AF

PUSH AF
PUSH BC
PUSH DE
PUSH HL
CALL _ADDR1
CALL _ADDR2
POP HL
POP DE
POP BC
POP AF
Functioning (Contd…)
Source Code:
If ( a<b ) {
a = a + b;
}
 Peephole optimization of jumps
 Eliminate jumps to jumps
 Eliminate jumps after conditional branches
“Adjacent” instructions = “Adjacent in control flow”
IL Code:
PUSH a
PUSH b
CMP a,b
JUMP L1
EXIT
L1:
ADD a,b

Other Considerations
Control-flow operations
 Can clear simplifier’s window at branch or label
 More aggressive approach: combine across branches
 Same considerations arise with predication
Physical versus logical windows
 Can run optimizer over a logical window
 Logical windows (within block) improve effectiveness
Conclusion
So…
 Peephole optimization remains viable
 Post allocation improvements
 Cleans up rough edges
 Peephole technology works for selection
 Description driven matchers
 Used in several important systems
All of this will work equally well in binary-to-binary translation
References
 https://en.wikipedia.org/wiki/Peephole_optimization
 http://www.iosrjournals.org/iosr-jce/papers/Vol9-Issue4/N0948086.pdf?id=255
 https://class.coursera.org/compilers/lecture/76
 https://www.slideshare.net/AnulChaudhary/peephole-optimization-techniques-in-
compiler-design
That’s all
Any Question
Peephole Optimization

More Related Content

What's hot

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code GeneratorDarshan sai Reddy
 
Three Address code
Three Address code Three Address code
Three Address code Pooja Dixit
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
 
Superscalar & superpipeline processor
Superscalar & superpipeline processorSuperscalar & superpipeline processor
Superscalar & superpipeline processorMuhammad Ishaq
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniquesMani Kanth
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignmentKarthi Keyan
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environmentIffat Anjum
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dagsindhu mathi
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler designRajkumar R
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Raster scan system & random scan system
Raster scan system & random scan systemRaster scan system & random scan system
Raster scan system & random scan systemshalinikarunakaran1
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 

What's hot (20)

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
Three Address code
Three Address code Three Address code
Three Address code
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Superscalar & superpipeline processor
Superscalar & superpipeline processorSuperscalar & superpipeline processor
Superscalar & superpipeline processor
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Code generation
Code generationCode generation
Code generation
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Disk structure
Disk structureDisk structure
Disk structure
 
Raster scan system & random scan system
Raster scan system & random scan systemRaster scan system & random scan system
Raster scan system & random scan system
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 

Similar to Peephole Optimization

Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization TechniquesJoud Khattab
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimizationKarthik Vivek
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
lect23_optimization.ppt
lect23_optimization.pptlect23_optimization.ppt
lect23_optimization.pptssuser0be977
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design LogsAk
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFaisal Shehzad
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCAFxX
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languagesAnkit Pandey
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesMarina Kolpakova
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPMax Romanovsky
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimizationZongYing Lyu
 
Chp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxChp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxssuser10ed71
 
Compiler optimization techniques
Compiler optimization techniquesCompiler optimization techniques
Compiler optimization techniquesHardik Devani
 
H2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff ClickH2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff ClickSri Ambati
 
Cray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesCray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesJeff Larkin
 

Similar to Peephole Optimization (20)

Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Computer Architecture Assignment Help
Computer Architecture Assignment HelpComputer Architecture Assignment Help
Computer Architecture Assignment Help
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
lect23_optimization.ppt
lect23_optimization.pptlect23_optimization.ppt
lect23_optimization.ppt
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
 
Chp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxChp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptx
 
Compiler optimization techniques
Compiler optimization techniquesCompiler optimization techniques
Compiler optimization techniques
 
H2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff ClickH2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff Click
 
Cray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesCray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best Practices
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 

More from United International University (15)

Digital Banking - Revolution in Bangladesh
Digital Banking - Revolution in BangladeshDigital Banking - Revolution in Bangladesh
Digital Banking - Revolution in Bangladesh
 
Happiness advantage
Happiness advantageHappiness advantage
Happiness advantage
 
Project report on arduino based parking lot system
Project report on arduino based parking lot systemProject report on arduino based parking lot system
Project report on arduino based parking lot system
 
Talk shows-Are they entertaining ?
Talk shows-Are they entertaining ?Talk shows-Are they entertaining ?
Talk shows-Are they entertaining ?
 
Game using Java
Game using JavaGame using Java
Game using Java
 
Systematic Project Implementation
Systematic Project Implementation Systematic Project Implementation
Systematic Project Implementation
 
Project Management Tools
Project Management ToolsProject Management Tools
Project Management Tools
 
JIT Compiler
JIT CompilerJIT Compiler
JIT Compiler
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Academic Pressure Too Much To Handle
Academic Pressure Too Much To HandleAcademic Pressure Too Much To Handle
Academic Pressure Too Much To Handle
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
 
Arduino Based Parking Lot System
Arduino Based Parking Lot SystemArduino Based Parking Lot System
Arduino Based Parking Lot System
 
BCD ADDER
BCD ADDER BCD ADDER
BCD ADDER
 
Cinema & Its Impact On Society
Cinema & Its Impact On SocietyCinema & Its Impact On Society
Cinema & Its Impact On Society
 
Cyber Crime-The New War of the 21st Century
Cyber Crime-The New War of the 21st CenturyCyber Crime-The New War of the 21st Century
Cyber Crime-The New War of the 21st Century
 

Recently uploaded

Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsmeharikiros2
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesRashidFaridChishti
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information SystemsAnge Felix NSANZIYERA
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
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...drmkjayanthikannan
 
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 startQuintin Balsdon
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257subhasishdas79
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)ChandrakantDivate1
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxNANDHAKUMARA10
 

Recently uploaded (20)

Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
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...
 
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
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 

Peephole Optimization

  • 1. Welcome to my Presentation Topic : Peephole Optimization Samrin Ahmed ID: 011142021
  • 2. CONTENTS Functioning of Peephole Optimization & Example Replacement Rules Working Flow of Peephole Optimization Introduction to Peephole Optimization What is an Optimization 2 Conclusion References
  • 3. What is Optimization ??  Process of transforming a piece of code to make it more efficient (either in terms of time or space) without changing its output or side-effects.  Tries to minimize or maximize some attributes of an executable computer program.
  • 4. Introduction to Peephole Optimization ??  Optimization performed over a very small set of instructions in a segment of generated code.  Works by recognizing sets of instructions that can be replaced by shorter or faster sets of instructions.  Goals:  improve performance  reduce code size  reduce memory footprint
  • 5. Why it’s needed ?? After compilation, the code still has some flaws  Scheduling & allocation really are NP-Complete  Optimizer may not implement every needed transformation Curing the problem  More work on scheduling and allocation  Implement more optimizations — or —  Optimize after compilation  Peephole optimization  Link-time optimization
  • 6. Working Flow of Peephole Optimization
  • 7. Replacement Rules Common techniques applied in peephole optimization:-  Constant folding – Evaluate constant sub-expressions in advance.  Strength reduction – Replace slow operations with faster equivalents.  Null sequences – Delete useless operations.  Combine operations – Replace several operations with one equivalent.  Algebraic laws – Use algebraic laws to simplify or reorder instructions.  Special case instructions – Use instructions designed for special operand cases.  Address mode operations – Use address modes to simplify code.
  • 8. Functioning of Peephole Optimization  Replacing slow instructions with faster ones  Removing redundant code  Removing redundant stack instructions
  • 9. Functioning (Contd…)  Replacing slow instructions with faster ones The following Java byteCode ... load 1 load 1 mul ... Can be replaced by ... load 1 dup mul ...
  • 10. Functioning (Contd…)  Removing redundant code  Another example is to eliminate redundant load stores. a = b + c; d = a + e; is straightforwardly implemented as MOV b, R0 # Copy b to the register ADD c, R0 # Add c to the register, the register is now b+c MOV R0, a # Copy the register to a MOV a, R0 # Copy a to the register ADD e, R0 # Add e to the register, the register is now a+e [(b+c)+e] MOV R0, d # Copy the register to d
  • 11. Functioning (Contd…)  Removing redundant code but can be optimized to MOV b, R0 # Copy b to the register ADD c, R0 # Add c to the register, which is now b+c (a) MOV R0, a # Copy the register to a ADD e, R0 # Add e to the register, which is now b+c+e [(a)+e] MOV R0, d # Copy the register to d
  • 12. Functioning (Contd…)  Removing redundant stack instructions PUSH AF PUSH BC PUSH DE PUSH HL CALL _ADDR1 POP HL POP DE POP BC POP AF PUSH AF PUSH BC PUSH DE PUSH HL CALL _ADDR2 POP HL POP DE POP BC POP AF  PUSH AF PUSH BC PUSH DE PUSH HL CALL _ADDR1 CALL _ADDR2 POP HL POP DE POP BC POP AF
  • 13. Functioning (Contd…) Source Code: If ( a<b ) { a = a + b; }  Peephole optimization of jumps  Eliminate jumps to jumps  Eliminate jumps after conditional branches “Adjacent” instructions = “Adjacent in control flow” IL Code: PUSH a PUSH b CMP a,b JUMP L1 EXIT L1: ADD a,b 
  • 14. Other Considerations Control-flow operations  Can clear simplifier’s window at branch or label  More aggressive approach: combine across branches  Same considerations arise with predication Physical versus logical windows  Can run optimizer over a logical window  Logical windows (within block) improve effectiveness
  • 15. Conclusion So…  Peephole optimization remains viable  Post allocation improvements  Cleans up rough edges  Peephole technology works for selection  Description driven matchers  Used in several important systems All of this will work equally well in binary-to-binary translation
  • 16. References  https://en.wikipedia.org/wiki/Peephole_optimization  http://www.iosrjournals.org/iosr-jce/papers/Vol9-Issue4/N0948086.pdf?id=255  https://class.coursera.org/compilers/lecture/76  https://www.slideshare.net/AnulChaudhary/peephole-optimization-techniques-in- compiler-design