8.0 Introduction

8.1 Comparison of Algorithms

8.2 What to Optimize

8.3 Issues in Optimization

8.4 Optimization Phases

8.5 Control Flow Analysis

8.6 Loops

8.7 Summary

Web References

Exercises

8.0 Introduction

The optimization phase makes changes to the intermediate representation so that the code generator will put out better but equivalent code.

The term optimization is a misnomer. The problem of changing code in all cases to the best it can be is an undecidable problem; it cannot be solved an algorithm on a computer.

We can, however, improve code in most cases.

There are machine dependent optimizations such as good allocation of registers and machine independent optimizations such as computing constants; constant computation at compile-time rather than generating code to compute them saves execution time.

Optimization can consume a lot of compile-time, so we want the most payoff for the least effort. In particular, the compiler needs to guess where the most frequently executed parts of the program are.

Send questions and comments to: Karen Lemone