diff options
author | Dan Gohman <gohman@apple.com> | 2009-07-17 23:55:56 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-07-17 23:55:56 +0000 |
commit | 016de81177ec5c950f1668be4a48992bc1ee0d75 (patch) | |
tree | d851a88d72bc9c18dd42143f0fdbef05a31bd405 /include/llvm/Operator.h | |
parent | 5918304c4cd0354c995a610e790162cff0ba78ba (diff) |
Convert more code to use Operator instead of explicitly handling both
ConstantExpr and Instruction. This involves duplicating some code
between GetElementPtrInst and GEPOperator, but it's not a lot.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76265 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Operator.h')
-rw-r--r-- | include/llvm/Operator.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/llvm/Operator.h b/include/llvm/Operator.h index 1413ce3d20..2f9f9ca12c 100644 --- a/include/llvm/Operator.h +++ b/include/llvm/Operator.h @@ -129,6 +129,48 @@ public: class GEPOperator : public Operator { public: + inline op_iterator idx_begin() { return op_begin()+1; } + inline const_op_iterator idx_begin() const { return op_begin()+1; } + inline op_iterator idx_end() { return op_end(); } + inline const_op_iterator idx_end() const { return op_end(); } + + Value *getPointerOperand() { + return getOperand(0); + } + const Value *getPointerOperand() const { + return getOperand(0); + } + static unsigned getPointerOperandIndex() { + return 0U; // get index for modifying correct operand + } + + /// getPointerOperandType - Method to return the pointer operand as a + /// PointerType. + const PointerType *getPointerOperandType() const { + return reinterpret_cast<const PointerType*>(getPointerOperand()->getType()); + } + + unsigned getNumIndices() const { // Note: always non-negative + return getNumOperands() - 1; + } + + bool hasIndices() const { + return getNumOperands() > 1; + } + + /// hasAllZeroIndices - Return true if all of the indices of this GEP are + /// zeros. If so, the result pointer and the first operand have the same + /// value, just potentially different types. + bool hasAllZeroIndices() const { + for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) { + if (Constant *C = dyn_cast<Constant>(I)) + if (C->isNullValue()) + continue; + return false; + } + return true; + } + /// hasNoPointerOverflow - Return true if this GetElementPtr is known to /// never have overflow in the pointer addition portions of its effective /// computation. GetElementPtr computation involves several phases; |