Eliminate the remaining uses of getTypeSize. This
should only effect x86 when using long double. Now
12/16 bytes are output for long double globals (the
exact amount depends on the alignment). This brings
globals in line with the rest of LLVM: the space
reserved for an object is now always the ABI size.
One tricky point is that only 10 bytes should be
output for long double if it is a field in a packed
struct, which is the reason for the additional
argument to EmitGlobalConstant.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43688 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 47a5345..eb9375c 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -192,13 +192,13 @@
MachineConstantPoolEntry CPE = CP[i];
const Type *Ty = CPE.getType();
if (TAI->getFourByteConstantSection() &&
- TM.getTargetData()->getTypeSize(Ty) == 4)
+ TM.getTargetData()->getABITypeSize(Ty) == 4)
FourByteCPs.push_back(std::make_pair(CPE, i));
else if (TAI->getEightByteConstantSection() &&
- TM.getTargetData()->getTypeSize(Ty) == 8)
+ TM.getTargetData()->getABITypeSize(Ty) == 8)
EightByteCPs.push_back(std::make_pair(CPE, i));
else if (TAI->getSixteenByteConstantSection() &&
- TM.getTargetData()->getTypeSize(Ty) == 16)
+ TM.getTargetData()->getABITypeSize(Ty) == 16)
SixteenByteCPs.push_back(std::make_pair(CPE, i));
else
OtherCPs.push_back(std::make_pair(CPE, i));
@@ -229,7 +229,7 @@
if (i != e-1) {
const Type *Ty = CP[i].first.getType();
unsigned EntSize =
- TM.getTargetData()->getTypeSize(Ty);
+ TM.getTargetData()->getABITypeSize(Ty);
unsigned ValEnd = CP[i].first.getOffset() + EntSize;
// Emit inter-object padding for alignment.
EmitZeros(CP[i+1].first.getOffset()-ValEnd);
@@ -750,7 +750,7 @@
// We can emit the pointer value into this slot if the slot is an
// integer slot greater or equal to the size of the pointer.
if (Ty->isInteger() &&
- TD->getTypeSize(Ty) >= TD->getTypeSize(Op->getType()))
+ TD->getABITypeSize(Ty) >= TD->getABITypeSize(Op->getType()))
return EmitConstantValueOnly(Op);
assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
@@ -805,23 +805,21 @@
}
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
-///
-void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
+/// If Packed is false, pad to the ABI size.
+void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) {
const TargetData *TD = TM.getTargetData();
+ unsigned Size = Packed ?
+ TD->getTypeStoreSize(CV->getType()) : TD->getABITypeSize(CV->getType());
if (CV->isNullValue() || isa<UndefValue>(CV)) {
- EmitZeros(TD->getTypeSize(CV->getType()));
+ EmitZeros(Size);
return;
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
if (CVA->isString()) {
EmitString(CVA);
} else { // Not a string. Print the values in successive locations
- for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) {
- EmitGlobalConstant(CVA->getOperand(i));
- const Type* EltTy = CVA->getType()->getElementType();
- uint64_t padSize = TD->getABITypeSize(EltTy) - TD->getTypeSize(EltTy);
- EmitZeros(padSize);
- }
+ for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
+ EmitGlobalConstant(CVA->getOperand(i), false);
}
return;
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
@@ -832,14 +830,14 @@
const Constant* field = CVS->getOperand(i);
// Check if padding is needed and insert one or more 0s.
- uint64_t fieldSize = TD->getTypeSize(field->getType());
+ uint64_t fieldSize = TD->getTypeStoreSize(field->getType());
uint64_t padSize = ((i == e-1? cvsLayout->getSizeInBytes()
: cvsLayout->getElementOffset(i+1))
- cvsLayout->getElementOffset(i)) - fieldSize;
sizeSoFar += fieldSize + padSize;
// Now print the actual field value
- EmitGlobalConstant(field);
+ EmitGlobalConstant(field, CVS->getType()->isPacked());
// Insert the field padding unless it's zero bytes...
EmitZeros(padSize);
@@ -916,6 +914,7 @@
<< "\t" << TAI->getCommentString()
<< " long double most significant halfword\n";
}
+ EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty));
return;
} else if (CFP->getType() == Type::PPC_FP128Ty) {
// all long double variants are printed as hex
@@ -978,7 +977,7 @@
const VectorType *PTy = CP->getType();
for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
- EmitGlobalConstant(CP->getOperand(I));
+ EmitGlobalConstant(CP->getOperand(I), false);
return;
}
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp
index 8ecddb8..efdf029 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -258,7 +258,7 @@
const Type *GVType = (const Type*)GV->getType();
unsigned Align = TM.getTargetData()->getPrefTypeAlignment(GVType);
- unsigned Size = TM.getTargetData()->getTypeSize(GVType);
+ unsigned Size = TM.getTargetData()->getABITypeSize(GVType);
// If this global has a zero initializer, it is part of the .bss or common
// section.
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index 0c74375..9389088 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -259,7 +259,7 @@
// "giant object for PIC" optimization.
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
const Type *Ty = CP[i].getType();
- unsigned Size = TM.getTargetData()->getTypeSize(Ty);
+ unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
MachOWriter::MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal);
OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
@@ -333,7 +333,7 @@
void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
const Type *Ty = GV->getType()->getElementType();
- unsigned Size = TM.getTargetData()->getTypeSize(Ty);
+ unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
unsigned Align = GV->getAlignment();
if (Align == 0)
Align = TM.getTargetData()->getPrefTypeAlignment(Ty);
@@ -380,7 +380,7 @@
void MachOWriter::EmitGlobal(GlobalVariable *GV) {
const Type *Ty = GV->getType()->getElementType();
- unsigned Size = TM.getTargetData()->getTypeSize(Ty);
+ unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
bool NoInit = !GV->hasInitializer();
// If this global has a zero initializer, it is part of the .bss or common
@@ -803,7 +803,8 @@
if (isa<UndefValue>(PC)) {
continue;
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(PC)) {
- unsigned ElementSize = TD->getTypeSize(CP->getType()->getElementType());
+ unsigned ElementSize =
+ TD->getABITypeSize(CP->getType()->getElementType());
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
WorkList.push_back(CPair(CP->getOperand(i), PA+i*ElementSize));
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(PC)) {
@@ -904,9 +905,10 @@
abort();
}
} else if (isa<ConstantAggregateZero>(PC)) {
- memset((void*)PA, 0, (size_t)TD->getTypeSize(PC->getType()));
+ memset((void*)PA, 0, (size_t)TD->getABITypeSize(PC->getType()));
} else if (const ConstantArray *CPA = dyn_cast<ConstantArray>(PC)) {
- unsigned ElementSize = TD->getTypeSize(CPA->getType()->getElementType());
+ unsigned ElementSize =
+ TD->getABITypeSize(CPA->getType()->getElementType());
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
WorkList.push_back(CPair(CPA->getOperand(i), PA+i*ElementSize));
} else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(PC)) {
diff --git a/lib/CodeGen/MachOWriter.h b/lib/CodeGen/MachOWriter.h
index 6d88832..0492c9e 100644
--- a/lib/CodeGen/MachOWriter.h
+++ b/lib/CodeGen/MachOWriter.h
@@ -466,7 +466,7 @@
const Type *Ty = C->getType();
if (Ty->isPrimitiveType() || Ty->isInteger()) {
- unsigned Size = TM.getTargetData()->getTypeSize(Ty);
+ unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
switch(Size) {
default: break; // Fall through to __TEXT,__const
case 4:
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index ca74684..c35674a 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -435,7 +435,7 @@
unsigned Offset = 0;
if (!Constants.empty()) {
Offset = Constants.back().getOffset();
- Offset += TD->getTypeSize(Constants.back().getType());
+ Offset += TD->getABITypeSize(Constants.back().getType());
Offset = (Offset+AlignMask)&~AlignMask;
}
@@ -459,7 +459,7 @@
unsigned Offset = 0;
if (!Constants.empty()) {
Offset = Constants.back().getOffset();
- Offset += TD->getTypeSize(Constants.back().getType());
+ Offset += TD->getABITypeSize(Constants.back().getType());
Offset = (Offset+AlignMask)&~AlignMask;
}