[Mlir-commits] [flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)

Sergio Afonso llvmlistbot at llvm.org
Thu Aug 28 07:14:17 PDT 2025


================
@@ -595,9 +656,44 @@ bool collectLoopRelatedInfo(
   if (auto *clause =
           ClauseFinder::findUniqueClause<omp::clause::Collapse>(clauses)) {
     collapseValue = evaluate::ToInt64(clause->v).value();
-    found = true;
+    numCollapse = collapseValue;
+  }
+
+  // Collect sizes from tile directive if present
+  std::int64_t sizesLengthValue = 0l;
+  if (auto *ompCons{eval.getIf<parser::OpenMPConstruct>()}) {
+    if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u)}) {
+      const auto &nestedOptional =
+          std::get<std::optional<parser::NestedConstruct>>(ompLoop->t);
+      assert(nestedOptional.has_value() &&
+             "Expected a DoConstruct or OpenMPLoopConstruct");
+      const auto *innerConstruct =
+          std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
+              &(nestedOptional.value()));
+      if (innerConstruct) {
+        const auto &innerLoopDirective = innerConstruct->value();
+        const auto &innerBegin =
+            std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
+        const auto &innerDirective =
+            std::get<parser::OmpLoopDirective>(innerBegin.t).v;
+
+        if (innerDirective == llvm::omp::Directive::OMPD_tile) {
+          // Get the size values from parse tree and convert to a vector
+          const auto &innerClauseList{
+              std::get<parser::OmpClauseList>(innerBegin.t)};
+          for (const auto &clause : innerClauseList.v)
+            if (const auto tclause{
+                    std::get_if<parser::OmpClause::Sizes>(&clause.u)}) {
+              sizesLengthValue = tclause->v.size();
+            }
----------------
skatrak wrote:

Nit: After finding the relevant clause once, we don't need to keep looking (it's a unique clause as per the spec).
```suggestion
            if (const auto tclause{
                    std::get_if<parser::OmpClause::Sizes>(&clause.u)}) {
              sizesLengthValue = tclause->v.size();
              break;
            }
```

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


More information about the Mlir-commits mailing list