[polly] r245091 - Make TempScopInfo a RegionPass

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 13:10:27 PDT 2015


Author: meinersbur
Date: Fri Aug 14 15:10:27 2015
New Revision: 245091

URL: http://llvm.org/viewvc/llvm-project?rev=245091&view=rev
Log:
Make TempScopInfo a RegionPass

This modifies the order in which Polly passes are executed.

Assuming a function has two scops (A and B), the order before was:

FunctionPassManager
  ScopDetection
  IndependentBlocks
  TempScopInfo for A and B
  RegionPassManager
    ScopInfo for A
    DependenceInfo for A
    IslScheduleOptimizer for A
    IslAstInfo for A
    CodeGeneration for A
    ScopInfo for B
    DependenceInfo for B
    IslScheduleOptimizer for B
    IslAstInfo for B
    CodeGeneration for B

After this patch:

FunctionPassManager
  ScopDetection
  IndependentBlocks
  RegionPassManager
    TempScopInfo for A
    ScopInfo for A
    DependenceInfo for A
    IslScheduleOptimizer for A
    IslAstInfo for A
    CodeGeneration for A
    TempScopInfo for B
    ScopInfo for B
    DependenceInfo for B
    IslScheduleOptimizer for B
    IslAstInfo for B
    CodeGeneration for B

TempScopInfo for B might store information and references to the IR
that CodeGeneration for A might modify. Changing the order ensures that
the IR is not modified from the analysis of a region until code
generation.

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12014


Modified:
    polly/trunk/include/polly/TempScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/Analysis/TempScopInfo.cpp
    polly/trunk/lib/CodeGen/CodeGeneration.cpp

Modified: polly/trunk/include/polly/TempScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/TempScopInfo.h?rev=245091&r1=245090&r2=245091&view=diff
==============================================================================
--- polly/trunk/include/polly/TempScopInfo.h (original)
+++ polly/trunk/include/polly/TempScopInfo.h Fri Aug 14 15:10:27 2015
@@ -206,7 +206,7 @@ typedef std::map<const Region *, TempSco
 /// @brief The Function Pass to extract temporary information for Static control
 ///        part in llvm function.
 ///
-class TempScopInfo : public FunctionPass {
+class TempScopInfo : public RegionPass {
   //===-------------------------------------------------------------------===//
   TempScopInfo(const TempScopInfo &) = delete;
   const TempScopInfo &operator=(const TempScopInfo &) = delete;
@@ -240,8 +240,8 @@ class TempScopInfo : public FunctionPass
   // zero scev every time when we need it.
   const SCEV *ZeroOffset;
 
-  // Mapping regions to the corresponding Scop in current function.
-  TempScopMapType TempScops;
+  // The TempScop for this region.
+  TempScop *TempScopOfRegion;
 
   // Clear the context.
   void clear();
@@ -308,20 +308,19 @@ class TempScopInfo : public FunctionPass
 
 public:
   static char ID;
-  explicit TempScopInfo() : FunctionPass(ID) {}
+  explicit TempScopInfo() : RegionPass(ID), TempScopOfRegion(nullptr) {}
   ~TempScopInfo();
 
-  /// @brief Get the temporay Scop information in LLVM IR represent
-  ///        for Region R.
+  /// @brief Get the temporay Scop information in LLVM IR for this region.
   ///
   /// @return The Scop information in LLVM IR represent.
-  TempScop *getTempScop(const Region *R) const;
+  TempScop *getTempScop() const;
 
-  /// @name FunctionPass interface
+  /// @name RegionPass interface
   //@{
   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
   virtual void releaseMemory() { clear(); }
-  virtual bool runOnFunction(Function &F);
+  virtual bool runOnRegion(Region *R, RGPassManager &RGM);
   virtual void print(raw_ostream &OS, const Module *) const;
   //@}
 };

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=245091&r1=245090&r2=245091&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Fri Aug 14 15:10:27 2015
@@ -1977,7 +1977,7 @@ bool ScopInfo::runOnRegion(Region *R, RG
   ScopDetection &SD = getAnalysis<ScopDetection>();
   ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
 
-  TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
+  TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop();
 
   // This region is no Scop.
   if (!tempScop) {

Modified: polly/trunk/lib/Analysis/TempScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/TempScopInfo.cpp?rev=245091&r1=245090&r2=245091&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/TempScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/TempScopInfo.cpp Fri Aug 14 15:10:27 2015
@@ -460,34 +460,30 @@ TempScop *TempScopInfo::buildTempScop(Re
   return TScop;
 }
 
-TempScop *TempScopInfo::getTempScop(const Region *R) const {
-  TempScopMapType::const_iterator at = TempScops.find(R);
-  return at == TempScops.end() ? 0 : at->second;
-}
+TempScop *TempScopInfo::getTempScop() const { return TempScopOfRegion; }
 
 void TempScopInfo::print(raw_ostream &OS, const Module *) const {
-  for (TempScopMapType::const_iterator I = TempScops.begin(),
-                                       E = TempScops.end();
-       I != E; ++I)
-    I->second->print(OS, SE, LI);
+  if (TempScopOfRegion)
+    TempScopOfRegion->print(OS, SE, LI);
 }
 
-bool TempScopInfo::runOnFunction(Function &F) {
+bool TempScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
+  SD = &getAnalysis<ScopDetection>();
+
+  if (!SD->isMaxRegionInScop(*R))
+    return false;
+
+  Function *F = R->getEntry()->getParent();
   DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
   PDT = &getAnalysis<PostDominatorTree>();
   SE = &getAnalysis<ScalarEvolution>();
   LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
-  SD = &getAnalysis<ScopDetection>();
   AA = &getAnalysis<AliasAnalysis>();
-  TD = &F.getParent()->getDataLayout();
-  ZeroOffset = SE->getConstant(TD->getIntPtrType(F.getContext()), 0);
+  TD = &F->getParent()->getDataLayout();
+  ZeroOffset = SE->getConstant(TD->getIntPtrType(F->getContext()), 0);
 
-  for (ScopDetection::iterator I = SD->begin(), E = SD->end(); I != E; ++I) {
-    if (!SD->isMaxRegionInScop(**I))
-      continue;
-    Region *R = const_cast<Region *>(*I);
-    TempScops.insert(std::make_pair(R, buildTempScop(*R)));
-  }
+  assert(!TempScopOfRegion && "Build the TempScop only once");
+  TempScopOfRegion = buildTempScop(*R);
 
   return false;
 }
@@ -508,8 +504,9 @@ TempScopInfo::~TempScopInfo() { clear();
 void TempScopInfo::clear() {
   BBConds.clear();
   AccFuncMap.clear();
-  DeleteContainerSeconds(TempScops);
-  TempScops.clear();
+  if (TempScopOfRegion)
+    delete TempScopOfRegion;
+  TempScopOfRegion = nullptr;
 }
 
 //===----------------------------------------------------------------------===//

Modified: polly/trunk/lib/CodeGen/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/CodeGeneration.cpp?rev=245091&r1=245090&r2=245091&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/CodeGeneration.cpp Fri Aug 14 15:10:27 2015
@@ -30,6 +30,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Analysis/PostDominators.h"
 
 using namespace polly;
 using namespace llvm;
@@ -170,6 +171,7 @@ public:
 
     AU.addPreserved<LoopInfoWrapperPass>();
     AU.addPreserved<DominatorTreeWrapperPass>();
+    AU.addPreserved<PostDominatorTree>();
     AU.addPreserved<IslAstInfo>();
     AU.addPreserved<ScopDetection>();
     AU.addPreserved<ScalarEvolution>();




More information about the llvm-commits mailing list