Group 16 - Compiler Design
Group 16 - Compiler Design
Group 16 - Compiler Design
(Function preserving)
GROUP – 16 SECTION- A
◉ INTRODUCTION
◉ TYPES OF CODE OPTIMIZATION
◉ FUNCTION PRESERVING TRANSFORMATIONS
◉ ADVANTAGES OF CODE OPTIMIZATION
◉ CONCLUSION
◉ ACKNOWLEDGEMENT
◉ RESOURCES
1 INTRODUCTION
-Code optimization
-When to optimize?
-Why optimize?
-Where to optimize?
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.
When to optimize?
should not only save the CPU cycles, but can be used on any processor.
Machine Dependent optimization
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
Area of circle = pi x radius x radius
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.
Dead-code elimination
In this technique,
◉ As the name suggests, it involves eliminating the dead code.
◉ The statements of the code which either never executes or are
unreachable or their output is never used are eliminated.
Example
Here, ‘if’ statement is dead code because this condition will never get
satisfied.
Constant folding
In this technique,
◉ 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
In this technique,
◉ As the name suggests, it involves movement of the code.
◉ The code present inside the loop is moved out if it does not matter whether
it is present inside or outside.
◉ Such a code unnecessarily gets execute again and again with each iteration
of the loop.
◉ This leads to the wastage of time at run time.
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.
Strength reduction
In this technique,
◉ 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,
◉ The expression “A x 2” is replaced with the expression “A + A”.
◉ This is because the cost of multiplication operator is higher than that of
addition operator.
4 Advantages
Advantages of code optimization
◉ https://www.ijtre.com/images/scripts/2015030511.pdf
◉ https://www.geeksforgeeks.org/code-optimization-in-compiler-design/
◉ https://edurev.in/studytube/Function-Preserving-Transformations-Compil
er-
Desig/1f4598ab-01b0-437b-aca9-ddaa48c60b0a_t#
◉ https://
www.tutorialspoint.com/compiler_design/compiler_design_code_optimiza
tion.htm
◉ https://www.gatevidyalay.com/code-optimization-techniques/
Thanks!