>> 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
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
Chris, On Thu, May 7, 2009 at 7:20 PM, Chris Lattner <clattner at apple.com> wrote:> nd 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?I misunderstood your earlier email. Now I understand. Setting alignment on a global variable will work for many of my needs. However, say I need to construct an array of OpaqueTypes; can I set an alignment on the elements of that array? For instance, is it possible to have an array where each element is forced to be a multiple of the cacheline size? Thank you again! -- Nick Johnson