unladen swallow: python and llvm

Nick Craig-Wood nick at craig-wood.com
Fri Jun 5 05:29:41 EDT 2009


Luis M  González <luismgz 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 <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list