[LLVMdev] [PATCH] - Union types, attempt 2

Chris Lattner clattner at apple.com
Fri Jan 15 10:14:16 PST 2010


On Jan 14, 2010, at 8:27 PM, Talin wrote:

> I'm still working on the next patch, it's going somewhat slowly. I  
> wanted to create a unit test that actually created a union, and in  
> order to do that I had to implement constant unions. And rather than  
> creating a special syntax for constructing a union, I decided that  
> it was simplest to implement the insertvalue instruction for a  
> constant union expression:
>
>     @foo = constant union { i32, float } insertvalue union { i32,  
> float } undef, i32 4, 0
>
> What this says is to start with an undef, and then insert the value  
> '4' into the integer field (the zeroth field) of the union.

Insertvalue constant exprs should work on these, but that should fall  
out from insertvalue just working on unions.  However:

>
> The reason for doing it this way is that to construct a union, you  
> really need 4 pieces of information: The type of the union, the type  
> and value of the member to be initialized, and the index of which  
> member is being initialized. Originally I thought about having the  
> last be detected automatically by what type of initializer was used:
>
>     @foo = constant union { i32, float } i32 4

I think we really do need a "ConstantUnion" class.  How about syntax  
like this:

     @foo = constant union { i32, float, double, i32*, i32 } { i32 4 }

That seems simple and unambiguous, and analogous to structs.

-Chris



More information about the llvm-dev mailing list