[ScopDetection] Remove unused DetectionContexts during expansion.
authorMichael Kruse <llvm@meinersbur.de>
Mon, 8 Aug 2016 22:39:32 +0000 (22:39 +0000)
committerMichael Kruse <llvm@meinersbur.de>
Mon, 8 Aug 2016 22:39:32 +0000 (22:39 +0000)
The function expandRegion() frees Region* objects again when it determines that
these are not valid SCoPs. However, the DetectionContext added to the
DetectionContextMap still holds a reference. The validity is checked using the
ValidRegions lookup table. When a new Region is added to that list, it might
share the same address, such that the DetectionContext contains two
Region* associations that are in ValidRegions, but that are unrelated and of
which one has already been free.

Also remove the DetectionContext when not a valid expansion.

llvm-svn: 278062

polly/lib/Analysis/ScopDetection.cpp

index 433a72f..95995bb 100644 (file)
@@ -1151,12 +1151,16 @@ Region *ScopDetection::expandRegion(Region &R) {
       //  - if false, .tbd. => stop  (should this really end the loop?)
       if (!allBlocksValid(Context) || Context.Log.hasErrors()) {
         removeCachedResults(*ExpandedRegion);
+        DetectionContextMap.erase(It.first);
         break;
       }
 
       // Store this region, because it is the greatest valid (encountered so
       // far).
-      removeCachedResults(*LastValidRegion);
+      if (LastValidRegion) {
+        removeCachedResults(*LastValidRegion);
+        DetectionContextMap.erase(getBBPairForRegion(LastValidRegion.get()));
+      }
       LastValidRegion = std::move(ExpandedRegion);
 
       // Create and test the next greater region (if any)
@@ -1166,6 +1170,7 @@ Region *ScopDetection::expandRegion(Region &R) {
     } else {
       // Create and test the next greater region (if any)
       removeCachedResults(*ExpandedRegion);
+      DetectionContextMap.erase(It.first);
       ExpandedRegion =
           std::unique_ptr<Region>(ExpandedRegion->getExpandedRegion());
     }