unladen swallow: python and llvm
python at mrabarnett.plus.com
Sun Jun 7 13:34:46 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
>> 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?
No. CPython is written in C (hence the name). It compiles Python source
code to bytecodes. The bytecodes are instructions for a VM which is
written in C, and they are interpreted one by one. There's no
compilation to machine code.
More information about the Python-list