The code optimizer optimizes the code produced by the intermediate code generator in the terms of time and space. 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. 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
The classification of optimization can be done in two ways:
- Machine Dependent code optimization
- Machine Independent Code Optimization
Machine Independent Code 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.
Machine Dependent Code optimization:
- Machine-dependent optimization is done after the target code has been generated and when the code is transformed according to the target machine architecture. It involves CPU registers and may have absolute memory references rather than relative references. Machine-dependent optimizers put efforts to take maximum advantage of memory hierarchy.