[LLVMdev] Union type, is it really used or necessary?

Erik de Castro Lopo mle+cl at mega-nerd.com
Tue Sep 7 17:35:23 PDT 2010


Dan Gohman wrote:

> If you want to make sure the pointer field is properly aligned, why not
> just use a non-packed struct: { i32, pointer } ?  Or if you really want
> a packed struct, can you use <{ i32, i32, pointer }>, since you're
> already emitting target-dependent IR anyway?
>
> If you're computing the offset in order to use as a value
> within the program, you can use ConstantExpr::getOffsetOf.
> (If this isn't exposed in whatever bindings you're using,
> that can be fixed.)

The thing is, I am not using the LLVM library, I generate IR
code directly from Haskell (not using the library because it
makes bootstrapping the compiler I'm working on more difficult).

Secondly, my code, which currently works with llvm-2.7, assumes
packed structs and unions. Using

     <{ i32, i32, pointer }>

won't work for me because the 32 bit version looks like:

     <{ i32, pointer }>

and that means the the pointer element will have different struct
indices depending on whether I'm compiling for 32 vs 64 bit
targets.

Another possible solution is using:

     <{ i64, pointer }>      ; 64 bit version
     <{ i32, pointer }>      ; 32 bit version

but then the first elements are of different types.

Generating IR code without the benefit of unions, makes both
me generating and generated code far less readable. I'm going
to have to stick with version 2.7 and work on getting unions
back in 2.9.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/



More information about the llvm-dev mailing list