COS 401: Compiler Theory

advertisement
CIS 324: Language Design and Implementation
Code Optimization
1. Improving Transformations
The code produced by straightforward compiling algorithms can be
made to run faster using code improving transformations. Compilers
using such transformations are called optimizing compilers.
The main subject of research are machine-independent optimisations.
They are implemented by algorithms that improve the target code
without taking into consideration any properties of the target machine.
Making machine-dependent optimisations, such as register allocation
and utilization of machine idioms is also possible.
The purpose behind making such optimisations is make more efficient
the most frequently executed parts of the compiler.
2. Optimizing Compiler
An optimising compiler should provide the following properties:
- the transformations should preserve the semantics of the programs,
that is the changes should guarantee that the same input produces
the same outputs (and should not cause errors);
- the transformations should speed up considerably the compiler on
the average (although occasionally on some inputs this may not
be demonstrated, on most of the inputs it should become faster);
- the transformation should be worth the intellectual effort.
3. Sources of Optimization
The possibilities to improve a compiler can be explained with the following
most frequently applied transformation techniques:
-
Function-preserving transformations;
Common subexpressions identification;
Copy propagation;
Dead-code elimination;
Loop optimisations;
Induction variables and reduction in strength.
A code improving transformation is called local if it is performed by
looking at statements within one concrete block.
Respectively, a code improving transformation is global if it is performed
by looking at statements not only in one concrete block, but also outside
in global and other outside blocks.
Download