[polly] b687fc9 - [Polly] Port PruneUnprofitable to the NewPM.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 21:58:57 PST 2021


Author: Michael Kruse
Date: 2021-02-09T23:56:20-06:00
New Revision: b687fc9122c883f0ce7cf056aa56313ec1671445

URL: https://github.com/llvm/llvm-project/commit/b687fc9122c883f0ce7cf056aa56313ec1671445
DIFF: https://github.com/llvm/llvm-project/commit/b687fc9122c883f0ce7cf056aa56313ec1671445.diff

LOG: [Polly] Port PruneUnprofitable to the NewPM.

Added: 
    

Modified: 
    polly/include/polly/LinkAllPasses.h
    polly/include/polly/PruneUnprofitable.h
    polly/lib/Analysis/PruneUnprofitable.cpp
    polly/lib/Support/PollyPasses.def
    polly/lib/Support/RegisterPasses.cpp
    polly/test/PruneUnprofitable/prune_only_scalardeps.ll

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/LinkAllPasses.h b/polly/include/polly/LinkAllPasses.h
index 4be8aeb9d44f..286b58f46d52 100644
--- a/polly/include/polly/LinkAllPasses.h
+++ b/polly/include/polly/LinkAllPasses.h
@@ -16,7 +16,6 @@
 
 #include "polly/CodeGen/PPCGCodeGeneration.h"
 #include "polly/Config/config.h"
-#include "polly/PruneUnprofitable.h"
 #include "polly/Simplify.h"
 #include "polly/Support/DumpModulePass.h"
 #include "llvm/ADT/StringRef.h"
@@ -60,6 +59,7 @@ llvm::Pass *createFlattenSchedulePass();
 llvm::Pass *createForwardOpTreeWrapperPass();
 llvm::Pass *createDeLICMWrapperPass();
 llvm::Pass *createMaximalStaticExpansionPass();
+llvm::Pass *createPruneUnprofitableWrapperPass();
 
 extern char &CodePreparationID;
 } // namespace polly
@@ -100,7 +100,7 @@ struct PollyForcePassLinking {
     polly::createDeLICMWrapperPass();
     polly::createDumpModulePass("", true);
     polly::createSimplifyPass();
-    polly::createPruneUnprofitablePass();
+    polly::createPruneUnprofitableWrapperPass();
   }
 } PollyForcePassLinking; // Force link by creating a global definition.
 } // namespace
@@ -125,6 +125,7 @@ void initializePollyCanonicalizePass(llvm::PassRegistry &);
 void initializeFlattenSchedulePass(llvm::PassRegistry &);
 void initializeForwardOpTreeWrapperPassPass(llvm::PassRegistry &);
 void initializeDeLICMWrapperPassPass(llvm::PassRegistry &);
+void initializePruneUnprofitableWrapperPassPass(llvm::PassRegistry &);
 } // namespace llvm
 
 #endif

diff  --git a/polly/include/polly/PruneUnprofitable.h b/polly/include/polly/PruneUnprofitable.h
index 3327e1435013..6335708fae86 100644
--- a/polly/include/polly/PruneUnprofitable.h
+++ b/polly/include/polly/PruneUnprofitable.h
@@ -13,17 +13,26 @@
 #ifndef POLLY_PRUNEUNPROFITABLE_H
 #define POLLY_PRUNEUNPROFITABLE_H
 
-namespace llvm {
+#include "polly/ScopPass.h"
 
+namespace llvm {
 class Pass;
 class PassRegistry;
-
-void initializePruneUnprofitablePass(PassRegistry &);
 } // namespace llvm
 
 namespace polly {
+llvm::Pass *createPruneUnprofitableWrapperPass();
 
-llvm::Pass *createPruneUnprofitablePass();
+struct PruneUnprofitablePass : llvm::PassInfoMixin<PruneUnprofitablePass> {
+  PruneUnprofitablePass() {}
+
+  llvm::PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
+                              ScopStandardAnalysisResults &SAR, SPMUpdater &U);
+};
 } // namespace polly
 
+namespace llvm {
+void initializePruneUnprofitableWrapperPassPass(PassRegistry &);
+}
+
 #endif // POLLY_PRUNEUNPROFITABLE_H

diff  --git a/polly/lib/Analysis/PruneUnprofitable.cpp b/polly/lib/Analysis/PruneUnprofitable.cpp
index f2780a3e9f5c..abcbf3d809d9 100644
--- a/polly/lib/Analysis/PruneUnprofitable.cpp
+++ b/polly/lib/Analysis/PruneUnprofitable.cpp
@@ -40,65 +40,84 @@ STATISTIC(NumLoopsInScop, "Number of loops in scops after pruning");
 STATISTIC(NumBoxedLoops, "Number of boxed loops in SCoPs after pruning");
 STATISTIC(NumAffineLoops, "Number of affine loops in SCoPs after pruning");
 
