[polly] e200df9 - [Polly] Port IslScheduleOptimizer to the NewPM.

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


Author: Michael Kruse
Date: 2021-02-09T23:56:21-06:00
New Revision: e200df952bc5b6958ce808c7f19696e65ec9e9d5

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

LOG: [Polly] Port IslScheduleOptimizer to the NewPM.

Added: 
    

Modified: 
    polly/include/polly/LinkAllPasses.h
    polly/include/polly/ScheduleOptimizer.h
    polly/lib/Support/PollyPasses.def
    polly/lib/Support/RegisterPasses.cpp
    polly/lib/Transform/ScheduleOptimizer.cpp
    polly/test/ScheduleOptimizer/computeout.ll
    polly/test/ScheduleOptimizer/focaltech_test_detail_threshold-7bc17e.ll

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/LinkAllPasses.h b/polly/include/polly/LinkAllPasses.h
index 286b58f46d52..2c01933fb53a 100644
--- a/polly/include/polly/LinkAllPasses.h
+++ b/polly/include/polly/LinkAllPasses.h
@@ -54,7 +54,7 @@ llvm::Pass *
 createManagedMemoryRewritePassPass(GPUArch Arch = GPUArch::NVPTX64,
                                    GPURuntime Runtime = GPURuntime::CUDA);
 #endif
-llvm::Pass *createIslScheduleOptimizerPass();
+llvm::Pass *createIslScheduleOptimizerWrapperPass();
 llvm::Pass *createFlattenSchedulePass();
 llvm::Pass *createForwardOpTreeWrapperPass();
 llvm::Pass *createDeLICMWrapperPass();
@@ -93,7 +93,7 @@ struct PollyForcePassLinking {
     polly::createPPCGCodeGenerationPass();
     polly::createManagedMemoryRewritePassPass();
 #endif
-    polly::createIslScheduleOptimizerPass();
+    polly::createIslScheduleOptimizerWrapperPass();
     polly::createMaximalStaticExpansionPass();
     polly::createFlattenSchedulePass();
     polly::createForwardOpTreeWrapperPass();
@@ -119,7 +119,7 @@ void initializeRewriteByrefParamsPass(llvm::PassRegistry &);
 void initializePPCGCodeGenerationPass(llvm::PassRegistry &);
 void initializeManagedMemoryRewritePassPass(llvm::PassRegistry &);
 #endif
-void initializeIslScheduleOptimizerPass(llvm::PassRegistry &);
+void initializeIslScheduleOptimizerWrapperPassPass(llvm::PassRegistry &);
 void initializeMaximalStaticExpanderPass(llvm::PassRegistry &);
 void initializePollyCanonicalizePass(llvm::PassRegistry &);
 void initializeFlattenSchedulePass(llvm::PassRegistry &);

diff  --git a/polly/include/polly/ScheduleOptimizer.h b/polly/include/polly/ScheduleOptimizer.h
index c32ddfa31409..cac11139800f 100644
--- a/polly/include/polly/ScheduleOptimizer.h
+++ b/polly/include/polly/ScheduleOptimizer.h
@@ -9,11 +9,13 @@
 #ifndef POLLY_SCHEDULEOPTIMIZER_H
 #define POLLY_SCHEDULEOPTIMIZER_H
 
+#include "polly/ScopPass.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "isl/isl-noexceptions.h"
 
 namespace llvm {
-
+class Pass;
+class PassRegistry;
 class TargetTransformInfo;
 } // namespace llvm
 
@@ -39,7 +41,6 @@ struct MacroKernelParamsTy {
 };
 
 namespace polly {
-
 struct Dependences;
 class MemoryAccess;
 class Scop;
@@ -68,8 +69,34 @@ struct MatMulInfoTy {
 };
 
 extern bool DisablePollyTiling;
+
+llvm::Pass *createIslScheduleOptimizerWrapperPass();
+
+struct IslScheduleOptimizerPass
+    : llvm::PassInfoMixin<IslScheduleOptimizerPass> {
+  IslScheduleOptimizerPass() {}
+
+  llvm::PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
+                              ScopStandardAnalysisResults &SAR, SPMUpdater &U);
+};
+
+struct IslScheduleOptimizerPrinterPass
+    : llvm::PassInfoMixin<IslScheduleOptimizerPrinterPass> {
+  IslScheduleOptimizerPrinterPass(raw_ostream &OS) : OS(OS) {}
+
+  PreservedAnalyses run(Scop &S, ScopAnalysisManager &,
+                        ScopStandardAnalysisResults &SAR, SPMUpdater &);
+
+private:
+  llvm::raw_ostream &OS;
+};
+
 } // namespace polly
 
