What is machine dependent optimization?
Machine
dependent optimization involves transformations that take into consideration,
the properties of the target machine like registers and special machine
instruction sequences available, etc. these techniques are applied on generated
target code.
The machine
dependent optimization is attained by the following measures:
- Allocation of adequate number of resources to enhance the
execution efficiency of the program
- Use of immediate instructions wherever required
- The use of intermix instructions
Why is Machine Dependent Optimization Needed?
Generally, the
statement by statement code generation strategy followed by most compilers
generate a target code that consists of redundant instructions and suboptimal
constructs.
To improve such
code, some machine dependent transformations are applied on it.
Peephole
optimization technique is simple and an effective machine dependent technique.
What is Peephole Optimization?
It is a simple
but effective technique for locally improving the target code.
This technique
tries to improve the performance of the target code by examining a short
sequence of target instructions known as peephole, and replacing them by a
shorter and faster sequence whenever possible.
What is Peephole?
It is a short
sequence of target instruction. The peephole can be considered as a moving
window on the target program. The instructions in the peephole need not be
contiguous.
What is the characteristic of Peephole Optimization?
The
characteristic of peephole optimization is, one improvement may spawn
opportunities for additional improvements. Hence, to get maximum benefit from
this technique repeated passes over the target program are necessary.
What are the Transformations done in Peephole
Optimization?
In general
peephole optimization involves the following six transformations:
Redundant
instruction elimination
Unreachable code
elimination
Flow of control
optimization
Algebraic
simplification
Reduction in
strength
Use of machine
idioms
Note: the
techniques of peephole optimization can also be applied to the intermediate
code.