17 #define DEBUG_TYPE "loop-delete"
26 STATISTIC(NumDeleted,
"Number of loops deleted");
29 class LoopDeletion :
public LoopPass {
63 "Delete dead loops",
false,
false)
73 return new LoopDeletion();
79 bool LoopDeletion::isLoopDead(
Loop *L,
91 while (
PHINode *
P = dyn_cast<PHINode>(BI)) {
92 Value *incoming =
P->getIncomingValueForBlock(exitingBlocks[0]);
98 for (
unsigned i = 1, e = exitingBlocks.
size(); i < e; ++i) {
99 if (incoming !=
P->getIncomingValueForBlock(exitingBlocks[i]))
118 if (BI->mayHaveSideEffects())
158 if (exitBlocks.
size() != 1)
162 bool Changed =
false;
163 if (!isLoopDead(L, exitingBlocks, exitBlocks, Changed, preheader))
170 if (isa<SCEVCouldNotCompute>(S))
194 while (
PHINode *
P = dyn_cast<PHINode>(BI)) {
195 int j =
P->getBasicBlockIndex(exitingBlock);
196 assert(j >= 0 &&
"Can't find exiting block in exit block's phi node!");
197 P->setIncomingBlock(j, preheader);
198 for (
unsigned i = 1; i < exitingBlocks.
size(); ++i)
199 P->removeIncomingValue(exitingBlocks[i]);
211 ChildNodes.
insert(ChildNodes.begin(), DT[*
LI]->begin(), DT[*
LI]->end());
213 DE = ChildNodes.end(); DI !=
DE; ++DI) {
222 (*LI)->dropAllReferences();
231 (*LI)->eraseFromParent();
235 LoopInfo &loopInfo = getAnalysis<LoopInfo>();
239 E = blocks.end();
I != E; ++
I)
AnalysisUsage & addPreserved()
INITIALIZE_PASS_BEGIN(LoopDeletion,"loop-deletion","Delete dead loops", false, false) INITIALIZE_PASS_END(LoopDeletion
static PassRegistry * getPassRegistry()
iterator insert(iterator I, const T &Elt)
BlockT * getHeader() const
LoopInfoBase< BlockT, LoopT > * LI
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
void changeImmediateDominator(BasicBlock *N, BasicBlock *NewIDom)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
void getExitingBlocks(SmallVectorImpl< BlockT * > &ExitingBlocks) const
ID
LLVM Calling Convention Representation.
void eraseNode(BasicBlock *BB)
AnalysisUsage & addPreservedID(const void *ID)
void replaceUsesOfWith(Value *From, Value *To)
BlockT * getLoopPreheader() const
LLVM Basic Block Representation.
void initializeLoopDeletionPass(PassRegistry &)
const SCEV * getMaxBackedgeTakenCount(const Loop *L)
bool makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt=0) const
bool hasDedicatedExits() const
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
AnalysisUsage & addRequiredID(const void *ID)
void deleteLoopFromQueue(Loop *L)
Delete loop from the loop queue and loop hierarchy (LoopInfo).
STATISTIC(NumDeleted,"Number of loops deleted")
Pass * createLoopDeletionPass()
std::vector< BlockT * >::const_iterator block_iterator
block_iterator block_end() const
void forgetLoop(const Loop *L)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
void removeBlock(BasicBlock *BB)
LLVM Value Representation.
block_iterator block_begin() const