llvm.org GIT mirror llvm / ceb4d1a
Rename getABITypeSize to getTypePaddedSize, as suggested by Chris. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62099 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
53 changed file(s) with 154 addition(s) and 150 deletion(s). Raw diff Collapse all Expand all
6969 external store_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
7070
7171 (** Computes the ABI size of a type in bytes for a target.
72 See the method llvm::TargetData::getABITypeSize. *)
72 See the method llvm::TargetData::getTypePaddedSize. *)
7373 external abi_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
7474
7575 (** Computes the ABI alignment of a type in bytes for a target.
587587 Mikhail Glushenkov
588588 LLVM Compiler Infrastructure
589589
590 Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $
590 Last modified: $Date$
591591
592592
593593
172172 return 8*getTypeStoreSize(Ty);
173173 }
174174
175 /// getABITypeSize - Return the offset in bytes between successive objects
175 /// getTypePaddedSize - Return the offset in bytes between successive objects
176176 /// of the specified type, including alignment padding. This is the amount
177177 /// that alloca reserves for this type. For example, returns 12 or 16 for
178178 /// x86_fp80, depending on alignment.
179 uint64_t getABITypeSize(const Type* Ty) const {
179 uint64_t getTypePaddedSize(const Type* Ty) const {
180180 // Round up to the next alignment boundary.
181181 return RoundUpAlignment(getTypeStoreSize(Ty), getABITypeAlignment(Ty));
182182 }
183183
184 /// getABITypeSizeInBits - Return the offset in bits between successive
184 /// getTypePaddedSizeInBits - Return the offset in bits between successive
185185 /// objects of the specified type, including alignment padding; always a
186186 /// multiple of 8. This is the amount that alloca reserves for this type.
187187 /// For example, returns 96 or 128 for x86_fp80, depending on alignment.
188 uint64_t getABITypeSizeInBits(const Type* Ty) const {
189 return 8*getABITypeSize(Ty);
188 uint64_t getTypePaddedSizeInBits(const Type* Ty) const {
189 return 8*getTypePaddedSize(Ty);
190190 }
191191
192192 /// getABITypeAlignment - Return the minimum ABI-required alignment for the
6969 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
7070
7171 /** Computes the ABI size of a type in bytes for a target.
72 See the method llvm::TargetData::getABITypeSize. */
72 See the method llvm::TargetData::getTypePaddedSize. */
7373 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
7474
7575 /** Computes the ABI alignment of a type in bytes for a target.
194194 }
195195
196196 if (AccessTy->isSized())
197 return TD.getABITypeSize(AccessTy) < Size;
197 return TD.getTypePaddedSize(AccessTy) < Size;
198198 return false;
199199 }
200200
7575 Offset += TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue());
7676 } else {
7777 const SequentialType *SQT = cast(*GTI);
78 Offset += TD.getABITypeSize(SQT->getElementType())*CI->getSExtValue();
78 Offset += TD.getTypePaddedSize(SQT->getElementType())*CI->getSExtValue();
7979 }
8080 }
8181 return true;
458458 const Type *IndexedTy = GTI.getIndexedType();
459459 if (!IndexedTy->isSized()) return;
460460 unsigned GEPOpiBits = Index->getType()->getPrimitiveSizeInBits();
461 uint64_t TypeSize = TD ? TD->getABITypeSize(IndexedTy) : 1;
461 uint64_t TypeSize = TD ? TD->getTypePaddedSize(IndexedTy) : 1;
462462 LocalMask = APInt::getAllOnesValue(GEPOpiBits);
463463 LocalKnownZero = LocalKnownOne = APInt(GEPOpiBits, 0);
464464 ComputeMaskedBits(Index, LocalMask,
297297 // Emit inter-object padding for alignment.
298298 if (J != E) {
299299 const Type *Ty = Entry.getType();
300 unsigned EntSize = TM.getTargetData()->getABITypeSize(Ty);
300 unsigned EntSize = TM.getTargetData()->getTypePaddedSize(Ty);
301301 unsigned ValEnd = Entry.getOffset() + EntSize;
302302 EmitZeros(J->second.first.getOffset()-ValEnd);
303303 }
856856
857857 // We can emit the pointer value into this slot if the slot is an
858858 // integer slot greater or equal to the size of the pointer.
859 if (TD->getABITypeSize(Ty) >= TD->getABITypeSize(Op->getType()))
859 if (TD->getTypePaddedSize(Ty) >= TD->getTypePaddedSize(Op->getType()))
860860 return EmitConstantValueOnly(Op);
861861
862862 O << "((";
863863 EmitConstantValueOnly(Op);
864 APInt ptrMask = APInt::getAllOnesValue(TD->getABITypeSizeInBits(Ty));
864 APInt ptrMask = APInt::getAllOnesValue(TD->getTypePaddedSizeInBits(Ty));
865865
866866 SmallString<40> S;
867867 ptrMask.toStringUnsigned(S);
957957 void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS) {
958958 // Print the fields in successive locations. Pad to align if needed!
959959 const TargetData *TD = TM.getTargetData();
960 unsigned Size = TD->getABITypeSize(CVS->getType());
960 unsigned Size = TD->getTypePaddedSize(CVS->getType());
961961 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
962962 uint64_t sizeSoFar = 0;
963963 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
964964 const Constant* field = CVS->getOperand(i);
965965
966966 // Check if padding is needed and insert one or more 0s.
967 uint64_t fieldSize = TD->getABITypeSize(field->getType());
967 uint64_t fieldSize = TD->getTypePaddedSize(field->getType());
968968 uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
969969 - cvsLayout->getElementOffset(i)) - fieldSize;
970970 sizeSoFar += fieldSize + padSize;
10581058 << '\t' << TAI->getCommentString()
10591059 << " long double most significant halfword\n";
10601060 }
1061 EmitZeros(TD->getABITypeSize(Type::X86_FP80Ty) -
1061 EmitZeros(TD->getTypePaddedSize(Type::X86_FP80Ty) -
10621062 TD->getTypeStoreSize(Type::X86_FP80Ty));
10631063 return;
10641064 } else if (CFP->getType() == Type::PPC_FP128Ty) {
11381138 void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
11391139 const TargetData *TD = TM.getTargetData();
11401140 const Type *type = CV->getType();
1141 unsigned Size = TD->getABITypeSize(type);
1141 unsigned Size = TD->getTypePaddedSize(type);
11421142
11431143 if (CV->isNullValue() || isa(CV)) {
11441144 EmitZeros(Size);
275275
276276 unsigned Align = TM.getTargetData()->getPreferredAlignment(GV);
277277 unsigned Size =
278 TM.getTargetData()->getABITypeSize(GV->getType()->getElementType());
278 TM.getTargetData()->getTypePaddedSize(GV->getType()->getElementType());
279279
280280 // If this global has a zero initializer, it is part of the .bss or common
281281 // section.
275275 // "giant object for PIC" optimization.
276276 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
277277 const Type *Ty = CP[i].getType();
278 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
278 unsigned Size = TM.getTargetData()->getTypePaddedSize(Ty);
279279
280280 MachOWriter::MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal);
281281 OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
349349
350350 void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
351351 const Type *Ty = GV->getType()->getElementType();
352 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
352 unsigned Size = TM.getTargetData()->getTypePaddedSize(Ty);
353353 unsigned Align = TM.getTargetData()->getPreferredAlignment(GV);
354354
355355 // Reserve space in the .bss section for this symbol while maintaining the
394394
395395 void MachOWriter::EmitGlobal(GlobalVariable *GV) {
396396 const Type *Ty = GV->getType()->getElementType();
397 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
397 unsigned Size = TM.getTargetData()->getTypePaddedSize(Ty);
398398 bool NoInit = !GV->hasInitializer();
399399
400400 // If this global has a zero initializer, it is part of the .bss or common
819819 continue;
820820 } else if (const ConstantVector *CP = dyn_cast(PC)) {
821821 unsigned ElementSize =
822 TD->getABITypeSize(CP->getType()->getElementType());
822 TD->getTypePaddedSize(CP->getType()->getElementType());
823823 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
824824 WorkList.push_back(CPair(CP->getOperand(i), PA+i*ElementSize));
825825 } else if (const ConstantExpr *CE = dyn_cast(PC)) {
920920 abort();
921921 }
922922 } else if (isa(PC)) {
923 memset((void*)PA, 0, (size_t)TD->getABITypeSize(PC->getType()));
923 memset((void*)PA, 0, (size_t)TD->getTypePaddedSize(PC->getType()));
924924 } else if (const ConstantArray *CPA = dyn_cast(PC)) {
925925 unsigned ElementSize =
926 TD->getABITypeSize(CPA->getType()->getElementType());
926 TD->getTypePaddedSize(CPA->getType()->getElementType());
927927 for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
928928 WorkList.push_back(CPair(CPA->getOperand(i), PA+i*ElementSize));
929929 } else if (const ConstantStruct *CPS = dyn_cast(PC)) {
467467
468468 const Type *Ty = C->getType();
469469 if (Ty->isPrimitiveType() || Ty->isInteger()) {
470 unsigned Size = TM.getTargetData()->getABITypeSize(Ty);
470 unsigned Size = TM.getTargetData()->getTypePaddedSize(Ty);
471471 switch(Size) {
472472 default: break; // Fall through to __TEXT,__const
473473 case 4:
502502 unsigned Offset = 0;
503503 if (!Constants.empty()) {
504504 Offset = Constants.back().getOffset();
505 Offset += TD->getABITypeSize(Constants.back().getType());
505 Offset += TD->getTypePaddedSize(Constants.back().getType());
506506 Offset = (Offset+AlignMask)&~AlignMask;
507507 }
508508
526526 unsigned Offset = 0;
527527 if (!Constants.empty()) {
528528 Offset = Constants.back().getOffset();
529 Offset += TD->getABITypeSize(Constants.back().getType());
529 Offset += TD->getTypePaddedSize(Constants.back().getType());
530530 Offset = (Offset+AlignMask)&~AlignMask;
531531 }
532532
272272 if (ConstantInt *CI = dyn_cast(Idx)) {
273273 if (CI->getZExtValue() == 0) continue;
274274 uint64_t Offs =
275 TD.getABITypeSize(Ty)*cast(CI)->getSExtValue();
275 TD.getTypePaddedSize(Ty)*cast(CI)->getSExtValue();
276276 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
277277 if (N == 0)
278278 // Unhandled operand. Halt "fast" selection and bail.
281281 }
282282
283283 // N = N + Idx * ElementSize;
284 uint64_t ElementSize = TD.getABITypeSize(Ty);
284 uint64_t ElementSize = TD.getTypePaddedSize(Ty);
285285 unsigned IdxN = getRegForGEPIndex(Idx);
286286 if (IdxN == 0)
287287 // Unhandled operand. Halt "fast" selection and bail.
35713571 SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0);
35723572 // Increment the pointer, VAList, to the next vaarg
35733573 Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList,
3574 DAG.getConstant(TLI.getTargetData()->getABITypeSize(VT.getTypeForMVT()),
3575 TLI.getPointerTy()));
3574 DAG.getConstant(TLI.getTargetData()->
3575 getTypePaddedSize(VT.getTypeForMVT()),
3576 TLI.getPointerTy()));
35763577 // Store the incremented VAList to the legalized pointer
35773578 Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0);
35783579 // Load the actual argument out of the pointer VAList
295295 Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type);
296296 if (Align == 0) {
297297 // Alignment of vector types. FIXME!
298 Align = TM.getTargetData()->getABITypeSize(Type);
298 Align = TM.getTargetData()->getTypePaddedSize(Type);
299299 Align = Log2_64(Align);
300300 }
301301 }
124124 // Given an array type, recursively traverse the elements.
125125 if (const ArrayType *ATy = dyn_cast(Ty)) {
126126 const Type *EltTy = ATy->getElementType();
127 uint64_t EltSize = TLI.getTargetData()->getABITypeSize(EltTy);
127 uint64_t EltSize = TLI.getTargetData()->getTypePaddedSize(EltTy);
128128 for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
129129 ComputeValueVTs(TLI, EltTy, ValueVTs, Offsets,
130130 StartingOffset + i * EltSize);
287287 if (AllocaInst *AI = dyn_cast(I))
288288 if (ConstantInt *CUI = dyn_cast(AI->getArraySize())) {
289289 const Type *Ty = AI->getAllocatedType();
290 uint64_t TySize = TLI.getTargetData()->getABITypeSize(Ty);
290 uint64_t TySize = TLI.getTargetData()->getTypePaddedSize(Ty);
291291 unsigned Align =
292292 std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty),
293293 AI->getAlignment());
26022602 if (ConstantInt *CI = dyn_cast(Idx)) {
26032603 if (CI->getZExtValue() == 0) continue;
26042604 uint64_t Offs =
2605 TD->getABITypeSize(Ty)*cast(CI)->getSExtValue();
2605 TD->getTypePaddedSize(Ty)*cast(CI)->getSExtValue();
26062606 N = DAG.getNode(ISD::ADD, N.getValueType(), N,
26072607 DAG.getIntPtrConstant(Offs));
26082608 continue;
26092609 }
26102610
26112611 // N = N + Idx * ElementSize;
2612 uint64_t ElementSize = TD->getABITypeSize(Ty);
2612 uint64_t ElementSize = TD->getTypePaddedSize(Ty);
26132613 SDValue IdxN = getValue(Idx);
26142614
26152615 // If the index is smaller or larger than intptr_t, truncate or extend
26452645 return; // getValue will auto-populate this.
26462646
26472647 const Type *Ty = I.getAllocatedType();
2648 uint64_t TySize = TLI.getTargetData()->getABITypeSize(Ty);
2648 uint64_t TySize = TLI.getTargetData()->getTypePaddedSize(Ty);
26492649 unsigned Align =
26502650 std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty),
26512651 I.getAlignment());
49504950 // Otherwise, create a stack slot and emit a store to it before the
49514951 // asm.
49524952 const Type *Ty = OpVal->getType();
4953 uint64_t TySize = TLI.getTargetData()->getABITypeSize(Ty);
4953 uint64_t TySize = TLI.getTargetData()->getTypePaddedSize(Ty);
49544954 unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty);
49554955 MachineFunction &MF = DAG.getMachineFunction();
49564956 int SSFI = MF.getFrameInfo()->CreateStackObject(TySize, Align);
52355235 Src = DAG.getNode(ISD::ZERO_EXTEND, IntPtr, Src);
52365236
52375237 // Scale the source by the type size.
5238 uint64_t ElementSize = TD->getABITypeSize(I.getType()->getElementType());
5238 uint64_t ElementSize = TD->getTypePaddedSize(I.getType()->getElementType());
52395239 Src = DAG.getNode(ISD::MUL, Src.getValueType(),
52405240 Src, DAG.getIntPtrConstant(ElementSize));
52415241
53365336 const PointerType *Ty = cast(I->getType());
53375337 const Type *ElementTy = Ty->getElementType();
53385338 unsigned FrameAlign = getByValTypeAlignment(ElementTy);
5339 unsigned FrameSize = getTargetData()->getABITypeSize(ElementTy);
5339 unsigned FrameSize = getTargetData()->getTypePaddedSize(ElementTy);
53405340 // For ByVal, alignment should be passed from FE. BE will guess if
53415341 // this info is not there but there are cases it cannot get right.
53425342 if (F.getParamAlignment(j))
54695469 const PointerType *Ty = cast(Args[i].Ty);
54705470 const Type *ElementTy = Ty->getElementType();
54715471 unsigned FrameAlign = getByValTypeAlignment(ElementTy);
5472 unsigned FrameSize = getTargetData()->getABITypeSize(ElementTy);
5472 unsigned FrameSize = getTargetData()->getTypePaddedSize(ElementTy);
54735473 // For ByVal, alignment should come from FE. BE will guess if this
54745474 // info is not there but there are cases it cannot get right.
54755475 if (Args[i].Alignment)
113113 if (const ArrayType *AT = dyn_cast(AI->getAllocatedType()))
114114 // If an array has more than SSPBufferSize bytes of allocated space,
115115 // then we emit stack protectors.
116 if (SSPBufferSize <= TD->getABITypeSize(AT))
116 if (SSPBufferSize <= TD->getTypePaddedSize(AT))
117117 return true;
118118 }
119119 }
5353
5454 char* ExecutionEngine::getMemoryForGV(const GlobalVariable* GV) {
5555 const Type *ElTy = GV->getType()->getElementType();
56 size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy);
56 size_t GVSize = (size_t)getTargetData()->getTypePaddedSize(ElTy);
5757 return new char[GVSize];
5858 }
5959
844844 return;
845845 } else if (const ConstantVector *CP = dyn_cast(Init)) {
846846 unsigned ElementSize =
847 getTargetData()->getABITypeSize(CP->getType()->getElementType());
847 getTargetData()->getTypePaddedSize(CP->getType()->getElementType());
848848 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
849849 InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
850850 return;
851851 } else if (isa(Init)) {
852 memset(Addr, 0, (size_t)getTargetData()->getABITypeSize(Init->getType()));
852 memset(Addr, 0, (size_t)getTargetData()->getTypePaddedSize(Init->getType()));
853853 return;
854854 } else if (const ConstantArray *CPA = dyn_cast(Init)) {
855855 unsigned ElementSize =
856 getTargetData()->getABITypeSize(CPA->getType()->getElementType());
856 getTargetData()->getTypePaddedSize(CPA->getType()->getElementType());
857857 for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
858858 InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
859859 return;
10001000 InitializeMemory(GV->getInitializer(), GA);
10011001
10021002 const Type *ElTy = GV->getType()->getElementType();
1003 size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy);
1003 size_t GVSize = (size_t)getTargetData()->getTypePaddedSize(ElTy);
10041004 NumInitBytes += (unsigned)GVSize;
10051005 ++NumGlobals;
10061006 }
749749 unsigned NumElements =
750750 getOperandValue(I.getOperand(0), SF).IntVal.getZExtValue();
751751
752 unsigned TypeSize = (size_t)TD.getABITypeSize(Ty);
752 unsigned TypeSize = (size_t)TD.getTypePaddedSize(Ty);
753753
754754 // Avoid malloc-ing zero bytes, use max()...
755755 unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
809809 assert(BitWidth == 64 && "Invalid index type for getelementptr");
810810 Idx = (int64_t)IdxGV.IntVal.getZExtValue();
811811 }
812 Total += TD.getABITypeSize(ST->getElementType())*Idx;
812 Total += TD.getTypePaddedSize(ST->getElementType())*Idx;
813813 }
814814 }
815815
561561 // emit it into memory. It goes in the same array as the generated
562562 // code, jump tables, etc.
563563 const Type *GlobalType = GV->getType()->getElementType();
564 size_t S = getTargetData()->getABITypeSize(GlobalType);
564 size_t S = getTargetData()->getTypePaddedSize(GlobalType);
565565 size_t A = getTargetData()->getPreferredAlignment(GV);
566566 if (GV->isThreadLocal()) {
567567 MutexGuard locked(lock);
616616 ///
617617 char* JIT::getMemoryForGV(const GlobalVariable* GV) {
618618 const Type *ElTy = GV->getType()->getElementType();
619 size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy);
619 size_t GVSize = (size_t)getTargetData()->getTypePaddedSize(ElTy);
620620 if (GV->isThreadLocal()) {
621621 MutexGuard locked(lock);
622622 return TJI.allocateThreadLocalMemory(GVSize);
658658 unsigned Size = CPE.Offset;
659659 const Type *Ty = CPE.isMachineConstantPoolEntry()
660660 ? CPE.Val.MachineCPVal->getType() : CPE.Val.ConstVal->getType();
661 Size += TheJIT->getTargetData()->getABITypeSize(Ty);
661 Size += TheJIT->getTargetData()->getTypePaddedSize(Ty);
662662 return Size;
663663 }
664664
686686
687687 unsigned JITEmitter::addSizeOfGlobal(const GlobalVariable *GV, unsigned Size) {
688688 const Type *ElTy = GV->getType()->getElementType();
689 size_t GVSize = (size_t)TheJIT->getTargetData()->getABITypeSize(ElTy);
689 size_t GVSize = (size_t)TheJIT->getTargetData()->getTypePaddedSize(ElTy);
690690 size_t GVAlign =
691691 (size_t)TheJIT->getTargetData()->getPreferredAlignment(GV);
692692 DOUT << "JIT: Adding in size " << GVSize << " alignment " << GVAlign;
10791079 unsigned Size = CPE.Offset;
10801080 const Type *Ty = CPE.isMachineConstantPoolEntry()
10811081 ? CPE.Val.MachineCPVal->getType() : CPE.Val.ConstVal->getType();
1082 Size += TheJIT->getTargetData()->getABITypeSize(Ty);
1082 Size += TheJIT->getTargetData()->getTypePaddedSize(Ty);
10831083
10841084 unsigned Align = 1 << MCP->getConstantPoolAlignment();
10851085 ConstantPoolBase = allocateSpace(Size, Align);
294294
295295 const TargetData &TD = *Fn.getTarget().getTargetData();
296296 for (unsigned i = 0, e = CPs.size(); i != e; ++i) {
297 unsigned Size = TD.getABITypeSize(CPs[i].getType());
297 unsigned Size = TD.getTypePaddedSize(CPs[i].getType());
298298 // Verify that all constant pool entries are a multiple of 4 bytes. If not,
299299 // we would have to pad them out or something so that instructions stay
300300 // aligned.
824824 std::string name = Mang->getValueName(GVar);
825825 Constant *C = GVar->getInitializer();
826826 const Type *Type = C->getType();
827 unsigned Size = TD->getABITypeSize(Type);
827 unsigned Size = TD->getTypePaddedSize(Type);
828828 unsigned Align = TD->getPreferredAlignmentLog(GVar);
829829 bool isDarwin = Subtarget->isTargetDarwin();
830830
215215
216216 std::string name = Mang->getValueName(GVar);
217217 Constant *C = GVar->getInitializer();
218 unsigned Size = TD->getABITypeSize(C->getType());
218 unsigned Size = TD->getTypePaddedSize(C->getType());
219219 unsigned Align = TD->getPreferredAlignmentLog(GVar);
220220
221221 // 0: Switch to section
489489 const VectorType *VTy = cast(Ty);
490490 return printSimpleType(Out, VTy->getElementType(), isSigned,
491491 " __attribute__((vector_size(" +
492 utostr(TD->getABITypeSize(VTy)) + " ))) " + NameSoFar);
492 utostr(TD->getTypePaddedSize(VTy)) + " ))) " + NameSoFar);
493493 }
494494
495495 default:
534534 const VectorType *VTy = cast(Ty);
535535 return printSimpleType(Out, VTy->getElementType(), isSigned,
536536 " __attribute__((vector_size(" +
537 utostr(TD->getABITypeSize(VTy)) + " ))) " + NameSoFar);
537 utostr(TD->getTypePaddedSize(VTy)) + " ))) " + NameSoFar);
538538 }
539539
540540 default:
528528
529529 Constant *C = GVar->getInitializer();
530530 const Type *Type = C->getType();
531 unsigned Size = TD->getABITypeSize(Type);
531 unsigned Size = TD->getTypePaddedSize(Type);
532532 unsigned Align = TD->getPreferredAlignmentLog(GVar);
533533
534534 SwitchToSection(TAI->SectionForGlobal(GVar));
116116 Constant *C = cast(GV)->getInitializer();
117117 const Type *Type = cast(C)->getType()->getElementType();
118118
119 unsigned Size = TD->getABITypeSize(Type);
119 unsigned Size = TD->getTypePaddedSize(Type);
120120 if (Size) {
121121 unsigned Align = TD->getPreferredAlignment(GV);
122122 if (Align <= 32)
137137 DarwinTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
138138 const TargetData *TD = TM.getTargetData();
139139
140 unsigned Size = TD->getABITypeSize(Ty);
140 unsigned Size = TD->getTypePaddedSize(Ty);
141141 if (Size == 4)
142142 return FourByteConstantSection;
143143 else if (Size == 8)
108108 // FIXME: string here is temporary, until stuff will fully land in.
109109 // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's
110110 // currently directly used by asmprinter.
111 unsigned Size = TD->getABITypeSize(Ty);
111 unsigned Size = TD->getTypePaddedSize(Ty);
112112 if (Size == 4 || Size == 8 || Size == 16) {
113113 std::string Name = ".rodata.cst" + utostr(Size);
114114
127127 const ConstantArray *CVA = cast(C);
128128 const Type *Ty = CVA->getType()->getElementType();
129129
130 unsigned Size = TD->getABITypeSize(Ty);
130 unsigned Size = TD->getTypePaddedSize(Ty);
131131 if (Size <= 16) {
132132 assert(getCStringSection() && "Should have string section prefix");
133133
265265 O << "\n\n";
266266 std::string name = Mang->getValueName(GVar);
267267 Constant *C = GVar->getInitializer();
268 unsigned Size = TD->getABITypeSize(C->getType());
268 unsigned Size = TD->getTypePaddedSize(C->getType());
269269 unsigned Align = TD->getPreferredAlignmentLog(GVar);
270270
271271 printVisibility(name, GVar->getVisibility());
377377 case Type::DoubleTyID:
378378 return "r8";
379379 case Type::PointerTyID:
380 return "i"+utostr(TD->getABITypeSize(Ty));
380 return "i"+utostr(TD->getTypePaddedSize(Ty));
381381 default:
382382 cerr << "TypeID = " << Ty->getTypeID() << '\n';
383383 assert(0 && "Invalid type in TypeToPostfix()");
687687 uint64_t FieldIndex = cast(IndexValue)->getZExtValue();
688688 // Offset is the sum of all previous structure fields.
689689 for (uint64_t F = 0; F
690 Size += TD->getABITypeSize(StrucTy->getContainedType((unsigned)F));
690 Size += TD->getTypePaddedSize(StrucTy->getContainedType((unsigned)F));
691691 printPtrLoad(Size);
692692 printSimpleInstruction("add");
693693 continue;
694694 } else if (const SequentialType* SeqTy = dyn_cast(*I)) {
695 Size = TD->getABITypeSize(SeqTy->getElementType());
695 Size = TD->getTypePaddedSize(SeqTy->getElementType());
696696 } else {
697 Size = TD->getABITypeSize(*I);
697 Size = TD->getTypePaddedSize(*I);
698698 }
699699 // Add offset of current element to stack top.
700700 if (!isZeroValue(IndexValue)) {
10191019
10201020
10211021 void MSILWriter::printAllocaInstruction(const AllocaInst* Inst) {
1022 uint64_t Size = TD->getABITypeSize(Inst->getAllocatedType());
1022 uint64_t Size = TD->getTypePaddedSize(Inst->getAllocatedType());
10231023 // Constant optimization.
10241024 if (const ConstantInt* CInt = dyn_cast(Inst->getOperand(0))) {
10251025 printPtrLoad(CInt->getZExtValue()*Size);
14351435 // Print not duplicated type
14361436 if (Printed.insert(Ty).second) {
14371437 Out << ".class value explicit ansi sealed '" << Name << "'";
1438 Out << " { .pack " << 1 << " .size " << TD->getABITypeSize(Ty)<< " }\n\n";
1438 Out << " { .pack " << 1 << " .size " << TD->getTypePaddedSize(Ty);
1439 Out << " }\n\n";
14391440 }
14401441 }
14411442 }
14641465 const Type* Ty = C->getType();
14651466 // Print zero initialized constant.
14661467 if (isa(C) || C->isNullValue()) {
1467 TySize = TD->getABITypeSize(C->getType());
1468 TySize = TD->getTypePaddedSize(C->getType());
14681469 Offset += TySize;
14691470 Out << "int8 (0) [" << TySize << "]";
14701471 return;
14721473 // Print constant initializer
14731474 switch (Ty->getTypeID()) {
14741475 case Type::IntegerTyID: {
1475 TySize = TD->getABITypeSize(Ty);
1476 TySize = TD->getTypePaddedSize(Ty);
14761477 const ConstantInt* Int = cast(C);
14771478 Out << getPrimitiveTypeName(Ty,true) << "(" << Int->getSExtValue() << ")";
14781479 break;
14791480 }
14801481 case Type::FloatTyID:
14811482 case Type::DoubleTyID: {
1482 TySize = TD->getABITypeSize(Ty);
1483 TySize = TD->getTypePaddedSize(Ty);
14831484 const ConstantFP* FP = cast(C);
14841485 if (Ty->getTypeID() == Type::FloatTyID)
14851486 Out << "int32 (" <<
14981499 }
14991500 break;
15001501 case Type::PointerTyID:
1501 TySize = TD->getABITypeSize(C->getType());
1502 TySize = TD->getTypePaddedSize(C->getType());
15021503 // Initialize with global variable address
15031504 if (const GlobalVariable *G = dyn_cast(C)) {
15041505 std::string name = getValueName(G);
479479 std::string name = Mang->getValueName(GVar);
480480 Constant *C = GVar->getInitializer();
481481 const Type *CTy = C->getType();
482 unsigned Size = TD->getABITypeSize(CTy);
482 unsigned Size = TD->getTypePaddedSize(CTy);
483483 const ConstantArray *CVA = dyn_cast(C);
484484 bool printSizeAndType = true;
485485
211211 return false;
212212
213213 const Type *Ty = GV->getType()->getElementType();
214 unsigned Size = TD->getABITypeSize(Ty);
214 unsigned Size = TD->getTypePaddedSize(Ty);
215215
216216 // if this is a internal constant string, there is a special
217217 // section for it, but not in small data/bss.
542542 // hacking it. This feature should come soon so we can uncomment the
543543 // stuff below.
544544 //if (!Subtarget->hasABICall() &&
545 // IsInSmallSection(getTargetData()->getABITypeSize(C->getType()))) {
545 // IsInSmallSection(getTargetData()->getTypePaddedSize(C->getType()))) {
546546 // SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, MVT::i32, CP);
547547 // SDValue GOT = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i32);
548548 // ResNode = DAG.getNode(ISD::ADD, MVT::i32, GOT, GPRelNode);
6565
6666 if (isa(GV)) {
6767 const TargetData *TD = TM.getTargetData();
68 unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
68 unsigned Size = TD->getTypePaddedSize(GV->getType()->getElementType());
6969 unsigned Threshold = Subtarget->getSSectionThreshold();
7070
7171 if (Size > 0 && Size <= Threshold) {
298298 continue;
299299
300300 const Type *Ty = C->getType();
301 unsigned Size = TD->getABITypeSize(Ty);
301 unsigned Size = TD->getTypePaddedSize(Ty);
302302 O << name << " " <<"RES"<< " " << Size ;
303303 O << "\n";
304304 }
326326 O << CurrentFnName << ".retval:\n";
327327 const Type *RetType = F->getReturnType();
328328 if (RetType->getTypeID() != Type::VoidTyID) {
329 unsigned RetSize = TD->getABITypeSize(RetType);
329 unsigned RetSize = TD->getTypePaddedSize(RetType);
330330 if (RetSize > 0)
331331 O << CurrentFnName << ".retval" << " RES " << RetSize;
332332 }
336336 AI != AE; ++AI) {
337337 std::string ArgName = Mang->getValueName(AI);
338338 const Type *ArgTy = AI->getType();
339 unsigned ArgSize = TD->getABITypeSize(ArgTy);
339 unsigned ArgSize = TD->getTypePaddedSize(ArgTy);
340340 O << CurrentFnName << ".args." << ArgName << " RES " << ArgSize;
341341 }
342342 // Emit the function variables.
356356
357357 Constant *C = I->getInitializer();
358358 const Type *Ty = C->getType();
359 unsigned Size = TD->getABITypeSize(Ty);
359 unsigned Size = TD->getTypePaddedSize(Ty);
360360 // Emit memory reserve directive.
361361 O << VarName << " RES " << Size << "\n";
362362 }
678678
679679 Constant *C = GVar->getInitializer();
680680 const Type *Type = C->getType();
681 unsigned Size = TD->getABITypeSize(Type);
681 unsigned Size = TD->getTypePaddedSize(Type);
682682 unsigned Align = TD->getPreferredAlignmentLog(GVar);
683683
684684 SwitchToSection(TAI->SectionForGlobal(GVar));
903903
904904 Constant *C = GVar->getInitializer();
905905 const Type *Type = C->getType();
906 unsigned Size = TD->getABITypeSize(Type);
906 unsigned Size = TD->getTypePaddedSize(Type);
907907 unsigned Align = TD->getPreferredAlignmentLog(GVar);
908908
909909 SwitchToSection(TAI->SectionForGlobal(GVar));
245245 O << "\n\n";
246246 std::string name = Mang->getValueName(GVar);
247247 Constant *C = GVar->getInitializer();
248 unsigned Size = TD->getABITypeSize(C->getType());
248 unsigned Size = TD->getTypePaddedSize(C->getType());
249249 unsigned Align = TD->getPreferredAlignment(GVar);
250250
251251 printVisibility(name, GVar->getVisibility());
5252 }
5353
5454 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
55 return unwrap(TD)->getABITypeSize(unwrap(Ty));
55 return unwrap(TD)->getTypePaddedSize(unwrap(Ty));
5656 }
5757
5858 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
5757 StructAlignment = std::max(TyAlign, StructAlignment);
5858
5959 MemberOffsets[i] = StructSize;
60 StructSize += TD.getABITypeSize(Ty); // Consume space for this data item
60 StructSize += TD.getTypePaddedSize(Ty); // Consume space for this data item
6161 }
6262
6363 // Empty structures have alignment of 1 byte.
424424 return getPointerSizeInBits();
425425 case Type::ArrayTyID: {
426426 const ArrayType *ATy = cast(Ty);
427 return getABITypeSizeInBits(ATy->getElementType())*ATy->getNumElements();
427 return getTypePaddedSizeInBits(ATy->getElementType())*ATy->getNumElements();
428428 }
429429 case Type::StructTyID:
430430 // Get the layout annotation... which is lazily created on demand.
567567
568568 // Get the array index and the size of each array element.
569569 int64_t arrayIdx = cast(Indices[CurIDX])->getSExtValue();
570 Result += arrayIdx * (int64_t)getABITypeSize(Ty);
570 Result += arrayIdx * (int64_t)getTypePaddedSize(Ty);
571571 }
572572 }
573573
7474 Ty = cast(Ty)->getElementType();
7575
7676 // Size should be aligned to DWORD boundary
77 Size += ((TD->getABITypeSize(Ty) + 3)/4)*4;
77 Size += ((TD->getTypePaddedSize(Ty) + 3)/4)*4;
7878 }
7979
8080 // We're not supporting tooooo huge arguments :)
766766 std::string name = Mang->getValueName(GVar);
767767 Constant *C = GVar->getInitializer();
768768 const Type *Type = C->getType();
769 unsigned Size = TD->getABITypeSize(Type);
769 unsigned Size = TD->getTypePaddedSize(Type);
770770 unsigned Align = TD->getPreferredAlignmentLog(GVar);
771771
772772 printVisibility(name, GVar->getVisibility());
5757 Ty = cast(Ty)->getElementType();
5858
5959 // Size should be aligned to DWORD boundary
60 Size += ((TD->getABITypeSize(Ty) + 3)/4)*4;
60 Size += ((TD->getTypePaddedSize(Ty) + 3)/4)*4;
6161 }
6262
6363 // We're not supporting tooooo huge arguments :)
385385 unsigned Idx = cast(Op)->getZExtValue();
386386 Disp += SL->getElementOffset(Idx);
387387 } else {
388 uint64_t S = TD.getABITypeSize(GTI.getIndexedType());
388 uint64_t S = TD.getTypePaddedSize(GTI.getIndexedType());
389389 if (ConstantInt *CI = dyn_cast(Op)) {
390390 // Constant-offset addressing.
391391 Disp += CI->getSExtValue() * S;
14681468 unsigned Align = TD.getPreferredTypeAlignmentShift(C->getType());
14691469 if (Align == 0) {
14701470 // Alignment of vector types. FIXME!
1471 Align = TD.getABITypeSize(C->getType());
1471 Align = TD.getTypePaddedSize(C->getType());
14721472 Align = Log2_64(Align);
14731473 }
14741474
213213
214214 EmitAlignment(Align, GV, 2);
215215
216 unsigned Size = TD->getABITypeSize(C->getType());
216 unsigned Size = TD->getTypePaddedSize(C->getType());
217217 if (GV->isThreadLocal()) {
218218 Size *= MaxThreads;
219219 }
264264 }
265265 SDValue base = getGlobalAddressWrapper(GA, GV, DAG);
266266 const TargetData *TD = TM.getTargetData();
267 unsigned Size = TD->getABITypeSize(Ty);
267 unsigned Size = TD->getTypePaddedSize(Ty);
268268 SDValue offset = DAG.getNode(ISD::MUL, MVT::i32, BuildGetId(DAG),
269269 DAG.getConstant(Size, MVT::i32));
270270 return DAG.getNode(ISD::ADD, MVT::i32, base, offset);
105105 XCoreTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
106106 const TargetData *TD = TM.getTargetData();
107107
108 unsigned Size = TD->getABITypeSize(Ty);
108 unsigned Size = TD->getTypePaddedSize(Ty);
109109 if (Size == 4 || Size == 8 || Size == 16) {
110110 std::string Name = ".cp.const" + utostr(Size);
111111
510510 return 0; // It's not worth it.
511511 NewGlobals.reserve(NumElements);
512512
513 uint64_t EltSize = TD.getABITypeSize(STy->getElementType());
513 uint64_t EltSize = TD.getTypePaddedSize(STy->getElementType());
514514 unsigned EltAlign = TD.getABITypeAlignment(STy->getElementType());
515515 for (unsigned i = 0, e = NumElements; i != e; ++i) {
516516 Constant *In = getAggregateConstantElement(Init,
14441444 // (2048 bytes currently), as we don't want to introduce a 16M global or
14451445 // something.
14461446 if (NElements->getZExtValue()*
1447 TD.getABITypeSize(MI->getAllocatedType()) < 2048) {
1447 TD.getTypePaddedSize(MI->getAllocatedType()) < 2048) {
14481448 GVI = OptimizeGlobalAddressOfMalloc(GV, MI);
14491449 return true;
14501450 }
816816 cast(AddrInst->getOperand(i))->getZExtValue();
817817 ConstantOffset += SL->getElementOffset(Idx);
818818 } else {
819 uint64_t TypeSize = TD->getABITypeSize(GTI.getIndexedType());
819 uint64_t TypeSize = TD->getTypePaddedSize(GTI.getIndexedType());
820820 if (ConstantInt *CI = dyn_cast(AddrInst->getOperand(i))) {
821821 ConstantOffset += CI->getSExtValue()*TypeSize;
822822 } else if (TypeSize) { // Scales of zero don't do anything.
304304 if (AllocaInst* A = dyn_cast(*I)) {
305305 if (ConstantInt* C = dyn_cast(A->getArraySize()))
306306 pointerSize = C->getZExtValue() *
307 TD.getABITypeSize(A->getAllocatedType());
307 TD.getTypePaddedSize(A->getAllocatedType());
308308 } else {
309309 const PointerType* PT = cast(
310310 cast(*I)->getType());
311 pointerSize = TD.getABITypeSize(PT->getElementType());
311 pointerSize = TD.getTypePaddedSize(PT->getElementType());
312312 }
313313
314314 // See if the call site touches it
381381 if (AllocaInst* A = dyn_cast(*I)) {
382382 if (ConstantInt* C = dyn_cast(A->getArraySize()))
383383 pointerSize = C->getZExtValue() *
384 TD.getABITypeSize(A->getAllocatedType());
384 TD.getTypePaddedSize(A->getAllocatedType());
385385 } else {
386386 const PointerType* PT = cast(cast(*I)->getType());
387 pointerSize = TD.getABITypeSize(PT->getElementType());
387 pointerSize = TD.getTypePaddedSize(PT->getElementType());
388388 }
389389
390390 // See if this pointer could alias it
51415141 for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e;
51425142 ++i, ++GTI) {
51435143 Value *Op = *i;
5144 uint64_t Size = TD.getABITypeSize(GTI.getIndexedType()) & PtrSizeMask;
5144 uint64_t Size = TD.getTypePaddedSize(GTI.getIndexedType()) & PtrSizeMask;
51455145 if (ConstantInt *OpC = dyn_cast(Op)) {
51465146 if (OpC->isZero()) continue;
51475147
52325232 if (const StructType *STy = dyn_cast(*GTI)) {
52335233 Offset += TD.getStructLayout(STy)->getElementOffset(CI->getZExtValue());
52345234 } else {
5235 uint64_t Size = TD.getABITypeSize(GTI.getIndexedType());
5235 uint64_t Size = TD.getTypePaddedSize(GTI.getIndexedType());
52365236 Offset += Size*CI->getSExtValue();
52375237 }
52385238 } else {
52485248 Value *VariableIdx = GEP->getOperand(i);
52495249 // Determine the scale factor of the variable element. For example, this is
52505250 // 4 if the variable index is into an array of i32.
5251 uint64_t VariableScale = TD.getABITypeSize(GTI.getIndexedType());
5251 uint64_t VariableScale = TD.getTypePaddedSize(GTI.getIndexedType());
52525252
52535253 // Verify that there are no other variable indices. If so, emit the hard way.
52545254 for (++i, ++GTI; i != e; ++i, ++GTI) {
52625262 if (const StructType *STy = dyn_cast(*GTI)) {
52635263 Offset += TD.getStructLayout(STy)->getElementOffset(CI->getZExtValue());
52645264 } else {
5265 uint64_t Size = TD.getABITypeSize(GTI.getIndexedType());
5265 uint64_t Size = TD.getTypePaddedSize(GTI.getIndexedType());
52665266 Offset += Size*CI->getSExtValue();
52675267 }
52685268 }
74187418 // same, we open the door to infinite loops of various kinds.
74197419 if (!AI.hasOneUse() && CastElTyAlign == AllocElTyAlign) return 0;
74207420
7421 uint64_t AllocElTySize = TD->getABITypeSize(AllocElTy);
7422 uint64_t CastElTySize = TD->getABITypeSize(CastElTy);
7421 uint64_t AllocElTySize = TD->getTypePaddedSize(AllocElTy);
7422 uint64_t CastElTySize = TD->getTypePaddedSize(CastElTy);
74237423 if (CastElTySize == 0 || AllocElTySize == 0) return 0;
74247424
74257425 // See if we can satisfy the modulus by pulling a scale out of the array
77077707 // is something like [0 x {int, int}]
77087708 const Type *IntPtrTy = TD->getIntPtrType();
77097709 int64_t FirstIdx = 0;
7710 if (int64_t TySize = TD->getABITypeSize(Ty)) {
7710 if (int64_t TySize = TD->getTypePaddedSize(Ty)) {
77117711 FirstIdx = Offset/TySize;
77127712 Offset -= FirstIdx*TySize;
77137713
77397739 Offset -= SL->getElementOffset(Elt);
77407740 Ty = STy->getElementType(Elt);
77417741 } else if (const ArrayType *AT = dyn_cast(Ty)) {
7742 uint64_t EltSize = TD->getABITypeSize(AT->getElementType());
7742 uint64_t EltSize = TD->getTypePaddedSize(AT->getElementType());
77437743 assert(EltSize && "Cannot index into a zero-sized array");
77447744 NewIndices.push_back(ConstantInt::get(IntPtrTy,Offset/EltSize));
77457745 Offset %= EltSize;
84068406 // is a single-index GEP.
84078407 if (X->getType() == CI.getType()) {
84088408 // Get the size of the pointee type.
8409 uint64_t Size = TD->getABITypeSize(DestPointee);
8409 uint64_t Size = TD->getTypePaddedSize(DestPointee);
84108410
84118411 // Convert the constant to intptr type.
84128412 APInt Offset = Cst->getValue();
84268426 // "inttoptr+GEP" instead of "add+intptr".
84278427
84288428 // Get the size of the pointee type.
8429 uint64_t Size = TD->getABITypeSize(DestPointee);
8429 uint64_t Size = TD->getTypePaddedSize(DestPointee);
84308430
84318431 // Convert the constant to intptr type.
84328432 APInt Offset = Cst->getValue();
94919491 const Type* DstTy = cast(CI->getType())->getElementType();
94929492 if (!SrcTy->isSized() || !DstTy->isSized())
94939493 return false;
9494 if (TD->getABITypeSize(SrcTy) != TD->getABITypeSize(DstTy))
9494 if (TD->getTypePaddedSize(SrcTy) != TD->getTypePaddedSize(DstTy))
94959495 return false;
94969496 return true;
94979497 }
1060710607 const Type *SrcElTy = cast(X->getType())->getElementType();
1060810608 const Type *ResElTy=cast(PtrOp->getType())->getElementType();
1060910609 if (isa(SrcElTy) &&
10610 TD->getABITypeSize(cast(SrcElTy)->getElementType()) ==
10611 TD->getABITypeSize(ResElTy)) {
10610 TD->getTypePaddedSize(cast(SrcElTy)->getElementType()) ==
10611 TD->getTypePaddedSize(ResElTy)) {
1061210612 Value *Idx[2];
1061310613 Idx[0] = Constant::getNullValue(Type::Int32Ty);
1061410614 Idx[1] = GEP.getOperand(1);
1062510625
1062610626 if (isa(SrcElTy) && ResElTy == Type::Int8Ty) {
1062710627 uint64_t ArrayEltSize =
10628 TD->getABITypeSize(cast(SrcElTy)->getElementType());
10628 TD->getTypePaddedSize(cast(SrcElTy)->getElementType());
1062910629
1063010630 // Check to see if "tmp" is a scale by a multiple of ArrayEltSize. We
1063110631 // allow either a mul, shift, or constant here.
1077810778 // Note that we only do this for alloca's, because malloc should allocate and
1077910779 // return a unique pointer, even for a zero byte allocation.
1078010780 if (isa(AI) && AI.getAllocatedType()->isSized() &&
10781 TD->getABITypeSize(AI.getAllocatedType()) == 0)
10781 TD->getTypePaddedSize(AI.getAllocatedType()) == 0)
1078210782 return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
1078310783
1078410784 return 0;
329329 Value *OpVal = getCastedVersionOf(opcode, *i);
330330 SCEVHandle Idx = SE->getSCEV(OpVal);
331331
332 uint64_t TypeSize = TD->getABITypeSize(GTI.getIndexedType());
332 uint64_t TypeSize = TD->getTypePaddedSize(GTI.getIndexedType());
333333 if (TypeSize != 1)
334334 Idx = SE->getMulExpr(Idx,
335335 SE->getConstant(ConstantInt::get(UIntPtrTy,
103103
104104 // Otherwise, we have a sequential type like an array or vector. Multiply
105105 // the index by the ElementSize.
106 uint64_t Size = TD.getABITypeSize(GTI.getIndexedType());
106 uint64_t Size = TD.getTypePaddedSize(GTI.getIndexedType());
107107 Offset += Size*OpC->getSExtValue();
108108 }
109109
510510 if (!srcArraySize)
511511 return false;
512512
513 uint64_t srcSize = TD.getABITypeSize(srcAlloca->getAllocatedType()) *
513 uint64_t srcSize = TD.getTypePaddedSize(srcAlloca->getAllocatedType()) *
514514 srcArraySize->getZExtValue();
515515
516516 if (cpyLength->getZExtValue() < srcSize)
525525 if (!destArraySize)
526526 return false;
527527
528 uint64_t destSize = TD.getABITypeSize(A->getAllocatedType()) *
528 uint64_t destSize = TD.getTypePaddedSize(A->getAllocatedType()) *
529529 destArraySize->getZExtValue();
530530
531531 if (destSize < srcSize)
537537 return false;
538538
539539 const Type* StructTy = cast(A->getType())->getElementType();
540 uint64_t destSize = TD.getABITypeSize(StructTy);
540 uint64_t destSize = TD.getTypePaddedSize(StructTy);
541541
542542 if (destSize < srcSize)
543543 return false;
242242 isa(AI->getAllocatedType())) &&
243243 AI->getAllocatedType()->isSized() &&
244244 // Do not promote any struct whose size is larger than "128" bytes.
245 TD->getABITypeSize(AI->getAllocatedType()) < SRThreshold &&
245 TD->getTypePaddedSize(AI->getAllocatedType()) < SRThreshold &&
246246 // Do not promote any struct into more than "32" separate vars.
247247 getNumSAElements(AI->getAllocatedType()) < SRThreshold/4) {
248248 // Check that all of the users of the allocation are capable of being
561561
562562 // If not the whole aggregate, give up.
563563 if (Length->getZExtValue() !=
564 TD->getABITypeSize(AI->getType()->getElementType()))
564 TD->getTypePaddedSize(AI->getType()->getElementType()))
565565 return MarkUnsafe(Info);
566566
567567 // We only know about memcpy/memset/memmove.
594594 // cast a {i32,i32}* to i64* and store through it. This is similar to the
595595 // memcpy case and occurs in various "byval" cases and emulated memcpys.
596596 if (isa(SI->getOperand(0)->getType()) &&
597 TD->getABITypeSize(SI->getOperand(0)->getType()) ==
598 TD->getABITypeSize(AI->getType()->getElementType())) {
597 TD->getTypePaddedSize(SI->getOperand(0)->getType()) ==
598 TD->getTypePaddedSize(AI->getType()->getElementType())) {
599599 Info.isMemCpyDst = true;
600600 continue;
601601 }
606606 // cast a {i32,i32}* to i64* and load through it. This is similar to the
607607 // memcpy case and occurs in various "byval" cases and emulated memcpys.
608608 if (isa(LI->getType()) &&
609 TD->getABITypeSize(LI->getType()) ==
610 TD->getABITypeSize(AI->getType()->getElementType())) {
609 TD->getTypePaddedSize(LI->getType()) ==
610 TD->getTypePaddedSize(AI->getType()->getElementType())) {
611611 Info.isMemCpySrc = true;
612612 continue;
613613 }
788788 OtherElt = new BitCastInst(OtherElt, BytePtrTy,OtherElt->getNameStr(),
789789 MI);
790790
791 unsigned EltSize = TD->getABITypeSize(EltTy);
791 unsigned EltSize = TD->getTypePaddedSize(EltTy);
792792
793793 // Finally, insert the meminst for this element.
794794 if (isa(MI) || isa(MI)) {
822822 // and store the element value to the individual alloca.
823823 Value *SrcVal = SI->getOperand(0);
824824 const Type *AllocaEltTy = AI->getType()->getElementType();
825 uint64_t AllocaSizeBits = TD->getABITypeSizeInBits(AllocaEltTy);
825 uint64_t AllocaSizeBits = TD->getTypePaddedSizeInBits(AllocaEltTy);
826826
827827 // If this isn't a store of an integer to the whole alloca, it may be a store
828828 // to the first element. Just ignore the store in this case and normal SROA
829829 // will handle it.
830830 if (!isa(SrcVal->getType()) ||
831 TD->getABITypeSizeInBits(SrcVal->getType()) != AllocaSizeBits)
831 TD->getTypePaddedSizeInBits(SrcVal->getType()) != AllocaSizeBits)
832832 return;
833833
834834 DOUT << "PROMOTING STORE TO WHOLE ALLOCA: " << *AI << *SI;
844844 uint64_t Shift = Layout->getElementOffsetInBits(i);
845845
846846 if (TD->isBigEndian())
847 Shift = AllocaSizeBits-Shift-TD->getABITypeSizeInBits(FieldTy);
847 Shift = AllocaSizeBits-Shift-TD->getTypePaddedSizeInBits(FieldTy);
848848
849849 Value *EltVal = SrcVal;
850850 if (Shift) {
879879 } else {
880880 const ArrayType *ATy = cast(AllocaEltTy);
881881 const Type *ArrayEltTy = ATy->getElementType();
882 uint64_t ElementOffset = TD->getABITypeSizeInBits(ArrayEltTy);
882 uint64_t ElementOffset = TD->getTypePaddedSizeInBits(ArrayEltTy);
883883 uint64_t ElementSizeBits = TD->getTypeSizeInBits(ArrayEltTy);
884884
885885 uint64_t Shift;
934934 // Extract each element out of the NewElts according to its structure offset
935935 // and form the result value.
936936 const Type *AllocaEltTy = AI->getType()->getElementType();
937 uint64_t AllocaSizeBits = TD->getABITypeSizeInBits(AllocaEltTy);
937 uint64_t AllocaSizeBits = TD->getTypePaddedSizeInBits(AllocaEltTy);
938938
939939 // If this isn't a load of the whole alloca to an integer, it may be a load
940940 // of the first element. Just ignore the load in this case and normal SROA
941941 // will handle it.
942942 if (!isa(LI->getType()) ||
943 TD->getABITypeSizeInBits(LI->getType()) != AllocaSizeBits)
943 TD->getTypePaddedSizeInBits(LI->getType()) != AllocaSizeBits)
944944 return;
945945
946946 DOUT << "PROMOTING LOAD OF WHOLE ALLOCA: " << *AI << *LI;
953953 Layout = TD->getStructLayout(EltSTy);
954954 } else {
955955 const Type *ArrayEltTy = cast(AllocaEltTy)->getElementType();
956 ArrayEltBitOffset = TD->getABITypeSizeInBits(ArrayEltTy);
956 ArrayEltBitOffset = TD->getTypePaddedSizeInBits(ArrayEltTy);
957957 }
958958
959959 Value *ResultVal = Constant::getNullValue(LI->getType());
10471047 } else if (const VectorType *VTy = dyn_cast(Ty)) {
10481048 return HasPadding(VTy->getElementType(), TD);
10491049 }
1050 return TD.getTypeSizeInBits(Ty) != TD.getABITypeSizeInBits(Ty);
1050 return TD.getTypeSizeInBits(Ty) != TD.getTypePaddedSizeInBits(Ty);
10511051 }
10521052
10531053 /// isSafeStructAllocaToScalarRepl - Check to see if the specified allocation of
12691269 // Check to see if this is stepping over an element: GEP Ptr, int C
12701270 if (GEP->getNumOperands() == 2 && isa(GEP->getOperand(1))) {
12711271 unsigned Idx = cast(GEP->getOperand(1))->getZExtValue();
1272 unsigned ElSize = TD->getABITypeSize(PTy->getElementType());
1272 unsigned ElSize = TD->getTypePaddedSize(PTy->getElementType());
12731273 unsigned BitOffset = Idx*ElSize*8;
12741274 if (BitOffset > 64 || !isPowerOf2_32(ElSize)) return 0;
12751275
12781278 if (SubElt == 0) return 0;
12791279 if (SubElt != Type::VoidTy && SubElt->isInteger()) {
12801280 const Type *NewTy =
1281 getIntAtLeastAsBigAs(TD->getABITypeSizeInBits(SubElt)+BitOffset);
1281 getIntAtLeastAsBigAs(TD->getTypePaddedSizeInBits(SubElt)+BitOffset);
12821282 if (NewTy == 0 || MergeInType(NewTy, UsedType, *TD)) return 0;
12831283 continue;
12841284 }
13191319 } else {
13201320 return 0;
13211321 }
1322 const Type *NTy = getIntAtLeastAsBigAs(TD->getABITypeSizeInBits(AggTy));
1322 const Type *NTy =
1323 getIntAtLeastAsBigAs(TD->getTypePaddedSizeInBits(AggTy));
13231324 if (NTy == 0 || MergeInType(NTy, UsedType, *TD)) return 0;
13241325 const Type *SubTy = CanConvertToScalar(GEP, IsNotTrivial);
13251326 if (SubTy == 0) return 0;
13951396 const PointerType *AggPtrTy =
13961397 cast(GEP->getOperand(0)->getType());
13971398 unsigned AggSizeInBits =
1398 TD->getABITypeSizeInBits(AggPtrTy->getElementType());
1399 TD->getTypePaddedSizeInBits(AggPtrTy->getElementType());
13991400
14001401 // Check to see if this is stepping over an element: GEP Ptr, int C
14011402 unsigned NewOffset = Offset;
14161417 const Type *AggTy = AggPtrTy->getElementType();
14171418 if (const SequentialType *SeqTy = dyn_cast(AggTy)) {
14181419 unsigned ElSizeBits =
1419 TD->getABITypeSizeInBits(SeqTy->getElementType());
1420 TD->getTypePaddedSizeInBits(SeqTy->getElementType());
14201421
14211422 NewOffset += ElSizeBits*Idx;
14221423 } else {
14701471 // Otherwise it must be an element access.
14711472 unsigned Elt = 0;
14721473 if (Offset) {
1473 unsigned EltSize = TD->getABITypeSizeInBits(VTy->getElementType());
1474 unsigned EltSize = TD->getTypePaddedSizeInBits(VTy->getElementType());
14741475 Elt = Offset/EltSize;
14751476 Offset -= EltSize*Elt;
14761477 }
15561557 SV = new BitCastInst(SV, AllocaType, SV->getName(), SI);
15571558 } else {
15581559 // Must be an element insertion.
1559 unsigned Elt = Offset/TD->getABITypeSizeInBits(PTy->getElementType());
1560 unsigned Elt = Offset/TD->getTypePaddedSizeInBits(PTy->getElementType());
15601561 SV = InsertElementInst::Create(Old, SV,
15611562 ConstantInt::get(Type::Int32Ty, Elt),
15621563 "tmp", SI);
114114 // malloc(type) becomes sbyte *malloc(size)
115115 Value *MallocArg;
116116 if (LowerMallocArgToInteger)
117 MallocArg = ConstantInt::get(Type::Int64Ty, TD.getABITypeSize(AllocTy));
117 MallocArg = ConstantInt::get(Type::Int64Ty,
118 TD.getTypePaddedSize(AllocTy));
118119 else
119120 MallocArg = ConstantExpr::getSizeOf(AllocTy);
120121 MallocArg = ConstantExpr::getTruncOrBitCast(cast(MallocArg),
162162 O << Size << ", ";
163163 else
164164 O << "\n" << IndentStr << " State.getTarget().getTargetData()"
165 "->getABITypeSize(LocVT.getTypeForMVT()), ";
165 "->getTypePaddedSize(LocVT.getTypeForMVT()), ";
166166 if (Align)
167167 O << Align;
168168 else