[llvm] [NFC][VP] Reduce parameters in `LoopVectorizePass::runImpl` (PR #103551)

Shao-Ce SUN via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 04:38:41 PDT 2024


https://github.com/sunshaoce updated https://github.com/llvm/llvm-project/pull/103551

>From b944d94a9ab7e3170b0b0e0cea595b1f1d72b98a Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN <sunshaoce at outlook.com>
Date: Wed, 14 Aug 2024 11:54:56 +0800
Subject: [PATCH 1/2] [NFC][VP] Reduce parameters in
 `LoopVectorizePass::runImpl`

---
 .../llvm/Transforms/Vectorize/LoopVectorize.h |  8 +--
 .../Transforms/Vectorize/LoopVectorize.cpp    | 53 +++++++------------
 2 files changed, 19 insertions(+), 42 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
index 9d564a3279ce77..24b6354662955e 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
@@ -188,13 +188,7 @@ struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
                      function_ref<StringRef(StringRef)> MapClassName2PassName);
 
   // Shim for old PM.
-  LoopVectorizeResult runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
-                              TargetTransformInfo &TTI_, DominatorTree &DT_,
-                              BlockFrequencyInfo *BFI_, TargetLibraryInfo *TLI_,
-                              DemandedBits &DB_, AssumptionCache &AC_,
-                              LoopAccessInfoManager &LAIs_,
-                              OptimizationRemarkEmitter &ORE_,
-                              ProfileSummaryInfo *PSI_);
+  LoopVectorizeResult runImpl(Function &F);
 
   bool processLoop(Loop *L);
 };
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f5337b11edc977..83e41f04b2f0ff 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10176,22 +10176,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
   return true;
 }
 
