]> granicus.if.org Git - llvm/commitdiff
[LoopDeletion] (cleanup, NFC) Make simple helper functions static
authorChandler Carruth <chandlerc@gmail.com>
Tue, 17 Jan 2017 22:07:26 +0000 (22:07 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 17 Jan 2017 22:07:26 +0000 (22:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292274 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Scalar/LoopDeletion.h
lib/Transforms/Scalar/LoopDeletion.cpp

index a2ebf9dac945aee3f35e31ff9e87cbbd8dd1ca87..539dce8bfdc13715161be8ee95c1e56c85e48579 100644 (file)
@@ -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);
 };
 }
 
index 5d9ff3d662097ee29e91721910d72527c52a9de5..bd9efb7ceb2da0cbfc5643793d52bfec179db75a 100644 (file)
@@ -29,13 +29,14 @@ 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,
-                                  SmallVectorImpl<BasicBlock *> &ExitingBlocks,
-                                  BasicBlock *ExitBlock, bool &Changed,
-                                  BasicBlock *Preheader) {
+/// 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) {
   // Make sure that all PHI entries coming from the loop are loop invariant.
   // Because the code is in LCSSA form, any values used outside of the loop
   // must pass through a PHI in the exit block, meaning that this check is
@@ -89,14 +90,22 @@ 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,
-                               LoopInfo &LI) {
+/// 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!");
 
   // We can only remove the loop if there is a preheader that we can
@@ -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);
 }