www.au.dk

Optimization

www.au.dk
dOvs
DAIMI / Courses / dOvs

The goal of this assignment is to write a collection of peephole patterns to optimize the bytecode output of the code generation phase. It does not include any compiler phases as part of the assignment itself. The peephole optimization is performed by the Optimization phase, which is part of the skeleton.

You must hand in a file peepholes.peep containing a number of peephole patterns written in the peephole language as described on the slides. You must post a blog entry where you explain how you undertook the task of writing peephole patterns and argue for the soundness and termination of your pattern collection. You can write some of the documentation as comments in the peephole file if you feel that writing it this way clarifies the argumentation.

You enable peephole optimization in the Joos compiler by running it with the option -O peepholes.peep (where peepholes.peep is the pattern collection you want to use).

Another option you may find useful is the -noverify option which tells the Limits phase not to abort the compilation if some stack heights do not match. This way you can inspect the (malformed) jasmin output to locate the source of the error.

You can check your peephole patterns for static correctness by running the command java dovs.peephole.Loader peepholes.peep (with the Joos classes in your classpath).

As in the code generation phase, you are allowed to add more instruction classes to the existing collection if you find them useful in your peephole patterns. These should be uploaded under optimization along with your peephole patterns. Any instructions added must implement all methods declared in the Instruction class according to the specification. When you are testing your patterns with the joos2c compiler, make sure that your extra instructions are in your Java classpath. You can ensure this by calling the command from the classes subdirectory of your Joos compiler directory, or by adding this directory to your classpath. Be aware that the joos2c compiler generates different code with and without the -joos1 switch.

The peephole contest

Apart from being part of the project, your peephole collection will also enter into the dOvs 2010 Peephole Contest. The goal of the contest is to write the collection of peephole patterns that reduces the sizes of the benchmark programs as much as possible. We will compile all of the Joos 1 benchmark programs that were handed in, using joos2c -joos1 with your peephole collection. We then measure the size of the output by running this script on the output jasmin files. The winner of the competition is the group whose peephole pattern collection obtains the smallest total size of all benchmark programs.

To qualify for the competition, your pattern collection must be sound. At the very least, it must not cause any failures when used in the online test with -joos1 and only the optimization phase enabled for testing. We will also briefly inspect your pattern collection and disqualify patterns with any obvious soundness violations.

The results of the contest will be announced at an event after the multiple choice test, and the winners will receive fabulous prizes!

Note that the contest has no relationship with the project or the exam.