diff options
author | Chris Lattner <sabre@nondot.org> | 2007-04-27 20:35:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-04-27 20:35:56 +0000 |
commit | 6b0974cd1d5ab238e8777ede08acaad06e6b5ffa (patch) | |
tree | d8dd15f27fd32a33366b985c8c6c1e95b0f04135 | |
parent | 4c6d20a096ad28aa6f812c07a48268e8a6ccb8fe (diff) |
add a GEP helper function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36515 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Instructions.h | 6 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 236a1fdcce..146d1f50a6 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -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; } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 2bd350080e..4c792a56af 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -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 |