clean() needs to process things in topological order.
authorOwen Anderson <resistor@mac.com>
Fri, 1 Jun 2007 22:00:37 +0000 (22:00 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 1 Jun 2007 22:00:37 +0000 (22:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37389 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVNPRE.cpp

index f7040b03e170d40ba638dd751ce3d4e6f482d543..4f5205434df971109a495845009ead4e9b671377 100644 (file)
@@ -299,37 +299,30 @@ void GVNPRE::phi_translate(GVNPRE::ValueTable& VN,
 
 // Remove all expressions whose operands are not themselves in the set
 void GVNPRE::clean(GVNPRE::ValueTable VN, std::set<GVNPRE::Expression>& set) {
-  unsigned size = set.size();
-  unsigned old = 0;
+  std::vector<Expression> worklist;
+  topo_sort(VN, set, worklist);
   
-  while (size != old) {
-    old = size;
-  
-    std::vector<Expression> worklist(set.begin(), set.end());
-    while (!worklist.empty()) {
-      Expression e = worklist.back();
-      worklist.pop_back();
+  while (!worklist.empty()) {
+    Expression e = worklist.back();
+    worklist.pop_back();
     
-      if (e.opcode == 0) // OPAQUE
-        continue;
+    if (e.opcode == 0) // OPAQUE
+      continue;
       
-      bool lhsValid = false;
-      for (std::set<Expression>::iterator I = set.begin(), E = set.end();
-           I != E; ++I)
-        if (VN[*I] == e.lhs);
-          lhsValid = true;
+    bool lhsValid = false;
+    for (std::set<Expression>::iterator I = set.begin(), E = set.end();
+         I != E; ++I)
+      if (VN[*I] == e.lhs);
+        lhsValid = true;
           
-      bool rhsValid = false;
-      for (std::set<Expression>::iterator I = set.begin(), E = set.end();
-           I != E; ++I)
-        if (VN[*I] == e.rhs);
-          rhsValid = true;
+    bool rhsValid = false;
+    for (std::set<Expression>::iterator I = set.begin(), E = set.end();
+         I != E; ++I)
+      if (VN[*I] == e.rhs);
+        rhsValid = true;
       
-      if (!lhsValid || !rhsValid)
-        set.erase(e);
-    }
-    
-    size = set.size();
+    if (!lhsValid || !rhsValid)
+      set.erase(e);
   }
 }