Take advantage of the new fast SmallPtrSet assignment operator when propagating AVAIL...
authorOwen Anderson <resistor@mac.com>
Mon, 9 Jul 2007 22:29:50 +0000 (22:29 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 9 Jul 2007 22:29:50 +0000 (22:29 +0000)
This reduces the time to optimize Anton's testcase from 31.2s to 21.s!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@38475 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVNPRE.cpp

index 94e458c936142f6f373478074d4a76c65404c076..73739c161a978b398fff7002b7c694470f268081 100644 (file)
@@ -574,7 +574,8 @@ class ValueNumberedSet {
       numbers.set(i);
     }
     
-    void copyNumbers(ValueNumberedSet& other) {
+    void operator=(const ValueNumberedSet& other) {
+      contents = other.contents;
       numbers = other.numbers;
     }
     
@@ -710,11 +711,10 @@ void GVNPRE::val_insert(ValueNumberedSet& s, Value* v) {
 void GVNPRE::val_replace(ValueNumberedSet& s, Value* v) {
   uint32_t num = VN.lookup(v);
   Value* leader = find_leader(s, num);
-  while (leader != 0) {
+  if (leader != 0)
     s.erase(leader);
-    leader = find_leader(s, num);
-  }
   s.insert(v);
+  s.set(num);
 }
 
 /// phi_translate - Given a value, its parent block, and a predecessor of its
@@ -1154,8 +1154,6 @@ void GVNPRE::dump(ValueNumberedSet& s) const {
 /// elimination by walking the dominator tree and removing any instruction that 
 /// is dominated by another instruction with the same value number.
 bool GVNPRE::elimination() {
-  DOUT << "\n\nPhase 3: Elimination\n\n";
-  
   bool changed_function = false;
   
   std::vector<std::pair<Instruction*, Value*> > replace;
@@ -1167,10 +1165,6 @@ bool GVNPRE::elimination() {
          E = df_end(DT.getRootNode()); DI != E; ++DI) {
     BasicBlock* BB = DI->getBlock();
     
-    //DOUT << "Block: " << BB->getName() << "\n";
-    //dump(availableOut[BB]);
-    //DOUT << "\n\n";
-    
     for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
          BI != BE; ++BI) {
 
@@ -1354,7 +1348,6 @@ bool GVNPRE::buildsets_anticout(BasicBlock* BB,
   if (BB->getTerminator()->getNumSuccessors() == 1) {
     if (BB->getTerminator()->getSuccessor(0) != BB &&
         visited.count(BB->getTerminator()->getSuccessor(0)) == 0) {
-          DOUT << "DEFER: " << BB->getName() << "\n";
       return true;
     }
     else {
@@ -1459,12 +1452,8 @@ void GVNPRE::buildsets(Function& F) {
     BasicBlock* BB = DI->getBlock();
   
     // A block inherits AVAIL_OUT from its dominator
-    if (DI->getIDom() != 0) {
-      currAvail.insert(availableOut[DI->getIDom()->getBlock()].begin(),
-                       availableOut[DI->getIDom()->getBlock()].end());
-    
-      currAvail.copyNumbers(availableOut[DI->getIDom()->getBlock()]);
-    }
+    if (DI->getIDom() != 0)
+      currAvail = availableOut[DI->getIDom()->getBlock()];
 
     for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
          BI != BE; ++BI)
@@ -1517,8 +1506,6 @@ void GVNPRE::buildsets(Function& F) {
     
     iterations++;
   }
-  
-  DOUT << "ITERATIONS: " << iterations << "\n";
 }
 
 /// insertion_pre - When a partial redundancy has been identified, eliminate it
@@ -1528,7 +1515,6 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB,
                            std::map<BasicBlock*, Value*>& avail,
                     std::map<BasicBlock*, ValueNumberedSet>& new_sets) {
   for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
-    DOUT << "PRED: " << (*PI)->getName() << "\n";
     Value* e2 = avail[*PI];
     if (!availableOut[*PI].test(VN.lookup(e2))) {
       User* U = cast<User>(e2);