+namespace llvm {
+void initializeIslScheduleOptimizerWrapperPassPass(llvm::PassRegistry &);
+}
+
 class ScheduleTreeOptimizer {
 public:
   /// Apply schedule tree transformations.

diff  --git a/polly/lib/Support/PollyPasses.def b/polly/lib/Support/PollyPasses.def
index 701421e3e6b4..f2111e3bd14f 100644
--- a/polly/lib/Support/PollyPasses.def
+++ b/polly/lib/Support/PollyPasses.def
@@ -36,4 +36,6 @@ 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())
+SCOP_PASS("polly-opt-isl", IslScheduleOptimizerPass())
+SCOP_PASS("print<polly-opt-isl>", IslScheduleOptimizerPrinterPass(outs()))
 #undef SCOP_PASS

diff  --git a/polly/lib/Support/RegisterPasses.cpp b/polly/lib/Support/RegisterPasses.cpp
index 4c8d94c13fea..b68d65c0a7fd 100644
--- a/polly/lib/Support/RegisterPasses.cpp
+++ b/polly/lib/Support/RegisterPasses.cpp
@@ -31,6 +31,7 @@
 #include "polly/LinkAllPasses.h"
 #include "polly/PolyhedralInfo.h"
 #include "polly/PruneUnprofitable.h"
+#include "polly/ScheduleOptimizer.h"
 #include "polly/ScopDetection.h"
 #include "polly/ScopInfo.h"
 #include "polly/Simplify.h"
