[LLVMdev] GEP::getIndexValid() with other iterators
Matthijs Kooijman
matthijs at stdin.nl
Wed Jul 16 09:58:08 PDT 2008
Hi all,
once more with the patch inline for easy review. I did not include the
argpromotion pass here, since it's not the main topic of this post.
Gr.
Matthijs
Index: lib/VMCore/Instructions.cpp
===================================================================
--- lib/VMCore/Instructions.cpp (revision 53672)
+++ lib/VMCore/Instructions.cpp (working copy)
@@ -1068,41 +1068,6 @@
init(Ptr, Idx, Name);
}
-// getIndexedType - Returns the type of the element that would be loaded with
-// a load instruction with the specified parameters.
-//
-// 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) {
- const PointerType *PTy = dyn_cast<PointerType>(Ptr);
- if (!PTy) return 0; // Type isn't a pointer type!
- const Type *Agg = PTy->getElementType();
-
- // Handle the special case of the empty set index set...
- if (NumIdx == 0)
- return Agg;
-
- unsigned CurIdx = 1;
- for (; CurIdx != NumIdx; ++CurIdx) {
- const CompositeType *CT = dyn_cast<CompositeType>(Agg);
- if (!CT || isa<PointerType>(CT)) return 0;
- Value *Index = Idxs[CurIdx];
- if (!CT->indexValid(Index)) return 0;
- Agg = CT->getTypeAtIndex(Index);
-
- // If the new type forwards to another type, then it is in the middle
- // of being refined to another type (and hence, may have dropped all
- // references to what it was using before). So, use the new forwarded
- // type.
- if (const Type *Ty = Agg->getForwardedType())
- Agg = Ty;
- }
- return CurIdx == NumIdx ? Agg : 0;
-}
-
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
const PointerType *PTy = dyn_cast<PointerType>(Ptr);
if (!PTy) return 0; // Type isn't a pointer type!
Index: include/llvm/Instructions.h
===================================================================
--- include/llvm/Instructions.h (revision 53672)
+++ include/llvm/Instructions.h (working copy)
@@ -407,9 +407,35 @@
/// Null is returned if the indices are invalid for the specified
/// pointer type.
///
+ template <typename IndexTy>
static const Type *getIndexedType(const Type *Ptr,
- Value* const *Idx, unsigned NumIdx);
+ IndexTy const *Idxs, unsigned NumIdx) {
+ const PointerType *PTy = dyn_cast<PointerType>(Ptr);
+ if (!PTy) return 0; // Type isn't a pointer type!
+ const Type *Agg = PTy->getElementType();
+ // Handle the special case of the empty set index set...
+ if (NumIdx == 0)
+ return Agg;
+
+ unsigned CurIdx = 1;
+ for (; CurIdx != NumIdx; ++CurIdx) {
+ const CompositeType *CT = dyn_cast<CompositeType>(Agg);
+ if (!CT || isa<PointerType>(CT)) return 0;
+ IndexTy Index = Idxs[CurIdx];
+ if (!CT->indexValid(Index)) return 0;
+ Agg = CT->getTypeAtIndex(Index);
+
+ // If the new type forwards to another type, then it is in the middle
+ // of being refined to another type (and hence, may have dropped all
+ // references to what it was using before). So, use the new forwarded
+ // type.
+ if (const Type *Ty = Agg->getForwardedType())
+ Agg = Ty;
+ }
+ return CurIdx == NumIdx ? Agg : 0;
+ }
+
template<typename InputIterator>
static const Type *getIndexedType(const Type *Ptr,
InputIterator IdxBegin,
@@ -422,7 +448,7 @@
if (NumIdx 0)
// This requires that the iterator points to contiguous memory.
- return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx);
+ return getIndexedType(Ptr, &*IdxBegin, NumIdx);
else
return getIndexedType(Ptr, (Value *const*)0, NumIdx);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080716/0b844a2d/attachment.sig>
More information about the llvm-dev
mailing list