[LLVMdev] Preferred alignment of globals > 16bytes

Richard Osborne richard at xmos.com
Thu Sep 6 08:51:52 PDT 2012


I recently noticed that all globals bigger than 16 bytes are being 16 
byte aligned by LLVM (assuming there isn't an explicitly requested 
alignment). I'd really rather avoid this, at least for the XCore 
backend. I tracked this down to the following code in TargetData.cpp:

   if (GV->hasInitializer() && GVAlignment == 0) {
     if (Alignment < 16) {
       // If the global is not external, see if it is large.  If so, 
give it a
       // larger alignment.
       if (getTypeSizeInBits(ElemType) > 128)
         Alignment = 16;    // 16-byte alignment.
     }
   }

I was a bit surprised to see these numbers hardcoded in TargetData since 
everything else is taken from the datalayout string. I was wondering 
what the logic was behind the number 16. Would it make sense to derive 
this number from the other alignments somehow (e.g. the maximum 
preferred alignment across all types). Alternatively would it make sense 
to make it configurable in the datalayout string?

-- 
Richard Osborne | XMOS
http://www.xmos.com




More information about the llvm-dev mailing list