AU.addPreserved<LoopInfo>();
AU.addPreservedID(LoopSimplifyID);
AU.addPreservedID(LCSSAID);
+ AU.addPreserved<DominanceFrontier>();
}
};
}
char LoopDeletion::ID = 0;
static RegisterPass<LoopDeletion> X("loop-deletion", "Delete dead loops");
-LoopPass* llvm::createLoopDeletionPass() {
+Pass* llvm::createLoopDeletionPass() {
return new LoopDeletion();
}
LI != LE; ++LI) {
for (BasicBlock::iterator BI = (*LI)->begin(), BE = (*LI)->end();
BI != BE; ++BI) {
- if (BI->mayWriteToMemory())
+ if (BI->mayHaveSideEffects())
return false;
- else if (LoadInst* L = dyn_cast<LoadInst>(BI))
- if (L->isVolatile())
- return false;
}
}
// Don't remove loops for which we can't solve the trip count.
// They could be infinite, in which case we'd be changing program behavior.
ScalarEvolution& SE = getAnalysis<ScalarEvolution>();
- SCEVHandle S = SE.getIterationCount(L);
+ const SCEV *S = SE.getBackedgeTakenCount(L);
if (isa<SCEVCouldNotCompute>(S))
return false;
// Because we're deleting a large chunk of code at once, the sequence in which
// we remove things is very important to avoid invalidation issues. Don't
// mess with this unless you have good reason and know what you're doing.
-
+
+ // Tell ScalarEvolution that the loop is deleted. Do this before
+ // deleting the loop so that ScalarEvolution can look at the loop
+ // to determine what it needs to clean up.
+ SE.forgetLoopBackedgeTakenCount(L);
+
// Move simple loop-invariant expressions out of the loop, since they
// might be needed by the exit phis.
for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
// Update the dominator tree and remove the instructions and blocks that will
// be deleted from the reference counting scheme.
DominatorTree& DT = getAnalysis<DominatorTree>();
+ DominanceFrontier* DF = getAnalysisIfAvailable<DominanceFrontier>();
SmallPtrSet<DomTreeNode*, 8> ChildNodes;
for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
LI != LE; ++LI) {
// allows us to remove the domtree entry for the block.
ChildNodes.insert(DT[*LI]->begin(), DT[*LI]->end());
for (SmallPtrSet<DomTreeNode*, 8>::iterator DI = ChildNodes.begin(),
- DE = ChildNodes.end(); DI != DE; ++DI)
+ DE = ChildNodes.end(); DI != DE; ++DI) {
DT.changeImmediateDominator(*DI, DT[preheader]);
+ if (DF) DF->changeImmediateDominator((*DI)->getBlock(), preheader, &DT);
+ }
ChildNodes.clear();
DT.eraseNode(*LI);
-
- // Remove instructions that we're deleting from ScalarEvolution.
- for (BasicBlock::iterator BI = (*LI)->begin(), BE = (*LI)->end();
- BI != BE; ++BI)
- SE.deleteValueFromRecords(BI);
-
- SE.deleteValueFromRecords(*LI);
-
+ if (DF) DF->removeBlock(*LI);
+
// Remove the block from the reference counting scheme, so that we can
// delete it freely later.
(*LI)->dropAllReferences();
for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
LI != LE; ++LI)
(*LI)->eraseFromParent();
-
+
// Finally, the blocks from loopinfo. This has to happen late because
// otherwise our loop iterators won't work.
LoopInfo& loopInfo = getAnalysis<LoopInfo>();