[Polly] Port DeLICM to the NewPM.
GitOrigin-RevId: 7903d594eae71a52b951316418f862635809f36a
diff --git a/include/polly/DeLICM.h b/include/polly/DeLICM.h
index 7ef382f..3b6928b 100644
--- a/include/polly/DeLICM.h
+++ b/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 @@
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 @@
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/include/polly/LinkAllPasses.h b/include/polly/LinkAllPasses.h
index 3fe255d..4be8aeb 100644
--- a/include/polly/LinkAllPasses.h
+++ b/include/polly/LinkAllPasses.h
@@ -58,7 +58,7 @@
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 @@
polly::createMaximalStaticExpansionPass();
polly::createFlattenSchedulePass();
polly::createForwardOpTreeWrapperPass();
- polly::createDeLICMPass();
+ polly::createDeLICMWrapperPass();
polly::createDumpModulePass("", true);
polly::createSimplifyPass();
polly::createPruneUnprofitablePass();
@@ -124,7 +124,7 @@
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/lib/Support/PollyPasses.def b/lib/Support/PollyPasses.def
index 1b6095f..f712fce 100644
--- a/lib/Support/PollyPasses.def
+++ b/lib/Support/PollyPasses.def
@@ -32,4 +32,6 @@
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/lib/Support/RegisterPasses.cpp b/lib/Support/RegisterPasses.cpp
index 37dedd7..bc4f3ec 100644
--- a/lib/Support/RegisterPasses.cpp
+++ b/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 @@
initializeCodegenCleanupPass(Registry);
initializeFlattenSchedulePass(Registry);
initializeForwardOpTreeWrapperPassPass(Registry);
- initializeDeLICMPass(Registry);
+ initializeDeLICMWrapperPassPass(Registry);
initializeSimplifyLegacyPassPass(Registry);
initializeDumpModulePass(Registry);
initializePruneUnprofitablePass(Registry);
@@ -323,7 +324,7 @@
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 @@
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/lib/Transform/DeLICM.cpp b/lib/Transform/DeLICM.cpp
index a0a88d6..cc93614 100644
--- a/lib/Transform/DeLICM.cpp
+++ b/lib/Transform/DeLICM.cpp
@@ -1180,9 +1180,6 @@
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 @@
}
printAccesses(OS, Indent);
}
+
+ /// Return whether at least one transformation been applied.
+ bool isModified() const { return NumberOfTargetsMapped > 0; }
};
-class DeLICM : public ScopPass {
+static std::unique_ptr<DeLICMImpl> collapseToUnused(Scop &S, LoopInfo &LI) {
+ std::unique_ptr<DeLICMImpl> Impl = std::make_unique<DeLICMImpl>(&S, &LI);
+
+ if (!Impl->computeZone()) {
+ LLVM_DEBUG(dbgs() << "Abort because cannot reliably compute lifetimes\n");
+ return Impl;
+ }
+
+ LLVM_DEBUG(dbgs() << "Collapsing scalars to unused array elements...\n");
+ Impl->greedyCollapse();
+
+ 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;
+
+ return Impl;
+}
+
+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:
- DeLICM(const DeLICM &) = delete;
- const DeLICM &operator=(const DeLICM &) = delete;
+ DeLICMWrapperPass(const DeLICMWrapperPass &) = delete;
+ const DeLICMWrapperPass &operator=(const DeLICMWrapperPass &) = delete;
/// The pass implementation, also holding per-scop data.
std::unique_ptr<DeLICMImpl> Impl;
- void collapseToUnused(Scop &S) {
- auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
- Impl = std::make_unique<DeLICMImpl>(&S, &LI);
-
- if (!Impl->computeZone()) {
- LLVM_DEBUG(dbgs() << "Abort because cannot reliably compute lifetimes\n");
- return;
- }
-
- LLVM_DEBUG(dbgs() << "Collapsing scalars to unused array elements...\n");
- Impl->greedyCollapse();
-
- LLVM_DEBUG(dbgs() << "\nFinal Scop:\n");
- LLVM_DEBUG(dbgs() << S);
- }
-
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 @@
// Free resources for previous scop's computation, if not yet done.
releaseMemory();
- collapseToUnused(S);
+ auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+ Impl = runDeLICM(S, LI);
- auto ScopStats = S.getStatistics();
- NumValueWrites += ScopStats.NumValueWrites;
- NumValueWritesInLoops += ScopStats.NumValueWritesInLoops;
- NumPHIWrites += ScopStats.NumPHIWrites;
- NumPHIWritesInLoops += ScopStats.NumPHIWritesInLoops;
- NumSingletonWrites += ScopStats.NumSingletonWrites;
- NumSingletonWritesInLoops += ScopStats.NumSingletonWritesInLoops;
-
- return false;
+ return Impl->isModified();
}
virtual void printScop(raw_ostream &OS, Scop &S) const override {
@@ -1417,17 +1453,30 @@
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/test/DeLICM/map_memset_zero.ll b/test/DeLICM/map_memset_zero.ll
index e0da689..82c482d 100644
--- a/test/DeLICM/map_memset_zero.ll
+++ b/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/test/DeLICM/pass_existence.ll b/test/DeLICM/pass_existence.ll
index dcec39c..403787c 100644
--- a/test/DeLICM/pass_existence.ll
+++ b/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.
;