Merge of r51073-51074 from use-diet branch.
authorGabor Greif <ggreif@gmail.com>
Tue, 13 May 2008 22:51:52 +0000 (22:51 +0000)
committerGabor Greif <ggreif@gmail.com>
Tue, 13 May 2008 22:51:52 +0000 (22:51 +0000)
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

include/llvm/Instructions.h
include/llvm/Use.h
lib/VMCore/Instructions.cpp
lib/VMCore/Use.cpp

index 3b3aecf816614ab9e80162477401156ac66a2443..4808e11eb4a38935894c17297962cffabd19d806 100644 (file)
@@ -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;
index b4d4bda620e8e6de7c4e3bcabc0ad62121f8aa64..79bcdd177b42e254a3cfd7291140154cacc07ddc 100644 (file)
@@ -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<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
@@ -107,7 +109,7 @@ public:
     return RHS;
   }
   const Use &operator=(const Use &RHS) {
-    set(RHS.get());
+    set(RHS.Val);
     return *this;
   }
 
index cea496d1ca78e28e9b9f1aa84c3045cb55623c23..ff565606138c5633a1e63efdc22c26643c009bf3 100644 (file)
@@ -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;
 }
 
index a510d1a41ce5a99db01e48f0737e864760b6a6b3..0672209bffaf97c50585a75b972e09437b1a7fa4 100644 (file)
 
 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
 //===----------------------------------------------------------------------===//