Compiler Design
By Sandeep Negi
Introduction
What optimization is?
Optimization at different levels.
Pareto principle & Hotspots
When to Optimize?
Automated and Manual Optimization
Classification of optimization technique
Optimizing Transformations
What Optimization is?
Definition:It is process of modifying a software system to make some aspect of it work more efficiently or use fewer resources. Main aim is to find superior algorithm.
Optimization of a code to add n numbers
Things we should take care during optimization
Factors influencing optimization
Optimization at different levels Few Terms to know
1.
2.
3.
4.
Algorithm
Algorithmic efficiency
Compiler optimization
JIT – Just in time compiler
Optimization can be done in almost all phases of
Compilation - diagram
1.
2.
3.
4.
5.
Design Level
Source Code Level
Compiler Level
Assembly Level
Run Time Level
Pareto Principle & Hotspots
Pareto Principle:20% of the code is responsible for 80% of the results.
90/10 Law in Software Engineering.
Hotspot
Region of a computer program where a high proportion of executed instructions occur.
In general loops are hot spot.
When to Optimize?
Donald Knuth Statement:"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil".
Premature Optimization
Phrase used to describe a situation where a programmer lets performance considerations affects the design of a piece of code
Automated & Manual
Optimization
Automatic Optimization
1.
2.
3.
4.
5.
6.
Can’t optimize whole system
Easy
Cost effective
Fast
Pre defined and Tested
Will not effect the algorithm
Manual Optimization
Slow
Costly
Very effective
Produce efficient code
More chances of bug creation
IQ
Classification of Optimization
Technique
Optimization Techniques
1.
2.
3.
4.
Peephole optimization
Local optimizations
Global Optimizations
Loop optimization
Objectives
1. Avoid redundancy: something already computed need not be