[polly] r303056 - [Polly][NewPM] Port ScopInfo to the new PassManager

Philip Pfaffe via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 05:55:15 PDT 2017


Author: pfaffe
Date: Mon May 15 07:55:14 2017
New Revision: 303056

URL: http://llvm.org/viewvc/llvm-project?rev=303056&view=rev
Log:
[Polly][NewPM] Port ScopInfo to the new PassManager

Modified:
    polly/trunk/include/polly/PolyhedralInfo.h
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/DependenceInfo.cpp
    polly/trunk/lib/Analysis/PolyhedralInfo.cpp
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/include/polly/PolyhedralInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/PolyhedralInfo.h?rev=303056&r1=303055&r2=303056&view=diff
==============================================================================
--- polly/trunk/include/polly/PolyhedralInfo.h (original)
+++ polly/trunk/include/polly/PolyhedralInfo.h Mon May 15 07:55:14 2017
@@ -27,7 +27,7 @@ class Loop;
 namespace polly {
 
 class Scop;
-class ScopInfoWrapperPass;
+class ScopInfo;
 class DependenceInfoWrapperPass;
 
 class PolyhedralInfo : public llvm::FunctionPass {
@@ -87,7 +87,7 @@ private:
   bool checkParallel(llvm::Loop *L,
                      __isl_give isl_pw_aff **MinDepDistPtr = nullptr) const;
 
-  ScopInfoWrapperPass *SI;
+  ScopInfo *SI;
   DependenceInfoWrapperPass *DI;
 };
 

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=303056&r1=303055&r2=303056&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Mon May 15 07:55:14 2017
@@ -2762,16 +2762,7 @@ public:
   void getAnalysisUsage(AnalysisUsage &AU) const override;
 };
 
