[LLVMdev] TargetData::getPreferredAlignment(const GlobalVariable *GV) is strange ...

Duncan Sands baldrick at free.fr
Wed Mar 9 08:40:30 PST 2011


Hi Fabian,

> I am somewhat confused by the following method within the LLVM,
> especially the lines
> "confusion starts" ->  "confusion ends" are hard to follow.

yes, this seems like a wart.  It has been there ever since Chris added the
getPreferredAlignmentLog method in commit 25978.  Maybe he can comment on
whether the code to bump up the alignment for big objects is still needed.

Ciao, Duncan.

  Maybe the
> idea is that if there
> are such big data structures one does not waste much memory anyway if
> they are aligned
>   to a 16-byte boundary. However, my assembler complains here because
> it only supports
>   1-, 2-, 4- and 8-byte boundaries :-(
>
> I checked the svn log but I didn't find any explanation, the doxygen
> docu is not very helpful
> here, too. So, any help on this issue is highly appreciated.
>
> Thanks in advance!
>
> Ciao, Fabian
>
> unsigned TargetData::getPreferredAlignment(const GlobalVariable *GV) const {
>    const Type *ElemType = GV->getType()->getElementType();
>    unsigned Alignment = getPrefTypeAlignment(ElemType);
>    if (GV->getAlignment()>  Alignment)
>      Alignment = GV->getAlignment();
>
> ==================== confusion starts ========================
>    if (GV->hasInitializer()) {
>      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.
>      }
>    }
> ==================== confusion ends =========================
>
>    return Alignment;
> }
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list