[polly] 0232c1d - [Polly] Decompose object construction and detection algorithm. NFC.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 13 10:46:55 PDT 2021
Author: Michael Kruse
Date: 2021-08-13T12:44:37-05:00
New Revision: 0232c1d10dd79f5c8f9530d636655488eb3c9e7e
URL: https://github.com/llvm/llvm-project/commit/0232c1d10dd79f5c8f9530d636655488eb3c9e7e
DIFF: https://github.com/llvm/llvm-project/commit/0232c1d10dd79f5c8f9530d636655488eb3c9e7e.diff
LOG: [Polly] Decompose object construction and detection algorithm. NFC.
Avoid doing the detection work inside the constructor. In addition to
polymorphism being unintuitive in constructors and other design problems
such as if an exception is thrown, the ScopDetection class is usable
without detection in the sense of "no Scop found" or "function skipped".
Added:
Modified:
polly/include/polly/ScopDetection.h
polly/lib/Analysis/ScopDetection.cpp
Removed:
################################################################################
diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h
index 86a3a8e1a6d0c..df9e275c59c24 100644
--- a/polly/include/polly/ScopDetection.h
+++ b/polly/include/polly/ScopDetection.h
@@ -497,7 +497,7 @@ class ScopDetection {
/// Check if the function @p F is marked as invalid.
///
/// @note An OpenMP subfunction will be marked as invalid.
- bool isValidFunction(Function &F);
+ static bool isValidFunction(Function &F);
/// Can ISL compute the trip count of a loop.
///
@@ -529,9 +529,10 @@ class ScopDetection {
Args &&...Arguments) const;
public:
- ScopDetection(Function &F, const DominatorTree &DT, ScalarEvolution &SE,
- LoopInfo &LI, RegionInfo &RI, AAResults &AA,
- OptimizationRemarkEmitter &ORE);
+ ScopDetection(const DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI,
+ RegionInfo &RI, AAResults &AA, OptimizationRemarkEmitter &ORE);
+
+ void detect(Function &F);
/// Get the RegionInfo stored in this pass.
///
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 2d7c1c3900f56..65694b78f90ca 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -333,10 +333,14 @@ static bool doesStringMatchAnyRegex(StringRef Str,
//===----------------------------------------------------------------------===//
// ScopDetection.
-ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
- ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
- AliasAnalysis &AA, OptimizationRemarkEmitter &ORE)
- : DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) {
+ScopDetection::ScopDetection(const DominatorTree &DT, ScalarEvolution &SE,
+ LoopInfo &LI, RegionInfo &RI, AliasAnalysis &AA,
+ OptimizationRemarkEmitter &ORE)
+ : DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) {}
+
+void ScopDetection::detect(Function &F) {
+ assert(ValidRegions.empty() && "Detection must run only once");
+
if (!PollyProcessUnprofitable && LI.empty())
return;
@@ -1875,7 +1879,9 @@ bool ScopDetectionWrapperPass::runOnFunction(Function &F) {
auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
- Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA, ORE));
+
+ Result = std::make_unique<ScopDetection>(DT, SE, LI, RI, AA, ORE);
+ Result->detect(F);
return false;
}
@@ -1922,7 +1928,10 @@ ScopDetection ScopAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
- return {F, DT, SE, LI, RI, AA, ORE};
+
+ ScopDetection Result(DT, SE, LI, RI, AA, ORE);
+ Result.detect(F);
+ return Result;
}
PreservedAnalyses ScopAnalysisPrinterPass::run(Function &F,
More information about the llvm-commits
mailing list