Group 16 - Compiler Design Term Paper
Group 16 - Compiler Design Term Paper
Group 16 - Compiler Design Term Paper
(Function Preserving)
Bachelor of Technology
Computer Science and Engineering
Submitted By
Ronit kundu(13000119051)
Kaustav Dey(13000119056)
Subham Ghosh(13000119058)
MONTH 2021
1. Abstract
2. Introduction
3. Body
3.1. Why optimize?
3.2. When and Where to optimize?
3.3. Phases of Optimization
3.4. Types of Code Optimization
3.4.1. Machine Independent Optimization
3.4.2. Machine Dependent Optimization
3.5. Function preserving transformation
3.5.1. Common sub expression elimination
3.5.2. Copy Propagation
3.5.3. Dead Code elimination
3.5.4. Constant folding
3.5.5. Code movement
3.5.6. Strength reduction
3.6. Advantages of optimization
4. Conclusion
5. References
TISL/CSE/Term-Paper/Semester- 2
1. Abstract
The main motive of this paper is to present the need of the code optimization and work done
in the field of the code optimization. The improvement within the quality of code remains an
enormous issue from the sooner days. Typically it's troublesome for a computer programmer
to seek out that a part of code consumes a lot of resources and thence result in an inefficient
code. Antecedently most of the improvement were done manually or are often same as
statically those results in variety of issues to the computer programmer and additionally had a
number of the restrictions. However, of late many compilers area unit obtainable that makes
the improvement to be performed dynamically. During this treatise work, an endeavor has
been created to style and implement a system that may mechanically optimize the code so as
to reduce the quality of the code specified the code becomes a lot of economical.
2. Introduction
The code optimization in the synthesis phase is a program transformation technique, which
tries to improve the intermediate code by making it consume fewer resources (i.e. CPU,
Memory) so that faster-running machine code will result. Compiler optimizing process
should meet the following objectives :
The optimization must be correct, it must not, in any way, change the meaning of the
program.
Optimization should increase the speed and performance of the program.
The compilation time must be kept reasonable.
The optimization process should not delay the overall compiling process.
3. Body
Optimizing an algorithm is beyond the scope of the code optimization phase. So the
program is optimized. And it may involve reducing the size of the code. So
optimization helps to:
TISL/CSE/Term-Paper/Semester- 3
3.2. When and Where to optimize?
Optimization of the code is often performed at the end of the development stage since it
reduces readability and adds code that is used to increase the performance.
Source program
Optimizing the source program involves making changes to the algorithm or
changing the loop structures. User is the actor here.
Intermediate Code
Optimizing the intermediate code involves changing the address calculations
and transforming the procedure calls involved. Here compiler is the actor.
Target Code
Optimizing the target code is done by the compiler. Usage of registers, select
and move instructions is part of optimization involved in the target code.
Global Optimization:
Transformations are applied to large program segments that includes
functions,procedures and loops.
Local Optimization:
Transformations are applied to small blocks of statements.The local
optimization is done prior to global optimization.
In this optimization, the compiler takes in the intermediate code and transforms
a part of the code that does not involve any CPU registers and/or absolute
memory locations. For example:
TISL/CSE/Term-Paper/Semester- 4
This code involves repeated assignment of the identifier item, which if we put this
way:
should not only save the CPU cycles, but can be used on any processor.
There are a number of ways in which a compiler can improve a program without
changing the function it computes. The transformations are:-
1. Common sub expression elimination
2. Copy propagation
3. Dead-code elimination
4. Constant folding
5. Code movement
6. Strength reduction
Frequently, a program will include several calculations of the same value, such as an
offset in an array. Some of the duplicate calculations cannot be avoided by the
programmer because they lie below the level of detail accessible within the source
language.
TISL/CSE/Term-Paper/Semester- 5
3.5.1. Common sub expression elimination
The expression that has been already computed before and appears again in the code for
computation is called as Common Sub-Expression.
In this technique:
Example:
TISL/CSE/Term-Paper/Semester- 6
In this technique,
If some variable has been assigned some constant value, then it replaces that
variable with its constant value in the further program during compilation.
The condition is that the value of variable must not get alter in between.
Example:
Pi = 3.14
radius = 10
Here,
This technique substitutes the value of variables ‘pi’ and ‘radius’ at compile time.
It then evaluates the expression 3.14 x 10 x 10.
The expression is then replaced with its result 314.
This saves the time at run time.
In this technique,
Example:
Here ‘if’ condition is dead code because this condition will never satisfied.
3.5.4. Constant folding
In this technique,
TISL/CSE/Term-Paper/Semester- 7
As the name suggests, it involves folding the constants.
The expressions that contain the operands having constant values at compile time
are evaluated.
Those expressions are then replaced with their respective results.
Example:
Here,
This technique evaluates the expression 22/7 at compile time.
The expression is then replaced with its result 3.14.
This saves the time at run time.
In this technique,
Example:
Here x=y+z is present inside the loop but does not matter if it’s present inside or
outside, so it’s moved out to stop unnecessary execution.
In this technique,
TISL/CSE/Term-Paper/Semester- 8
As the name suggests, it involves reducing the strength of expressions.
This technique replaces the expensive and costly operators with the simple and
cheaper ones.
Example:
Here,
4. Conclusion
Code Optimization is the interesting concept and it is always the continuous process to
device the new method of optimizing the code. Various research in the field of the code
optimization is going on and due to the importance of this concept in the field of
programming and computing we in our future work will extend research in the field of the
code optimization.
5. References
https://www.ijtre.com/images/scripts/2015030511.pdf
https://edurev.in/studytube/Function-Preserving-Transformations-Compiler-
Desig/1f4598ab-01b0-437b-aca9-ddaa48c60b0a_t#
TISL/CSE/Term-Paper/Semester- 9
https://www.geeksforgeeks.org/code-optimization-in-compiler-design/
https://www.tutorialspoint.com/compiler_design/compiler_design_code
_optimization.htm
https://www.gatevidyalay.com/code-optimization-techniques/
TISL/CSE/Term-Paper/Semester- 10