[llvm-commits] [llvm] r46495 - in /llvm/trunk: include/llvm/Target/TargetData.h lib/CodeGen/ELFWriter.cpp lib/CodeGen/MachOWriter.cpp lib/ExecutionEngine/JIT/JIT.cpp lib/Target/IA64/IA64AsmPrinter.cpp lib/Target/Sparc/SparcAsmPrinter.cpp lib/Target/TargetData.cpp
Duncan Sands
baldrick at free.fr
Mon Jan 28 22:23:44 PST 2008
Author: baldrick
Date: Tue Jan 29 00:23:44 2008
New Revision: 46495
URL: http://llvm.org/viewvc/llvm-project?rev=46495&view=rev
Log:
Use getPreferredAlignmentLog or getPreferredAlignment
to get the alignment of global variables, rather than
using hand-made versions.
Modified:
llvm/trunk/include/llvm/Target/TargetData.h
llvm/trunk/lib/CodeGen/ELFWriter.cpp
llvm/trunk/lib/CodeGen/MachOWriter.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp
llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
llvm/trunk/lib/Target/TargetData.cpp
Modified: llvm/trunk/include/llvm/Target/TargetData.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetData.h?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetData.h (original)
+++ llvm/trunk/include/llvm/Target/TargetData.h Tue Jan 29 00:23:44 2008
@@ -200,7 +200,7 @@
/// getPrefTypeAlignment - Return the preferred stack/global alignment for
- /// the specified type.
+ /// the specified type. This is always at least as good as the ABI alignment.
unsigned char getPrefTypeAlignment(const Type *Ty) const;
/// getPreferredTypeAlignmentShift - Return the preferred alignment for the
@@ -230,6 +230,11 @@
/// avoid a dangling pointer in this cache.
void InvalidateStructLayoutInfo(const StructType *Ty) const;
+ /// getPreferredAlignment - Return the preferred alignment of the specified
+ /// global. This includes an explicitly requested alignment (if the global
+ /// has one).
+ unsigned getPreferredAlignment(const GlobalVariable *GV) const;
+
/// getPreferredAlignmentLog - Return the preferred alignment of the
/// specified global, returned in log form. This includes an explicitly
/// requested alignment (if the global has one).
Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Tue Jan 29 00:23:44 2008
@@ -257,7 +257,7 @@
}
const Type *GVType = (const Type*)GV->getType();
- unsigned Align = TM.getTargetData()->getPrefTypeAlignment(GVType);
+ unsigned Align = TM.getTargetData()->getPreferredAlignment(GV);
unsigned Size = TM.getTargetData()->getABITypeSize(GVType);
// If this global has a zero initializer, it is part of the .bss or common
Modified: llvm/trunk/lib/CodeGen/MachOWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.cpp?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachOWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachOWriter.cpp Tue Jan 29 00:23:44 2008
@@ -334,10 +334,8 @@
void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
const Type *Ty = GV->getType()->getElementType();
unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
- unsigned Align = GV->getAlignment();
- if (Align == 0)
- Align = TM.getTargetData()->getPrefTypeAlignment(Ty);
-
+ unsigned Align = TM.getTargetData()->getPreferredAlignment(GV);
+
// Reserve space in the .bss section for this symbol while maintaining the
// desired section alignment, which must be at least as much as required by
// this symbol.
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Tue Jan 29 00:23:44 2008
@@ -355,7 +355,7 @@
// compilation.
const Type *GlobalType = GV->getType()->getElementType();
size_t S = getTargetData()->getABITypeSize(GlobalType);
- size_t A = getTargetData()->getPrefTypeAlignment(GlobalType);
+ size_t A = getTargetData()->getPreferredAlignment(GV);
if (A <= 8) {
Ptr = malloc(S);
} else {
Modified: llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp Tue Jan 29 00:23:44 2008
@@ -271,8 +271,8 @@
std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer();
unsigned Size = TD->getABITypeSize(C->getType());
- unsigned Align = TD->getPreferredTypeAlignmentShift(C->getType());
-
+ unsigned Align = TD->getPreferredAlignmentLog(I);
+
if (C->isNullValue() &&
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
Modified: llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp Tue Jan 29 00:23:44 2008
@@ -229,7 +229,7 @@
std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer();
unsigned Size = TD->getABITypeSize(C->getType());
- unsigned Align = TD->getPrefTypeAlignment(C->getType());
+ unsigned Align = TD->getPreferredAlignment(I);
if (C->isNullValue() &&
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
Modified: llvm/trunk/lib/Target/TargetData.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetData.cpp?rev=46495&r1=46494&r2=46495&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetData.cpp (original)
+++ llvm/trunk/lib/Target/TargetData.cpp Tue Jan 29 00:23:44 2008
@@ -101,6 +101,7 @@
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 @@
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 @@
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));
+}
More information about the llvm-commits
mailing list