-//===----------------------------------------------------------------------===//
-/// The legacy pass manager's analysis pass to compute scop information
-///        for the whole function.
-///
-/// This pass will maintain a map of the maximal region within a scop to its
-/// scop object for all the feasible scops present in a function.
-/// This pass is an alternative to the ScopInfoRegionPass in order to avoid a
-/// region pass manager.
-class ScopInfoWrapperPass : public FunctionPass {
-
+class ScopInfo {
 public:
   using RegionToScopMapTy = DenseMap<Region *, std::unique_ptr<Scop>>;
   using iterator = RegionToScopMapTy::iterator;
@@ -2783,10 +2774,9 @@ private:
   RegionToScopMapTy RegionToScopMap;
 
 public:
-  static char ID; // Pass identification, replacement for typeid
-
-  ScopInfoWrapperPass() : FunctionPass(ID) {}
-  ~ScopInfoWrapperPass() {}
+  ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE,
+           LoopInfo &LI, AliasAnalysis &AA, DominatorTree &DT,
+           AssumptionCache &AC);
 
   /// Get the Scop object for the given Region
   ///
@@ -2805,11 +2795,44 @@ public:
   iterator end() { return RegionToScopMap.end(); }
   const_iterator begin() const { return RegionToScopMap.begin(); }
   const_iterator end() const { return RegionToScopMap.end(); }
+};
+
+struct ScopInfoAnalysis : public AnalysisInfoMixin<ScopInfoAnalysis> {
+  static AnalysisKey Key;
+  using Result = ScopInfo;
+  Result run(Function &, FunctionAnalysisManager &);
+};
+
+struct ScopInfoPrinterPass : public PassInfoMixin<ScopInfoPrinterPass> {
+  ScopInfoPrinterPass(raw_ostream &O) : Stream(O) {}
+  PreservedAnalyses run(Function &, FunctionAnalysisManager &);
+  raw_ostream &Stream;
+};
+
+//===----------------------------------------------------------------------===//
+/// The legacy pass manager's analysis pass to compute scop information
+///        for the whole function.
+///
+/// This pass will maintain a map of the maximal region within a scop to its
+/// scop object for all the feasible scops present in a function.
+/// This pass is an alternative to the ScopInfoRegionPass in order to avoid a
+/// region pass manager.
+class ScopInfoWrapperPass : public FunctionPass {
+  std::unique_ptr<ScopInfo> Result;
+
+public:
+  ScopInfoWrapperPass() : FunctionPass(ID) {}
+  ~ScopInfoWrapperPass() = default;
+
+  static char ID; // Pass identification, replacement for typeid
+
+  ScopInfo *getSI() { return Result.get(); }
+  const ScopInfo *getSI() const { return Result.get(); }
 
   /// Calculate all the polyhedral scops for a given function.
   bool runOnFunction(Function &F) override;
 
-  void releaseMemory() override { RegionToScopMap.clear(); }
+  void releaseMemory() override { Result.reset(); }
 
   void print(raw_ostream &O, const Module *M = nullptr) const override;
 

Modified: polly/trunk/lib/Analysis/DependenceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/DependenceInfo.cpp?rev=303056&r1=303055&r2=303056&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/DependenceInfo.cpp (original)
+++ polly/trunk/lib/Analysis/DependenceInfo.cpp Mon May 15 07:55:14 2017
@@ -982,7 +982,7 @@ const Dependences &DependenceInfoWrapper
 }
 
 bool DependenceInfoWrapperPass::runOnFunction(Function &F) {
-  auto &SI = getAnalysis<ScopInfoWrapperPass>();
+  auto &SI = *getAnalysis<ScopInfoWrapperPass>().getSI();
   for (auto &It : SI) {
     assert(It.second && "Invalid SCoP object!");
     recomputeDependences(It.second.get(), Dependences::AL_Access);

Modified: polly/trunk/lib/Analysis/PolyhedralInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/PolyhedralInfo.cpp?rev=303056&r1=303055&r2=303056&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/PolyhedralInfo.cpp (original)
+++ polly/trunk/lib/Analysis/PolyhedralInfo.cpp Mon May 15 07:55:14 2017
@@ -53,7 +53,7 @@ void PolyhedralInfo::getAnalysisUsage(An
 
 bool PolyhedralInfo::runOnFunction(Function &F) {
   DI = &getAnalysis<DependenceInfoWrapperPass>();
-  SI = &getAnalysis<ScopInfoWrapperPass>();
+  SI = getAnalysis<ScopInfoWrapperPass>().getSI();
   return false;
 }
 

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=303056&r1=303055&r2=303056&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon May 15 07:55:14 2017
@@ -4810,6 +4810,52 @@ INITIALIZE_PASS_END(ScopInfoRegionPass,
                     false)
 
 //===----------------------------------------------------------------------===//
+ScopInfo::ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE,
+                   LoopInfo &LI, AliasAnalysis &AA, DominatorTree &DT,
+                   AssumptionCache &AC) {
+  /// Create polyhedral descripton of scops for all the valid regions of a
+  /// function.
+  for (auto &It : SD) {
+    Region *R = const_cast<Region *>(It);
+    if (!SD.isMaxRegionInScop(*R))
+      continue;
+
+    ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE);
+    std::unique_ptr<Scop> S = SB.getScop();
+    if (!S)
+      continue;
+    bool Inserted = RegionToScopMap.insert({R, std::move(S)}).second;
+    assert(Inserted && "Building Scop for the same region twice!");
+    (void)Inserted;
+  }
+}
+
+AnalysisKey ScopInfoAnalysis::Key;
+
+ScopInfoAnalysis::Result ScopInfoAnalysis::run(Function &F,
+                                               FunctionAnalysisManager &FAM) {
+  auto &SD = FAM.getResult<ScopAnalysis>(F);
+  auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
+  auto &LI = FAM.getResult<LoopAnalysis>(F);
+  auto &AA = FAM.getResult<AAManager>(F);
+  auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
+  auto &AC = FAM.getResult<AssumptionAnalysis>(F);
+  auto &DL = F.getParent()->getDataLayout();
+  return {DL, SD, SE, LI, AA, DT, AC};
+}
+
+PreservedAnalyses ScopInfoPrinterPass::run(Function &F,
+                                           FunctionAnalysisManager &FAM) {
+  auto &SI = FAM.getResult<ScopInfoAnalysis>(F);
+  for (auto &It : SI) {
+    if (It.second)
+      It.second->print(Stream);
+    else
+      Stream << "Invalid Scop!\n";
+  }
+  return PreservedAnalyses::all();
+}
+
 void ScopInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<LoopInfoWrapperPass>();
   AU.addRequired<RegionInfoPass>();
@@ -4823,7 +4869,6 @@ void ScopInfoWrapperPass::getAnalysisUsa
 
 bool ScopInfoWrapperPass::runOnFunction(Function &F) {
   auto &SD = getAnalysis<ScopDetectionWrapperPass>().getSD();
-
   auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
   auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
   auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
@@ -4831,27 +4876,12 @@ bool ScopInfoWrapperPass::runOnFunction(
   auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
   auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
 
-  /// Create polyhedral descripton of scops for all the valid regions of a
-  /// function.
-  for (auto &It : SD) {
-    Region *R = const_cast<Region *>(It);
-    if (!SD.isMaxRegionInScop(*R))
-      continue;
-
-    ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE);
-    std::unique_ptr<Scop> S = SB.getScop();
-    if (!S)
-      continue;
-    bool Inserted =
-        RegionToScopMap.insert(std::make_pair(R, std::move(S))).second;
-    assert(Inserted && "Building Scop for the same region twice!");
-    (void)Inserted;
-  }
+  Result.reset(new ScopInfo{DL, SD, SE, LI, AA, DT, AC});
   return false;
 }
 
 void ScopInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
-  for (auto &It : RegionToScopMap) {
+  for (auto &It : *Result) {
     if (It.second)
       It.second->print(OS);
     else




More information about the llvm-commits mailing list