From 0232c1d10dd79f5c8f9530d636655488eb3c9e7e Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Fri, 13 Aug 2021 12:26:35 -0500 Subject: [PATCH] [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". --- polly/include/polly/ScopDetection.h | 9 +++++---- polly/lib/Analysis/ScopDetection.cpp | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index 86a3a8e1a6d0..df9e275c59c2 100644 --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -497,7 +497,7 @@ private: /// 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 @@ private: 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 2d7c1c3900f5..65694b78f90c 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().getSE(); auto &DT = getAnalysis().getDomTree(); auto &ORE = getAnalysis().getORE(); - Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA, ORE)); + + Result = std::make_unique(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(F); auto &DT = FAM.getResult(F); auto &ORE = FAM.getResult(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,