[polly] r253818 - ScopInfo: Remove domains of error blocks (and blocks they dominate) early on

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 22 03:06:53 PST 2015


Author: grosser
Date: Sun Nov 22 05:06:51 2015
New Revision: 253818

URL: http://llvm.org/viewvc/llvm-project?rev=253818&view=rev
Log:
ScopInfo: Remove domains of error blocks (and blocks they dominate) early on

Trying to build up access functions for any of these blocks is likely to fail,
as error blocks may contain invalid/non-representable instructions, and blocks
dominated by error blocks may reference such instructions, which wil also cause
failures. As all of these blocks are anyhow assumed to not be executed, we can
just remove them early on.

This fixes http://llvm.org/PR25596

Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/ScopInfo/non-pure-function-calls-causes-dead-blocks.ll

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=253818&r1=253817&r2=253818&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Sun Nov 22 05:06:51 2015
@@ -1218,6 +1218,10 @@ private:
   /// @param R  The region we currently build branching conditions for.
   void propagateDomainConstraints(Region *R);
 
+  /// @brief Remove domains of error blocks/regions (and blocks dominated by
+  ///        them).
+  void removeErrorBlockDomains();
+
   /// @brief Compute the domain for each basic block in @p R.
   ///
   /// @param R  The region we currently traverse.

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=253818&r1=253817&r2=253818&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Sun Nov 22 05:06:51 2015
@@ -23,6 +23,7 @@
 #include "polly/Support/GICHelper.h"
 #include "polly/Support/SCEVValidator.h"
 #include "polly/Support/ScopHelper.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/STLExtras.h"
@@ -2005,6 +2006,38 @@ isl_set *Scop::getDomainConditions(Basic
   return isl_set_copy(DomainMap[BB]);
 }
 
+void Scop::removeErrorBlockDomains() {
+  auto removeDomains = [this](BasicBlock *Start) {
+    auto BBNode = DT.getNode(Start);
+    for (auto ErrorChild : depth_first(BBNode)) {
+      auto ErrorChildBlock = ErrorChild->getBlock();
+      auto CurrentDomain = DomainMap[ErrorChildBlock];
+      auto Empty = isl_set_empty(isl_set_get_space(CurrentDomain));
+      DomainMap[ErrorChildBlock] = Empty;
+      isl_set_free(CurrentDomain);
+    }
+  };
+
+  std::vector<Region *> Todo = {&R};
+
+  while (!Todo.empty()) {
+    auto SubRegion = Todo.back();
+    Todo.pop_back();
+
+    if (!SD.isNonAffineSubRegion(SubRegion, &getRegion())) {
+      for (auto &Child : *SubRegion)
+        Todo.push_back(Child.get());
+      continue;
+    }
+    if (containsErrorBlock(SubRegion->getNode(), getRegion(), LI, DT))
+      removeDomains(SubRegion->getEntry());
+  }
+
+  for (auto BB : R.blocks())
+    if (isErrorBlock(*BB, R, LI, DT))
+      removeDomains(BB);
+}
+
 void Scop::buildDomains(Region *R) {
 
   auto *EntryBB = R->getEntry();
@@ -2024,6 +2057,16 @@ void Scop::buildDomains(Region *R) {
 
   buildDomainsWithBranchConstraints(R);
   propagateDomainConstraints(R);
+
+  // Error blocks and blocks dominated by them have been assumed to never be
+  // executed. Representing them in the Scop does not add any value. In fact,
+  // it is likely to cause issues during construction of the ScopStmts. The
+  // contents of error blocks have not been verfied to be expressible and
+  // will cause problems when building up a ScopStmt for them.
+  // Furthermore, basic blocks dominated by error blocks may reference
+  // instructions in the error block which, if the error block is not modeled,
+  // can themselves not be constructed properly.
+  removeErrorBlockDomains();
 }
 
 void Scop::buildDomainsWithBranchConstraints(Region *R) {

Modified: polly/trunk/test/ScopInfo/non-pure-function-calls-causes-dead-blocks.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/non-pure-function-calls-causes-dead-blocks.ll?rev=253818&r1=253817&r2=253818&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/non-pure-function-calls-causes-dead-blocks.ll (original)
+++ polly/trunk/test/ScopInfo/non-pure-function-calls-causes-dead-blocks.ll Sun Nov 22 05:06:51 2015
@@ -37,8 +37,7 @@
 ; CHECK:    Assumed Context:
 ; CHECK-NEXT:    [timeit, N] -> { : timeit = 0 }
 ; CHECK:    Statements {
-; CHECK:      Stmt_if_then_split
-; CHECK:        [timeit, N] -> { Stmt_if_then_split[] : timeit <= -1 or timeit >= 1 };
+; CHECK-NOT:      Stmt_if_then_split
 ; CHECK:      Stmt_for_body
 ; CHECK:      Stmt_for_body_9
 ; CHECK:    }




More information about the llvm-commits mailing list