[polly] r271259 - Decouple SCoP building logic from pass

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue May 31 02:41:05 PDT 2016


Author: jdoerfert
Date: Tue May 31 04:41:04 2016
New Revision: 271259

URL: http://llvm.org/viewvc/llvm-project?rev=271259&view=rev
Log:
Decouple SCoP building logic from pass

  Created a new pass ScopInfoRegionPass. As name suggests, it is a
  region pass and it is there to preserve compatibility with our
  existing Polly passes.  ScopInfoRegionPass will return a SCoP object
  for a valid region while the creation of the SCoP stays in the
  ScopInfo class.

  Contributed-by: Utpal Bora <cs14mtech11017 at iith.ac.in>
  Reviewed-by: Tobias Grosser <tobias at grosser.es>,
               Johannes Doerfert <doerfert at cs.uni-saarland.de>

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

Modified:
    polly/trunk/include/polly/LinkAllPasses.h
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/DependenceInfo.cpp
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/Analysis/ScopPass.cpp
    polly/trunk/lib/CodeGen/CodeGeneration.cpp
    polly/trunk/lib/CodeGen/IslAst.cpp
    polly/trunk/lib/Exchange/JSONExporter.cpp
    polly/trunk/lib/Support/RegisterPasses.cpp
    polly/trunk/lib/Transform/DeadCodeElimination.cpp
    polly/trunk/lib/Transform/ScheduleOptimizer.cpp

Modified: polly/trunk/include/polly/LinkAllPasses.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/LinkAllPasses.h?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/include/polly/LinkAllPasses.h (original)
+++ polly/trunk/include/polly/LinkAllPasses.h Tue May 31 04:41:04 2016
@@ -37,7 +37,7 @@ llvm::Pass *createJSONExporterPass();
 llvm::Pass *createJSONImporterPass();
 llvm::Pass *createPollyCanonicalizePass();
 llvm::Pass *createScopDetectionPass();
-llvm::Pass *createScopInfoPass();
+llvm::Pass *createScopInfoRegionPassPass();
 llvm::Pass *createIslAstInfoPass();
 llvm::Pass *createCodeGenerationPass();
 llvm::Pass *createIslScheduleOptimizerPass();
