From 218a8223e62c41ae6318e28e8f4c672fcfbb5082 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Jun 2004 01:13:18 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14258 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index a0c86fea4fe..87bd00cefcf 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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 #include #include @@ -64,19 +66,19 @@ static bool PropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { } } - // 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(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(OldVal) && cast(OldVal)->getParent() == BB) { PHINode *OldValPN = cast(OldVal); - for (std::vector::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::const_iterator PredI = BBPreds.begin(), End = BBPreds.end(); PredI != End; ++PredI) { @@ -563,7 +565,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // 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 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // 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 @@ -636,7 +638,6 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // 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 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { 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 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { } 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 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // 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();