[LLVMdev] Proposal: intp type

Kenneth Uildriks kennethuil at gmail.com
Wed Nov 11 05:00:06 PST 2009


On Tue, Nov 10, 2009 at 6:41 PM, Kenneth Uildriks <kennethuil at gmail.com> wrote:
> On Tue, Nov 10, 2009 at 6:10 PM, Talin <viridia at gmail.com> wrote:
(A similar esoteric use case is: "which of
>> the following two types is larger, 3 x int32 or 2 x {}*? -- i.e. the union
>> problem.)

The size of a union can be compiled into a ConstantExpr.  i.e.,

(sizeof(T1) > sizeof(T2)) ? sizeof(T1) : sizeof(T2))

Since sizeof(T1) and sizeof(T2) themselves are ConstantExpr's, and so
is icmp(ConstantExpr, ConstantExpr) and select (ConstantExpr,
ConstantExpr, ConstantExpr).

You won't be able to tell which is bigger from your front-end, but
you'll have a ConstantExpr that you can feed to malloc, etc.



More information about the llvm-dev mailing list