[pypy-dev] RE: LLVM backend

Chris Lattner sabre at nondot.org
Thu Feb 17 06:29:01 CET 2005

<sorry I'm joining in late here>

Carl Friedrich Bolz wrote:
> I just checked my LLVM-backend in (I hope I did nothing wrong). It 
> resides in pypy/translator/llvm.

Wow cool, I had no idea that you guys were this far along!

Here are some answers to LLVM related questions:

> I just removed the usage of llvmc so if that was really the problem
> it could work now. The only llvm tools that genllvm now uses are
> llvm-as (which works in your case) and llc (produces native code).

Yup, unfortunately, 'llvmc' was not quite stable when the 1.4 release was 
put out.  It's a bit better in LLVM CVS now, but is still a work in 
progress.  Just not using it is a good way to go for now.

> - I think there should be some more intelligent way to produce the
>   necessary LLLVM-implementations for the space operations of more
>   complex types than just writing them in LLVM-assembler, which can be
>   quite tedious (it's no fun writing programs in SSA form).

Oh yeah, generating SSA is quite a pain.  The traditional way that LLVM 
front-ends deal with this is to use 'alloca's for local variables and use 
explicit loads/stores to them.  This generates really gross looking code, 
but the LLVM optimizers (specifically mem2reg) rip them up.  For example, 
for something simple like:

    X = 1;
      = X;
    X = 2;

You can generate code that looks like this:

   %X = alloca int   ;; in the entry block for the fn
   store int 1, int* %X
     = load int* %X
   store int 2, int* %X

If you run this sort of code through the LLVM "-mem2reg" optimization, it 
will promote all of these to SSA values, so you don't have to do it 
yourself.  If the "..."'s contain control flow, this is a non-trivial 
task. :)

> - List and Strings should be relatively easy to implement with arrays.
>   I'm not quite shure wether I manage to do it, I'll just ask questions
>   if I run into problems.

If you have any LLVM specific question, please feel free to contact the 
llvmdev list (http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev), the 
people on the list are quite helpful and would love to help you in any way 
they can.

> - Are tuples really only used for returning multiple values from a
>   function? If yes they could be avoided altogether using additional
>   pointer arguments that point to where the return value should be
>   stored.

On the LLVM side of things, the only way for a function to return multiple 
values is (as you mention) to pass a pointer that indicates where to store 
the result.  In the future (say 3-4 months out), LLVM will be extended to 
allow functions to return multiple values in registers.

Another thought: I see that you're currently using llc to build your 
programs, have you considered using the LLVM JIT?

Anyway, if you have any questions or run into problems, again, we'd love 
to help, just let us know. :)



More information about the Pypy-dev mailing list