[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


================
@@ -577,12 +598,52 @@ static void convertLoopBounds(lower::AbstractConverter &converter,
   }
 }
 
-bool collectLoopRelatedInfo(
+/// Populates the sizes vector with values if the given OpenMPConstruct
+/// Contains a loop construct with an inner tiling construct.
+void collectTileSizesFromOpenMPConstruct(
+    const parser::OpenMPConstruct *ompCons,
+    llvm::SmallVectorImpl<int64_t> &tileSizes, SemanticsContext &semaCtx) {
+  if (!ompCons)
+    return;
+
+  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)}) {
+            for (auto &tval : tclause->v) {
+              if (const auto v{EvaluateInt64(semaCtx, tval)})
+                tileSizes.push_back(*v);
+            }
+          }
----------------
skatrak wrote:

Nit: As below, we can stop looking at clauses after we find the relevant one. Also, I think we need to add braces to the top `for` loop since its body is relatively large.
```suggestion
        for (const auto &clause : innerClauseList.v) {
          if (const auto tclause{
                  std::get_if<parser::OmpClause::Sizes>(&clause.u)}) {
            for (auto &tval : tclause->v) {
              if (const auto v{EvaluateInt64(semaCtx, tval)})
                tileSizes.push_back(*v);
            }
            break;
          }
        }
```

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


More information about the Mlir-commits mailing list