[Polly][CodeGen] Allow nesting of BandAttr mark without loop.
authorMichael Kruse <llvm-project@meinersbur.de>
Tue, 16 Mar 2021 20:59:59 +0000 (15:59 -0500)
committerMichael Kruse <llvm-project@meinersbur.de>
Tue, 16 Mar 2021 21:17:07 +0000 (16:17 -0500)
BandAttr markers are added as parents of schedule tree bands. These also
appear as markers its equivalent AST, but a band does not necessarily
corresponds to a loop in this. Iterations may be peeled or the loop
being unrolled (e.g. if it has just one iteration). In such cases it may
happend that there is not loop between a BandAttr marker and the marker
for a loop nested in the former parent band/loop.

Handle the situation by giving priority to the inner marker over the
outer.

Fixes the polly-x86_64-linux-test-suite buildbot.

polly/lib/CodeGen/IslNodeBuilder.cpp

index 1ce407d..fd0d50a 100644 (file)
@@ -428,9 +428,14 @@ void IslNodeBuilder::createMark(__isl_take isl_ast_node *Node) {
   }
 
   BandAttr *ChildLoopAttr = getLoopAttr(isl::manage_copy(Id));
+  BandAttr *AncestorLoopAttr;
   if (ChildLoopAttr) {
-    assert(!Annotator.getStagingAttrEnv() &&
-           "conflicting loop attr environments");
+    // Save current LoopAttr environment to restore again when leaving this
+    // subtree. This means there was no loop between the ancestor LoopAttr and
+    // this mark, i.e. the ancestor LoopAttr did not directly mark a loop. This
+    // can happen e.g. if the AST build peeled or unrolled the loop.
+    AncestorLoopAttr = Annotator.getStagingAttrEnv();
+
     Annotator.getStagingAttrEnv() = ChildLoopAttr;
   }
 
@@ -438,8 +443,8 @@ void IslNodeBuilder::createMark(__isl_take isl_ast_node *Node) {
 
   if (ChildLoopAttr) {
     assert(Annotator.getStagingAttrEnv() == ChildLoopAttr &&
-           "Nest  must not overwrite loop attr environment");
-    Annotator.getStagingAttrEnv() = nullptr;
+           "Nest must not overwrite loop attr environment");
+    Annotator.getStagingAttrEnv() = AncestorLoopAttr;
   }
 
   isl_id_free(Id);