add a GEP helper function
authorChris Lattner <sabre@nondot.org>
Fri, 27 Apr 2007 20:35:56 +0000 (20:35 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 27 Apr 2007 20:35:56 +0000 (20:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36515 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
lib/VMCore/Instructions.cpp

index 236a1fdcced8cc6bc5a508afcfddc9929b9ff77d..146d1f50a645d0aede3f2ff7e934766f01a0e15a 100644 (file)
@@ -441,6 +441,12 @@ public:
   /// zeros.  If so, the result pointer and the first operand have the same
   /// value, just potentially different types.
   bool hasAllZeroIndices() const;
+  
+  /// hasAllConstantIndices - Return true if all of the indices of this GEP are
+  /// constant integers.  If so, the result pointer and the first operand have
+  /// a constant offset between them.
+  bool hasAllConstantIndices() const;
+  
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GetElementPtrInst *) { return true; }
index 2bd350080e3273a6717767abb530fd7b449305d4..4c792a56afb260e8d48bed0f6cbd6795ab8de287 100644 (file)
@@ -1043,6 +1043,17 @@ bool GetElementPtrInst::hasAllZeroIndices() const {
   return true;
 }
 
+/// hasAllConstantIndices - Return true if all of the indices of this GEP are
+/// constant integers.  If so, the result pointer and the first operand have
+/// a constant offset between them.
+bool GetElementPtrInst::hasAllConstantIndices() const {
+  for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
+    if (!isa<ConstantInt>(getOperand(i)))
+      return false;
+  }
+  return true;
+}
+
 
 //===----------------------------------------------------------------------===//
 //                           ExtractElementInst Implementation