Skip to content

Commit 0232c1d

Browse files
committed
[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".
1 parent 581a803 commit 0232c1d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

polly/include/polly/ScopDetection.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class ScopDetection {
497497
/// Check if the function @p F is marked as invalid.
498498
///
499499
/// @note An OpenMP subfunction will be marked as invalid.
500-
bool isValidFunction(Function &F);
500+
static bool isValidFunction(Function &F);
501501

502502
/// Can ISL compute the trip count of a loop.
503503
///
@@ -529,9 +529,10 @@ class ScopDetection {
529529
Args &&...Arguments) const;
530530

531531
public:
532-
ScopDetection(Function &F, const DominatorTree &DT, ScalarEvolution &SE,
533-
LoopInfo &LI, RegionInfo &RI, AAResults &AA,
534-
OptimizationRemarkEmitter &ORE);
532+
ScopDetection(const DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI,
533+
RegionInfo &RI, AAResults &AA, OptimizationRemarkEmitter &ORE);
534+
535+
void detect(Function &F);
535536

536537
/// Get the RegionInfo stored in this pass.
537538
///

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,14 @@ static bool doesStringMatchAnyRegex(StringRef Str,
333333
//===----------------------------------------------------------------------===//
334334
// ScopDetection.
335335

336-
ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
337-
ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
338-
AliasAnalysis &AA, OptimizationRemarkEmitter &ORE)
339-
: DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) {
336+
ScopDetection::ScopDetection(const DominatorTree &DT, ScalarEvolution &SE,
337+
LoopInfo &LI, RegionInfo &RI, AliasAnalysis &AA,
338+
OptimizationRemarkEmitter &ORE)
339+
: DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) {}
340+
341+
void ScopDetection::detect(Function &F) {
342+
assert(ValidRegions.empty() && "Detection must run only once");
343+
340344
if (!PollyProcessUnprofitable && LI.empty())
341345
return;
342346

@@ -1875,7 +1879,9 @@ bool ScopDetectionWrapperPass::runOnFunction(Function &F) {
18751879
auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
18761880
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
18771881
auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
1878-
Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA, ORE));
1882+
1883+
Result = std::make_unique<ScopDetection>(DT, SE, LI, RI, AA, ORE);
1884+
Result->detect(F);
18791885
return false;
18801886
}
18811887

@@ -1922,7 +1928,10 @@ ScopDetection ScopAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
19221928
auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
19231929
auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
19241930
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
1925-
return {F, DT, SE, LI, RI, AA, ORE};
1931+
1932+
ScopDetection Result(DT, SE, LI, RI, AA, ORE);
1933+
Result.detect(F);
1934+
return Result;
19261935
}
19271936

19281937
PreservedAnalyses ScopAnalysisPrinterPass::run(Function &F,

0 commit comments

Comments
 (0)