Related articles |
---|
Optimizing in my toy compiler boriel@gmail.com (Boriel) (2008-02-07) |
Optimizing in my toy compiler nmh@t3x.org (Nils M Holm) (2008-02-11) |
Re: Optimizing in my toy compiler max@gustavus.edu (Max Hailperin) (2008-02-12) |
From: | Max Hailperin <max@gustavus.edu> |
Newsgroups: | comp.compilers |
Date: | Tue, 12 Feb 2008 19:00:54 -0600 |
Organization: | Compilers Central |
References: | 08-02-029 |
Keywords: | optimize |
Posted-Date: | 12 Feb 2008 20:05:40 EST |
Boriel <boriel@gmail.com> writes:
> .. now I'm interested in creating intermediate code for a
> test-language ... compiler created with this [python-based] tool.
> If I'm not wrong, stack-oriented code is easy to generate, but
> difficult to optimize whilst three or quad code is much easy to
> optimize. Any ideas? Which one should you suggest? ...
I suggest generating LLVM intermediate code in textual (assembly
language) form. There are tools provided in the LLVM distribution
that can translate between this form and the bitcode, and there are
tools provided for optimization, interpretation, and compilation to
native machine code. All in all, is is a slick package for someone
who wants to concentrate on the front end, but have a good back end,
and also is interested in still having visibility into the back end,
including being able to experiment with the effect of different
optimizations. This is what I'm having the students in my compiler
design course use.
When you first look at LLVM, you may think it is a bit hard to
generate because of it being an SSA representation. But you can
totally ignore that if you allocate memory locations for all variables
and emit load and store operations, rather than trying to keep
variables in (pseudo-)registers. The mem2reg optimization pass will
then do the dirty work of eliminating the memory operations and
generating the appropriate SSA plumbing instead. The LLVM Tutorial
illustrates this approach (in chapter 7). The tutorial assumes you
are coding your front-end in C++ and thus able to directly link in the
LLVM library. But the same approach also works with a front end in
Python (or anything else) that is generating LLVM assembly language.
-max
Return to the
comp.compilers page.
Search the
comp.compilers archives again.