[LLVMdev] Status of first-class aggregate types

Talin viridia at gmail.com
Sun Dec 20 00:27:31 PST 2009

What's the current status on support for first-class structs? The last I
heard was:

   - Structs which are smaller or equal to two pointers can be passed /
   returned / loaded / stored by value.
   - There are plans to expand this in the future to support arbitrary-sized
   structs as first class values. (Probably via some transformation pass the
   converts the return value into a hidden parameter.)

First question - are those statements still true?

Another thing I noticed recently was that although we have insert/extract
value, there's no 'constructvalue' instruction. I'm thinking of something
that would take a structure type + a list of individual field values and
returns a first class aggregate. Right now, if you want to construct a new
aggregate, it seems that you either have to alloca it, use GEP to fill in
the fields, and then load it - or you have to alloca it, load the
uninitialized struct, and then use successive insertvalue instructions to
initialize it. At least, I can't think of another way to do it. (Of course,
you can get SSA struct values from other places, but I'm talking about
creating a fresh value.)

The reason I am asking all of this is that I am starting to work on
supporting tuple types in my language - and I'm trying to decide what is the
best way to implement them. Since these are value types, not reference
types, they need to be copied when passing to or returning from a function.
The two approaches I am considering is (a) always pass them by reference
internally, using a hidden parameter for the return value, and then have the
receiver of the value copy it into an SSA value before use, and (b) for
types <= 2 pointers, use SSA values only, and then pass larger types as in
case (a). Of course, if support for large, first-class SSA values was
finished, then I wouldn't have to care about any of these issues :)

-- Talin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091220/7bd35494/attachment.html>

More information about the llvm-dev mailing list