-class PruneUnprofitable : public ScopPass {
-private:
-  void updateStatistics(Scop &S, bool Pruned) {
-    auto ScopStats = S.getStatistics();
-    if (Pruned) {
-      ScopsPruned++;
-      NumPrunedLoops += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
-      NumPrunedBoxedLoops += ScopStats.NumBoxedLoops;
-      NumPrunedAffineLoops += ScopStats.NumAffineLoops;
-    } else {
-      ScopsSurvived++;
-      NumLoopsInScop += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
-      NumBoxedLoops += ScopStats.NumBoxedLoops;
-      NumAffineLoops += ScopStats.NumAffineLoops;
-    }
+static void updateStatistics(Scop &S, bool Pruned) {
+  Scop::ScopStatistics ScopStats = S.getStatistics();
+  if (Pruned) {
+    ScopsPruned++;
+    NumPrunedLoops += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
+    NumPrunedBoxedLoops += ScopStats.NumBoxedLoops;
+    NumPrunedAffineLoops += ScopStats.NumAffineLoops;
+  } else {
+    ScopsSurvived++;
+    NumLoopsInScop += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
+    NumBoxedLoops += ScopStats.NumBoxedLoops;
+    NumAffineLoops += ScopStats.NumAffineLoops;
   }
+}
 
+static bool runPruneUnprofitable(Scop &S) {
+  if (PollyProcessUnprofitable) {
+    LLVM_DEBUG(
+        dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
+                  "anything\n");
+    return false;
+  }
+
+  ScopsProcessed++;
+
+  if (!S.isProfitable(true)) {
+    LLVM_DEBUG(
+        dbgs() << "SCoP pruned because it probably cannot be optimized in "
+                  "a significant way\n");
+    S.invalidate(PROFITABLE, DebugLoc());
+    updateStatistics(S, true);
+  } else {
+    updateStatistics(S, false);
+  }
+
+  return false;
+}
+
+class PruneUnprofitableWrapperPass : public ScopPass {
 public:
   static char ID;
 
-  explicit PruneUnprofitable() : ScopPass(ID) {}
-  PruneUnprofitable(const PruneUnprofitable &) = delete;
-  PruneUnprofitable &operator=(const PruneUnprofitable &) = delete;
+  explicit PruneUnprofitableWrapperPass() : ScopPass(ID) {}
+  PruneUnprofitableWrapperPass(const PruneUnprofitableWrapperPass &) = delete;
+  PruneUnprofitableWrapperPass &
+  operator=(const PruneUnprofitableWrapperPass &) = delete;
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<ScopInfoRegionPass>();
     AU.setPreservesAll();
   }
 
-  bool runOnScop(Scop &S) override {
-    if (PollyProcessUnprofitable) {
-      LLVM_DEBUG(
-          dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
-                    "anything\n");
-      return false;
-    }
-
-    ScopsProcessed++;
-
-    if (!S.isProfitable(true)) {
-      LLVM_DEBUG(
-          dbgs() << "SCoP pruned because it probably cannot be optimized in "
-                    "a significant way\n");
-      S.invalidate(PROFITABLE, DebugLoc());
-      updateStatistics(S, true);
-    } else {
-      updateStatistics(S, false);
-    }
-
-    return false;
-  }
+  bool runOnScop(Scop &S) override { return runPruneUnprofitable(S); }
 };
 } // namespace
 
-char PruneUnprofitable::ID;
+char PruneUnprofitableWrapperPass::ID;
 
-Pass *polly::createPruneUnprofitablePass() { return new PruneUnprofitable(); }
+Pass *polly::createPruneUnprofitableWrapperPass() {
+  return new PruneUnprofitableWrapperPass();
+}
 
