[LLVMdev] Some question on LLVM design

Chris Lattner sabre at nondot.org
Sun Oct 24 09:53:14 PDT 2004


On Sun, 24 Oct 2004, Misha Brukman wrote:

> On Sun, Oct 24, 2004 at 01:17:19AM -0500, Chris Lattner wrote:
> > The one advantage that mallocinst has over using an intrnisic is that
> > instructions can have different return values in various parts of the
> > program (e.g., you can write 'malloc int' instead of
> > '(int*)malloc(4)').
> OK, then you could say that the *real* advantage of the malloc/alloca
> instructions is that it can take a type as an operand (which an
> intrinsic cannot do) and hence can represent code in a more
> target-independent manner.
>
> Consider malloc(sizeof(long)).  That may be 4 on one target, 8 on
> another, so either you always allocate 8 to be correct (with an
> intrinsic) or you tie the bytecode to a particular size of long, where
> as with the instruction, just say 'malloc long'.

Yup, exactly.

Note that this is *still* syntactic sugar, as you can write 'sizeof'
portably in LLVM.  The real question is why we give special support for
malloc/free, which we don't give to other language runtime allocation
functions (e.g. operator new' in C++, new in Java, etc).

Going forward, it will be interesting to see how we can generalize support
for other allocators, I don't think that there is anything intrinsically
hard, but it is something that we eventually want to do.

-Chris

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




More information about the llvm-dev mailing list