[LLVMdev] Set alignment of a structure?

Chris Lattner clattner at apple.com
Fri May 8 10:23:08 PDT 2009

On May 8, 2009, at 7:18 AM, Nick Johnson wrote:
> I would like to create an array of handles so that the threads can
> simply index into the array by their instance number.  Like before, I
> want to guarantee that if two threads i and i+1 try to access their
> handles in the handles array, that handles[i] and handles[i+1] do not
> share a cacheline.
> In this case, I cannot even manually pad the arrays, because I cannot
> determine the size of the OpaqueType handle.  Ideally, I want to tell
> llvm that, no matter how big or small a handle is, it should ensure
> that each element of the array is a multiple of cacheline size.
> Again, this is an alignment property of the array /element/ type, not
> of the array storage location.

I don't think you need to do anything fancy here, just pass the size  
of the struct as a symbolic variable value.  Given that, you can use  
something like:

void *P = base_of_array;

P = (char*)P + threadno*handlesize;

The code that sets up the handles array just needs to make sure that  
handlesize is a multiple of the cache line size.


More information about the llvm-dev mailing list