[LoopDeletion] (cleanup, NFC) Make simple helper functions static
instead of members. No state was being provided by the object so this seems strictly simpler. I've also tried to improve the name and comments for the functions to more thoroughly document what they are doing. llvm-svn: 292274
This commit is contained in:
parent
bb7e4b46e9
commit
26169f001c
|
@ -26,13 +26,6 @@ public:
|
|||
LoopDeletionPass() {}
|
||||
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
|
||||
LoopStandardAnalysisResults &AR, LPMUpdater &U);
|
||||
|
||||
bool runImpl(Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI);
|
||||
|
||||
private:
|
||||
bool isLoopDead(Loop *L, ScalarEvolution &SE,
|
||||
SmallVectorImpl<BasicBlock *> &ExitingBlocks,
|
||||
BasicBlock *ExitBlock, bool &Changed, BasicBlock *Preheader);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,11 @@ using namespace llvm;
|
|||
|
||||
STATISTIC(NumDeleted, "Number of loops deleted");
|
||||
|
||||
/// isLoopDead - Determined if a loop is dead. This assumes that we've already
|
||||
/// checked for unique exit and exiting blocks, and that the code is in LCSSA
|
||||
/// form.
|
||||
bool LoopDeletionPass::isLoopDead(Loop *L, ScalarEvolution &SE,
|
||||
/// Determines if a loop is dead.
|
||||
///
|
||||
/// This assumes that we've already checked for unique exit and exiting blocks,
|
||||
/// and that the code is in LCSSA form.
|
||||
static bool isLoopDead(Loop *L, ScalarEvolution &SE,
|
||||
SmallVectorImpl<BasicBlock *> &ExitingBlocks,
|
||||
BasicBlock *ExitBlock, bool &Changed,
|
||||
BasicBlock *Preheader) {
|
||||
|
@ -89,13 +90,21 @@ bool LoopDeletionPass::isLoopDead(Loop *L, ScalarEvolution &SE,
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Remove dead loops, by which we mean loops that do not impact the observable
|
||||
/// behavior of the program other than finite running time. Note we do ensure
|
||||
/// that this never remove a loop that might be infinite, as doing so could
|
||||
/// change the halting/non-halting nature of a program. NOTE: This entire
|
||||
/// process relies pretty heavily on LoopSimplify and LCSSA in order to make
|
||||
/// various safety checks work.
|
||||
bool LoopDeletionPass::runImpl(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
|
||||
/// Remove a loop if it is dead.
|
||||
///
|
||||
/// A loop is considered dead if it does not impact the observable behavior of
|
||||
/// the program other than finite running time. This never removes a loop that
|
||||
/// might be infinite, as doing so could change the halting/non-halting nature
|
||||
/// of a program.
|
||||
///
|
||||
/// This entire process relies pretty heavily on LoopSimplify form and LCSSA in
|
||||
/// order to make various safety checks work.
|
||||
///
|
||||
/// \returns true if any changes are made, even if the loop is not deleted.
|
||||
///
|
||||
/// This also updates the relevant analysis information in \p DT, \p SE, and \p
|
||||
/// LI.
|
||||
static bool deleteLoopIfDead(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
|
||||
LoopInfo &LI) {
|
||||
assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
|
||||
|
||||
|
@ -217,7 +226,7 @@ bool LoopDeletionPass::runImpl(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
|
|||
PreservedAnalyses LoopDeletionPass::run(Loop &L, LoopAnalysisManager &AM,
|
||||
LoopStandardAnalysisResults &AR,
|
||||
LPMUpdater &) {
|
||||
bool Changed = runImpl(&L, AR.DT, AR.SE, AR.LI);
|
||||
bool Changed = deleteLoopIfDead(&L, AR.DT, AR.SE, AR.LI);
|
||||
if (!Changed)
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
|
@ -258,6 +267,5 @@ bool LoopDeletionLegacyPass::runOnLoop(Loop *L, LPPassManager &) {
|
|||
ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||
LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
|
||||
LoopDeletionPass Impl;
|
||||
return Impl.runImpl(L, DT, SE, LI);
|
||||
return deleteLoopIfDead(L, DT, SE, LI);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue