[llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Jun 19 20:21:01 PDT 2004


Changes in directory llvm/lib/Transforms/Utils:

SimplifyCFG.cpp updated: 1.42 -> 1.43

---
Log message:

Add some DEBUG output to the simplifycfg routines
Fix another non-deterministic behavior, this one should actually speed up the
code though as it was doing silly things.


---
Diffs of the changes:  (+13 -14)

Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.42 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.43
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.42	Sat Jun 19 02:02:14 2004
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp	Sat Jun 19 20:13:18 2004
@@ -11,11 +11,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "simplifycfg"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Constants.h"
 #include "llvm/Instructions.h"
 #include "llvm/Type.h"
 #include "llvm/Support/CFG.h"
+#include "Support/Debug.h"
 #include <algorithm>
 #include <functional>
 #include <set>
@@ -64,19 +66,19 @@
       }
     }
 
-  // Loop over all of the PHI nodes in the successor BB
+  // Loop over all of the PHI nodes in the successor BB.
   for (BasicBlock::iterator I = Succ->begin();
        PHINode *PN = dyn_cast<PHINode>(I); ++I) {
     Value *OldVal = PN->removeIncomingValue(BB, false);
     assert(OldVal && "No entry in PHI for Pred BB!");
 
-    // If this incoming value is one of the PHI nodes in BB...
+    // If this incoming value is one of the PHI nodes in BB, the new entries in
+    // the PHI node are the entries from the old PHI.
     if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->getParent() == BB) {
       PHINode *OldValPN = cast<PHINode>(OldVal);
-      for (std::vector<BasicBlock*>::const_iterator PredI = BBPreds.begin(), 
-             End = BBPreds.end(); PredI != End; ++PredI) {
-        PN->addIncoming(OldValPN->getIncomingValueForBlock(*PredI), *PredI);
-      }
+      for (unsigned i = 0, e = OldValPN->getNumIncomingValues(); i != e; ++i)
+        PN->addIncoming(OldValPN->getIncomingValue(i),
+                        OldValPN->getIncomingBlock(i));
     } else {
       for (std::vector<BasicBlock*>::const_iterator PredI = BBPreds.begin(), 
              End = BBPreds.end(); PredI != End; ++PredI) {
@@ -563,7 +565,7 @@
   // Remove basic blocks that have no predecessors... which are unreachable.
   if (pred_begin(BB) == pred_end(BB) ||
       *pred_begin(BB) == BB && ++pred_begin(BB) == pred_end(BB)) {
-    //cerr << "Removing BB: \n" << BB;
+    DEBUG(std::cerr << "Removing BB: \n" << BB);
 
     // Loop through all of our successors and make sure they know that one
     // of their predecessors is going away.
@@ -611,7 +613,7 @@
         // we cannot do this transformation!
         //
 	if (!PropagatePredecessorsForPHIs(BB, Succ)) {
-          //cerr << "Killing Trivial BB: \n" << BB;
+          DEBUG(std::cerr << "Killing Trivial BB: \n" << BB);
           std::string OldName = BB->getName();
 
           std::vector<BasicBlock*>
@@ -636,7 +638,6 @@
               // this means that we should any newly added incoming edges should
               // use the PHI node as the value for these edges, because they are
               // loop back edges.
-              
               for (unsigned i = 0, e = OldSuccPreds.size(); i != e; ++i)
                 if (OldSuccPreds[i] != BB)
                   PN->addIncoming(PN, OldSuccPreds[i]);
@@ -650,8 +651,6 @@
 	
           if (!OldName.empty() && !Succ->hasName())  // Transfer name if we can
             Succ->setName(OldName);
-          
-          //cerr << "Function after removal: \n" << M;
           return true;
 	}
       }
@@ -919,7 +918,7 @@
   }
 
   if (OnlySucc) {
-    //cerr << "Merging: " << BB << "into: " << OnlyPred;
+    DEBUG(std::cerr << "Merging: " << BB << "into: " << OnlyPred);
     TerminatorInst *Term = OnlyPred->getTerminator();
 
     // Resolve any PHI nodes at the start of the block.  They are all
@@ -1016,8 +1015,8 @@
       //
       BasicBlock *IfTrue, *IfFalse;
       if (Value *IfCond = GetIfCondition(BB, IfTrue, IfFalse)) {
-        //std::cerr << "FOUND IF CONDITION!  " << *IfCond << "  T: "
-        //       << IfTrue->getName() << "  F: " << IfFalse->getName() << "\n";
+        DEBUG(std::cerr << "FOUND IF CONDITION!  " << *IfCond << "  T: "
+              << IfTrue->getName() << "  F: " << IfFalse->getName() << "\n");
 
         // Figure out where to insert instructions as necessary.
         BasicBlock::iterator AfterPHIIt = BB->begin();





More information about the llvm-commits mailing list