Finegrainify namespacification

Fix bug: LoopSimplify/2003-12-10-ExitBlocksProblem.ll

llvm-svn: 10373
This commit is contained in:
Chris Lattner 2003-12-10 17:20:35 +00:00
parent 679b49d7f5
commit 7710f2f49e
1 changed files with 21 additions and 22 deletions

View File

@ -17,8 +17,9 @@
// //
// Loop exit-block insertion guarantees that all exit blocks from the loop // Loop exit-block insertion guarantees that all exit blocks from the loop
// (blocks which are outside of the loop that have predecessors inside of the // (blocks which are outside of the loop that have predecessors inside of the
// loop) are dominated by the loop header. This simplifies transformations such // loop) only have predecessors from inside of the loop (and are thus dominated
// as store-sinking that are built into LICM. // by the loop header). This simplifies transformations such as store-sinking
// that are built into LICM.
// //
// This pass also guarantees that loops will have exactly one backedge. // This pass also guarantees that loops will have exactly one backedge.
// //
@ -42,12 +43,11 @@
#include "Support/SetOperations.h" #include "Support/SetOperations.h"
#include "Support/Statistic.h" #include "Support/Statistic.h"
#include "Support/DepthFirstIterator.h" #include "Support/DepthFirstIterator.h"
using namespace llvm;
namespace llvm {
namespace { namespace {
Statistic<> Statistic<>
NumInserted("loopsimplify", "Number of pre-header blocks inserted"); NumInserted("loopsimplify", "Number of pre-header or exit blocks inserted");
struct LoopSimplify : public FunctionPass { struct LoopSimplify : public FunctionPass {
virtual bool runOnFunction(Function &F); virtual bool runOnFunction(Function &F);
@ -81,8 +81,8 @@ namespace {
} }
// Publically exposed interface to pass... // Publically exposed interface to pass...
const PassInfo *LoopSimplifyID = X.getPassInfo(); const PassInfo *llvm::LoopSimplifyID = X.getPassInfo();
Pass *createLoopSimplifyPass() { return new LoopSimplify(); } Pass *llvm::createLoopSimplifyPass() { return new LoopSimplify(); }
/// runOnFunction - Run down all loops in the CFG (recursively, but we could do /// runOnFunction - Run down all loops in the CFG (recursively, but we could do
/// it in any convenient order) inserting preheaders... /// it in any convenient order) inserting preheaders...
@ -111,18 +111,20 @@ bool LoopSimplify::ProcessLoop(Loop *L) {
Changed = true; Changed = true;
} }
// Regardless of whether or not we added a preheader to the loop we must // Next, check to make sure that all exit nodes of the loop only have
// guarantee that the preheader dominates all exit nodes. If there are any // predecessors that are inside of the loop. This check guarantees that the
// exit nodes not dominated, split them now. // loop preheader/header will dominate the exit blocks. If the exit block has
DominatorSet &DS = getAnalysis<DominatorSet>(); // predecessors from outside of the loop, split the edge now.
BasicBlock *Header = L->getHeader(); for (unsigned i = 0, e = L->getExitBlocks().size(); i != e; ++i) {
for (unsigned i = 0, e = L->getExitBlocks().size(); i != e; ++i) BasicBlock *ExitBlock = L->getExitBlocks()[i];
if (!DS.dominates(Header, L->getExitBlocks()[i])) { for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock);
RewriteLoopExitBlock(L, L->getExitBlocks()[i]); PI != PE; ++PI)
assert(DS.dominates(Header, L->getExitBlocks()[i]) && if (!L->contains(*PI)) {
"RewriteLoopExitBlock failed?"); RewriteLoopExitBlock(L, ExitBlock);
NumInserted++; NumInserted++;
Changed = true; Changed = true;
break;
}
} }
// The preheader may have more than two predecessors at this point (from the // The preheader may have more than two predecessors at this point (from the
@ -342,8 +344,6 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
void LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) { void LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
DominatorSet &DS = getAnalysis<DominatorSet>(); DominatorSet &DS = getAnalysis<DominatorSet>();
assert(!DS.dominates(L->getHeader(), Exit) &&
"Loop already dominates exit block??");
assert(std::find(L->getExitBlocks().begin(), L->getExitBlocks().end(), Exit) assert(std::find(L->getExitBlocks().begin(), L->getExitBlocks().end(), Exit)
!= L->getExitBlocks().end() && "Not a current exit block!"); != L->getExitBlocks().end() && "Not a current exit block!");
@ -576,4 +576,3 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
} }
} }
} // End llvm namespace