diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index f68517fc7387..e30826a92545 100644 --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -287,6 +287,16 @@ private: /// @return True if all blocks in R are valid, false otherwise. bool allBlocksValid(DetectionContext &Context) const; + /// @brief Check if a region is profitable to optimize. + /// + /// Regions that are unlikely to expose interesting optimization opportunities + /// are called 'unprofitable' and may be skipped during scop detection. + /// + /// @param Context The context of scop detection. + /// + /// @return True if region is profitable to optimize, false otherwise. + bool isProfitableRegion(DetectionContext &Context) const; + /// @brief Check if a region is a Scop. /// /// @param Context The context of scop detection. diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index 2c69ca3a6593..759d3cb4f55e 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -1134,6 +1134,26 @@ bool ScopDetection::allBlocksValid(DetectionContext &Context) const { return true; } +bool ScopDetection::isProfitableRegion(DetectionContext &Context) const { + Region &CurRegion = Context.CurRegion; + + if (PollyProcessUnprofitable) + return true; + + // We can probably not do a lot on scops that only write or only read + // data. + if (!Context.hasStores || !Context.hasLoads) + return invalid(Context, /*Assert=*/true, &CurRegion); + + // Check if there are sufficent non-overapproximated loops. + int NumLoops = countBeneficialLoops(&CurRegion); + int NumAffineLoops = NumLoops - Context.BoxedLoopsSet.size(); + if (NumAffineLoops < 2) + return invalid(Context, /*Assert=*/true, &CurRegion); + + return true; +} + bool ScopDetection::isValidRegion(DetectionContext &Context) const { Region &CurRegion = Context.CurRegion; @@ -1158,22 +1178,11 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) const { &(CurRegion.getEntry()->getParent()->getEntryBlock())) return invalid(Context, /*Assert=*/true, CurRegion.getEntry()); - int NumLoops = countBeneficialLoops(&CurRegion); - if (!PollyProcessUnprofitable && NumLoops < 2) - return invalid(Context, /*Assert=*/true, &CurRegion); - if (!allBlocksValid(Context)) return false; - // We can probably not do a lot on scops that only write or only read - // data. - if (!PollyProcessUnprofitable && (!Context.hasStores || !Context.hasLoads)) - return invalid(Context, /*Assert=*/true, &CurRegion); - - // Check if there are sufficent non-overapproximated loops. - int NumAffineLoops = NumLoops - Context.BoxedLoopsSet.size(); - if (!PollyProcessUnprofitable && NumAffineLoops < 2) - return invalid(Context, /*Assert=*/true, &CurRegion); + if (!isProfitableRegion(Context)) + return false; DEBUG(dbgs() << "OK\n"); return true;