Use the built-in postorder iterators rather than computing a postorder walk by hand.
authorOwen Anderson <resistor@mac.com>
Mon, 25 Jun 2007 18:25:31 +0000 (18:25 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 25 Jun 2007 18:25:31 +0000 (18:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37721 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVNPRE.cpp

index e1f4af072f363b0b8155b2c270e9c80430410b44..67dbabd045e9157ffbbdb4953cf8af3f908fb0d6 100644 (file)
@@ -27,6 +27,7 @@
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/CFG.h"
@@ -935,39 +936,6 @@ unsigned GVNPRE::buildsets(Function& F) {
 
   // Phase 1, Part 2: calculate ANTIC_IN
   
-  DOUT << "Calculating walk\n";
-  // Calculate a postorder CFG walk
-  std::vector<BasicBlock*> walk;
-  std::vector<BasicBlock*> walkStack;
-  SmallPtrSet<BasicBlock*, 16> walkVisited;
-  walkStack.push_back(&F.getEntryBlock());
-  walkVisited.insert(&F.getEntryBlock());
-  
-  while (!walkStack.empty()) {
-    BasicBlock* BB = walkStack.back();
-    walkVisited.insert(BB);
-    
-    bool inserted = false;
-    for (unsigned i = 0; i < BB->getTerminator()->getNumSuccessors(); ++i) {
-      BasicBlock* succ = BB->getTerminator()->getSuccessor(i);
-      if (walkVisited.count(succ) == 0) {
-        walkStack.push_back(succ);
-        inserted = true;
-      }
-    }
-    
-    if (inserted)
-      continue;
-    else {
-      walk.push_back(BB);
-      walkStack.pop_back();
-    }
-  }
-  
-  DOUT << "Finished calculating walk\n";
-  
-  // Perform the ANTIC_IN calculation
-  
   std::set<BasicBlock*> visited;
   
   bool changed = true;
@@ -977,8 +945,8 @@ unsigned GVNPRE::buildsets(Function& F) {
     SmallPtrSet<Value*, 32> anticOut;
     
     // Top-down walk of the postdominator tree
-    for (std::vector<BasicBlock*>::iterator BBI = walk.begin(), BBE = walk.end();
-         BBI != BBE; ++BBI) {
+    for (po_iterator<BasicBlock*> BBI = po_begin(&F.getEntryBlock()),
+         BBE = po_end(&F.getEntryBlock()); BBI != BBE; ++BBI) {
       BasicBlock* BB = *BBI;
       if (BB == 0)
         continue;