[LLVMdev] Some question on LLVM design

Chris Lattner sabre at nondot.org
Tue Oct 26 12:04:21 PDT 2004


On Mon, 25 Oct 2004, Marc Ordinas i Llopis wrote:
> Misha Brukman wrote:
> >>1. Opcodes and intrinsics
> >>
> > That's not really correct.  The intrinsics such as llvm.frameaddress and
> > llvm.returnaddress have no equivalents in LLVM opcodes -- the meaning of
> > the intrinsics is specifically machine-dependent, and LLVM (and its
> > opcodes) are machine-independent, so there is no valid interchange of
> > these intrinsics with any combination of LLVM opcodes.
> >
>
> Yes, I understand that those intrinsics are mapped differently on
> different machines, but isn't 'add' mapped differently too?
>
> It seems to me that those intrinsics are there to support the GNU C
> extensions, making them a 'language feature' of sorts. That's why they
> are intrinsics and not opcodes.

Yes, that is accurate.  In fact, these intrinsics COULD be made into
opcodes, but it would add little value to do so.

> >>3. Control transfer
> >>
> > LLVM has the 'call' instruction that abstracts the target machine's
> > calling convention.  See http://llvm.cs.uiuc.edu/docs/LangRef.html#i_call
> > for more information.
> >
>
> Yes, it abstracts the target's C calling convention. But I'm trying to
> see if other types of languages can be implemented using LLVM.

Sure they can. :)

> > 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.

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'm not sure what support you would need in LLVM for lazy allocation.

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list