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 | 2705829925b275ae8fb833218baec003ef8a4282 (patch) | |
tree | 5662a6162712846f0d2d4586b176d0ee0822bb48 | |
parent | 99cb63029afa1523b8ddb7e3374dd78af0945526 (diff) | |
download | bcm5719-llvm-2705829925b275ae8fb833218baec003ef8a4282.tar.gz bcm5719-llvm-2705829925b275ae8fb833218baec003ef8a4282.zip |
add a GEP helper function
llvm-svn: 36515
-rw-r--r-- | llvm/include/llvm/Instructions.h | 6 | ||||
-rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 11 |
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 |