diff options
author | Eduard Burtescu <edy.burt@gmail.com> | 2016-01-22 03:08:27 +0000 |
---|---|---|
committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-01-22 03:08:27 +0000 |
commit | 68e7f49f8e2c9e775e8fcbda3bdf4daeed11708b (patch) | |
tree | f25cfd38637e77ebeeafcbd382557218f7682168 /llvm/lib/IR/DataLayout.cpp | |
parent | e2a69178493c02eaabab69a418b39746e17b5978 (diff) | |
download | bcm5719-llvm-68e7f49f8e2c9e775e8fcbda3bdf4daeed11708b.tar.gz bcm5719-llvm-68e7f49f8e2c9e775e8fcbda3bdf4daeed11708b.zip |
[opaque pointer types] [NFC] DataLayout::getIndexedOffset: take source element type instead of pointer type and rename to getIndexedOffsetInType.
Summary:
Reviewers: mjacob, dblaikie
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D16282
llvm-svn: 258478
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 0f2e5ba5895..de3dfb0754d 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -723,40 +723,33 @@ unsigned DataLayout::getLargestLegalIntTypeSize() const { return Max != LegalIntWidths.end() ? *Max : 0; } -uint64_t DataLayout::getIndexedOffset(Type *ptrTy, - ArrayRef<Value *> Indices) const { - Type *Ty = ptrTy; - assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()"); +uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy, + ArrayRef<Value *> Indices) const { uint64_t Result = 0; // We can use 0 as the address space as we don't need // to get pointer types back from gep_type_iterator. unsigned AS = 0; generic_gep_type_iterator<Value* const*> - TI = gep_type_begin(ptrTy->getPointerElementType(), AS, Indices); - for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX; - ++CurIDX, ++TI) { - if (StructType *STy = dyn_cast<StructType>(*TI)) { - assert(Indices[CurIDX]->getType() == - Type::getInt32Ty(ptrTy->getContext()) && + GTI = gep_type_begin(ElemTy, AS, Indices), + GTE = gep_type_end(ElemTy, AS, Indices); + for (; GTI != GTE; ++GTI) { + Value *Idx = GTI.getOperand(); + if (StructType *STy = dyn_cast<StructType>(*GTI)) { + assert(Idx->getType() == + Type::getInt32Ty(ElemTy->getContext()) && "Illegal struct idx"); - unsigned FieldNo = cast<ConstantInt>(Indices[CurIDX])->getZExtValue(); + unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue(); // Get structure layout information... const StructLayout *Layout = getStructLayout(STy); // Add in the offset, as calculated by the structure layout info... Result += Layout->getElementOffset(FieldNo); - - // Update Ty to refer to current element - Ty = STy->getElementType(FieldNo); } else { - // Update Ty to refer to current element - Ty = cast<SequentialType>(Ty)->getElementType(); - // Get the array index and the size of each array element. - if (int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue()) - Result += (uint64_t)arrayIdx * getTypeAllocSize(Ty); + if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue()) + Result += (uint64_t)arrayIdx * getTypeAllocSize(GTI.getIndexedType()); } } |