[llvm-commits] [llvm] r51073 - in /llvm/branches/ggreif/use-diet: 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 14:59:34 PDT 2008
Author: ggreif
Date: Tue May 13 16:59:34 2008
New Revision: 51073
URL: http://llvm.org/viewvc/llvm-project?rev=51073&view=rev
Log:
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.
Modified:
llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
llvm/branches/ggreif/use-diet/include/llvm/Use.h
llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp
Modified: llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Instructions.h?rev=51073&r1=51072&r2=51073&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Tue May 13 16:59:34 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/branches/ggreif/use-diet/include/llvm/Use.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Use.h?rev=51073&r1=51072&r2=51073&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Use.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Use.h Tue May 13 16:59:34 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/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp?rev=51073&r1=51072&r2=51073&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp Tue May 13 16:59:34 2008
@@ -1566,7 +1566,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/branches/ggreif/use-diet/lib/VMCore/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp?rev=51073&r1=51072&r2=51073&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp Tue May 13 16:59:34 2008
@@ -16,6 +16,29 @@
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);
+ }
+ if (V1) {
+ RHS.Val = V1;
+ V1->addUse(RHS);
+ }
+ }
+}
+
+//===----------------------------------------------------------------------===//
// Use getImpliedUser Implementation
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list