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

Jack Styles via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 06:14:35 PDT 2025


================
@@ -131,20 +134,55 @@ class CanonicalizationOfOmp {
       // Ignore compiler directives.
       if (GetConstructIf<parser::CompilerDirective>(*nextIt))
         continue;
+      // Keep track of the loops to handle the end loop directives
+      llvm::SmallVector<parser::OpenMPLoopConstruct *> loops;
+      loops.push_back(&x);
+      if (auto *innerOmpLoop{GetOmpIf<parser::OpenMPLoopConstruct>(*nextIt)}) {
+        auto &innerBeginDir{
+            std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
+        auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
+        if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
+          auto &innerLoop = std::get<
+              std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
+              loops.back()->t);
+          innerLoop = std::move(*innerOmpLoop);
+          // Retrieveing the address so that DoConstruct or inner loop can be
+          // set later.
+          loops.push_back(&(innerLoop.value().value()));
+          nextIt = block.erase(nextIt);
+        }
+      }
 
       if (auto *doCons{GetConstructIf<parser::DoConstruct>(*nextIt)}) {
         if (doCons->GetLoopControl()) {
-          // move DoConstruct
-          std::get<std::optional<parser::DoConstruct>>(x.t) =
+          std::get<std::optional<parser::DoConstruct>>(loops.back()->t) =
               std::move(*doCons);
           nextIt = block.erase(nextIt);
           // try to match OmpEndLoopDirective
-          if (nextIt != block.end()) {
+          while (nextIt != block.end() && !loops.empty()) {
----------------
Stylie777 wrote:

I have working on a similar thing for both `tile` and `unroll` in #145917, but this takes a different approach to finding the EndDirective and nested loops. I think we should agree on a unified approach over both PR's to reduce the need for re-work once one is merged.

I am not sure the `loops` variable is needed, this can be done just using `block` and recursion (the approach I took in my PR)

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


More information about the llvm-commits mailing list