[LLVMdev] Status of first-class aggregate types

John McCall
2009-12-20T09:00:18Z

On Dec 20, 2009, at 12:27 AM, Talin wrote:
> 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?

I can't answer this or most of your other questions, but:

> 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 way to do this is to start with undef and repeatedly insert into it.  For
example:
  %0 = insertvalue undef {i1,i8*}, i32 0, i1 0
  %1 = insertvalue {i1,i8*} %0, i32 1, i8* %pointer

Arguably there should be a helper method for this on IRBuilder.

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