The goal of this assignment is to write a collection of peephole patterns to optimize the bytecode output of the code generation phase. The peephole optimization is performed by the Optimization phase, which is part of the skeleton.

You must hand in a file peepholes.ml 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 -peephole.

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.

The peephole contest

Apart from being part of the project, your peephole collection will also enter into the dOvs 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 the reference compiler in Joos 1 mode 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.