diff options
-rw-r--r-- | include/llvm/OperandTraits.h | 22 | ||||
-rw-r--r-- | include/llvm/User.h | 13 |
2 files changed, 19 insertions, 16 deletions
diff --git a/include/llvm/OperandTraits.h b/include/llvm/OperandTraits.h index a4b634c..83c1025 100644 --- a/include/llvm/OperandTraits.h +++ b/include/llvm/OperandTraits.h @@ -124,8 +124,8 @@ struct HungoffOperandTraits { inline op_iterator op_end(); \ inline const_op_iterator op_end() const; \ protected: \ - template <unsigned> inline Use &Op(); \ - template <unsigned> inline const Use &Op() const; \ + template <int> inline Use &Op(); \ + template <int> inline const Use &Op() const; \ public: \ inline unsigned getNumOperands() const @@ -157,12 +157,11 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ unsigned CLASS::getNumOperands() const { \ return OperandTraits<CLASS>::operands(this); \ } \ -template <unsigned Idx_nocapture> Use &CLASS::Op() { \ - return OperandTraits<CLASS>::op_begin(this)[Idx_nocapture]; \ +template <int Idx_nocapture> Use &CLASS::Op() { \ + return this->OpFrom<Idx_nocapture>(this); \ } \ -template <unsigned Idx_nocapture> const Use &CLASS::Op() const { \ - return OperandTraits<CLASS>::op_begin( \ - const_cast<CLASS*>(this))[Idx_nocapture]; \ +template <int Idx_nocapture> const Use &CLASS::Op() const { \ + return this->OpFrom<Idx_nocapture>(this); \ } @@ -195,12 +194,11 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ unsigned CLASS::getNumOperands() const { \ return OperandTraits<CLASS>::operands(this); \ } \ -template <unsigned Idx_nocapture> Use &CLASS::Op() { \ - return OperandTraits<CLASS>::op_begin(this)[Idx_nocapture]; \ +template <int Idx_nocapture> Use &CLASS::Op() { \ + return this->OpFrom<Idx_nocapture>(this); \ } \ -template <unsigned Idx_nocapture> const Use &CLASS::Op() const { \ - return OperandTraits<CLASS>::op_begin( \ - const_cast<CLASS*>(this))[Idx_nocapture]; \ +template <int Idx_nocapture> const Use &CLASS::Op() const { \ + return this->OpFrom<Idx_nocapture>(this); \ } diff --git a/include/llvm/User.h b/include/llvm/User.h index f2df23e..1a88ce0 100644 --- a/include/llvm/User.h +++ b/include/llvm/User.h @@ -83,11 +83,16 @@ public: assert(0 && "Constructor throws?"); } protected: - template <unsigned Idx> Use &Op() { - return OperandTraits<User>::op_begin(this)[Idx]; + template <int Idx, typename U> static Use &OpFrom(const U *that) { + return Idx < 0 + ? OperandTraits<U>::op_end(const_cast<U*>(that))[Idx] + : OperandTraits<U>::op_begin(const_cast<U*>(that))[Idx]; } - template <unsigned Idx> const Use &Op() const { - return OperandTraits<User>::op_begin(const_cast<User*>(this))[Idx]; + template <int Idx> Use &Op() { + return OpFrom<Idx>(this); + } + template <int Idx> const Use &Op() const { + return OpFrom<Idx>(this); } public: Value *getOperand(unsigned i) const { |