[flang-commits] [flang] [flang][OpenMP] Tolerate compiler directives in loop constructs (PR #169346)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Mon Nov 24 11:02:53 PST 2025


================
@@ -796,6 +796,28 @@ static void processTileSizesFromOpenMPConstruct(
   }
 }
 
+static pft::Evaluation *getNestedDoConstruct(pft::Evaluation &eval) {
+  for (pft::Evaluation &nested : eval.getNestedEvaluations()) {
+    // In an OpenMPConstruct there can be compiler directives:
+    // 1 <<OpenMPConstruct>>
+    //     2 CompilerDirective: !unroll
+    //     <<DoConstruct>> -> 8
+    if (nested.getIf<parser::CompilerDirective>())
+      continue;
+    // Within a DoConstruct, there can be compiler directives, plus
+    // there is a DoStmt before the body:
+    // <<DoConstruct>> -> 8
+    //     3 NonLabelDoStmt -> 7: do i = 1, n
+    //     <<DoConstruct>> -> 7
+    if (nested.getIf<parser::NonLabelDoStmt>())
+      continue;
+    assert(nested.getIf<parser::DoConstruct>() &&
+           "Unexpected construct in the nested evaluations");
+    return &nested;
+  }
+  llvm_unreachable("Expected do loop to be in the nested evaluations");
+}
----------------
kiranchandramohan wrote:

Will this work with loop generating OpenMP constructs?
```
!$omp parallel do
!$omp tile sizes(4)
  do i = 1, n
    a(i) = real(i)
  end do
!$omp end parallel do
```

https://github.com/llvm/llvm-project/pull/169346


More information about the flang-commits mailing list