From: eopXD Date: Fri, 28 May 2021 07:48:04 +0000 (+0000) Subject: Revert "[LoopNest][LoopFlatten] Change LoopFlattenPass to LoopNest pass" X-Git-Tag: llvmorg-14-init~5367 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e06cf8f1ba2263b52f91f96aca01ff033d96cd9;p=platform%2Fupstream%2Fllvm.git Revert "[LoopNest][LoopFlatten] Change LoopFlattenPass to LoopNest pass" This reverts commit ffc4d3e06855550a8bd2a691f6d05828d5bf4ddf. --- diff --git a/llvm/include/llvm/Transforms/Scalar/LoopFlatten.h b/llvm/include/llvm/Transforms/Scalar/LoopFlatten.h index 41f91f0..3d259bd 100644 --- a/llvm/include/llvm/Transforms/Scalar/LoopFlatten.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopFlatten.h @@ -24,7 +24,8 @@ class LoopFlattenPass : public PassInfoMixin { public: LoopFlattenPass() = default; - PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + PreservedAnalyses run(LoopNest &LN, LoopAnalysisManager &LAM, + LoopStandardAnalysisResults &AR, LPMUpdater &U); }; } // end namespace llvm diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index eb94d28..b39481d 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -616,7 +616,7 @@ PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level, FPM.addPass(SimplifyCFGPass()); FPM.addPass(InstCombinePass()); if (EnableLoopFlatten) - FPM.addPass(LoopFlattenPass()); + FPM.addPass(createFunctionToLoopPassAdaptor(LoopFlattenPass())); // The loop passes in LPM2 (LoopFullUnrollPass) do not preserve MemorySSA. // *All* loop passes must preserve it, in order to be able to use it. FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), @@ -791,7 +791,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, FPM.addPass(SimplifyCFGPass()); FPM.addPass(InstCombinePass()); if (EnableLoopFlatten) - FPM.addPass(LoopFlattenPass()); + FPM.addPass(createFunctionToLoopPassAdaptor(LoopFlattenPass())); // The loop passes in LPM2 (LoopIdiomRecognizePass, IndVarSimplifyPass, // LoopDeletionPass and LoopFullUnrollPass) do not preserve MemorySSA. // *All* loop passes must preserve it, in order to be able to use it. @@ -1841,7 +1841,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, // More loops are countable; try to optimize them. if (EnableLoopFlatten && Level.getSpeedupLevel() > 1) - MainFPM.addPass(LoopFlattenPass()); + MainFPM.addPass(createFunctionToLoopPassAdaptor(LoopFlattenPass())); if (EnableConstraintElimination) MainFPM.addPass(ConstraintEliminationPass()); diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 128c9f3..a66c814 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -247,7 +247,7 @@ FUNCTION_PASS("guard-widening", GuardWideningPass()) FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass()) FUNCTION_PASS("loop-simplify", LoopSimplifyPass()) FUNCTION_PASS("loop-sink", LoopSinkPass()) -FUNCTION_PASS("loop-flatten", LoopFlattenPass()) +FUNCTION_PASS("loop-unroll-and-jam", LoopUnrollAndJamPass()) FUNCTION_PASS("lowerinvoke", LowerInvokePass()) FUNCTION_PASS("lowerswitch", LowerSwitchPass()) FUNCTION_PASS("mem2reg", PromotePass()) @@ -388,6 +388,7 @@ LOOP_PASS("canon-freeze", CanonicalizeFreezeInLoopsPass()) LOOP_PASS("dot-ddg", DDGDotPrinterPass()) LOOP_PASS("invalidate", InvalidateAllAnalysesPass()) LOOP_PASS("licm", LICMPass()) +LOOP_PASS("loop-flatten", LoopFlattenPass()) LOOP_PASS("loop-idiom", LoopIdiomRecognizePass()) LOOP_PASS("loop-instsimplify", LoopInstSimplifyPass()) LOOP_PASS("loop-interchange", LoopInterchangePass()) diff --git a/llvm/lib/Transforms/Scalar/LoopFlatten.cpp b/llvm/lib/Transforms/Scalar/LoopFlatten.cpp index 4c5ffdc..37bfff4 100644 --- a/llvm/lib/Transforms/Scalar/LoopFlatten.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFlatten.cpp @@ -658,10 +658,10 @@ static bool FlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI, return DoFlattenLoopPair(FI, DT, LI, SE, AC, TTI); } -bool Flatten(DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, +bool Flatten(LoopNest &LN, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, TargetTransformInfo *TTI) { bool Changed = false; - for (auto *InnerLoop : LI->getLoopsInPreorder()) { + for (Loop *InnerLoop : LN.getLoops()) { auto *OuterLoop = InnerLoop->getParentLoop(); if (!OuterLoop) continue; @@ -671,13 +671,9 @@ bool Flatten(DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, return Changed; } -PreservedAnalyses LoopFlattenPass::run(Function &F, - FunctionAnalysisManager &AM) { - auto *DT = &AM.getResult(F); - auto *LI = &AM.getResult(F); - auto *SE = &AM.getResult(F); - auto *AC = &AM.getResult(F); - auto *TTI = &AM.getResult(F); +PreservedAnalyses LoopFlattenPass::run(LoopNest &LN, LoopAnalysisManager &LAM, + LoopStandardAnalysisResults &AR, + LPMUpdater &U) { bool Changed = false; @@ -685,15 +681,7 @@ PreservedAnalyses LoopFlattenPass::run(Function &F, // in simplified form, and also needs LCSSA. Running // this pass will simplify all loops that contain inner loops, // regardless of whether anything ends up being flattened. - for (const auto &L : *LI) { - if (L->isInnermost()) - continue; - Changed |= - simplifyLoop(L, DT, LI, SE, AC, nullptr, false /* PreserveLCSSA */); - Changed |= formLCSSARecursively(*L, *DT, LI, SE); - } - - Changed |= Flatten(DT, LI, SE, AC, TTI); + Changed |= Flatten(LN, &AR.DT, &AR.LI, &AR.SE, &AR.AC, &AR.TTI); if (!Changed) return PreservedAnalyses::all(); @@ -740,5 +728,10 @@ bool LoopFlattenLegacyPass::runOnFunction(Function &F) { auto &TTIP = getAnalysis(); auto *TTI = &TTIP.getTTI(F); auto *AC = &getAnalysis().getAssumptionCache(F); - return Flatten(DT, LI, SE, AC, TTI); + bool Changed = false; + for (Loop *L : *LI) { + auto LN = LoopNest::getLoopNest(*L, *SE); + Changed |= Flatten(*LN, DT, LI, SE, AC, TTI); + } + return Changed; }