On Sun, Aug 15, 2010 at 3:38 PM, Eric Christopher <echristo at apple.com> wrote:> > On Aug 15, 2010, at 2:34 PM, Nick Lewycky wrote: > >> Anton Korobeynikov wrote: >>> Hello >>> >>>> I just noticed that my union seems to look like an array....is that actually >>>> a union or do I have a problem somewhere? >>> Yes. Unions are pretty much broken and unimplemented. They can be >>> removed pretty soon (say, after 2.8) >> >> We've never released with unions. Could we remove them for the 2.8 >> release instead of afterwards when they're part of our forever forwards >> compatible bitcode format? >> >> Similar to what we did to the vfcmp and ficmp instructions maybe? > > I'm for it. I thought I'd seen something to that effect anyhow.Could you not just keep the IRBuilder instructions for the union, but have it lower it to whatever the necessary IR code is? Unions are nice as you do not need to worry about the size, else you have to figure out what size it needs to be if you handle it manually, and sometime that is exceedingly difficult before code generation time, causing a lot more code generation.
OvermindDL1 wrote:> On Sun, Aug 15, 2010 at 3:38 PM, Eric Christopher<echristo at apple.com> wrote: >> >> On Aug 15, 2010, at 2:34 PM, Nick Lewycky wrote: >> >>> Anton Korobeynikov wrote: >>>> Hello >>>> >>>>> I just noticed that my union seems to look like an array....is that actually >>>>> a union or do I have a problem somewhere? >>>> Yes. Unions are pretty much broken and unimplemented. They can be >>>> removed pretty soon (say, after 2.8) >>> >>> We've never released with unions. Could we remove them for the 2.8 >>> release instead of afterwards when they're part of our forever forwards >>> compatible bitcode format? >>> >>> Similar to what we did to the vfcmp and ficmp instructions maybe? >> >> I'm for it. I thought I'd seen something to that effect anyhow. > > Could you not just keep the IRBuilder instructions for the union, but > have it lower it to whatever the necessary IR code is? Unions are > nice as you do not need to worry about the size, else you have to > figure out what size it needs to be if you handle it manually, and > sometime that is exceedingly difficult before code generation time, > causing a lot more code generation.Unions are an entire new *type*. If it were merely new instructions that would certainly be feasible. The point of union is that it can express something you can't express in any other way, a type with a size of the max of a set of other types, even when you don't know those other sizes. You can get equivalent behaviour in LLVM IR with the GEP trick[1] and alloca'ing the right about of space, but there's no way at all to make it match the API of a type. Nick [1] - http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt
Forgot the mailing list is still oddly configured compared to the other 30 I use, sending to list... On Sun, Aug 15, 2010 at 5:23 PM, OvermindDL1 <overminddl1 at gmail.com> wrote:> On Sun, Aug 15, 2010 at 5:06 PM, Nick Lewycky <nicholas at mxc.ca> wrote: >> OvermindDL1 wrote: >>> Could you not just keep the IRBuilder instructions for the union, but >>> have it lower it to whatever the necessary IR code is? Unions are >>> nice as you do not need to worry about the size, else you have to >>> figure out what size it needs to be if you handle it manually, and >>> sometime that is exceedingly difficult before code generation time, >>> causing a lot more code generation. >> >> Unions are an entire new *type*. If it were merely new instructions that >> would certainly be feasible. The point of union is that it can express >> something you can't express in any other way, a type with a size of the max >> of a set of other types, even when you don't know those other sizes. >> >> You can get equivalent behaviour in LLVM IR with the GEP trick[1] and >> alloca'ing the right about of space, but there's no way at all to make it >> match the API of a type. >> >> [1] - >> http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt > > That is what I was referring to, I know it would not be a single > instruction, but a CreateUnion in the IRBuilder or so could take a > list of types and so forth and find out the max in the IR using the > GEP trick an allocate an appropriate sized type that it returns for > use, in the IR you would see a lot of new lines based on how many > types are passed in to figure out the size of the returned type or so, > then just use the 'memory' by casting as necessary, knowing that you > have the appropriate size in any case. >