Do not rely on std::swap<Use>, provide a (faster) member function instead.
This change is primarily necessitated by MSVC++'s incompatibility with
declaring std::swap<Use> to be a friend of Use.
Also contains some minor tweaks to Use inline functions,
to undo pointless changes that sneaked in with the last merge.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51078
91177308-0d34-0410-b5e6-
96231b3b80d8
/// @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;
/// @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;
//
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<Use>
+ /// that also works with less standard-compliant compilers
+ void swap(Use &RHS);
private:
- /// Allow std::swap some intimacy
- template <typename U> 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
return RHS;
}
const Use &operator=(const Use &RHS) {
- set(RHS.get());
+ set(RHS.Val);
return *this;
}
bool BinaryOperator::swapOperands() {
if (!isCommutative())
return true; // Can't commute operands
- std::swap(Op<0>(), Op<1>());
+ Op<0>().swap(Op<1>());
return false;
}
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
//===----------------------------------------------------------------------===//