From 636d36b9c94b75106250bba57464e2e64f10048a Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Fri, 22 Jan 2016 01:33:43 +0000 Subject: [PATCH] [opaque pointer types] [NFC] gep_type_{begin,end} now take source element type and address space. Reviewers: mjacob, dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16436 llvm-svn: 258474 --- include/llvm/Analysis/TargetTransformInfoImpl.h | 2 +- include/llvm/IR/GetElementPtrTypeIterator.h | 12 +++--------- lib/IR/DataLayout.cpp | 5 ++++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index 41bc72ca3ad..f4257dadf3a 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -423,7 +423,7 @@ public: // Assumes the address space is 0 when Ptr is nullptr. unsigned AS = (Ptr == nullptr ? 0 : Ptr->getType()->getPointerAddressSpace()); - auto GTI = gep_type_begin(PointerType::get(PointeeType, AS), Operands); + auto GTI = gep_type_begin(PointeeType, AS, Operands); for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) { // We assume that the cost of Scalar GEP with constant index and the // cost of Vector GEP with splat constant index are the same. diff --git a/include/llvm/IR/GetElementPtrTypeIterator.h b/include/llvm/IR/GetElementPtrTypeIterator.h index 7cb13fa33aa..4953aebbe8a 100644 --- a/include/llvm/IR/GetElementPtrTypeIterator.h +++ b/include/llvm/IR/GetElementPtrTypeIterator.h @@ -33,12 +33,6 @@ namespace llvm { generic_gep_type_iterator() {} public: - static generic_gep_type_iterator begin(Type *Ty, ItTy It) { - generic_gep_type_iterator I; - I.CurTy.setPointer(Ty); - I.OpIt = It; - return I; - } static generic_gep_type_iterator begin(Type *Ty, unsigned AddrSpace, ItTy It) { generic_gep_type_iterator I; @@ -125,13 +119,13 @@ namespace llvm { template inline generic_gep_type_iterator - gep_type_begin(Type *Op0, ArrayRef A) { - return generic_gep_type_iterator::begin(Op0, A.begin()); + gep_type_begin(Type *Op0, unsigned AS, ArrayRef A) { + return generic_gep_type_iterator::begin(Op0, AS, A.begin()); } template inline generic_gep_type_iterator - gep_type_end(Type * /*Op0*/, ArrayRef A) { + gep_type_end(Type * /*Op0*/, unsigned /*AS*/, ArrayRef A) { return generic_gep_type_iterator::end(A.end()); } } // end namespace llvm diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index 8230f429b05..0f2e5ba5895 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -729,8 +729,11 @@ uint64_t DataLayout::getIndexedOffset(Type *ptrTy, assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()"); 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 - TI = gep_type_begin(ptrTy, Indices); + TI = gep_type_begin(ptrTy->getPointerElementType(), AS, Indices); for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX; ++CurIDX, ++TI) { if (StructType *STy = dyn_cast(*TI)) {