On Tue, Jan 12, 2010 at 5:46 PM, Dan Gohman <span dir="ltr"><<a href="mailto:gohman@apple.com" target="_blank">gohman@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>
On Jan 12, 2010, at 5:01 PM, Talin wrote:<br>
<br>
> Here is the LangRef part of the patch.<br>
<br>
</div>> +<p>The union type is used to represent a set of possible data types which can<br>
> + exist at a given location in memory (also known as an "untagged"<br>
> + union).<br>
[...]<br>
<br>
This wording is somewhat misleading; memory in LLVM has no types.<br>
How about:<br>
<br>
"A union type describes an object with size and alignment suitable for<br>
an object of any one of a given set of types."<br></blockquote><div><br></div><div>OK </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Also, is it really useful to support<br>
insertvalue/extractvalue/getelementptr on unions? The benefit of unions<br>
that I'm aware of is it allows target-independent IR to work with<br>
appropriately sized and aligned memory. This doesn't require any special<br>
support for accessing union members; for example:<br>
<br>
%p = alloca union { i32, double }<br>
%q = bitcast union { i32, double }* %p to double*<br>
store i32 2.0, double* %q<br>
<br>
Would this be a reasonable approach?<br></blockquote><div><br></div><div>It depends on whether or not unions can be passed around as SSA values or not. I can think of situations where you would want to.</div><div><br></div>
<div>In particular, GEP is useful because you can avoid the bitcast above - GEP to element 0 if you want an int (in the example above), or to element 1 if you want a double.</div><div><br></div><div>Also, I'm thinking that insertvalue might be the best way to construct a constant union. Right now there's a bit of a problem in that the data type of a constant must match exactly the declared type; However in the case of a union what we want is for the data type of the initializer to exactly match the type of one of the union members. I thought this would be relatively easy to do, but it's a little trickier than I realized.</div>
</div><br>-- <br>-- Talin<br>