Next: Functional Languages Up: C73-Compiler Techniques Previous: Native Code Generation

Global Optimisation

Optimizations across basic blocks are called global. Optimization cannot not produce optimal code-two problems:

  1. opt. subsumes problems known to be undecidable, for example, reachability, which can be reduced to halting problem.
  2. even if solvable, opt. may be ridiculously expensive-many algorithms are O(e^n) and, in practice, heuristics are used.

Two issues:

safety
does the opt. code always produce the same results as the original program? Opts which compromise this are: associative reordering of operands; code motion (out of loops); loop unrolling.
profitability
is it worth the effort? Opt. can return 20-25%performance improvement, but an improved algorithm may take the program from O(n^2) to O(n) or from O(n) to O(log n) - optimization is not a substitute for good algorithms, it is the icing on the cake.

Optimized code may introduce errors and it is hard to debug An idealized optimizing compiler structure:


          dependent      independent
------------------------------------
source |  language   |   machine
CG     |  machine    |   language
IR     |             |   language and machine

Language design interacts with GO-some features help:

some features hinder:

GO examines flows between basic blocks-construct data flow graph. However, most gains come from analysing loops in scientific programs (FORTRAN) and many optimizing compilers only consider loops. In particular loops are a good source of common subexpressions, especially in array index computations. Two classes:

Other optimisations are:


Next: References Up: C73-Compiler Techniques Previous: Advanced Analysis


masjap@
Fri Oct 21 18:42:03 BST 1994