[llvm-commits] [llvm] r51078 - in /llvm/trunk: include/llvm/Instructions.h include/llvm/Use.h lib/VMCore/Instructions.cpp lib/VMCore/Use.cpp

Gabor Greif ggreif at gmail.com
Tue May 13 15:51:52 PDT 2008


Author: ggreif
Date: Tue May 13 17:51:52 2008
New Revision: 51078

URL: http://llvm.org/viewvc/llvm-project?rev=51078&view=rev
Log:
Merge of r51073-51074 from use-diet branch.

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.

Modified:
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/include/llvm/Use.h
    llvm/trunk/lib/VMCore/Instructions.cpp
    llvm/trunk/lib/VMCore/Use.cpp

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=51078&r1=51077&r2=51078&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Tue May 13 17:51:52 2008
@@ -760,7 +760,7 @@
   /// @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 @@
   /// @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;

Modified: llvm/trunk/include/llvm/Use.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Use.h?rev=51078&r1=51077&r2=51078&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Use.h (original)
+++ llvm/trunk/include/llvm/Use.h Tue May 13 17:51:52 2008
@@ -67,18 +67,20 @@
 //
 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 @@
     return RHS;
   }
   const Use &operator=(const Use &RHS) {
-    set(RHS.get());
+    set(RHS.Val);
     return *this;
   }
 

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=51078&r1=51077&r2=51078&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Tue May 13 17:51:52 2008
@@ -1563,7 +1563,7 @@
 bool BinaryOperator::swapOperands() {
   if (!isCommutative())
     return true; // Can't commute operands
-  std::swap(Op<0>(), Op<1>());
+  Op<0>().swap(Op<1>());
   return false;
 }
 

Modified: llvm/trunk/lib/VMCore/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Use.cpp?rev=51078&r1=51077&r2=51078&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Use.cpp (original)
+++ llvm/trunk/lib/VMCore/Use.cpp Tue May 13 17:51:52 2008
@@ -16,6 +16,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
 //===----------------------------------------------------------------------===//
 





More information about the llvm-commits mailing list