[LLVMdev] Set alignment of a structure?

Chris Lattner clattner at apple.com
Thu May 7 16:20:22 PDT 2009


On May 7, 2009, at 9:58 AM, Nick Johnson wrote:

>>> Is it possible to set the alignment of a StructType in llvm?
>>
>> Nope.  If this is for a global variable (For example), you build the
>> ConstantStruct with a type that ensures that the elements get the
>> right offsets, then you put the alignment on the GlobalVariable  
>> itself.
>
> That is unfortunate for a few reasons,
>
> (1) I am generating multi-threaded code, and I want to use alignment
> to ensure that the memory used by each thread is in separate cache
> lines.
>
> (2) The code I generate links against external libraries which contain
> complicated data types---also featuring alignment.  Because llvm
> doesn't support alignment, I must represent these as opaque types.
> However, that means that I cannot even manually pad the size of the
> structure with a char array, since there is no way to determine the
> size of the opaque type.
>
> I think the best solution to this problem is simply to set a structure
> alignment.  If I'm not mistaken, nothing in llvm really needs to know
> the exact structure alignment until GEPs have been lowered to native.

I don't understand what you're saying.  LLVM can and does already  
express this, just in a different form.  Why does this need to be in  
the type?

-Chris



More information about the llvm-dev mailing list