[polly] 7903d59 - [Polly] Port DeLICM to the NewPM.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 9 21:58:55 PST 2021
Author: Michael Kruse
Date: 2021-02-09T23:56:19-06:00
New Revision: 7903d594eae71a52b951316418f862635809f36a
URL: https://github.com/llvm/llvm-project/commit/7903d594eae71a52b951316418f862635809f36a
DIFF: https://github.com/llvm/llvm-project/commit/7903d594eae71a52b951316418f862635809f36a.diff
LOG: [Polly] Port DeLICM to the NewPM.
Added:
Modified:
polly/include/polly/DeLICM.h
polly/include/polly/LinkAllPasses.h
polly/lib/Support/PollyPasses.def
polly/lib/Support/RegisterPasses.cpp
polly/lib/Transform/DeLICM.cpp
polly/test/DeLICM/map_memset_zero.ll
polly/test/DeLICM/pass_existence.ll
Removed:
################################################################################
diff --git a/polly/include/polly/DeLICM.h b/polly/include/polly/DeLICM.h
index 7ef382fd548a..3b6928baa5df 100644
--- a/polly/include/polly/DeLICM.h
+++ b/polly/include/polly/DeLICM.h
@@ -17,6 +17,7 @@
#ifndef POLLY_DELICM_H
#define POLLY_DELICM_H
+#include "polly/ScopPass.h"
#include "isl/isl-noexceptions.h"
namespace llvm {
@@ -27,7 +28,24 @@ class raw_ostream;
namespace polly {
/// Create a new DeLICM pass instance.
-llvm::Pass *createDeLICMPass();
+llvm::Pass *createDeLICMWrapperPass();
+
+struct DeLICMPass : llvm::PassInfoMixin<DeLICMPass> {
+ DeLICMPass() {}
+
+ llvm::PreservedAnalyses run(Scop &S, ScopAnalysisManager &SAM,
+ ScopStandardAnalysisResults &SAR, SPMUpdater &U);
+};
+
+struct DeLICMPrinterPass : llvm::PassInfoMixin<DeLICMPrinterPass> {
+ DeLICMPrinterPass(raw_ostream &OS) : OS(OS) {}
+
+ PreservedAnalyses run(Scop &S, ScopAnalysisManager &,
+ ScopStandardAnalysisResults &SAR, SPMUpdater &);
+
+private:
+ llvm::raw_ostream &OS;
+};
/// Determine whether two lifetimes are conflicting.
///
@@ -39,10 +57,11 @@ bool isConflicting(isl::union_set ExistingOccupied,
isl::union_set ProposedUnused, isl::union_map ProposedKnown,
isl::union_map ProposedWrites,
llvm::raw_ostream *OS = nullptr, unsigned Indent = 0);
+
} // namespace polly
namespace llvm {
-void initializeDeLICMPass(llvm::PassRegistry &);
+void initializeDeLICMWrapperPassPass(llvm::PassRegistry &);
} // namespace llvm
#endif /* POLLY_DELICM_H */
diff --git a/polly/include/polly/LinkAllPasses.h b/polly/include/polly/LinkAllPasses.h
index 3fe255d8ff2c..4be8aeb9d44f 100644
--- a/polly/include/polly/LinkAllPasses.h
+++ b/polly/include/polly/LinkAllPasses.h
@@ -58,7 +58,7 @@ createManagedMemoryRewritePassPass(GPUArch Arch = GPUArch::NVPTX64,
llvm::Pass *createIslScheduleOptimizerPass();
llvm::Pass *createFlattenSchedulePass();
llvm::Pass *createForwardOpTreeWrapperPass();
-llvm::Pass *createDeLICMPass();
+llvm::Pass *createDeLICMWrapperPass();
llvm::Pass *createMaximalStaticExpansionPass();
extern char &CodePreparationID;
@@ -97,7 +97,7 @@ struct PollyForcePassLinking {
polly::createMaximalStaticExpansionPass();
polly::createFlattenSchedulePass();
polly::createForwardOpTreeWrapperPass();
- polly::createDeLICMPass();
+ polly::createDeLICMWrapperPass();
polly::createDumpModulePass("", true);
polly::createSimplifyPass();
polly::createPruneUnprofitablePass();
@@ -124,7 +124,7 @@ void initializeMaximalStaticExpanderPass(llvm::PassRegistry &);
void initializePollyCanonicalizePass(llvm::PassRegistry &);
void initializeFlattenSchedulePass(llvm::PassRegistry &);
void initializeForwardOpTreeWrapperPassPass(llvm::PassRegistry &);
-void initializeDeLICMPass(llvm::PassRegistry &);
+void initializeDeLICMWrapperPassPass(llvm::PassRegistry &);
} // namespace llvm
#endif
diff --git a/polly/lib/Support/PollyPasses.def b/polly/lib/Support/PollyPasses.def
index 1b6095f1800e..f712fce87bd3 100644
--- a/polly/lib/Support/PollyPasses.def
+++ b/polly/lib/Support/PollyPasses.def
@@ -32,4 +32,6 @@ SCOP_PASS("polly-simplify", SimplifyPass())
SCOP_PASS("print<polly-simplify>", SimplifyPrinterPass(outs()))
SCOP_PASS("polly-optree", ForwardOpTreePass())
SCOP_PASS("print<polly-optree>", ForwardOpTreePrinterPass(outs()))
+SCOP_PASS("polly-delicm", DeLICMPass())
+SCOP_PASS("print<polly-delicm>", DeLICMPrinterPass(outs()))
#undef SCOP_PASS
diff --git a/polly/lib/Support/RegisterPasses.cpp b/polly/lib/Support/RegisterPasses.cpp
index 37dedd7107f2..bc4f3ecbc6d6 100644
--- a/polly/lib/Support/RegisterPasses.cpp
+++ b/polly/lib/Support/RegisterPasses.cpp
@@ -24,6 +24,7 @@
#include "polly/CodeGen/CodegenCleanup.h"
#include "polly/CodeGen/IslAst.h"
#include "polly/CodePreparation.h"
+#include "polly/DeLICM.h"
#include "polly/DependenceInfo.h"
#include "polly/ForwardOpTree.h"
#include "polly/JSONExporter.h"
@@ -262,7 +263,7 @@ void initializePollyPasses(PassRegistry &Registry) {
initializeCodegenCleanupPass(Registry);
initializeFlattenSchedulePass(Registry);
initializeForwardOpTreeWrapperPassPass(Registry);
- initializeDeLICMPass(Registry);
+ initializeDeLICMWrapperPassPass(Registry);
initializeSimplifyLegacyPassPass(Registry);
initializeDumpModulePass(Registry);
initializePruneUnprofitablePass(Registry);
@@ -323,7 +324,7 @@ void registerPollyPasses(llvm::legacy::PassManagerBase &PM) {
if (EnableForwardOpTree)
PM.add(polly::createForwardOpTreeWrapperPass());
if (EnableDeLICM)
- PM.add(polly::createDeLICMPass());
+ PM.add(polly::createDeLICMWrapperPass());
if (EnableSimplify)
PM.add(polly::createSimplifyPass(1));
@@ -470,7 +471,8 @@ static void buildDefaultPollyPipeline(FunctionPassManager &PM,
assert(!EnablePolyhedralInfo && "This option is not implemented");
if (EnableForwardOpTree)
SPM.addPass(ForwardOpTreePass());
- assert(!EnableDeLICM && "This option is not implemented");
+ if (EnableDeLICM)
+ SPM.addPass(DeLICMPass());
assert(!EnableSimplify && "This option is not implemented");
if (ImportJScop)
SPM.addPass(JSONImportPass());
diff --git a/polly/lib/Transform/DeLICM.cpp b/polly/lib/Transform/DeLICM.cpp
index a0a88d6570f5..cc93614364d0 100644
--- a/polly/lib/Transform/DeLICM.cpp
+++ b/polly/lib/Transform/DeLICM.cpp
@@ -1180,9 +1180,6 @@ class DeLICMImpl : public ZoneAlgorithm {
OS.indent(Indent) << "}\n";
}
- /// Return whether at least one transformation been applied.
- bool isModified() const { return NumberOfTargetsMapped > 0; }
-
public:
DeLICMImpl(Scop *S, LoopInfo *LI) : ZoneAlgorithm("polly-delicm", S, LI) {}
@@ -1352,35 +1349,81 @@ class DeLICMImpl : public ZoneAlgorithm {
}
printAccesses(OS, Indent);
}
+
+ /// Return whether at least one transformation been applied.
+ bool isModified() const { return NumberOfTargetsMapped > 0; }
};
-class DeLICM : public ScopPass {
-private:
- DeLICM(const DeLICM &) = delete;
- const DeLICM &operator=(const DeLICM &) = delete;
+static std::unique_ptr<DeLICMImpl> collapseToUnused(Scop &S, LoopInfo &LI) {
+ std::unique_ptr<DeLICMImpl> Impl = std::make_unique<DeLICMImpl>(&S, &LI);
- /// The pass implementation, also holding per-scop data.
- std::unique_ptr<DeLICMImpl> Impl;
+ if (!Impl->computeZone()) {
+ LLVM_DEBUG(dbgs() << "Abort because cannot reliably compute lifetimes\n");
+ return Impl;
+ }
- void collapseToUnused(Scop &S) {
- auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
- Impl = std::make_unique<DeLICMImpl>(&S, &LI);
+ LLVM_DEBUG(dbgs() << "Collapsing scalars to unused array elements...\n");
+ Impl->greedyCollapse();
- if (!Impl->computeZone()) {
- LLVM_DEBUG(dbgs() << "Abort because cannot reliably compute lifetimes\n");
- return;
- }
+ LLVM_DEBUG(dbgs() << "\nFinal Scop:\n");
+ LLVM_DEBUG(dbgs() << S);
+
+ return Impl;
+}
+
+static std::unique_ptr<DeLICMImpl> runDeLICM(Scop &S, LoopInfo &LI) {
+ std::unique_ptr<DeLICMImpl> Impl = collapseToUnused(S, LI);
+
+ Scop::ScopStatistics ScopStats = S.getStatistics();
+ NumValueWrites += ScopStats.NumValueWrites;
+ NumValueWritesInLoops += ScopStats.NumValueWritesInLoops;
+ NumPHIWrites += ScopStats.NumPHIWrites;
+ NumPHIWritesInLoops += ScopStats.NumPHIWritesInLoops;
+ NumSingletonWrites += ScopStats.NumSingletonWrites;
+ NumSingletonWritesInLoops += ScopStats.NumSingletonWritesInLoops;
- LLVM_DEBUG(dbgs() << "Collapsing scalars to unused array elements...\n");
- Impl->greedyCollapse();
+ return Impl;
+}
- LLVM_DEBUG(dbgs() << "\nFinal Scop:\n");
- LLVM_DEBUG(dbgs() << S);
+static PreservedAnalyses runDeLICMUsingNPM(Scop &S, ScopAnalysisManager &SAM,
+ ScopStandardAnalysisResults &SAR,
+ SPMUpdater &U, raw_ostream *OS) {
+ LoopInfo &LI = SAR.LI;
+ std::unique_ptr<DeLICMImpl> Impl = runDeLICM(S, LI);
+
+ if (OS) {
+ *OS << "Printing analysis 'Polly - DeLICM/DePRE' for region: '"
+ << S.getName() << "' in function '" << S.getFunction().getName()
+ << "':\n";
+ if (Impl) {
+ assert(Impl->getScop() == &S);
+
+ *OS << "DeLICM result:\n";
+ Impl->print(*OS);
+ }
}
+ if (!Impl->isModified())
+ return PreservedAnalyses::all();
+
+ PreservedAnalyses PA;
+ PA.preserveSet<AllAnalysesOn<Module>>();
+ PA.preserveSet<AllAnalysesOn<Function>>();
+ PA.preserveSet<AllAnalysesOn<Loop>>();
+ return PA;
+}
+
+class DeLICMWrapperPass : public ScopPass {
+private:
+ DeLICMWrapperPass(const DeLICMWrapperPass &) = delete;
+ const DeLICMWrapperPass &operator=(const DeLICMWrapperPass &) = delete;
+
+ /// The pass implementation, also holding per-scop data.
+ std::unique_ptr<DeLICMImpl> Impl;
+
public:
static char ID;
- explicit DeLICM() : ScopPass(ID) {}
+ explicit DeLICMWrapperPass() : ScopPass(ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequiredTransitive<ScopInfoRegionPass>();
@@ -1392,17 +1435,10 @@ class DeLICM : public ScopPass {
// Free resources for previous scop's computation, if not yet done.
releaseMemory();
- collapseToUnused(S);
-
- auto ScopStats = S.getStatistics();
- NumValueWrites += ScopStats.NumValueWrites;
- NumValueWritesInLoops += ScopStats.NumValueWritesInLoops;
- NumPHIWrites += ScopStats.NumPHIWrites;
- NumPHIWritesInLoops += ScopStats.NumPHIWritesInLoops;
- NumSingletonWrites += ScopStats.NumSingletonWrites;
- NumSingletonWritesInLoops += ScopStats.NumSingletonWritesInLoops;
+ auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+ Impl = runDeLICM(S, LI);
- return false;
+ return Impl->isModified();
}
virtual void printScop(raw_ostream &OS, Scop &S) const override {
@@ -1417,17 +1453,30 @@ class DeLICM : public ScopPass {
virtual void releaseMemory() override { Impl.reset(); }
};
-char DeLICM::ID;
+char DeLICMWrapperPass::ID;
} // anonymous namespace
-Pass *polly::createDeLICMPass() { return new DeLICM(); }
+Pass *polly::createDeLICMWrapperPass() { return new DeLICMWrapperPass(); }
-INITIALIZE_PASS_BEGIN(DeLICM, "polly-delicm", "Polly - DeLICM/DePRE", false,
- false)
+INITIALIZE_PASS_BEGIN(DeLICMWrapperPass, "polly-delicm", "Polly - DeLICM/DePRE",
+ false, false)
INITIALIZE_PASS_DEPENDENCY(ScopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
-INITIALIZE_PASS_END(DeLICM, "polly-delicm", "Polly - DeLICM/DePRE", false,
- false)
+INITIALIZE_PASS_END(DeLICMWrapperPass, "polly-delicm", "Polly - DeLICM/DePRE",
+ false, false)
+
+llvm::PreservedAnalyses DeLICMPass::run(Scop &S, ScopAnalysisManager &SAM,
+ ScopStandardAnalysisResults &SAR,
+ SPMUpdater &U) {
+ return runDeLICMUsingNPM(S, SAM, SAR, U, nullptr);
+}
+
+llvm::PreservedAnalyses DeLICMPrinterPass::run(Scop &S,
+ ScopAnalysisManager &SAM,
+ ScopStandardAnalysisResults &SAR,
+ SPMUpdater &U) {
+ return runDeLICMUsingNPM(S, SAM, SAR, U, &OS);
+}
bool polly::isConflicting(
isl::union_set ExistingOccupied, isl::union_set ExistingUnused,
diff --git a/polly/test/DeLICM/map_memset_zero.ll b/polly/test/DeLICM/map_memset_zero.ll
index e0da6892b567..82c482d63d8d 100644
--- a/polly/test/DeLICM/map_memset_zero.ll
+++ b/polly/test/DeLICM/map_memset_zero.ll
@@ -1,4 +1,5 @@
; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-delicm -analyze < %s | FileCheck -match-full-lines %s
+; RUN: opt %loadPolly -polly-stmt-granularity=bb "-passes=scop(print<polly-delicm>)" -disable-output < %s | FileCheck -match-full-lines %s
;
; Check that PHI mapping works even in presence of a memset whose'
; zero value is used.
diff --git a/polly/test/DeLICM/pass_existence.ll b/polly/test/DeLICM/pass_existence.ll
index dcec39cce685..403787c1d18d 100644
--- a/polly/test/DeLICM/pass_existence.ll
+++ b/polly/test/DeLICM/pass_existence.ll
@@ -1,4 +1,5 @@
; RUN: opt %loadPolly -polly-delicm -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly "-passes=scop(print<polly-delicm>)" -disable-output < %s | FileCheck %s
;
; Simple test for the existence of the DeLICM pass.
;
More information about the llvm-commits
mailing list