aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/TargetData.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2008-01-29 06:23:44 +0000
committerDuncan Sands <baldrick@free.fr>2008-01-29 06:23:44 +0000
commitd102593b425da27fa96359300ff0e3d547d0ac8d (patch)
tree1e1c378b5a251371647bbaac306a9a2ea3873d21 /lib/Target/TargetData.cpp
parenta34d8a0d83bb39f4058e5dea4558e69cc4eda37c (diff)
Use getPreferredAlignmentLog or getPreferredAlignment
to get the alignment of global variables, rather than using hand-made versions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46495 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r--lib/Target/TargetData.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index 6d566693e8..64332a0df5 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -101,6 +101,7 @@ unsigned StructLayout::getElementContainingOffset(uint64_t Offset) const {
TargetAlignElem
TargetAlignElem::get(AlignTypeEnum align_type, unsigned char abi_align,
unsigned char pref_align, uint32_t bit_width) {
+ assert(abi_align <= pref_align && "Preferred alignment worse than ABI!");
TargetAlignElem retval;
retval.AlignType = align_type;
retval.ABIAlign = abi_align;
@@ -242,6 +243,7 @@ TargetData::TargetData(const Module *M)
void
TargetData::setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
unsigned char pref_align, uint32_t bit_width) {
+ assert(abi_align <= pref_align && "Preferred alignment worse than ABI!");
for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
if (Alignments[i].AlignType == align_type &&
Alignments[i].TypeBitWidth == bit_width) {
@@ -576,22 +578,29 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices,
return Result;
}
-/// getPreferredAlignmentLog - Return the preferred alignment of the
-/// specified global, returned in log form. This includes an explicitly
-/// requested alignment (if the global has one).
-unsigned TargetData::getPreferredAlignmentLog(const GlobalVariable *GV) const {
+/// getPreferredAlignment - Return the preferred alignment of the specified
+/// global. This includes an explicitly requested alignment (if the global
+/// has one).
+unsigned TargetData::getPreferredAlignment(const GlobalVariable *GV) const {
const Type *ElemType = GV->getType()->getElementType();
- unsigned Alignment = getPreferredTypeAlignmentShift(ElemType);
- if (GV->getAlignment() > (1U << Alignment))
- Alignment = Log2_32(GV->getAlignment());
-
+ unsigned Alignment = getPrefTypeAlignment(ElemType);
+ if (GV->getAlignment() > Alignment)
+ Alignment = GV->getAlignment();
+
if (GV->hasInitializer()) {
- if (Alignment < 4) {
+ 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 = 4; // 16-byte alignment.
+ Alignment = 16; // 16-byte alignment.
}
}
return Alignment;
}
+
+/// getPreferredAlignmentLog - Return the preferred alignment of the
+/// specified global, returned in log form. This includes an explicitly
+/// requested alignment (if the global has one).
+unsigned TargetData::getPreferredAlignmentLog(const GlobalVariable *GV) const {
+ return Log2_32(getPreferredAlignment(GV));
+}