[LLVMdev] Set alignment of a structure?

Nick Johnson nicholas.paul.johnson at gmail.com
Thu May 7 09:58:06 PDT 2009


>> 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.

-- 
Nick Johnson



More information about the llvm-dev mailing list