[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:24:06 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) {
+ if (std::holds_alternative<parser::OmpClause::Doacross>(clause.u)) {
+ found = true;
+ return;
+ }
+ if (const auto *depend{
+ std::get_if<parser::OmpClause::Depend>(&clause.u)}) {
+ if (std::holds_alternative<parser::OmpDoacross>(depend->v.u)) {
+ found = true;
+ return;
+ }
+ }
+ }
+ }
+};
+
+bool ContainsDoacrossDirective(const parser::Block &block) {
----------------
cenewcombe wrote:
Done ✔️
https://github.com/llvm/llvm-project/pull/202435
More information about the flang-commits
mailing list