[LLVMdev] TargetData::getPreferredAlignment(const GlobalVariable *GV) is strange ...
Fabian Scheler
fabian.scheler at gmail.com
Tue Mar 8 05:29:35 PST 2011
Hello everybody,
I am somewhat confused by the following method within the LLVM,
especially the lines
"confusion starts" -> "confusion ends" are hard to follow. 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;
}
More information about the llvm-dev
mailing list