diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 3b3aecf8166..4808e11eb4a 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -760,7 +760,7 @@ public: /// @brief Swap operands and adjust predicate. void swapOperands() { SubclassData = getSwappedPredicate(); - std::swap(Op<0>(), Op<1>()); + Op<0>().swap(Op<1>()); } virtual ICmpInst *clone() const; @@ -879,7 +879,7 @@ public: /// @brief Swap operands and adjust predicate. void swapOperands() { SubclassData = getSwappedPredicate(); - std::swap(Op<0>(), Op<1>()); + Op<0>().swap(Op<1>()); } virtual FCmpInst *clone() const; diff --git a/include/llvm/Use.h b/include/llvm/Use.h index b4d4bda620e..79bcdd177b4 100644 --- a/include/llvm/Use.h +++ b/include/llvm/Use.h @@ -67,18 +67,20 @@ inline T *transferTag(const T *From, const T *To) { // class Use { public: + /// init - specify Value and User + /// @deprecated in 2.4, will be removed soon inline void init(Value *V, User *U); + /// swap - provide a fast substitute to std::swap + /// that also works with less standard-compliant compilers + void swap(Use &RHS); private: - /// Allow std::swap some intimacy - template friend void std::swap(U&, U&); + /// Copy ctor - do not implement + Use(const Use &U); - /// Copy ctor - Only for std::swap - Use(const Use &U) { init(U.get(), 0); } - - /// Destructor - Only for zap() and std::swap + /// Destructor - Only for zap() inline ~Use() { - if (get()) removeFromList(); + if (Val) removeFromList(); } /// Default ctor - This leaves the Use completely uninitialized. The only thing @@ -107,7 +109,7 @@ public: return RHS; } const Use &operator=(const Use &RHS) { - set(RHS.get()); + set(RHS.Val); return *this; } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index cea496d1ca7..ff565606138 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1563,7 +1563,7 @@ const Value *BinaryOperator::getNotArgument(const Value *BinOp) { bool BinaryOperator::swapOperands() { if (!isCommutative()) return true; // Can't commute operands - std::swap(Op<0>(), Op<1>()); + Op<0>().swap(Op<1>()); return false; } diff --git a/lib/VMCore/Use.cpp b/lib/VMCore/Use.cpp index a510d1a41ce..0672209bffa 100644 --- a/lib/VMCore/Use.cpp +++ b/lib/VMCore/Use.cpp @@ -15,6 +15,35 @@ namespace llvm { +//===----------------------------------------------------------------------===// +// Use swap Implementation +//===----------------------------------------------------------------------===// + +void Use::swap(Use &RHS) { + Value *V1(Val); + Value *V2(RHS.Val); + if (V1 != V2) { + if (V1) { + removeFromList(); + } + + if (V2) { + RHS.removeFromList(); + Val = V2; + V2->addUse(*this); + } else { + Val = 0; + } + + if (V1) { + RHS.Val = V1; + V1->addUse(RHS); + } else { + RHS.Val = 0; + } + } +} + //===----------------------------------------------------------------------===// // Use getImpliedUser Implementation //===----------------------------------------------------------------------===//