25 #define DEBUG_TYPE "loop-delete"
27 STATISTIC(NumDeleted,
"Number of loops deleted");
30 class LoopDeletion :
public LoopPass {
64 "Delete dead loops",
false,
false)
74 return new LoopDeletion();
80 bool LoopDeletion::isLoopDead(
Loop *L,
92 while (
PHINode *
P = dyn_cast<PHINode>(BI)) {
93 Value *incoming =
P->getIncomingValueForBlock(exitingBlocks[0]);
99 for (
unsigned i = 1, e = exitingBlocks.
size(); i < e; ++i) {
100 if (incoming !=
P->getIncomingValueForBlock(exitingBlocks[i]))
119 if (BI->mayHaveSideEffects())
134 if (skipOptnoneFunction(L))
162 if (exitBlocks.
size() != 1)
166 bool Changed =
false;
167 if (!isLoopDead(L, exitingBlocks, exitBlocks, Changed, preheader))
174 if (isa<SCEVCouldNotCompute>(S))
198 while (
PHINode *
P = dyn_cast<PHINode>(BI)) {
199 int j =
P->getBasicBlockIndex(exitingBlock);
200 assert(j >= 0 &&
"Can't find exiting block in exit block's phi node!");
201 P->setIncomingBlock(j, preheader);
202 for (
unsigned i = 1; i < exitingBlocks.
size(); ++i)
203 P->removeIncomingValue(exitingBlocks[i]);
209 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
215 ChildNodes.
insert(ChildNodes.
begin(), DT[*LI]->begin(), DT[*LI]->end());
217 DE = ChildNodes.
end();
DI != DE; ++
DI) {
226 (*LI)->dropAllReferences();
235 (*LI)->eraseFromParent();
239 LoopInfo &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Pass interface - Implemented by all 'passes'.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
INITIALIZE_PASS_BEGIN(LoopDeletion,"loop-deletion","Delete dead loops", false, false) INITIALIZE_PASS_END(LoopDeletion
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void removeBlock(BlockT *BB)
removeBlock - This method completely removes BB from all data structures, including all of the Loop o...
STATISTIC(NumFunctions,"Total number of functions")
ScalarEvolution - This class is the main scalar evolution driver.
BlockT * getHeader() const
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void getExitingBlocks(SmallVectorImpl< BlockT * > &ExitingBlocks) const
getExitingBlocks - Return all blocks inside the loop that have successors outside of the loop...
AnalysisUsage & addPreservedID(const void *ID)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Subclasses of this class are all able to terminate a basic block.
BlockT * getLoopPreheader() const
getLoopPreheader - If there is a preheader for this loop, return it.
LLVM Basic Block Representation.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void initializeLoopDeletionPass(PassRegistry &)
Represent the analysis usage information of a pass.
const SCEV * getMaxBackedgeTakenCount(const Loop *L)
getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except return the least SCEV value that ...
bool hasDedicatedExits() const
hasDedicatedExits - Return true if no exit block for the loop has a predecessor that is outside the l...
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
getUniqueExitBlocks - Return all unique successor blocks of this loop.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt=nullptr) const
makeLoopInvariant - If the given value is an instruction inside of the loop and it can be hoisted...
AnalysisUsage & addRequiredID(const void *ID)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void deleteLoopFromQueue(Loop *L)
Delete loop from the loop queue and loop hierarchy (LoopInfo).
Pass * createLoopDeletionPass()
std::vector< BlockT * >::const_iterator block_iterator
iterator insert(iterator I, T &&Elt)
block_iterator block_end() const
void forgetLoop(const Loop *L)
forgetLoop - This method should be called by the client when it has changed a loop in a way that may ...
SCEV - This class represents an analyzed expression in the program.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
LLVM Value Representation.
block_iterator block_begin() const
The legacy pass manager's analysis pass to compute loop information.
Legacy analysis pass which computes a DominatorTree.