-INITIALIZE_PASS_BEGIN(PruneUnprofitable, "polly-prune-unprofitable",
+INITIALIZE_PASS_BEGIN(PruneUnprofitableWrapperPass, "polly-prune-unprofitable",
                       "Polly - Prune unprofitable SCoPs", false, false)
-INITIALIZE_PASS_END(PruneUnprofitable, "polly-prune-unprofitable",
+INITIALIZE_PASS_END(PruneUnprofitableWrapperPass, "polly-prune-unprofitable",
                     "Polly - Prune unprofitable SCoPs", false, false)
+
+llvm::PreservedAnalyses
+PruneUnprofitablePass::run(Scop &S, ScopAnalysisManager &SAM,
+                           ScopStandardAnalysisResults &SAR, SPMUpdater &U) {
+  bool Changed = runPruneUnprofitable(S);
+
+  if (!Changed)
+    return PreservedAnalyses::all();
+
+  PreservedAnalyses PA;
+  PA.preserveSet<AllAnalysesOn<Module>>();
+  PA.preserveSet<AllAnalysesOn<Function>>();
+  PA.preserveSet<AllAnalysesOn<Loop>>();
+  return PA;
+}

diff  --git a/polly/lib/Support/PollyPasses.def b/polly/lib/Support/PollyPasses.def
index f712fce87bd3..3083ae2b5a20 100644
--- a/polly/lib/Support/PollyPasses.def
+++ b/polly/lib/Support/PollyPasses.def
@@ -34,4 +34,5 @@ SCOP_PASS("polly-optree", ForwardOpTreePass())
 SCOP_PASS("print<polly-optree>", ForwardOpTreePrinterPass(outs()))
 SCOP_PASS("polly-delicm", DeLICMPass())
 SCOP_PASS("print<polly-delicm>", DeLICMPrinterPass(outs()))
+SCOP_PASS("polly-prune-unprofitable", PruneUnprofitablePass())
 #undef SCOP_PASS

diff  --git a/polly/lib/Support/RegisterPasses.cpp b/polly/lib/Support/RegisterPasses.cpp
index bc4f3ecbc6d6..39c965831993 100644
--- a/polly/lib/Support/RegisterPasses.cpp
+++ b/polly/lib/Support/RegisterPasses.cpp
@@ -30,6 +30,7 @@
 #include "polly/JSONExporter.h"
 #include "polly/LinkAllPasses.h"
 #include "polly/PolyhedralInfo.h"
+#include "polly/PruneUnprofitable.h"
 #include "polly/ScopDetection.h"
 #include "polly/ScopInfo.h"
 #include "polly/Simplify.h"
@@ -266,7 +267,7 @@ void initializePollyPasses(PassRegistry &Registry) {
   initializeDeLICMWrapperPassPass(Registry);
   initializeSimplifyLegacyPassPass(Registry);
   initializeDumpModulePass(Registry);
-  initializePruneUnprofitablePass(Registry);
+  initializePruneUnprofitableWrapperPassPass(Registry);
 }
 
 /// Register Polly passes such that they form a polyhedral optimizer.
@@ -338,7 +339,7 @@ void registerPollyPasses(llvm::legacy::PassManagerBase &PM) {
     PM.add(polly::createMaximalStaticExpansionPass());
 
   if (EnablePruneUnprofitable)
-    PM.add(polly::createPruneUnprofitablePass());
+    PM.add(polly::createPruneUnprofitableWrapperPass());
 
 #ifdef GPU_CODEGEN
   if (Target == TARGET_HYBRID)
@@ -477,7 +478,8 @@ static void buildDefaultPollyPipeline(FunctionPassManager &PM,
   if (ImportJScop)
     SPM.addPass(JSONImportPass());
   assert(!DeadCodeElim && "This option is not implemented");
-  assert(!EnablePruneUnprofitable && "This option is not implemented");
+  if (EnablePruneUnprofitable)
+    SPM.addPass(PruneUnprofitablePass());
   if (Target == TARGET_CPU || Target == TARGET_HYBRID)
     switch (Optimizer) {
     case OPTIMIZER_NONE:

diff  --git a/polly/test/PruneUnprofitable/prune_only_scalardeps.ll b/polly/test/PruneUnprofitable/prune_only_scalardeps.ll
index e817dcf67100..f2a7116ef5ca 100644
--- a/polly/test/PruneUnprofitable/prune_only_scalardeps.ll
+++ b/polly/test/PruneUnprofitable/prune_only_scalardeps.ll
@@ -1,4 +1,5 @@
 ; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-process-unprofitable=false -polly-unprofitable-scalar-accs=false -polly-prune-unprofitable -disable-output -stats < %s 2>&1 | FileCheck -match-full-lines %s
+; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-process-unprofitable=false -polly-unprofitable-scalar-accs=false "-passes=scop(polly-prune-unprofitable)" -disable-output -stats < %s 2>&1 | FileCheck -match-full-lines %s
 ; REQUIRES: asserts
 ;
 ; Skip this SCoP for having scalar dependencies between all statements,


        


More information about the llvm-commits mailing list