CMake: removed lib/VMCore/DebugInfoBuilder.cpp.
[oota-llvm.git] / lib / VMCore / Use.cpp
index a510d1a41ce5a99db01e48f0737e864760b6a6b3..0c566a9cb70aa3a25cfbe1cb6d3532b514da3227 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
 //===----------------------------------------------------------------------===//
@@ -23,7 +52,7 @@ const Use *Use::getImpliedUser() const {
   const Use *Current = this;
 
   while (true) {
-    unsigned Tag = extractTag<PrevPtrTag, fullStopTag>((Current++)->Prev);
+    unsigned Tag = (Current++)->Prev.getInt();
     switch (Tag) {
       case zeroDigitTag:
       case oneDigitTag:
@@ -33,7 +62,7 @@ const Use *Use::getImpliedUser() const {
         ++Current;
         ptrdiff_t Offset = 1;
         while (true) {
-          unsigned Tag = extractTag<PrevPtrTag, fullStopTag>(Current->Prev);
+          unsigned Tag = Current->Prev.getInt();
           switch (Tag) {
             case zeroDigitTag:
             case oneDigitTag:
@@ -62,11 +91,13 @@ Use *Use::initTags(Use * const Start, Use *Stop, ptrdiff_t Done) {
     --Stop;
     Stop->Val = 0;
     if (!Count) {
-      Stop->Prev = reinterpret_cast<Use**>(Done == 0 ? fullStopTag : stopTag);
+      Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(Done == 0
+                                                            ? fullStopTag
+                                                            : stopTag));
       ++Done;
       Count = Done;
     } else {
-      Stop->Prev = reinterpret_cast<Use**>(Count & 1);
+      Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(Count & 1));
       Count >>= 1;
       ++Done;
     }
@@ -98,7 +129,7 @@ void Use::zap(Use *Start, const Use *Stop, bool del) {
 //===----------------------------------------------------------------------===//
 
 struct AugmentedUse : Use {
-  User *ref;
+  PointerIntPair<User*, 1, Tag> ref;
   AugmentedUse(); // not implemented
 };
 
@@ -109,12 +140,12 @@ struct AugmentedUse : Use {
 
 User *Use::getUser() const {
   const Use *End = getImpliedUser();
-  User *She = static_cast<const AugmentedUse*>(End - 1)->ref;
-  She = extractTag<Tag, tagOne>(She)
-      ? llvm::stripTag<tagOne>(She)
-      : reinterpret_cast<User*>(const_cast<Use*>(End));
-
-  return She;
+  const PointerIntPair<User*, 1, Tag>& ref(
+                                static_cast<const AugmentedUse*>(End - 1)->ref);
+  User *She = ref.getPointer();
+  return ref.getInt()
+    ? She
+    : (User*)End;
 }
 
 //===----------------------------------------------------------------------===//
@@ -122,9 +153,13 @@ 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);
+  PointerIntPair<User*, 1, Tag>& ref(static_cast<AugmentedUse&>(End[-1]).ref);
+  ref.setPointer(const_cast<User*>(this));
+  ref.setInt(tagOne);
   return Use::initTags(Begin, End);
 }