llvm.org GIT mirror llvm / ca0ed74
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 Duncan Sands 13 years ago
16 changed file(s) with 54 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
285285 void EmitConstantValueOnly(const Constant *CV);
286286
287287 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
288 ///
289 void EmitGlobalConstant(const Constant* CV);
288 /// If Packed is false, pad to the ABI size.
289 void EmitGlobalConstant(const Constant* CV, bool Packed = false);
290290
291291 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
292292
189189 return 8*getABITypeSize(Ty);
190190 }
191191
192 /// getTypeSize - Obsolete method, do not use. Replaced by getTypeStoreSize
193 /// and getABITypeSize. For alias analysis of loads and stores you probably
194 /// want getTypeStoreSize. Use getABITypeSize for GEP computations and alloca
195 /// sizing.
196 uint64_t getTypeSize(const Type *Ty) const {
197 return getTypeStoreSize(Ty);
198 }
199
200192 /// getABITypeAlignment - Return the minimum ABI-required alignment for the
201193 /// specified type.
202194 unsigned char getABITypeAlignment(const Type *Ty) const;
191191 MachineConstantPoolEntry CPE = CP[i];
192192 const Type *Ty = CPE.getType();
193193 if (TAI->getFourByteConstantSection() &&
194 TM.getTargetData()->getTypeSize(Ty) == 4)
194 TM.getTargetData()->getABITypeSize(Ty) == 4)
195195 FourByteCPs.push_back(std::make_pair(CPE, i));
196196 else if (TAI->getEightByteConstantSection() &&
197 TM.getTargetData()->getTypeSize(Ty) == 8)
197 TM.getTargetData()->getABITypeSize(Ty) == 8)
198198 EightByteCPs.push_back(std::make_pair(CPE, i));
199199 else if (TAI->getSixteenByteConstantSection() &&
200 TM.getTargetData()->getTypeSize(Ty) == 16)
200 TM.getTargetData()->getABITypeSize(Ty) == 16)
201201 SixteenByteCPs.push_back(std::make_pair(CPE, i));
202202 else
203203 OtherCPs.push_back(std::make_pair(CPE, i));
228228 if (i != e-1) {
229229 const Type *Ty = CP[i].first.getType();
230230 unsigned EntSize =
231 TM.getTargetData()->getTypeSize(Ty);
231 TM.getTargetData()->getABITypeSize(Ty);
232232 unsigned ValEnd = CP[i].first.getOffset() + EntSize;
233233 // Emit inter-object padding for alignment.
234234 EmitZeros(CP[i+1].first.getOffset()-ValEnd);
749749 // We can emit the pointer value into this slot if the slot is an
750750 // integer slot greater or equal to the size of the pointer.
751751 if (Ty->isInteger() &&
752 TD->getTypeSize(Ty) >= TD->getTypeSize(Op->getType()))
752 TD->getABITypeSize(Ty) >= TD->getABITypeSize(Op->getType()))
753753 return EmitConstantValueOnly(Op);
754754
755755 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
804804 }
805805
806806 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
807 ///
808 void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
807 /// If Packed is false, pad to the ABI size.
808 void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) {
809809 const TargetData *TD = TM.getTargetData();
810 unsigned Size = Packed ?
811 TD->getTypeStoreSize(CV->getType()) : TD->getABITypeSize(CV->getType());
810812
811813 if (CV->isNullValue() || isa(CV)) {
812 EmitZeros(TD->getTypeSize(CV->getType()));
814 EmitZeros(Size);
813815 return;
814816 } else if (const ConstantArray *CVA = dyn_cast(CV)) {
815817 if (CVA->isString()) {
816818 EmitString(CVA);
817819 } else { // Not a string. Print the values in successive locations
818 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) {
819 EmitGlobalConstant(CVA->getOperand(i));
820 const Type* EltTy = CVA->getType()->getElementType();
821 uint64_t padSize = TD->getABITypeSize(EltTy) - TD->getTypeSize(EltTy);
822 EmitZeros(padSize);
823 }
820 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
821 EmitGlobalConstant(CVA->getOperand(i), false);
824822 }
825823 return;
826824 } else if (const ConstantStruct *CVS = dyn_cast(CV)) {
831829 const Constant* field = CVS->getOperand(i);
832830
833831 // Check if padding is needed and insert one or more 0s.
834 uint64_t fieldSize = TD->getTypeSize(field->getType());
832 uint64_t fieldSize = TD->getTypeStoreSize(field->getType());
835833 uint64_t padSize = ((i == e-1? cvsLayout->getSizeInBytes()
836834 : cvsLayout->getElementOffset(i+1))
837835 - cvsLayout->getElementOffset(i)) - fieldSize;
838836 sizeSoFar += fieldSize + padSize;
839837
840838 // Now print the actual field value
841 EmitGlobalConstant(field);
839 EmitGlobalConstant(field, CVS->getType()->isPacked());
842840
843841 // Insert the field padding unless it's zero bytes...
844842 EmitZeros(padSize);
915913 << "\t" << TAI->getCommentString()
916914 << " long double most significant halfword\n";
917915 }
916 EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty));
918917 return;
919918 } else if (CFP->getType() == Type::PPC_FP128Ty) {
920919 // all long double variants are printed as hex
977976 const VectorType *PTy = CP->getType();
978977
979978 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
980 EmitGlobalConstant(CP->getOperand(I));
979 EmitGlobalConstant(CP->getOperand(I), false);
981980
982981 return;
983982 }
257257
258258 const Type *GVType = (const Type*)GV->getType();
259259 unsigned Align = TM.getTargetData()->getPrefTypeAlignment(GVType);
260 unsigned Size = TM.getTargetData()->getTypeSize(GVType);
260 unsigned Size = TM.getTargetData()->getABITypeSize(GVType);
261261
262262 // If this global has a zero initializer, it is part of the .bss or common
263263 // section.
258258 // "giant object for PIC" optimization.
259259 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
260260 const Type *Ty = CP[i].getType();
261 unsigned Size = TM.getTargetData()->getTypeSize(Ty);
261 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
262262
263263 MachOWriter::MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal);
264264 OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
332332
333333 void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
334334 const Type *Ty = GV->getType()->getElementType();
335 unsigned Size = TM.getTargetData()->getTypeSize(Ty);
335 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
336336 unsigned Align = GV->getAlignment();
337337 if (Align == 0)
338338 Align = TM.getTargetData()->getPrefTypeAlignment(Ty);
379379
380380 void MachOWriter::EmitGlobal(GlobalVariable *GV) {
381381 const Type *Ty = GV->getType()->getElementType();
382 unsigned Size = TM.getTargetData()->getTypeSize(Ty);
382 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
383383 bool NoInit = !GV->hasInitializer();
384384
385385 // If this global has a zero initializer, it is part of the .bss or common
802802 if (isa(PC)) {
803803 continue;
804804 } else if (const ConstantVector *CP = dyn_cast(PC)) {
805 unsigned ElementSize = TD->getTypeSize(CP->getType()->getElementType());
805 unsigned ElementSize =
806 TD->getABITypeSize(CP->getType()->getElementType());
806807 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
807808 WorkList.push_back(CPair(CP->getOperand(i), PA+i*ElementSize));
808809 } else if (const ConstantExpr *CE = dyn_cast(PC)) {
903904 abort();
904905 }
905906 } else if (isa(PC)) {
906 memset((void*)PA, 0, (size_t)TD->getTypeSize(PC->getType()));
907 memset((void*)PA, 0, (size_t)TD->getABITypeSize(PC->getType()));
907908 } else if (const ConstantArray *CPA = dyn_cast(PC)) {
908 unsigned ElementSize = TD->getTypeSize(CPA->getType()->getElementType());
909 unsigned ElementSize =
910 TD->getABITypeSize(CPA->getType()->getElementType());
909911 for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
910912 WorkList.push_back(CPair(CPA->getOperand(i), PA+i*ElementSize));
911913 } else if (const ConstantStruct *CPS = dyn_cast(PC)) {
465465
466466 const Type *Ty = C->getType();
467467 if (Ty->isPrimitiveType() || Ty->isInteger()) {
468 unsigned Size = TM.getTargetData()->getTypeSize(Ty);
468 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
469469 switch(Size) {
470470 default: break; // Fall through to __TEXT,__const
471471 case 4:
434434 unsigned Offset = 0;
435435 if (!Constants.empty()) {
436436 Offset = Constants.back().getOffset();
437 Offset += TD->getTypeSize(Constants.back().getType());
437 Offset += TD->getABITypeSize(Constants.back().getType());
438438 Offset = (Offset+AlignMask)&~AlignMask;
439439 }
440440
458458 unsigned Offset = 0;
459459 if (!Constants.empty()) {
460460 Offset = Constants.back().getOffset();
461 Offset += TD->getTypeSize(Constants.back().getType());
461 Offset += TD->getABITypeSize(Constants.back().getType());
462462 Offset = (Offset+AlignMask)&~AlignMask;
463463 }
464464
820820 std::string name = Mang->getValueName(I);
821821 Constant *C = I->getInitializer();
822822 const Type *Type = C->getType();
823 unsigned Size = TD->getTypeSize(Type);
823 unsigned Size = TD->getABITypeSize(Type);
824824 unsigned Align = TD->getPreferredAlignmentLog(I);
825825
826826 const char *VisibilityDirective = NULL;
297297
298298 const TargetData &TD = *Fn.getTarget().getTargetData();
299299 for (unsigned i = 0, e = CPs.size(); i != e; ++i) {
300 unsigned Size = TD.getTypeSize(CPs[i].getType());
300 unsigned Size = TD.getABITypeSize(CPs[i].getType());
301301 // Verify that all constant pool entries are a multiple of 4 bytes. If not,
302302 // we would have to pad them out or something so that instructions stay
303303 // aligned.
213213
214214 std::string name = Mang->getValueName(I);
215215 Constant *C = I->getInitializer();
216 unsigned Size = TD->getTypeSize(C->getType());
216 unsigned Size = TD->getABITypeSize(C->getType());
217217 unsigned Align = TD->getPreferredAlignmentLog(I);
218218
219219 //1: hidden?
270270 O << "\n\n";
271271 std::string name = Mang->getValueName(I);
272272 Constant *C = I->getInitializer();
273 unsigned Size = TD->getTypeSize(C->getType());
273 unsigned Size = TD->getABITypeSize(C->getType());
274274 unsigned Align = TD->getPreferredTypeAlignmentShift(C->getType());
275275
276276 if (C->isNullValue() &&
278278 I->hasWeakLinkage() /* FIXME: Verify correct */)) {
279279 SwitchToDataSection(".data", I);
280280 if (I->hasInternalLinkage()) {
281 O << "\t.lcomm " << name << "#," << TD->getTypeSize(C->getType())
281 O << "\t.lcomm " << name << "#," << TD->getABITypeSize(C->getType())
282282 << "," << (1 << Align);
283283 O << "\n";
284284 } else {
285 O << "\t.common " << name << "#," << TD->getTypeSize(C->getType())
285 O << "\t.common " << name << "#," << TD->getABITypeSize(C->getType())
286286 << "," << (1 << Align);
287287 O << "\n";
288288 }
367367 case Type::DoubleTyID:
368368 return "r8";
369369 case Type::PointerTyID:
370 return "i"+utostr(TD->getTypeSize(Ty));
370 return "i"+utostr(TD->getABITypeSize(Ty));
371371 default:
372372 cerr << "TypeID = " << Ty->getTypeID() << '\n';
373373 assert(0 && "Invalid type in TypeToPostfix()");
676676 uint64_t FieldIndex = cast(IndexValue)->getZExtValue();
677677 // Offset is the sum of all previous structure fields.
678678 for (uint64_t F = 0; F
679 Size += TD->getTypeSize(StrucTy->getContainedType((unsigned)F));
679 Size += TD->getABITypeSize(StrucTy->getContainedType((unsigned)F));
680680 printPtrLoad(Size);
681681 printSimpleInstruction("add");
682682 continue;
683683 } else if (const SequentialType* SeqTy = dyn_cast(*I)) {
684 Size = TD->getTypeSize(SeqTy->getElementType());
684 Size = TD->getABITypeSize(SeqTy->getElementType());
685685 } else {
686 Size = TD->getTypeSize(*I);
686 Size = TD->getABITypeSize(*I);
687687 }
688688 // Add offset of current element to stack top.
689689 if (!isZeroValue(IndexValue)) {
10071007
10081008
10091009 void MSILWriter::printAllocaInstruction(const AllocaInst* Inst) {
1010 uint64_t Size = TD->getTypeSize(Inst->getAllocatedType());
1010 uint64_t Size = TD->getABITypeSize(Inst->getAllocatedType());
10111011 // Constant optimization.
10121012 if (const ConstantInt* CInt = dyn_cast(Inst->getOperand(0))) {
10131013 printPtrLoad(CInt->getZExtValue()*Size);
14251425 // Print not duplicated type
14261426 if (Printed.insert(Ty).second) {
14271427 Out << ".class value explicit ansi sealed '" << Name << "'";
1428 Out << " { .pack " << 1 << " .size " << TD->getTypeSize(Ty) << " }\n\n";
1428 Out << " { .pack " << 1 << " .size " << TD->getABITypeSize(Ty)<< " }\n\n";
14291429 }
14301430 }
14311431 }
14531453 const Type* Ty = C->getType();
14541454 // Print zero initialized constant.
14551455 if (isa(C) || C->isNullValue()) {
1456 TySize = TD->getTypeSize(C->getType());
1456 TySize = TD->getABITypeSize(C->getType());
14571457 Offset += TySize;
14581458 Out << "int8 (0) [" << TySize << "]";
14591459 return;
14611461 // Print constant initializer
14621462 switch (Ty->getTypeID()) {
14631463 case Type::IntegerTyID: {
1464 TySize = TD->getTypeSize(Ty);
1464 TySize = TD->getABITypeSize(Ty);
14651465 const ConstantInt* Int = cast(C);
14661466 Out << getPrimitiveTypeName(Ty,true) << "(" << Int->getSExtValue() << ")";
14671467 break;
14681468 }
14691469 case Type::FloatTyID:
14701470 case Type::DoubleTyID: {
1471 TySize = TD->getTypeSize(Ty);
1471 TySize = TD->getABITypeSize(Ty);
14721472 const ConstantFP* FP = cast(C);
14731473 if (Ty->getTypeID() == Type::FloatTyID)
14741474 Out << "int32 (" <<
14871487 }
14881488 break;
14891489 case Type::PointerTyID:
1490 TySize = TD->getTypeSize(C->getType());
1490 TySize = TD->getABITypeSize(C->getType());
14911491 // Initialize with global variable address
14921492 if (const GlobalVariable *G = dyn_cast(C)) {
14931493 std::string name = getValueName(G);
418418 O << "\n\n";
419419 std::string name = Mang->getValueName(I);
420420 Constant *C = I->getInitializer();
421 unsigned Size = TD->getTypeSize(C->getType());
421 unsigned Size = TD->getABITypeSize(C->getType());
422422 unsigned Align = TD->getPrefTypeAlignment(C->getType());
423423
424424 if (C->isNullValue() && (I->hasLinkOnceLinkage() ||
430430 O << "\t.local " << name << "\n";
431431
432432 O << "\t.comm " << name << ","
433 << TD->getTypeSize(C->getType())
433 << TD->getABITypeSize(C->getType())
434434 << "," << Align << "\n";
435435
436436 } else {
656656 O << Directive << name << "\n";
657657
658658 Constant *C = I->getInitializer();
659 unsigned Size = TD->getTypeSize(C->getType());
659 unsigned Size = TD->getABITypeSize(C->getType());
660660 unsigned Align = TD->getPreferredAlignmentLog(I);
661661
662662 if (C->isNullValue() && /* FIXME: Verify correct */
908908
909909 Constant *C = I->getInitializer();
910910 const Type *Type = C->getType();
911 unsigned Size = TD->getTypeSize(Type);
911 unsigned Size = TD->getABITypeSize(Type);
912912 unsigned Align = TD->getPreferredAlignmentLog(I);
913913
914914 if (C->isNullValue() && /* FIXME: Verify correct */
227227 O << "\n\n";
228228 std::string name = Mang->getValueName(I);
229229 Constant *C = I->getInitializer();
230 unsigned Size = TD->getTypeSize(C->getType());
230 unsigned Size = TD->getABITypeSize(C->getType());
231231 unsigned Align = TD->getPrefTypeAlignment(C->getType());
232232
233233 if (C->isNullValue() &&
237237 if (I->hasInternalLinkage())
238238 O << "\t.local " << name << "\n";
239239
240 O << "\t.comm " << name << "," << TD->getTypeSize(C->getType())
240 O << "\t.comm " << name << "," << TD->getABITypeSize(C->getType())
241241 << "," << Align;
242242 O << "\n";
243243 } else {
5050 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
5151 AI != AE; ++AI)
5252 // Size should be aligned to DWORD boundary
53 Size += ((TD->getTypeSize(AI->getType()) + 3)/4)*4;
53 Size += ((TD->getABITypeSize(AI->getType()) + 3)/4)*4;
5454
5555 // We're not supporting tooooo huge arguments :)
5656 Info.setBytesToPopOnReturn((unsigned int)Size);
155155 std::string name = Mang->getValueName(I);
156156 Constant *C = I->getInitializer();
157157 const Type *Type = C->getType();
158 unsigned Size = TD->getTypeSize(Type);
158 unsigned Size = TD->getABITypeSize(Type);
159159 unsigned Align = TD->getPreferredAlignmentLog(I);
160160
161161 if (I->hasHiddenVisibility()) {