[LLVMdev] Proposal: intp type

Kenneth Uildriks kennethuil at gmail.com
Wed Nov 11 06:22:23 PST 2009


On Wed, Nov 11, 2009 at 7:00 AM, Kenneth Uildriks <kennethuil at gmail.com> wrote:
> 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.
>

Of course if you try to represent it as an aggregate, rather than a
block of memory, you're stuck again, and for the same reason.  An
array type can't use a ConstantExpr for its size... it has to be
specified as a literal integer by the front-end.  So passing your
union as a parameter or returning it by value won't work... unions can
*only* live in memory unless you've got target data.

Very interesting problem (but one I don't feel ready to even
high-level-design a solution for yet)...




More information about the llvm-dev mailing list