@@ -253,7 +254,7 @@ void initializePollyPasses(PassRegistry &Registry) {
   initializeJSONImporterPass(Registry);
   initializeMaximalStaticExpanderPass(Registry);
   initializeIslAstInfoWrapperPassPass(Registry);
-  initializeIslScheduleOptimizerPass(Registry);
+  initializeIslScheduleOptimizerWrapperPassPass(Registry);
   initializePollyCanonicalizePass(Registry);
   initializePolyhedralInfoPass(Registry);
   initializeScopDetectionWrapperPassPass(Registry);
@@ -352,7 +353,7 @@ void registerPollyPasses(llvm::legacy::PassManagerBase &PM) {
       break; /* Do nothing */
 
     case OPTIMIZER_ISL:
-      PM.add(polly::createIslScheduleOptimizerPass());
+      PM.add(polly::createIslScheduleOptimizerWrapperPass());
       break;
     }
 
@@ -485,7 +486,7 @@ static void buildDefaultPollyPipeline(FunctionPassManager &PM,
     case OPTIMIZER_NONE:
       break; /* Do nothing */
     case OPTIMIZER_ISL:
-      llvm_unreachable("ISL optimizer is not implemented");
+      SPM.addPass(IslScheduleOptimizerPass());
       break;
     }
 

diff  --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp
index 2697b320161d..96248d77ba2e 100644
--- a/polly/lib/Transform/ScheduleOptimizer.cpp
+++ b/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -1383,13 +1383,13 @@ bool ScheduleTreeOptimizer::isProfitableSchedule(Scop &S,
 
 namespace {
 
-class IslScheduleOptimizer : public ScopPass {
+class IslScheduleOptimizerWrapperPass : public ScopPass {
 public:
   static char ID;
 
-  explicit IslScheduleOptimizer() : ScopPass(ID) {}
+  explicit IslScheduleOptimizerWrapperPass() : ScopPass(ID) {}
 
-  ~IslScheduleOptimizer() override { releaseMemory(); }
+  ~IslScheduleOptimizerWrapperPass() override { releaseMemory(); }
 
   /// Optimize the schedule of the SCoP @p S.
   bool runOnScop(Scop &S) override;
@@ -1402,18 +1402,17 @@ class IslScheduleOptimizer : public ScopPass {
 
   /// Release the internal memory.
   void releaseMemory() override {
-    isl_schedule_free(LastSchedule);
     LastSchedule = nullptr;
     IslCtx.reset();
   }
 
 private:
   std::shared_ptr<isl_ctx> IslCtx;
-  isl_schedule *LastSchedule = nullptr;
+  isl::schedule LastSchedule;
 };
 } // namespace
 
-char IslScheduleOptimizer::ID = 0;
+char IslScheduleOptimizerWrapperPass::ID = 0;
 
 /// Collect statistics for the schedule tree.
 ///
@@ -1468,7 +1467,10 @@ static void walkScheduleTreeForStatistics(isl::schedule Schedule, int Version) {
       &Version);
 }
 
-bool IslScheduleOptimizer::runOnScop(Scop &S) {
+static bool runIslScheduleOptimizer(
+    Scop &S,
+    function_ref<const Dependences &(Dependences::AnalysisLevel)> GetDeps,
+    TargetTransformInfo *TTI, isl::schedule &LastSchedule) {
   // Skip SCoPs in case they're already optimised by PPCGCodeGeneration
   if (S.isToBeSkipped())
     return false;
@@ -1480,8 +1482,7 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) {
     return false;
   }
 
-  const Dependences &D =
-      getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement);
+  const Dependences &D = GetDeps(Dependences::AL_Statement);
 
   if (D.getSharedIslCtx() != S.getSharedIslCtx()) {
     LLVM_DEBUG(dbgs() << "DependenceInfo for another SCoP/isl_ctx\n");
@@ -1491,9 +1492,6 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) {
   if (!D.hasValidDependences())
     return false;
 
-  isl_schedule_free(LastSchedule);
-  LastSchedule = nullptr;
-
   // Build input data.
   int ValidityKinds =
       Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW;
@@ -1618,8 +1616,6 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) {
     isl_printer_free(P);
   });
 
-  Function &F = S.getFunction();
-  auto *TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
   const OptimizerAdditionalInfoTy OAI = {TTI, const_cast<Dependences *>(&D)};
   auto NewSchedule = ScheduleTreeOptimizer::optimizeSchedule(Schedule, &OAI);
   NewSchedule = hoistExtensionNodes(NewSchedule);
@@ -1632,8 +1628,7 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) {
   ScopsOptimized++;
   NumAffineLoopsOptimized += ScopStats.NumAffineLoops;
   NumBoxedLoopsOptimized += ScopStats.NumBoxedLoops;
-  LastSchedule = NewSchedule.copy();
-  IslCtx = S.getSharedIslCtx();
+  LastSchedule = NewSchedule;
 
   S.setScheduleTree(NewSchedule);
   S.markAsOptimized();
@@ -1644,7 +1639,25 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) {
   return false;
 }
 
-void IslScheduleOptimizer::printScop(raw_ostream &OS, Scop &) const {
+bool IslScheduleOptimizerWrapperPass::runOnScop(Scop &S) {
+  releaseMemory();
+
+  Function &F = S.getFunction();
+  IslCtx = S.getSharedIslCtx();
+
+  auto getDependences =
+      [this](Dependences::AnalysisLevel) -> const Dependences & {
+    return getAnalysis<DependenceInfo>().getDependences(
+        Dependences::AL_Statement);
+  };
+  // auto &Deps  = getAnalysis<DependenceInfo>();
+  TargetTransformInfo *TTI =
+      &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
+  return runIslScheduleOptimizer(S, getDependences, TTI, LastSchedule);
+}
+
+static void runScheduleOptimizerPrinter(raw_ostream &OS,
+                                        isl::schedule LastSchedule) {
   isl_printer *p;
   char *ScheduleStr;
 
@@ -1655,9 +1668,9 @@ void IslScheduleOptimizer::printScop(raw_ostream &OS, Scop &) const {
     return;
   }
 
-  p = isl_printer_to_str(isl_schedule_get_ctx(LastSchedule));
+  p = isl_printer_to_str(LastSchedule.get_ctx().get());
   p = isl_printer_set_yaml_style(p, ISL_YAML_STYLE_BLOCK);
-  p = isl_printer_print_schedule(p, LastSchedule);
+  p = isl_printer_print_schedule(p, LastSchedule.get());
   ScheduleStr = isl_printer_get_str(p);
   isl_printer_free(p);
 
@@ -1666,7 +1679,12 @@ void IslScheduleOptimizer::printScop(raw_ostream &OS, Scop &) const {
   free(ScheduleStr);
 }
 
-void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
+void IslScheduleOptimizerWrapperPass::printScop(raw_ostream &OS, Scop &) const {
+  runScheduleOptimizerPrinter(OS, LastSchedule);
+}
+
+void IslScheduleOptimizerWrapperPass::getAnalysisUsage(
+    AnalysisUsage &AU) const {
   ScopPass::getAnalysisUsage(AU);
   AU.addRequired<DependenceInfo>();
   AU.addRequired<TargetTransformInfoWrapperPass>();
@@ -1674,14 +1692,55 @@ void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addPreserved<DependenceInfo>();
 }
 
-Pass *polly::createIslScheduleOptimizerPass() {
-  return new IslScheduleOptimizer();
+Pass *polly::createIslScheduleOptimizerWrapperPass() {
+  return new IslScheduleOptimizerWrapperPass();
 }
 
-INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-opt-isl",
+INITIALIZE_PASS_BEGIN(IslScheduleOptimizerWrapperPass, "polly-opt-isl",
                       "Polly - Optimize schedule of SCoP", false, false);
 INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
 INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass);
-INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-opt-isl",
+INITIALIZE_PASS_END(IslScheduleOptimizerWrapperPass, "polly-opt-isl",
                     "Polly - Optimize schedule of SCoP", false, false)
+
+static llvm::PreservedAnalyses
+runIslScheduleOptimizerUsingNPM(Scop &S, ScopAnalysisManager &SAM,
+                                ScopStandardAnalysisResults &SAR, SPMUpdater &U,
+                                raw_ostream *OS) {
+  DependenceAnalysis::Result &Deps = SAM.getResult<DependenceAnalysis>(S, SAR);
+  auto GetDeps = [&Deps](Dependences::AnalysisLevel) -> const Dependences & {
+    return Deps.getDependences(Dependences::AL_Statement);
+  };
+  TargetTransformInfo *TTI = &SAR.TTI;
+  isl::schedule LastSchedule;
+  bool Modified = runIslScheduleOptimizer(S, GetDeps, TTI, LastSchedule);
+  if (OS) {
+    *OS << "Printing analysis 'Polly - Optimize schedule of SCoP' for region: '"
+        << S.getName() << "' in function '" << S.getFunction().getName()
+        << "':\n";
+    runScheduleOptimizerPrinter(*OS, LastSchedule);
+  }
+
+  if (!Modified)
+    return PreservedAnalyses::all();
+
+  PreservedAnalyses PA;
+  PA.preserveSet<AllAnalysesOn<Module>>();
+  PA.preserveSet<AllAnalysesOn<Function>>();
+  PA.preserveSet<AllAnalysesOn<Loop>>();
+  return PA;
+}
+
+llvm::PreservedAnalyses
+IslScheduleOptimizerPass::run(Scop &S, ScopAnalysisManager &SAM,
+                              ScopStandardAnalysisResults &SAR, SPMUpdater &U) {
+  return runIslScheduleOptimizerUsingNPM(S, SAM, SAR, U, nullptr);
+}
+
+llvm::PreservedAnalyses
+IslScheduleOptimizerPrinterPass::run(Scop &S, ScopAnalysisManager &SAM,
+                                     ScopStandardAnalysisResults &SAR,
+                                     SPMUpdater &U) {
+  return runIslScheduleOptimizerUsingNPM(S, SAM, SAR, U, &OS);
+}

diff  --git a/polly/test/ScheduleOptimizer/computeout.ll b/polly/test/ScheduleOptimizer/computeout.ll
index 199160c67eb5..73f3ead9ad2c 100644
--- a/polly/test/ScheduleOptimizer/computeout.ll
+++ b/polly/test/ScheduleOptimizer/computeout.ll
@@ -1,5 +1,7 @@
 ; RUN: opt -S %loadPolly -basic-aa -polly-opt-isl -polly-opt-fusion=max -polly-ast -analyze < %s | FileCheck %s 
+; RUN: opt -S %loadPolly "-passes=scop(polly-opt-isl,print<polly-ast>)" -polly-opt-fusion=max -disable-output < %s | FileCheck %s
 ; RUN: opt -S %loadPolly -basic-aa -polly-opt-isl -polly-opt-fusion=max -polly-ast -analyze -polly-dependences-computeout=1 < %s | FileCheck %s -check-prefix=TIMEOUT
+; RUN: opt -S %loadPolly "-passes=scop(polly-opt-isl,print<polly-ast>)" -polly-opt-fusion=max -polly-dependences-computeout=1 -disable-output < %s | FileCheck %s -check-prefix=TIMEOUT
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 
 ;     for(i = 0; i < 100; i++ )

diff  --git a/polly/test/ScheduleOptimizer/focaltech_test_detail_threshold-7bc17e.ll b/polly/test/ScheduleOptimizer/focaltech_test_detail_threshold-7bc17e.ll
index 34cc41d2eb70..f588a05d9e57 100644
--- a/polly/test/ScheduleOptimizer/focaltech_test_detail_threshold-7bc17e.ll
+++ b/polly/test/ScheduleOptimizer/focaltech_test_detail_threshold-7bc17e.ll
@@ -1,4 +1,5 @@
 ; RUN: opt %loadPolly -polly-opt-isl -polly-opt-fusion=max -polly-vectorizer=stripmine -polly-invariant-load-hoisting -polly-optimized-scops -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly "-passes=scop(print<polly-opt-isl>)" -polly-opt-fusion=max -polly-vectorizer=stripmine -polly-invariant-load-hoisting -disable-output < %s | FileCheck %s
 ;
 ; llvm.org/PR46578
 ;


        


More information about the llvm-commits mailing list