[llvm-commits] [llvm] r42018 - in /llvm/trunk: include/llvm/ADT/SparseBitVector.h lib/Analysis/IPA/Andersens.cpp

Daniel Berlin dberlin at dberlin.org
Sun Sep 16 16:59:53 PDT 2007


Author: dannyb
Date: Sun Sep 16 18:59:53 2007
New Revision: 42018

URL: http://llvm.org/viewvc/llvm-project?rev=42018&view=rev
Log:
Fix bug in andersen's related to test_and_set.
Add operator == and != to SparseBitVector.
Simplify code for test_and_set

Modified:
    llvm/trunk/include/llvm/ADT/SparseBitVector.h
    llvm/trunk/lib/Analysis/IPA/Andersens.cpp

Modified: llvm/trunk/include/llvm/ADT/SparseBitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SparseBitVector.h?rev=42018&r1=42017&r2=42018&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/SparseBitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SparseBitVector.h Sun Sep 16 18:59:53 2007
@@ -128,9 +128,11 @@
 
   bool test_and_set (unsigned Idx) {
     bool old = test(Idx);
-    if (!old)
+    if (!old) {
       set(Idx);
-    return !old;
+      return true;
+    }
+    return false;
   }
 
   void reset(unsigned Idx) {
@@ -533,9 +535,29 @@
 
   bool test_and_set (unsigned Idx) {
     bool old = test(Idx);
-    if (!old)
+    if (!old) {
       set(Idx);
-    return !old;
+      return true;
+    }
+    return false;
+  }
+
+  bool operator!=(const SparseBitVector &RHS) {
+    return !(*this == RHS);
+  }
+
+  bool operator==(const SparseBitVector &RHS) {
+    ElementListConstIter Iter1 = Elements.begin();
+    ElementListConstIter Iter2 = RHS.Elements.begin();
+
+    while (Iter2 != RHS.Elements.end()) {
+      if (Iter1->index() != Iter2->index()
+          || *Iter1 != *Iter2)
+        return false;
+      ++Iter1;
+      ++Iter2;
+    }
+    return Iter1 == Elements.end();
   }
 
   // Union our bitmap with the RHS and return true if we changed.

Modified: llvm/trunk/lib/Analysis/IPA/Andersens.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/Andersens.cpp?rev=42018&r1=42017&r2=42018&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/IPA/Andersens.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/Andersens.cpp Sun Sep 16 18:59:53 2007
@@ -1212,10 +1212,9 @@
   }
 
   do {
-     Changed = false;
-
+    Changed = false;
     ++NumIters;
-    DOUT << "Starting iteration #" << Iteration++ << "!\n";
+    DOUT << "Starting iteration #" << Iteration++;
     // TODO: In the microoptimization category, we could just make Topo2Node
     // a fast map and thus only contain the visited nodes.
     for (unsigned i = 0; i < GraphNodes.size(); ++i) {
@@ -1295,7 +1294,7 @@
 
           // Add an edge to the graph, so we can just do regular bitmap ior next
           // time.  It may also let us notice a cycle.
-          if (!GraphNodes[*Src].Edges->test_and_set(*Dest)) {
+          if (GraphNodes[*Src].Edges->test_and_set(*Dest)) {
             if (GraphNodes[*Dest].PointsTo |= *(GraphNodes[*Src].PointsTo)) {
               GraphNodes[*Dest].Changed = true;
               // If we changed a node we've already processed, we need another





More information about the llvm-commits mailing list