[llvm-commits] [polly] r154260 - /polly/trunk/lib/Analysis/ScopDetection.cpp

Hongbin Zheng etherzhhb at gmail.com
Sat Apr 7 08:14:29 PDT 2012


Author: ether
Date: Sat Apr  7 10:14:28 2012
New Revision: 154260

URL: http://llvm.org/viewvc/llvm-project?rev=154260&view=rev
Log:
Rewritten expandRegion to clarify the intention and improve
  performance, patched by Johannes Doerfert <johannes at jdoerfert.de>.

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

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=154260&r1=154259&r2=154260&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Sat Apr  7 10:14:28 2012
@@ -376,45 +376,53 @@
 }
 
 Region *ScopDetection::expandRegion(Region &R) {
-  Region *CurrentRegion = &R;
-  Region *TmpRegion = R.getExpandedRegion();
+  // Initial no valid region was found (greater than R)
+  Region *LastValidRegion = NULL;
+  Region *ExpandedRegion  = R.getExpandedRegion();
 
   DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n");
 
-  while (TmpRegion) {
-    DetectionContext Context(*TmpRegion, *AA, false /*verifying*/);
-    DEBUG(dbgs() << "\t\tTrying " << TmpRegion->getNameStr() << "\n");
-
-    // Stop the expansion if there is any invalid block.
-    if (!allBlocksValid(Context))
-      break;
+  while (ExpandedRegion) {
+    DetectionContext Context(*ExpandedRegion, *AA, false /* verifying */);
+    DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n");
 
+    // Check the exit first (cheap)
     if (isValidExit(Context)) {
-      // If TmpRegion also has a valid exit, make it become the cadidate of the
-      // largest region as a valid SCoP.
-      if (CurrentRegion != &R)
-        delete CurrentRegion;
+      // If the exit is valid check all blocks
+      //  - if true, a valid region was found => store it + keep expanding
+      //  - if false, .tbd. => stop  (should this really end the loop?)
+      if (!allBlocksValid(Context))
+        break;
+
+      // Delete unnecessary regions (allocated by getExpandedRegion)
+      if (LastValidRegion)
+        delete LastValidRegion;
+
+      // Store this region, because it is the greatest valid (encountered so far)
+      LastValidRegion = ExpandedRegion;
+
+      // Create and test the next greater region (if any)
+      ExpandedRegion = ExpandedRegion->getExpandedRegion();
+
+    } else {
+      // Create and test the next greater region (if any)
+      Region *TmpRegion = ExpandedRegion->getExpandedRegion();
 
-      CurrentRegion = TmpRegion;
-    }
-
-    // Go on expand the region to find the largest region as a valid SCoP no
-    // matter it has a valid exit or not, because the expanded region may has
-    // a valid exit.
-    Region *TmpRegion2 = TmpRegion->getExpandedRegion();
-
-    if (TmpRegion != &R && TmpRegion != CurrentRegion)
-      delete TmpRegion;
+      // Delete unnecessary regions (allocated by getExpandedRegion)
+      delete ExpandedRegion;
 
-    TmpRegion = TmpRegion2;
+      ExpandedRegion = TmpRegion;
+    }
   }
 
-  if (&R == CurrentRegion)
-    return NULL;
-
-  DEBUG(dbgs() << "\tto " << CurrentRegion->getNameStr() << "\n");
+  DEBUG(
+  if (LastValidRegion)
+    dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n";
+  else
+    dbgs() << "\tExpanding " << R.getNameStr() << " failed\n";
+  );
 
-  return CurrentRegion;
+  return LastValidRegion;
 }
 
 





More information about the llvm-commits mailing list