[flang-commits] [flang] [flang][OpenMP] Implement collapse for imperfectly nested loops (PR #202435)

Caroline Newcombe via flang-commits flang-commits at lists.llvm.org
Tue Jun 23 08:17:00 PDT 2026


================
@@ -111,6 +111,49 @@ class AssociatedLoopChecker {
   std::int64_t level_;
   std::map<std::string, std::int64_t> constructNamesAndLevels_;
 };
+
+/// Visitor that detects an ordered directive with a doacross clause
+/// (or the pre-5.2 depend(sink/source) equivalent).
+/// Does not descend into nested OpenMP block or loop constructs, since
+/// doacross directives inside them bind to an inner worksharing-loop
+/// region, not the one being checked.
+struct DoacrossFinder {
+  bool found{false};
+  template <typename T> bool Pre(const T &) { return !found; }
+  template <typename T> void Post(const T &) {}
+
+  // Stop descent into nested OpenMP regions that create new binding contexts.
+  bool Pre(const parser::OmpBlockConstruct &) { return false; }
+  bool Pre(const parser::OpenMPLoopConstruct &) { return false; }
+
+  void Post(const parser::OpenMPSimpleStandaloneConstruct &x) {
+    if (found) {
+      return;
+    }
+    if (x.v.DirId() != llvm::omp::Directive::OMPD_ordered) {
+      return;
+    }
+    for (const auto &clause : x.v.Clauses().v) {
----------------
cenewcombe wrote:

Done (moved to openmp-utils.cpp)

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


More information about the flang-commits mailing list