Next: Examples Up: Compiling LL into Previous: User-defined Functions

The Peep-Hole Optimizer

The LL compiler sometimes produces code which by local inspection can be considerably improved. For these cases, a peep-hole optimizer is used which looks at the code and changes it to make it smaller and faster.

The most obvious inefficient constellations are those where something is first pushed on the stack and then directly discarded. The instructions responsible for this can simply be removed:

Another simplification is to collect remove instructions:

With this rule, a sequence of remove instructions is replaced by a single instruction. This situation occurs when multiple let forms end at a single location.

In the LLAMA, some instructions were introduced especially for the peep-hole optimizer: set-nth- and set-global-. Their counterparts without a trailing dash leave the top stack element on the stack, the versions with the dash remove it. An instruction sequence consisting of set-nth or set-global and a pop instruction (as it is produced by multiple setq statements) is replaced by the corresponding set-nth- or set-global- instruction:

Many additional peep-hole optimizations are possible, most of them also requiring new LLAMA instructions, e.g. cons* (executing cons times):



Next: Examples Up: Compiling LL into Previous: User-defined Functions


Harold Boley & Michael Sintek (sintek@dfki.uni-kl.de)