-LoopVectorizeResult LoopVectorizePass::runImpl(
-    Function &F, ScalarEvolution &SE_, LoopInfo &LI_, TargetTransformInfo &TTI_,
-    DominatorTree &DT_, BlockFrequencyInfo *BFI_, TargetLibraryInfo *TLI_,
-    DemandedBits &DB_, AssumptionCache &AC_, LoopAccessInfoManager &LAIs_,
-    OptimizationRemarkEmitter &ORE_, ProfileSummaryInfo *PSI_) {
-  SE = &SE_;
-  LI = &LI_;
-  TTI = &TTI_;
-  DT = &DT_;
-  BFI = BFI_;
-  TLI = TLI_;
-  AC = &AC_;
-  LAIs = &LAIs_;
-  DB = &DB_;
-  ORE = &ORE_;
-  PSI = PSI_;
+LoopVectorizeResult LoopVectorizePass::runImpl(Function &F) {
 
   // Don't attempt if
   // 1. the target claims to have no vector registers, and
@@ -10251,28 +10236,26 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
 
 PreservedAnalyses LoopVectorizePass::run(Function &F,
                                          FunctionAnalysisManager &AM) {
-    auto &LI = AM.getResult<LoopAnalysis>(F);
-    // There are no loops in the function. Return before computing other expensive
-    // analyses.
-    if (LI.empty())
+    LI = &AM.getResult<LoopAnalysis>(F);
+    // There are no loops in the function. Return before computing other
+    // expensive analyses.
+    if (LI->empty())
       return PreservedAnalyses::all();
-    auto &SE = AM.getResult<ScalarEvolutionAnalysis>(F);
-    auto &TTI = AM.getResult<TargetIRAnalysis>(F);
-    auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
-    auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
-    auto &AC = AM.getResult<AssumptionAnalysis>(F);
-    auto &DB = AM.getResult<DemandedBitsAnalysis>(F);
-    auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
-
-    LoopAccessInfoManager &LAIs = AM.getResult<LoopAccessAnalysis>(F);
+    SE = &AM.getResult<ScalarEvolutionAnalysis>(F);
+    TTI = &AM.getResult<TargetIRAnalysis>(F);
+    DT = &AM.getResult<DominatorTreeAnalysis>(F);
+    TLI = &AM.getResult<TargetLibraryAnalysis>(F);
+    AC = &AM.getResult<AssumptionAnalysis>(F);
+    DB = &AM.getResult<DemandedBitsAnalysis>(F);
+    ORE = &AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+    LAIs = &AM.getResult<LoopAccessAnalysis>(F);
+
     auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
-    ProfileSummaryInfo *PSI =
-        MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
-    BlockFrequencyInfo *BFI = nullptr;
+    PSI = MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
+    BFI = nullptr;
     if (PSI && PSI->hasProfileSummary())
       BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
-    LoopVectorizeResult Result =
-        runImpl(F, SE, LI, TTI, DT, BFI, &TLI, DB, AC, LAIs, ORE, PSI);
+    LoopVectorizeResult Result = runImpl(F);
     if (!Result.MadeAnyChange)
       return PreservedAnalyses::all();
     PreservedAnalyses PA;
@@ -10298,7 +10281,7 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
       PA.preserveSet<CFGAnalyses>();
     }
     return PA;
-}
+  }
 
 void LoopVectorizePass::printPipeline(
     raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {

>From e9feb646a3fe73c761c8b0fab85b2b4ea4f334d1 Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN <sunshaoce at outlook.com>
Date: Wed, 14 Aug 2024 19:38:27 +0800
Subject: [PATCH 2/2] fixup! clang-format

---
 .../Transforms/Vectorize/LoopVectorize.cpp    | 90 +++++++++----------
 1 file changed, 45 insertions(+), 45 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 83e41f04b2f0ff..f1bb96a38cfaa9 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10236,52 +10236,52 @@ LoopVectorizeResult LoopVectorizePass::runImpl(Function &F) {
 
 PreservedAnalyses LoopVectorizePass::run(Function &F,
                                          FunctionAnalysisManager &AM) {
-    LI = &AM.getResult<LoopAnalysis>(F);
-    // There are no loops in the function. Return before computing other
-    // expensive analyses.
-    if (LI->empty())
-      return PreservedAnalyses::all();
-    SE = &AM.getResult<ScalarEvolutionAnalysis>(F);
-    TTI = &AM.getResult<TargetIRAnalysis>(F);
-    DT = &AM.getResult<DominatorTreeAnalysis>(F);
-    TLI = &AM.getResult<TargetLibraryAnalysis>(F);
-    AC = &AM.getResult<AssumptionAnalysis>(F);
-    DB = &AM.getResult<DemandedBitsAnalysis>(F);
-    ORE = &AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
-    LAIs = &AM.getResult<LoopAccessAnalysis>(F);
-
-    auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
-    PSI = MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
-    BFI = nullptr;
-    if (PSI && PSI->hasProfileSummary())
-      BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
-    LoopVectorizeResult Result = runImpl(F);
-    if (!Result.MadeAnyChange)
-      return PreservedAnalyses::all();
-    PreservedAnalyses PA;
-
-    if (isAssignmentTrackingEnabled(*F.getParent())) {
-      for (auto &BB : F)
-        RemoveRedundantDbgInstrs(&BB);
-    }
-
-    PA.preserve<LoopAnalysis>();
-    PA.preserve<DominatorTreeAnalysis>();
-    PA.preserve<ScalarEvolutionAnalysis>();
-    PA.preserve<LoopAccessAnalysis>();
-
-    if (Result.MadeCFGChange) {
-      // Making CFG changes likely means a loop got vectorized. Indicate that
-      // extra simplification passes should be run.
-      // TODO: MadeCFGChanges is not a prefect proxy. Extra passes should only
-      // be run if runtime checks have been added.
-      AM.getResult<ShouldRunExtraVectorPasses>(F);
-      PA.preserve<ShouldRunExtraVectorPasses>();
-    } else {
-      PA.preserveSet<CFGAnalyses>();
-    }
-    return PA;
+  LI = &AM.getResult<LoopAnalysis>(F);
+  // There are no loops in the function. Return before computing other
+  // expensive analyses.
+  if (LI->empty())
+    return PreservedAnalyses::all();
+  SE = &AM.getResult<ScalarEvolutionAnalysis>(F);
+  TTI = &AM.getResult<TargetIRAnalysis>(F);
+  DT = &AM.getResult<DominatorTreeAnalysis>(F);
+  TLI = &AM.getResult<TargetLibraryAnalysis>(F);
+  AC = &AM.getResult<AssumptionAnalysis>(F);
+  DB = &AM.getResult<DemandedBitsAnalysis>(F);
+  ORE = &AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+  LAIs = &AM.getResult<LoopAccessAnalysis>(F);
+
+  auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
+  PSI = MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
+  BFI = nullptr;
+  if (PSI && PSI->hasProfileSummary())
+    BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
+  LoopVectorizeResult Result = runImpl(F);
+  if (!Result.MadeAnyChange)
+    return PreservedAnalyses::all();
+  PreservedAnalyses PA;
+
+  if (isAssignmentTrackingEnabled(*F.getParent())) {
+    for (auto &BB : F)
+      RemoveRedundantDbgInstrs(&BB);
+  }
+
+  PA.preserve<LoopAnalysis>();
+  PA.preserve<DominatorTreeAnalysis>();
+  PA.preserve<ScalarEvolutionAnalysis>();
+  PA.preserve<LoopAccessAnalysis>();
+
+  if (Result.MadeCFGChange) {
+    // Making CFG changes likely means a loop got vectorized. Indicate that
+    // extra simplification passes should be run.
+    // TODO: MadeCFGChanges is not a prefect proxy. Extra passes should only
+    // be run if runtime checks have been added.
+    AM.getResult<ShouldRunExtraVectorPasses>(F);
+    PA.preserve<ShouldRunExtraVectorPasses>();
+  } else {
+    PA.preserveSet<CFGAnalyses>();
   }
+  return PA;
+}
 
 void LoopVectorizePass::printPipeline(
     raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {



More information about the llvm-commits mailing list