[polly] [Polly][NFC] Use factory pattern (PR #190456)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 05:42:15 PDT 2026
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/190456
To (theoretically) reduce coupling with ScopBuilder
>From 20b195195f95b93c1ed038ac5fd83cf327fc627f Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Sat, 4 Apr 2026 14:17:53 +0200
Subject: [PATCH 1/2] Use factory pattern
---
polly/include/polly/ScopInfo.h | 11 ++++++-----
polly/lib/Analysis/ScopBuilder.cpp | 4 ++--
polly/lib/Analysis/ScopInfo.cpp | 25 +++++++++++++++----------
3 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h
index 4cfbffc134a3a..7a7389e873026 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 ce96211d08a41..c561eca07ec25 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -3621,8 +3621,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 d3aaa7840ae80..e5d6498df0905 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,21 @@ 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;
>From da157bb6e8ef56b8c3280d18fba86c36807109ca Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Sat, 4 Apr 2026 14:25:32 +0200
Subject: [PATCH 2/2] polly-clang-format
---
polly/lib/Analysis/ScopInfo.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index c5f785ad8bb73..38943f2557cf2 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1635,7 +1635,6 @@ 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)};
}
More information about the llvm-commits
mailing list