@@ -65,7 +65,7 @@ struct PollyForcePassLinking {
     polly::createJSONExporterPass();
     polly::createJSONImporterPass();
     polly::createScopDetectionPass();
-    polly::createScopInfoPass();
+    polly::createScopInfoRegionPassPass();
     polly::createPollyCanonicalizePass();
     polly::createIslAstInfoPass();
     polly::createCodeGenerationPass();

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Tue May 31 04:41:04 2016
@@ -2247,28 +2247,28 @@ static inline raw_ostream &operator<<(ra
 }
 
 /// @brief Build the Polly IR (Scop and ScopStmt) on a Region.
-class ScopInfo : public RegionPass {
+class ScopInfo {
   //===-------------------------------------------------------------------===//
   ScopInfo(const ScopInfo &) = delete;
   const ScopInfo &operator=(const ScopInfo &) = delete;
 
   /// @brief The AliasAnalysis to build AliasSetTracker.
-  AliasAnalysis *AA;
+  AliasAnalysis &AA;
 
   /// @brief Target data for element size computing.
-  const DataLayout *DL;
+  const DataLayout &DL;
 
   /// @brief DominatorTree to reason about guaranteed execution.
-  DominatorTree *DT;
+  DominatorTree &DT;
 
   /// @brief LoopInfo for information about loops
-  LoopInfo *LI;
+  LoopInfo &LI;
 
   /// @biref Valid Regions for Scop
-  ScopDetection *SD;
+  ScopDetection &SD;
 
   /// @brief The ScalarEvolution to help building Scop.
-  ScalarEvolution *SE;
+  ScalarEvolution &SE;
 
   /// @brief Set of instructions that might read any memory location.
   SmallVector<Instruction *, 16> GlobalReads;
@@ -2468,9 +2468,10 @@ class ScopInfo : public RegionPass {
   void addPHIReadAccess(PHINode *PHI);
 
 public:
-  static char ID;
-  explicit ScopInfo();
-  ~ScopInfo();
+  explicit ScopInfo(Region *R, AssumptionCache &AC, AliasAnalysis &AA,
+                    const DataLayout &DL, DominatorTree &DT, LoopInfo &LI,
+                    ScopDetection &SD, ScalarEvolution &SE);
+  ~ScopInfo() {}
 
   /// @brief Try to build the Polly IR of static control part on the current
   ///        SESE-Region.
@@ -2480,21 +2481,52 @@ public:
   ///         return null otherwise.
   Scop *getScop() { return scop.get(); }
   const Scop *getScop() const { return scop.get(); }
+};
+
+/// @brief The legacy pass manager's analysis pass to compute scop information
+///        for a region.
+class ScopInfoRegionPass : public RegionPass {
+  /// @brief The ScopInfo pointer which is used to construct a Scop.
+  std::unique_ptr<ScopInfo> SI;
+
+public:
+  static char ID; // Pass identification, replacement for typeid
+
+  ScopInfoRegionPass() : RegionPass(ID) {}
+  ~ScopInfoRegionPass() {}
+
+  /// @brief Build ScopInfo object, which constructs Polly IR of static control
+  ///        part for the current SESE-Region.
+  ///
+  /// @return Return Scop for the current Region.
+  Scop *getScop() {
+    if (SI)
+      return SI.get()->getScop();
+    else
+      return nullptr;
+  }
+  const Scop *getScop() const {
+    if (SI)
+      return SI.get()->getScop();
+    else
+      return nullptr;
+  }
+
+  /// @brief Calculate the polyhedral scop information for a given Region.
+  bool runOnRegion(Region *R, RGPassManager &RGM) override;
+
+  void releaseMemory() override { SI.reset(); }
+
+  void print(raw_ostream &O, const Module *M = nullptr) const override;
 
-  /// @name RegionPass interface
-  //@{
-  virtual bool runOnRegion(Region *R, RGPassManager &RGM);
-  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
-  virtual void releaseMemory() { clear(); }
-  virtual void print(raw_ostream &OS, const Module *) const;
-  //@}
+  void getAnalysisUsage(AnalysisUsage &AU) const override;
 };
 
 } // end namespace polly
 
 namespace llvm {
 class PassRegistry;
-void initializeScopInfoPass(llvm::PassRegistry &);
+void initializeScopInfoRegionPassPass(llvm::PassRegistry &);
 }
 
 #endif

Modified: polly/trunk/lib/Analysis/DependenceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/DependenceInfo.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/DependenceInfo.cpp (original)
+++ polly/trunk/lib/Analysis/DependenceInfo.cpp Tue May 31 04:41:04 2016
@@ -791,7 +791,7 @@ void polly::DependenceInfo::printScop(ra
 }
 
 void DependenceInfo::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequiredTransitive<ScopInfo>();
+  AU.addRequiredTransitive<ScopInfoRegionPass>();
   AU.setPreservesAll();
 }
 
@@ -801,6 +801,6 @@ Pass *polly::createDependenceInfoPass()
 
 INITIALIZE_PASS_BEGIN(DependenceInfo, "polly-dependences",
                       "Polly - Calculate dependences", false, false);
-INITIALIZE_PASS_DEPENDENCY(ScopInfo);
+INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
 INITIALIZE_PASS_END(DependenceInfo, "polly-dependences",
                     "Polly - Calculate dependences", false, false)

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Tue May 31 04:41:04 2016
@@ -4247,8 +4247,8 @@ void ScopInfo::buildPHIAccesses(PHINode
   // If we can synthesize a PHI we can skip it, however only if it is in
   // the region. If it is not it can only be in the exit block of the region.
   // In this case we model the operands but not the PHI itself.
-  auto *Scope = LI->getLoopFor(PHI->getParent());
-  if (!IsExitBlock && canSynthesize(PHI, *scop, LI, SE, Scope))
+  auto *Scope = LI.getLoopFor(PHI->getParent());
+  if (!IsExitBlock && canSynthesize(PHI, *scop, &LI, &SE, Scope))
     return;
 
   // PHI nodes are modeled as if they had been demoted prior to the SCoP
@@ -4311,9 +4311,9 @@ bool ScopInfo::buildAccessMultiDimFixed(
   Value *Val = Inst.getValueOperand();
   Type *ElementType = Val->getType();
   Value *Address = Inst.getPointerOperand();
-  const SCEV *AccessFunction = SE->getSCEVAtScope(Address, L);
+  const SCEV *AccessFunction = SE.getSCEVAtScope(Address, L);
   const SCEVUnknown *BasePointer =
-      dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
+      dyn_cast<SCEVUnknown>(SE.getPointerBase(AccessFunction));
   enum MemoryAccess::AccessType AccType =
       isa<LoadInst>(Inst) ? MemoryAccess::READ : MemoryAccess::MUST_WRITE;
 
@@ -4327,8 +4327,8 @@ bool ScopInfo::buildAccessMultiDimFixed(
       return false;
     }
     if (SrcTy->isPointerTy() && DstTy->isPointerTy() &&
-        DL->getTypeAllocSize(SrcTy->getPointerElementType()) ==
-            DL->getTypeAllocSize(DstTy->getPointerElementType()))
+        DL.getTypeAllocSize(SrcTy->getPointerElementType()) ==
+            DL.getTypeAllocSize(DstTy->getPointerElementType()))
       Address = Src;
   }
 
@@ -4338,7 +4338,7 @@ bool ScopInfo::buildAccessMultiDimFixed(
 
   std::vector<const SCEV *> Subscripts;
   std::vector<int> Sizes;
-  std::tie(Subscripts, Sizes) = getIndexExpressionsFromGEP(GEP, *SE);
+  std::tie(Subscripts, Sizes) = getIndexExpressionsFromGEP(GEP, SE);
   auto *BasePtr = GEP->getOperand(0);
 
   if (auto *BasePtrCast = dyn_cast<BitCastInst>(BasePtr))
@@ -4354,7 +4354,7 @@ bool ScopInfo::buildAccessMultiDimFixed(
   const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
   for (auto *Subscript : Subscripts) {
     InvariantLoadsSetTy AccessILS;
-    if (!isAffineExpr(&scop->getRegion(), L, Subscript, *SE, &AccessILS))
+    if (!isAffineExpr(&scop->getRegion(), L, Subscript, SE, &AccessILS))
       return false;
 
     for (LoadInst *LInst : AccessILS)
@@ -4366,7 +4366,7 @@ bool ScopInfo::buildAccessMultiDimFixed(
     return false;
 
   for (auto V : Sizes)
-    SizesSCEV.push_back(SE->getSCEV(
+    SizesSCEV.push_back(SE.getSCEV(
         ConstantInt::get(IntegerType::getInt64Ty(BasePtr->getContext()), V)));
 
   addArrayAccess(Inst, AccType, BasePointer->getValue(), ElementType, true,
@@ -4381,13 +4381,13 @@ bool ScopInfo::buildAccessMultiDimParam(
   Value *Address = Inst.getPointerOperand();
   Value *Val = Inst.getValueOperand();
   Type *ElementType = Val->getType();
-  unsigned ElementSize = DL->getTypeAllocSize(ElementType);
+  unsigned ElementSize = DL.getTypeAllocSize(ElementType);
   enum MemoryAccess::AccessType AccType =
       isa<LoadInst>(Inst) ? MemoryAccess::READ : MemoryAccess::MUST_WRITE;
 
-  const SCEV *AccessFunction = SE->getSCEVAtScope(Address, L);
+  const SCEV *AccessFunction = SE.getSCEVAtScope(Address, L);
   const SCEVUnknown *BasePointer =
-      dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
+      dyn_cast<SCEVUnknown>(SE.getPointerBase(AccessFunction));
 
   assert(BasePointer && "Could not find base pointer");
 
@@ -4422,14 +4422,14 @@ bool ScopInfo::buildAccessMemIntrinsic(M
   if (MemIntr == nullptr)
     return false;
 
-  auto *LengthVal = SE->getSCEVAtScope(MemIntr->getLength(), L);
+  auto *LengthVal = SE.getSCEVAtScope(MemIntr->getLength(), L);
   assert(LengthVal);
 
   // Check if the length val is actually affine or if we overapproximate it
   InvariantLoadsSetTy AccessILS;
   const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
   bool LengthIsAffine =
-      isAffineExpr(&scop->getRegion(), L, LengthVal, *SE, &AccessILS);
+      isAffineExpr(&scop->getRegion(), L, LengthVal, SE, &AccessILS);
   for (LoadInst *LInst : AccessILS)
     if (!ScopRIL.count(LInst))
       LengthIsAffine = false;
@@ -4439,7 +4439,7 @@ bool ScopInfo::buildAccessMemIntrinsic(M
   auto *DestPtrVal = MemIntr->getDest();
   assert(DestPtrVal);
 
-  auto *DestAccFunc = SE->getSCEVAtScope(DestPtrVal, L);
+  auto *DestAccFunc = SE.getSCEVAtScope(DestPtrVal, L);
   assert(DestAccFunc);
   // Ignore accesses to "NULL".
   // TODO: We could use this to optimize the region further, e.g., intersect
@@ -4449,9 +4449,9 @@ bool ScopInfo::buildAccessMemIntrinsic(M
   if (DestAccFunc->isZero())
     return true;
 
-  auto *DestPtrSCEV = dyn_cast<SCEVUnknown>(SE->getPointerBase(DestAccFunc));
+  auto *DestPtrSCEV = dyn_cast<SCEVUnknown>(SE.getPointerBase(DestAccFunc));
   assert(DestPtrSCEV);
-  DestAccFunc = SE->getMinusSCEV(DestAccFunc, DestPtrSCEV);
+  DestAccFunc = SE.getMinusSCEV(DestAccFunc, DestPtrSCEV);
   addArrayAccess(Inst, MemoryAccess::MUST_WRITE, DestPtrSCEV->getValue(),
                  IntegerType::getInt8Ty(DestPtrVal->getContext()), false,
                  {DestAccFunc, LengthVal}, {}, Inst.getValueOperand());
@@ -4463,16 +4463,16 @@ bool ScopInfo::buildAccessMemIntrinsic(M
   auto *SrcPtrVal = MemTrans->getSource();
   assert(SrcPtrVal);
 
-  auto *SrcAccFunc = SE->getSCEVAtScope(SrcPtrVal, L);
+  auto *SrcAccFunc = SE.getSCEVAtScope(SrcPtrVal, L);
   assert(SrcAccFunc);
   // Ignore accesses to "NULL".
   // TODO: See above TODO
   if (SrcAccFunc->isZero())
     return true;
 
-  auto *SrcPtrSCEV = dyn_cast<SCEVUnknown>(SE->getPointerBase(SrcAccFunc));
+  auto *SrcPtrSCEV = dyn_cast<SCEVUnknown>(SE.getPointerBase(SrcAccFunc));
   assert(SrcPtrSCEV);
-  SrcAccFunc = SE->getMinusSCEV(SrcAccFunc, SrcPtrSCEV);
+  SrcAccFunc = SE.getMinusSCEV(SrcAccFunc, SrcPtrSCEV);
   addArrayAccess(Inst, MemoryAccess::READ, SrcPtrSCEV->getValue(),
                  IntegerType::getInt8Ty(SrcPtrVal->getContext()), false,
                  {SrcAccFunc, LengthVal}, {}, Inst.getValueOperand());
@@ -4490,9 +4490,9 @@ bool ScopInfo::buildAccessCallInst(MemAc
     return true;
 
   bool ReadOnly = false;
-  auto *AF = SE->getConstant(IntegerType::getInt64Ty(CI->getContext()), 0);
+  auto *AF = SE.getConstant(IntegerType::getInt64Ty(CI->getContext()), 0);
   auto *CalledFunction = CI->getCalledFunction();
-  switch (AA->getModRefBehavior(CalledFunction)) {
+  switch (AA.getModRefBehavior(CalledFunction)) {
   case llvm::FMRB_UnknownModRefBehavior:
     llvm_unreachable("Unknown mod ref behaviour cannot be represented.");
   case llvm::FMRB_DoesNotAccessMemory:
@@ -4509,11 +4509,11 @@ bool ScopInfo::buildAccessCallInst(MemAc
       if (!Arg->getType()->isPointerTy())
         continue;
 
-      auto *ArgSCEV = SE->getSCEVAtScope(Arg, L);
+      auto *ArgSCEV = SE.getSCEVAtScope(Arg, L);
       if (ArgSCEV->isZero())
         continue;
 
-      auto *ArgBasePtr = cast<SCEVUnknown>(SE->getPointerBase(ArgSCEV));
+      auto *ArgBasePtr = cast<SCEVUnknown>(SE.getPointerBase(ArgSCEV));
       addArrayAccess(Inst, AccType, ArgBasePtr->getValue(),
                      ArgBasePtr->getType(), false, {AF}, {}, CI);
     }
@@ -4530,12 +4530,12 @@ void ScopInfo::buildAccessSingleDim(MemA
   enum MemoryAccess::AccessType AccType =
       isa<LoadInst>(Inst) ? MemoryAccess::READ : MemoryAccess::MUST_WRITE;
 
-  const SCEV *AccessFunction = SE->getSCEVAtScope(Address, L);
+  const SCEV *AccessFunction = SE.getSCEVAtScope(Address, L);
   const SCEVUnknown *BasePointer =
-      dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
+      dyn_cast<SCEVUnknown>(SE.getPointerBase(AccessFunction));
 
   assert(BasePointer && "Could not find base pointer");
-  AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
+  AccessFunction = SE.getMinusSCEV(AccessFunction, BasePointer);
 
   // Check if the access depends on a loop contained in a non-affine subregion.
   bool isVariantInNonAffineLoop = false;
@@ -4549,7 +4549,7 @@ void ScopInfo::buildAccessSingleDim(MemA
   InvariantLoadsSetTy AccessILS;
   bool IsAffine =
       !isVariantInNonAffineLoop &&
-      isAffineExpr(&scop->getRegion(), L, AccessFunction, *SE, &AccessILS);
+      isAffineExpr(&scop->getRegion(), L, AccessFunction, SE, &AccessILS);
 
   const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
   for (LoadInst *LInst : AccessILS)
@@ -4613,10 +4613,10 @@ void ScopInfo::buildAccessFunctions(Basi
                                     bool IsExitBlock) {
   // We do not build access functions for error blocks, as they may contain
   // instructions we can not model.
-  if (isErrorBlock(BB, scop->getRegion(), *LI, *DT) && !IsExitBlock)
+  if (isErrorBlock(BB, scop->getRegion(), LI, DT) && !IsExitBlock)
     return;
 
-  Loop *L = LI->getLoopFor(&BB);
+  Loop *L = LI.getLoopFor(&BB);
 
   for (Instruction &Inst : BB) {
     PHINode *PHI = dyn_cast<PHINode>(&Inst);
@@ -4674,7 +4674,7 @@ MemoryAccess *ScopInfo::addMemoryAccess(
     // executed. In non-affine regions there may exist MK_Values that do not
     // dominate the exit. MK_Values will always dominate the exit and MK_PHIs
     // only if there is at most one PHI_WRITE in the non-affine region.
-    if (DT->dominates(BB, Stmt->getRegion()->getExit()))
+    if (DT.dominates(BB, Stmt->getRegion()->getExit()))
       isKnownMustAccess = true;
   }
 
@@ -4730,8 +4730,8 @@ void ScopInfo::ensureValueRead(Value *V,
 
   // If the instruction can be synthesized and the user is in the region we do
   // not need to add a value dependences.
-  auto *Scope = LI->getLoopFor(UserBB);
-  if (canSynthesize(V, *scop, LI, SE, Scope))
+  auto *Scope = LI.getLoopFor(UserBB);
+  if (canSynthesize(V, *scop, &LI, &SE, Scope))
     return;
 
   // Do not build scalar dependences for required invariant loads as we will
@@ -4819,7 +4819,7 @@ void ScopInfo::addPHIReadAccess(PHINode
 }
 
 void ScopInfo::buildScop(Region &R, AssumptionCache &AC) {
-  scop.reset(new Scop(R, *SE, *LI, *SD->getDetectionContext(&R)));
+  scop.reset(new Scop(R, SE, LI, *SD.getDetectionContext(&R)));
 
   buildStmts(R);
   buildAccessFunctions(R);
@@ -4836,55 +4836,21 @@ void ScopInfo::buildScop(Region &R, Assu
                          /* IsExitBlock */ true);
 
   // Create memory accesses for global reads since all arrays are now known.
-  auto *AF = SE->getConstant(IntegerType::getInt64Ty(SE->getContext()), 0);
+  auto *AF = SE.getConstant(IntegerType::getInt64Ty(SE.getContext()), 0);
   for (auto *GlobalRead : GlobalReads)
     for (auto *BP : ArrayBasePointers)
       addArrayAccess(MemAccInst(GlobalRead), MemoryAccess::READ, BP,
                      BP->getType(), false, {AF}, {}, GlobalRead);
 
-  scop->init(*AA, AC, *DT, *LI);
+  scop->init(AA, AC, DT, LI);
 }
 
-void ScopInfo::print(raw_ostream &OS, const Module *) const {
-  if (!scop) {
-    OS << "Invalid Scop!\n";
-    return;
-  }
-
-  scop->print(OS);
-}
-
-void ScopInfo::clear() { scop.reset(); }
-
-//===----------------------------------------------------------------------===//
-ScopInfo::ScopInfo() : RegionPass(ID) {}
-
-ScopInfo::~ScopInfo() { clear(); }
-
-void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequired<LoopInfoWrapperPass>();
-  AU.addRequired<RegionInfoPass>();
-  AU.addRequired<DominatorTreeWrapperPass>();
-  AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
-  AU.addRequiredTransitive<ScopDetection>();
-  AU.addRequired<AAResultsWrapperPass>();
-  AU.addRequired<AssumptionCacheTracker>();
-  AU.setPreservesAll();
-}
-
-bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
-  SD = &getAnalysis<ScopDetection>();
-
-  if (!SD->isMaxRegionInScop(*R))
-    return false;
+ScopInfo::ScopInfo(Region *R, AssumptionCache &AC, AliasAnalysis &AA,
+                   const DataLayout &DL, DominatorTree &DT, LoopInfo &LI,
+                   ScopDetection &SD, ScalarEvolution &SE)
+    : AA(AA), DL(DL), DT(DT), LI(LI), SD(SD), SE(SE) {
 
   Function *F = R->getEntry()->getParent();
-  SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
-  LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
-  AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
-  DL = &F->getParent()->getDataLayout();
-  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
-  auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(*F);
 
   DebugLoc Beg, End;
   getDebugLocations(getBBPairForRegion(R), Beg, End);
@@ -4906,15 +4872,56 @@ bool ScopInfo::runOnRegion(Region *R, RG
   }
 
   emitOptimizationRemarkAnalysis(F->getContext(), DEBUG_TYPE, *F, End, Msg);
+}
 
+void ScopInfo::clear() { scop.reset(); }
+
+//===----------------------------------------------------------------------===//
+void ScopInfoRegionPass::getAnalysisUsage(AnalysisUsage &AU) const {
+  AU.addRequired<LoopInfoWrapperPass>();
+  AU.addRequired<RegionInfoPass>();
+  AU.addRequired<DominatorTreeWrapperPass>();
+  AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
+  AU.addRequiredTransitive<ScopDetection>();
+  AU.addRequired<AAResultsWrapperPass>();
+  AU.addRequired<AssumptionCacheTracker>();
+  AU.setPreservesAll();
+}
+
+bool ScopInfoRegionPass::runOnRegion(Region *R, RGPassManager &RGM) {
+  auto &SD = getAnalysis<ScopDetection>();
+
+  if (!SD.isMaxRegionInScop(*R))
+    return false;
+
+  Function *F = R->getEntry()->getParent();
+  auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
+  auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+  auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
+  auto const &DL = F->getParent()->getDataLayout();
+  auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+  auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(*F);
+
+  SI.reset(new ScopInfo(R, AC, AA, DL, DT, LI, SD, SE));
   return false;
 }
 
-char ScopInfo::ID = 0;
+void ScopInfoRegionPass::print(raw_ostream &OS, const Module *) const {
+  Scop *scop;
+  if (SI) {
+    if ((scop = SI->getScop())) {
+      scop->print(OS);
+      return;
+    }
+  }
+  OS << "Invalid Scop!\n";
+}
+
+char ScopInfoRegionPass::ID = 0;
 
-Pass *polly::createScopInfoPass() { return new ScopInfo(); }
+Pass *polly::createScopInfoRegionPassPass() { return new ScopInfoRegionPass(); }
 
-INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops",
+INITIALIZE_PASS_BEGIN(ScopInfoRegionPass, "polly-scops",
                       "Polly - Create polyhedral description of Scops", false,
                       false);
 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass);
@@ -4924,6 +4931,6 @@ INITIALIZE_PASS_DEPENDENCY(RegionInfoPas
 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
 INITIALIZE_PASS_DEPENDENCY(ScopDetection);
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass);
-INITIALIZE_PASS_END(ScopInfo, "polly-scops",
+INITIALIZE_PASS_END(ScopInfoRegionPass, "polly-scops",
                     "Polly - Create polyhedral description of Scops", false,
                     false)

Modified: polly/trunk/lib/Analysis/ScopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopPass.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopPass.cpp (original)
+++ polly/trunk/lib/Analysis/ScopPass.cpp Tue May 31 04:41:04 2016
@@ -20,7 +20,7 @@ using namespace polly;
 bool ScopPass::runOnRegion(Region *R, RGPassManager &RGM) {
   S = nullptr;
 
-  if ((S = getAnalysis<ScopInfo>().getScop()))
+  if ((S = getAnalysis<ScopInfoRegionPass>().getScop()))
     return runOnScop(*S);
 
   return false;
@@ -32,6 +32,6 @@ void ScopPass::print(raw_ostream &OS, co
 }
 
 void ScopPass::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequired<ScopInfo>();
+  AU.addRequired<ScopInfoRegionPass>();
   AU.setPreservesAll();
 }

Modified: polly/trunk/lib/CodeGen/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/CodeGeneration.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/CodeGeneration.cpp Tue May 31 04:41:04 2016
@@ -227,7 +227,7 @@ public:
     AU.addRequired<RegionInfoPass>();
     AU.addRequired<ScalarEvolutionWrapperPass>();
     AU.addRequired<ScopDetection>();
-    AU.addRequired<ScopInfo>();
+    AU.addRequired<ScopInfoRegionPass>();
     AU.addRequired<LoopInfoWrapperPass>();
 
     AU.addPreserved<DependenceInfo>();
@@ -246,7 +246,7 @@ public:
     // FIXME: We do not yet add regions for the newly generated code to the
     //        region tree.
     AU.addPreserved<RegionInfoPass>();
-    AU.addPreserved<ScopInfo>();
+    AU.addPreserved<ScopInfoRegionPass>();
   }
 };
 }

Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Tue May 31 04:41:04 2016
@@ -617,7 +617,7 @@ void IslAstInfo::printScop(raw_ostream &
 void IslAstInfo::getAnalysisUsage(AnalysisUsage &AU) const {
   // Get the Common analysis usage of ScopPasses.
   ScopPass::getAnalysisUsage(AU);
-  AU.addRequired<ScopInfo>();
+  AU.addRequired<ScopInfoRegionPass>();
   AU.addRequired<DependenceInfo>();
 }
 
@@ -628,7 +628,7 @@ Pass *polly::createIslAstInfoPass() { re
 INITIALIZE_PASS_BEGIN(IslAstInfo, "polly-ast",
                       "Polly - Generate an AST of the SCoP (isl)", false,
                       false);
-INITIALIZE_PASS_DEPENDENCY(ScopInfo);
+INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
 INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
 INITIALIZE_PASS_END(IslAstInfo, "polly-ast",
                     "Polly - Generate an AST from the SCoP (isl)", false, false)

Modified: polly/trunk/lib/Exchange/JSONExporter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Exchange/JSONExporter.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Exchange/JSONExporter.cpp (original)
+++ polly/trunk/lib/Exchange/JSONExporter.cpp Tue May 31 04:41:04 2016
@@ -171,7 +171,7 @@ bool JSONExporter::runOnScop(Scop &S) {
 
 void JSONExporter::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
-  AU.addRequired<ScopInfo>();
+  AU.addRequired<ScopInfoRegionPass>();
 }
 
 Pass *polly::createJSONExporterPass() { return new JSONExporter(); }

Modified: polly/trunk/lib/Support/RegisterPasses.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/RegisterPasses.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Support/RegisterPasses.cpp (original)
+++ polly/trunk/lib/Support/RegisterPasses.cpp Tue May 31 04:41:04 2016
@@ -154,7 +154,7 @@ void initializePollyPasses(PassRegistry
   initializeIslScheduleOptimizerPass(Registry);
   initializePollyCanonicalizePass(Registry);
   initializeScopDetectionPass(Registry);
-  initializeScopInfoPass(Registry);
+  initializeScopInfoRegionPassPass(Registry);
   initializeCodegenCleanupPass(Registry);
 }
 
@@ -199,7 +199,7 @@ void registerPollyPasses(llvm::legacy::P
   if (PollyOnlyPrinter)
     PM.add(polly::createDOTOnlyPrinterPass());
 
-  PM.add(polly::createScopInfoPass());
+  PM.add(polly::createScopInfoRegionPassPass());
 
   if (ImportJScop)
     PM.add(polly::createJSONImporterPass());

Modified: polly/trunk/lib/Transform/DeadCodeElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Transform/DeadCodeElimination.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Transform/DeadCodeElimination.cpp (original)
+++ polly/trunk/lib/Transform/DeadCodeElimination.cpp Tue May 31 04:41:04 2016
@@ -177,6 +177,6 @@ Pass *polly::createDeadCodeElimPass() {
 INITIALIZE_PASS_BEGIN(DeadCodeElim, "polly-dce",
                       "Polly - Remove dead iterations", false, false)
 INITIALIZE_PASS_DEPENDENCY(DependenceInfo)
-INITIALIZE_PASS_DEPENDENCY(ScopInfo)
+INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass)
 INITIALIZE_PASS_END(DeadCodeElim, "polly-dce", "Polly - Remove dead iterations",
                     false, false)

Modified: polly/trunk/lib/Transform/ScheduleOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Transform/ScheduleOptimizer.cpp?rev=271259&r1=271258&r2=271259&view=diff
==============================================================================
--- polly/trunk/lib/Transform/ScheduleOptimizer.cpp (original)
+++ polly/trunk/lib/Transform/ScheduleOptimizer.cpp Tue May 31 04:41:04 2016
@@ -750,6 +750,6 @@ Pass *polly::createIslScheduleOptimizerP
 INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-opt-isl",
                       "Polly - Optimize schedule of SCoP", false, false);
 INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
-INITIALIZE_PASS_DEPENDENCY(ScopInfo);
+INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
 INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-opt-isl",
                     "Polly - Optimize schedule of SCoP", false, false)




More information about the llvm-commits mailing list