diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 2305db4f775d49..f750157850bb2a 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -292,7 +292,6 @@ void initializeScopedNoAliasAAWrapperPassPass(PassRegistry&); void initializeSeparateConstOffsetFromGEPLegacyPassPass(PassRegistry &); void initializeShadowStackGCLoweringPass(PassRegistry&); void initializeShrinkWrapPass(PassRegistry&); -void initializeSimpleLoopUnswitchLegacyPassPass(PassRegistry&); void initializeSingleLoopExtractorPass(PassRegistry&); void initializeSinkingLegacyPassPass(PassRegistry&); void initializeSjLjEHPreparePass(PassRegistry&); diff --git a/llvm/include/llvm/Transforms/Scalar/SimpleLoopUnswitch.h b/llvm/include/llvm/Transforms/Scalar/SimpleLoopUnswitch.h index 68c121560b13ee..417e9668527bd1 100644 --- a/llvm/include/llvm/Transforms/Scalar/SimpleLoopUnswitch.h +++ b/llvm/include/llvm/Transforms/Scalar/SimpleLoopUnswitch.h @@ -79,11 +79,6 @@ class SimpleLoopUnswitchPass : public PassInfoMixin { function_ref MapClassName2PassName); }; -/// Create the legacy pass object for the simple loop unswitcher. -/// -/// See the documentaion for `SimpleLoopUnswitchPass` for details. -Pass *createSimpleLoopUnswitchLegacyPass(bool NonTrivial = false); - } // end namespace llvm #endif // LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index 80db06b03a901b..f5c6b48fed9f0b 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -47,7 +47,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeSROALegacyPassPass(Registry); initializeCFGSimplifyPassPass(Registry); initializeStructurizeCFGLegacyPassPass(Registry); - initializeSimpleLoopUnswitchLegacyPassPass(Registry); initializeSinkingLegacyPassPass(Registry); initializeTailCallElimPass(Registry); initializeTLSVariableHoistLegacyPassPass(Registry); diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index e9e6ead9ccb741..55606473765239 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -24,7 +24,6 @@ #include "llvm/Analysis/LoopAnalysisManager.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopIterator.h" -#include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/MemorySSA.h" #include "llvm/Analysis/MemorySSAUpdater.h" #include "llvm/Analysis/MustExecute.h" @@ -46,8 +45,6 @@ #include "llvm/IR/ProfDataUtils.h" #include "llvm/IR/Use.h" #include "llvm/IR/Value.h" -#include "llvm/InitializePasses.h" -#include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" @@ -3714,105 +3711,3 @@ void SimpleLoopUnswitchPass::printPipeline( OS << (Trivial ? "" : "no-") << "trivial"; OS << '>'; } - -namespace { - -class SimpleLoopUnswitchLegacyPass : public LoopPass { - bool NonTrivial; - -public: - static char ID; // Pass ID, replacement for typeid - - explicit SimpleLoopUnswitchLegacyPass(bool NonTrivial = false) - : LoopPass(ID), NonTrivial(NonTrivial) { - initializeSimpleLoopUnswitchLegacyPassPass( - *PassRegistry::getPassRegistry()); - } - - bool runOnLoop(Loop *L, LPPassManager &LPM) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired(); - AU.addRequired(); - AU.addRequired(); - AU.addPreserved(); - getLoopAnalysisUsage(AU); - } -}; - -} // end anonymous namespace - -bool SimpleLoopUnswitchLegacyPass::runOnLoop(Loop *L, LPPassManager &LPM) { - if (skipLoop(L)) - return false; - - Function &F = *L->getHeader()->getParent(); - - LLVM_DEBUG(dbgs() << "Unswitching loop in " << F.getName() << ": " << *L - << "\n"); - auto &DT = getAnalysis().getDomTree(); - auto &LI = getAnalysis().getLoopInfo(); - auto &AC = getAnalysis().getAssumptionCache(F); - auto &AA = getAnalysis().getAAResults(); - auto &TTI = getAnalysis().getTTI(F); - MemorySSA *MSSA = &getAnalysis().getMSSA(); - MemorySSAUpdater MSSAU(MSSA); - - auto *SEWP = getAnalysisIfAvailable(); - auto *SE = SEWP ? &SEWP->getSE() : nullptr; - - auto UnswitchCB = [&L, &LPM](bool CurrentLoopValid, bool PartiallyInvariant, - bool InjectedCondition, - ArrayRef NewLoops) { - // If we did a non-trivial unswitch, we have added new (cloned) loops. - for (auto *NewL : NewLoops) - LPM.addLoop(*NewL); - - // If the current loop remains valid, re-add it to the queue. This is - // a little wasteful as we'll finish processing the current loop as well, - // but it is the best we can do in the old PM. - if (CurrentLoopValid) { - // If the current loop has been unswitched using a partially invariant - // condition or injected invariant condition, we should not re-add the - // current loop to avoid unswitching on the same condition again. - if (!PartiallyInvariant && !InjectedCondition) - LPM.addLoop(*L); - } else - LPM.markLoopAsDeleted(*L); - }; - - auto DestroyLoopCB = [&LPM](Loop &L, StringRef /* Name */) { - LPM.markLoopAsDeleted(L); - }; - - if (VerifyMemorySSA) - MSSA->verifyMemorySSA(); - bool Changed = - unswitchLoop(*L, DT, LI, AC, AA, TTI, true, NonTrivial, UnswitchCB, SE, - &MSSAU, nullptr, nullptr, DestroyLoopCB); - - if (VerifyMemorySSA) - MSSA->verifyMemorySSA(); - - // Historically this pass has had issues with the dominator tree so verify it - // in asserts builds. - assert(DT.verify(DominatorTree::VerificationLevel::Fast)); - - return Changed; -} - -char SimpleLoopUnswitchLegacyPass::ID = 0; -INITIALIZE_PASS_BEGIN(SimpleLoopUnswitchLegacyPass, "simple-loop-unswitch", - "Simple unswitch loops", false, false) -INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) -INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) -INITIALIZE_PASS_DEPENDENCY(LoopPass) -INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass) -INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass) -INITIALIZE_PASS_END(SimpleLoopUnswitchLegacyPass, "simple-loop-unswitch", - "Simple unswitch loops", false, false) - -Pass *llvm::createSimpleLoopUnswitchLegacyPass(bool NonTrivial) { - return new SimpleLoopUnswitchLegacyPass(NonTrivial); -}