From e2afdedec5f876b88384e21a3e18f48444989346 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 29 Jul 2008 08:46:11 +0000 Subject: [PATCH] Add a GetElementPtrInst::getIndexedType that accepts uint64_t's instead of just Value*'s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54157 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Instructions.h | 10 +++++++--- lib/VMCore/Instructions.cpp | 24 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 7372b995b10..355103cfa64 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -408,9 +408,6 @@ class GetElementPtrInst : public Instruction { /// Null is returned if the indices are invalid for the specified /// pointer type. /// - static const Type *getIndexedType(const Type *Ptr, - Value* const *Idx, unsigned NumIdx); - template static const Type *getIndexedType(const Type *Ptr, InputIterator IdxBegin, @@ -509,6 +506,13 @@ public: typename std::iterator_traits:: iterator_category()); } + + static const Type *getIndexedType(const Type *Ptr, + Value* const *Idx, unsigned NumIdx); + + static const Type *getIndexedType(const Type *Ptr, + uint64_t const *Idx, unsigned NumIdx); + static const Type *getIndexedType(const Type *Ptr, Value *Idx); inline op_iterator idx_begin() { return op_begin()+1; } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 098560a549a..bedf74cd9cc 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1026,12 +1026,16 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, // getIndexedType - Returns the type of the element that would be loaded with // a load instruction with the specified parameters. // +// The Idxs pointer should point to a continuous piece of memory containing the +// indices, either as Value* or uint64_t. +// // A null type is returned if the indices are invalid for the specified // pointer type. // -const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, - Value* const *Idxs, - unsigned NumIdx) { +template +static const Type* getIndexedTypeInternal(const Type *Ptr, + IndexTy const *Idxs, + unsigned NumIdx) { const PointerType *PTy = dyn_cast(Ptr); if (!PTy) return 0; // Type isn't a pointer type! const Type *Agg = PTy->getElementType(); @@ -1044,7 +1048,7 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, for (; CurIdx != NumIdx; ++CurIdx) { const CompositeType *CT = dyn_cast(Agg); if (!CT || isa(CT)) return 0; - Value *Index = Idxs[CurIdx]; + IndexTy Index = Idxs[CurIdx]; if (!CT->indexValid(Index)) return 0; Agg = CT->getTypeAtIndex(Index); @@ -1058,6 +1062,18 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, return CurIdx == NumIdx ? Agg : 0; } +const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, + Value* const *Idxs, + unsigned NumIdx) { + return getIndexedTypeInternal(Ptr, Idxs, NumIdx); +} + +const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, + uint64_t const *Idxs, + unsigned NumIdx) { + return getIndexedTypeInternal(Ptr, Idxs, NumIdx); +} + const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) { const PointerType *PTy = dyn_cast(Ptr); if (!PTy) return 0; // Type isn't a pointer type!