[polly] r256149 - ScopDetect: Extract profitability check into subfunction

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 04:14:49 PST 2015


Author: grosser
Date: Mon Dec 21 06:14:48 2015
New Revision: 256149

URL: http://llvm.org/viewvc/llvm-project?rev=256149&view=rev
Log:
ScopDetect: Extract profitability check into subfunction

.. and add some documentation. We also simplify the code by dropping an early
check that is also covered by the the later checks. This might have a small
compile time impact, but as the scops that are skipped are small we should
probably only add this back in the unlikely case that this has a notable
compile-time cost.

No functional change intended.

Modified:
    polly/trunk/include/polly/ScopDetection.h
    polly/trunk/lib/Analysis/ScopDetection.cpp

Modified: polly/trunk/include/polly/ScopDetection.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=256149&r1=256148&r2=256149&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetection.h (original)
+++ polly/trunk/include/polly/ScopDetection.h Mon Dec 21 06:14:48 2015
@@ -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.

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=256149&r1=256148&r2=256149&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Mon Dec 21 06:14:48 2015
@@ -1134,6 +1134,26 @@ bool ScopDetection::allBlocksValid(Detec
   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<ReportUnprofitable>(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<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
+
+  return true;
+}
+
 bool ScopDetection::isValidRegion(DetectionContext &Context) const {
   Region &CurRegion = Context.CurRegion;
 
@@ -1158,22 +1178,11 @@ bool ScopDetection::isValidRegion(Detect
       &(CurRegion.getEntry()->getParent()->getEntryBlock()))
     return invalid<ReportEntry>(Context, /*Assert=*/true, CurRegion.getEntry());
 
-  int NumLoops = countBeneficialLoops(&CurRegion);
-  if (!PollyProcessUnprofitable && NumLoops < 2)
-    return invalid<ReportUnprofitable>(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<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
-
-  // Check if there are sufficent non-overapproximated loops.
-  int NumAffineLoops = NumLoops - Context.BoxedLoopsSet.size();
-  if (!PollyProcessUnprofitable && NumAffineLoops < 2)
-    return invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
+  if (!isProfitableRegion(Context))
+    return false;
 
   DEBUG(dbgs() << "OK\n");
   return true;




More information about the llvm-commits mailing list