Fix a bunch of 80col violations that arose from the Create API change. Tweak makefile...
[oota-llvm.git] / lib / VMCore / Use.cpp
index a510d1a41ce5a99db01e48f0737e864760b6a6b3..d96a0e57fd4dc1004c3555954b2b9c6c8b0e01a1 100644 (file)
@@ -1,4 +1,4 @@
-//===-- Use.cpp - Implement the Use class -------------------------------===//
+//===-- Use.cpp - Implement the Use class ---------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
 
 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
 //===----------------------------------------------------------------------===//
@@ -122,7 +151,9 @@ User *Use::getUser() const {
 //===----------------------------------------------------------------------===//
 
 Use *User::allocHungoffUses(unsigned N) const {
-  Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N + sizeof(AugmentedUse) - sizeof(Use)));
+  Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N
+                                                + sizeof(AugmentedUse)
+                                                - sizeof(Use)));
   Use *End = Begin + N;
   static_cast<AugmentedUse&>(End[-1]).ref = addTag(this, tagOne);
   return Use::initTags(Begin, End);