Code Optimization:
Reasons for Optimizing the Code
To improve performance and efficiency of a source code
To produce efficient target code by reducing the number of instructions in a program
Definition:
Code optimization is the process of reducing the number of instructions without affecting the outcome of the source program
Role of a Code optimization:
- It is a fifth phase of a compiler and optional phase in which code may or may not be optimized
- It takes intermediate form of a source code as its input and generates optimized code if possible
- Code optimization associates with symbol table to retrieve required information or store the information to process the source code
Programmer
Compiler
Optimization can be done at three levels. They are
- Writing efficient code with minimum the number of instructions by a programmer known as source code
- The optimization can be applied on an intermediate code which is the output of intermediate code generation phase called as machine independent code optimization
- The optimization can be applied on object code which is the output of code generator phase called machine dependent code optimization
Classification of Code Optimization:
The classification of optimization can be done in two ways:
Machine Dependent code optimization
Machine Independent Code Optimization
Machine Dependent code optimization
- The machine dependent optimization can be achieved using following criteria
- Allocation of sufficient number of resources to improve the execution efficiency of the program
- Using immediate instructions wherever necessary
- The use of intermix instructions. The intermixing of instruction along with the data increases the speed of execution
Machine Independent code optimization
The machine independent optimization can be achieved using the following criteria
- The code should be analysed completely and use alternative equivalent sequence of source code that will produce a minimum amount of target code
- Use appropriate program structure in order to improve the efficiency of target code
- From the source program eliminate the unreachable code
- Move two or more identical computations at one place and make use of the result instead of each time computing the expressions
0 comments:
Post a Comment