summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-27 20:35:56 +0000
committerChris Lattner <sabre@nondot.org>2007-04-27 20:35:56 +0000
commit2705829925b275ae8fb833218baec003ef8a4282 (patch)
tree5662a6162712846f0d2d4586b176d0ee0822bb48
parent99cb63029afa1523b8ddb7e3374dd78af0945526 (diff)
downloadbcm5719-llvm-2705829925b275ae8fb833218baec003ef8a4282.tar.gz
bcm5719-llvm-2705829925b275ae8fb833218baec003ef8a4282.zip
add a GEP helper function
llvm-svn: 36515
-rw-r--r--llvm/include/llvm/Instructions.h6
-rw-r--r--llvm/lib/VMCore/Instructions.cpp11
2 files changed, 17 insertions, 0 deletions
diff --git a/llvm/include/llvm/Instructions.h b/llvm/include/llvm/Instructions.h
index 236a1fdcced..146d1f50a64 100644
--- a/llvm/include/llvm/Instructions.h
+++ b/llvm/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/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 2bd350080e3..4c792a56afb 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud