[LLVMdev] Some question on LLVM design

Misha Brukman brukman at uiuc.edu
Sun Oct 24 01:13:43 PDT 2004


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

-- 
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu




More information about the llvm-dev mailing list