From 47d80039483c60040d0931df69813e15480ff7b2 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Sat, 4 Apr 2026 14:49:13 +0200 Subject: [PATCH] [Polly][NFC] Use factory pattern (#190456) To (theoretically) reduce coupling of Scop and ScopBuilder. --- polly/include/polly/ScopInfo.h | 11 ++++++----- polly/lib/Analysis/ScopBuilder.cpp | 4 ++-- polly/lib/Analysis/ScopInfo.cpp | 24 ++++++++++++++---------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index 8532229b0dd7..602cc30417fe 100644 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -1868,17 +1868,12 @@ private: 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 @@ public: Scop &operator=(const Scop &) = delete; ~Scop(); + /// Factory pattern for creating a new (empty) SCoP. + static std::unique_ptr 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 fe296c045069..8a143645a319 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 cff7606411e5..38943f2557cf 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::makeScop(Region &R, ScalarEvolution &SE, + LoopInfo &LI, DominatorTree &DT, + ScopDetection::DetectionContext &DC, + OptimizationRemarkEmitter &ORE, int ID) { + return std::unique_ptr{new Scop(R, SE, LI, DT, DC, ORE, ID)}; } Scop::~Scop() = default;