Ignore redundant constraints
[oota-llvm.git] / lib / Analysis / IPA / Andersens.cpp
index 247699c6b1eaf8b635433e42b6e935c26fb01a88..63a6cb553e02e8f2fa9536105fe84f7fd7c4551a 100644 (file)
@@ -134,6 +134,21 @@ namespace {
         assert(Offset == 0 || Ty != AddressOf &&
                "Offset is illegal on addressof constraints");
       }
+      bool operator==(const Constraint &RHS) const {
+        return RHS.Type == Type
+          && RHS.Dest == Dest
+          && RHS.Src == Src
+          && RHS.Offset == Offset;
+      }
+      bool operator<(const Constraint &RHS) const {
+        if (RHS.Type != Type)
+          return RHS.Type < Type;
+        else if (RHS.Dest != Dest)
+          return RHS.Dest < Dest;
+        else if (RHS.Src != Src)
+          return RHS.Src < Src;
+        return RHS.Offset < Offset;
+      }
     };
 
     // Node class - This class is used to represent a node in the constraint
@@ -1185,7 +1200,9 @@ bool Andersens::Node::intersectsIgnoring(Node *N, unsigned Ignoring) const {
 }
 
 void dumpToDOUT(SparseBitVector<> *bitmap) {
+#ifndef NDEBUG
   dump(*bitmap, DOUT);
+#endif
 }
 
 
@@ -1733,6 +1750,7 @@ void Andersens::HUValNum(unsigned NodeIndex) {
 /// replaced by their the pointer equivalence class representative.
 void Andersens::RewriteConstraints() {
   std::vector<Constraint> NewConstraints;
+  std::set<Constraint> Seen;
 
   PEClass2Node.clear();
   PENLEClass2Node.clear();
@@ -1766,12 +1784,14 @@ void Andersens::RewriteConstraints() {
     // it.
     if (C.Src == C.Dest && C.Type == Constraint::Copy)
       continue;
-    
+
     C.Src = FindEquivalentNode(RHSNode, RHSLabel);
     C.Dest = FindEquivalentNode(FindNode(LHSNode), LHSLabel);
-    if (C.Src == C.Dest && C.Type == Constraint::Copy)
+    if (C.Src == C.Dest && C.Type == Constraint::Copy
+        || Seen.count(C) != 0)
       continue;
 
+    Seen.insert(C);
     NewConstraints.push_back(C);
   }
   Constraints.swap(NewConstraints);