[LLVMdev] Some question on LLVM design

Vikram S. Adve vadve at cs.uiuc.edu
Wed Oct 27 04:03:50 PDT 2004


I agree with Chris's points below, but I would add a couple of caveats:


On Oct 26, 2004, at 2:04 PM, Chris Lattner wrote:

>>> What is that you are looking to express that isn't captured by the
>>> `call' instruction?
>>>
>>
>> Tail calls, closures, continuations, lazy allocation... Basically I'm
>> trying to see how am I going to implement high-level functions on 
>> LLVM.
>
> As for tail calls, my plans are here:
> http://nondot.org/sabre/LLVMNotes/GuaranteedEfficientTailCalls.txt
> Note that LLVM already has a pretty aggressive tail-call elimination 
> pass,
> so this is really more for completeness than anything else.

Actually, although we can optimize a tail call of a procedure calling 
itself, we cannot express an optimized tail call from one procedure to 
another.   We don't have a cross-procedure branch in LLVM.  Of course, 
a cross-procedure tail call could be optimized to a branch within a 
native back-end but that's not really what you want.

>
> Closures and continuations should not be a problem.  Closures are
> represented as a pair, where the first element is a pointer to a struct
> (containing any environment needed by the closure) and a function 
> pointer.
> To invoke the closure, just call the function pointer, passing the 
> pointer
> to struct.

I agree that closures should not be a problem.  In the case of closures 
for polymorphic functions, though, the type information for the  
function pointer in the closure will be imprecise and casts will 
probably be needed to use the function pointer.  The loss of type 
information is really due to lack of polymorphism at the LLVM level, 
not due to closures per se.

I'm not sure how well continuations will work.  As Chris implied, they 
can be expressed as closures, but "rediscovering" the continuations for 
any CPS-based analysis or optimizations could be inconvenient.

>
> I'm not sure what support you would need in LLVM for lazy allocation.

Me neither.  You should be able to *implement* it, but I don' t know 
what should be expressed in LLVM directly.

>
> -Chris
>


--Vikram
http://www.cs.uiuc.edu/~vadve
http://llvm.cs.uiuc.edu/





More information about the llvm-dev mailing list