[polly] 47d8003 - [Polly][NFC] Use factory pattern (#190456)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 4 05:49:18 PDT 2026


Author: Michael Kruse
Date: 2026-04-04T12:49:13Z
New Revision: 47d80039483c60040d0931df69813e15480ff7b2

URL: https://github.com/llvm/llvm-project/commit/47d80039483c60040d0931df69813e15480ff7b2
DIFF: https://github.com/llvm/llvm-project/commit/47d80039483c60040d0931df69813e15480ff7b2.diff

LOG: [Polly][NFC] Use factory pattern (#190456)

To (theoretically) reduce coupling of Scop and ScopBuilder.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h
index 8532229b0dd71..602cc30417fe6 100644
--- a/polly/include/polly/ScopInfo.h
+++ b/polly/include/polly/ScopInfo.h
@@ -1868,17 +1868,12 @@ class Scop final {
        ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE,
        int ID);
 
-  //@}
-
   /// Return the access for the base ptr of @p MA if any.
   MemoryAccess *lookupBasePtrAccess(MemoryAccess *MA);
 
   /// Create an id for @p Param and store it in the ParameterIds map.
   void createParameterId(const SCEV *Param);
 
-  /// Build the Context of the Scop.
-  void buildContext();
-
   /// Add the bounds of the parameters to the context.
   void addParameterBounds();
 
@@ -1942,6 +1937,12 @@ class Scop final {
   Scop &operator=(const Scop &) = delete;
   ~Scop();
 
+  /// Factory pattern for creating a new (empty) SCoP.
+  static std::unique_ptr<Scop> makeScop(Region &R, ScalarEvolution &SE,
+                                        LoopInfo &LI, DominatorTree &DT,
+                                        ScopDetection::DetectionContext &DC,
+                                        OptimizationRemarkEmitter &ORE, int ID);
+
   /// Increment actual number of aliasing assumptions taken
   ///
   /// @param Step    Number of new aliasing assumptions which should be added to

diff  --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index fe296c0450697..8a143645a3198 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -3653,8 +3653,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,
-                      SD.getNextID()));
+  scop = Scop::makeScop(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 cff7606411e5e..38943f2557cf2 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1492,14 +1492,6 @@ bool Scop::isDominatedBy(const DominatorTree &DT, BasicBlock *BB) const {
   return DT.dominates(BB, getEntry());
 }
 
-void Scop::buildContext() {
-  isl::space Space = isl::space::params_alloc(getIslCtx(), 0);
-  Context = isl::set::universe(Space);
-  InvalidContext = isl::set::empty(Space);
-  AssumedContext = isl::set::universe(Space);
-  DefinedBehaviorContext = isl::set::universe(Space);
-}
-
 void Scop::addParameterBounds() {
   unsigned PDim = 0;
   for (auto *Parameter : Parameters) {
@@ -1630,8 +1622,20 @@ Scop::Scop(Region &R, ScalarEvolution &ScalarEvolution, LoopInfo &LI,
                         IslParseFlags);
 
   if (IslOnErrorAbort)
-    isl_options_set_on_error(getIslCtx().get(), ISL_ON_ERROR_ABORT);
-  buildContext();
+    isl_options_set_on_error(IslCtx.get(), ISL_ON_ERROR_ABORT);
+
+  isl::space Space = isl::space::params_alloc(getIslCtx(), 0);
+  Context = isl::set::universe(Space);
+  InvalidContext = isl::set::empty(Space);
+  AssumedContext = isl::set::universe(Space);
+  DefinedBehaviorContext = isl::set::universe(Space);
+}
+
+std::unique_ptr<Scop> Scop::makeScop(Region &R, ScalarEvolution &SE,
+                                     LoopInfo &LI, DominatorTree &DT,
+                                     ScopDetection::DetectionContext &DC,
+                                     OptimizationRemarkEmitter &ORE, int ID) {
+  return std::unique_ptr<Scop>{new Scop(R, SE, LI, DT, DC, ORE, ID)};
 }
 
 Scop::~Scop() = default;


        


More information about the llvm-commits mailing list