[polly] 888b12b - [polly] Don't count scops in a global variable.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 24 17:12:29 PST 2020


Author: Eli Friedman
Date: 2020-02-24T17:12:08-08:00
New Revision: 888b12b270f3fb7b2e4030fec792e24321998c5b

URL: https://github.com/llvm/llvm-project/commit/888b12b270f3fb7b2e4030fec792e24321998c5b
DIFF: https://github.com/llvm/llvm-project/commit/888b12b270f3fb7b2e4030fec792e24321998c5b.diff

LOG: [polly] Don't count scops in a global variable.

This can cause issues with thread safety.

Differential Revision: https://reviews.llvm.org/D75089

Added: 
    

Modified: 
    polly/include/polly/ScopDetection.h
    polly/include/polly/ScopInfo.h
    polly/lib/Analysis/ScopBuilder.cpp
    polly/lib/Analysis/ScopInfo.cpp

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h
index a174b4b0d9b7..e3c435064ca7 100644
--- a/polly/include/polly/ScopDetection.h
+++ b/polly/include/polly/ScopDetection.h
@@ -185,6 +185,9 @@ class ScopDetection {
     int MaxDepth;
   };
 
+  int NextScopID = 0;
+  int getNextID() { return NextScopID++; }
+
 private:
   //===--------------------------------------------------------------------===//
 

diff  --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h
index 1822265c4567..7d99a38086d9 100644
--- a/polly/include/polly/ScopInfo.h
+++ b/polly/include/polly/ScopInfo.h
@@ -1709,12 +1709,6 @@ class Scop {
   /// The name of the SCoP (identical to the regions name)
   Optional<std::string> name;
 
-  /// The ID to be assigned to the next Scop in a function
-  static int NextScopID;
-
-  /// The name of the function currently under consideration
-  static std::string CurrentFunc;
-
   // Access functions of the SCoP.
   //
   // This owns all the MemoryAccess objects of the Scop created in this pass.
@@ -1899,12 +1893,10 @@ class Scop {
   DenseMap<const ScopArrayInfo *, SmallVector<MemoryAccess *, 4>>
       PHIIncomingAccs;
 
-  /// Return the ID for a new Scop within a function
-  static int getNextID(std::string ParentFunc);
-
   /// Scop constructor; invoked from ScopBuilder::buildScop.
   Scop(Region &R, ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT,
-       ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE);
+       ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE,
+       int ID);
 
   //@}
 

diff  --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index 19e1f970438b..9744cf44bfec 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -3631,7 +3631,8 @@ static void verifyUses(Scop *S, LoopInfo &LI, DominatorTree &DT) {
 #endif
 
 void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
-  scop.reset(new Scop(R, SE, LI, DT, *SD.getDetectionContext(&R), ORE));
+  scop.reset(new Scop(R, SE, LI, DT, *SD.getDetectionContext(&R), ORE,
+                      SD.getNextID()));
 
   buildStmts(R);
 

diff  --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index fe3514cb7ddd..d8b741c11280 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1692,25 +1692,12 @@ isl::set Scop::getDomainConditions(BasicBlock *BB) const {
   return getDomainConditions(BBR->getEntry());
 }
 
-int Scop::NextScopID = 0;
-
-std::string Scop::CurrentFunc;
-
-int Scop::getNextID(std::string ParentFunc) {
-  if (ParentFunc != CurrentFunc) {
-    CurrentFunc = ParentFunc;
-    NextScopID = 0;
-  }
-  return NextScopID++;
-}
-
 Scop::Scop(Region &R, ScalarEvolution &ScalarEvolution, LoopInfo &LI,
            DominatorTree &DT, ScopDetection::DetectionContext &DC,
-           OptimizationRemarkEmitter &ORE)
+           OptimizationRemarkEmitter &ORE, int ID)
     : IslCtx(isl_ctx_alloc(), isl_ctx_free), SE(&ScalarEvolution), DT(&DT),
       R(R), name(None), HasSingleExitEdge(R.getExitingBlock()), DC(DC),
-      ORE(ORE), Affinator(this, LI),
-      ID(getNextID((*R.getEntry()->getParent()).getName().str())) {
+      ORE(ORE), Affinator(this, LI), ID(ID) {
   if (IslOnErrorAbort)
     isl_options_set_on_error(getIslCtx().get(), ISL_ON_ERROR_ABORT);
   buildContext();


        


More information about the llvm-commits mailing list