[ Home ]
SBCL Internals

The pages on this CLiki-driven site can be edited by anybody at any time. No warranty of any kind can therefore be made; any implied warranties of merchantability or fitness for a particular purpose are expressly disclaimed
[ Home ] [ Recent Changes ] [ About CLiki ] [ Text Formatting ]

Peephole Optimizer

It has long been proposed to add a peephole optimizer (POP) to the compiler. Many wise programmers have started down this road (scan through #lisp and comp.lang.lisp), and have given up. I took a look at it also, and before I run away screaming, I wanted to post some notes in case some champion is inspired to accept the challenge.

[Feel free to correct any wrong info in the following]

Consensus seems to be that the Python compiler is very good about avoiding much of the need for a peephole optimizer. However there are still some optimizations and flow analysis that can be done to the assembly code, and that would be a win.

The problem is that there is no place where the assembly code is collected in one place. Instead, the emitter calls each VOP in turn, and the VOP then directly emits machine code into a code vector. There is minimal cleanup to the machine code (using Backpatches and Choosers), but these are basically a kludge for a few things that must be fixed later (after the branch labels are calculated?).

Before the fun of actually implementing a peephole optimizer (POP), there is the major issue of how to shoehorn it into the compiler. There seems to be four possible options:

1. Buffer up the assembly language: rewrite the emitter to collect the assembly instructions in a buffer (make one big VOP) POP them and then emit machine code

2. Capture the assembly instructions as the emitter emits the machine code, then POP the assembler and make appropriate changes to the machine code.

3. Do some VOP boundary analysis as the emitter is running. This would probably catch the familiar

mov esp ebx
mov ebx esp

code we all know and love.

4. Separate post-compiler POP stage, use disassembler to recreate assembly code, and then process is similar to #2.


This page is presently Uncategorized?: please add appropriate topic markers? and remove this text

This page is linked from: index  

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively