unladen swallow: python and llvm

Neuruss luismgz at gmail.com
Sun Jun 7 11:53:31 EDT 2009

On 5 jun, 06:29, Nick Craig-Wood <n... at craig-wood.com> wrote:
> Luis M  González <luis... at gmail.com> wrote:
> >  I am very excited by this project (as well as by pypy) and I read all
> >  their plan, which looks quite practical and impressive.
> >  But I must confess that I can't understand why LLVM is so great for
> >  python and why it will make a difference.
> CPython uses a C compiler to compile the python code (written in C)
> into native machine code.
> unladen-swallow uses an llvm-specific C compiler to compile the CPython
> code (written in C) into LLVM opcodes.
> The LLVM virtual machine executes those LLVM opcodes.  The LLVM
> virtual machine also has a JIT (just in time compiler) which converts
> the LLVM op-codes into native machine code.
> So both CPython and unladen-swallow compile C code into native machine
> code in different ways.
> So why use LLVM?  This enables unladen swallow to modify the python
> virtual machine to target LLVM instead of the python vm opcodes.
> These can then be run using the LLVM JIT as native machine code and
> hence run all python code much faster.
> The unladen swallow team have a lot more ideas for optimisations, but
> this seems to be the main one.
> It is an interesting idea for a number of reasons, the main one as far
> as I'm concerned is that it is more of a port of CPython to a new
> architecture than a complete re-invention of python (like PyPy /
> IronPython / jython) so stands a chance of being merged back into
> CPython.
> --
> Nick Craig-Wood <n... at craig-wood.com> --http://www.craig-wood.com/nick

Thanks Nick,
ok, let me see if I got it:
The Python vm is written in c, and generates its own bitecodes which
in turn get translated to machine code (one at a time).
Unladen Swallow aims to replace this vm by one compiled with the llvm
compiler, which I guess will generate different bytecodes, and in
addition, supplies a jit for free. Is that correct?

It's confussing to think about a compiler which is also a virtual
machine, which also has a jit...
Another thing that I don't understand is about the "upfront"
Actually, the project plan doesn't mention it, but I read a comment on
pypy's blog about a pycon presentation, where they said it would be
upfront compilation (?). What does it mean?

I guess it has nothing to do with the v8 strategy, because unladen
swallow will be a virtual machine, while v8 compiles everything to
machine code on the first run. But I still wonder what this mean and
how this is different.

By the way, I already posted a couple of question on unladen's site.
But now I see the discussion is way to "low level" for me, and I
wouldn't want to interrupt with my silly basic questions...


More information about the Python-list mailing list