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

via flang-commits flang-commits at lists.llvm.org
Wed Jun 11 07:48:22 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- flang/include/flang/Lower/OpenMP.h flang/include/flang/Parser/parse-tree.h flang/lib/Lower/OpenMP/OpenMP.cpp flang/lib/Lower/OpenMP/Utils.cpp flang/lib/Semantics/canonicalize-omp.cpp flang/lib/Semantics/resolve-directives.cpp llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 4ae1c354d..8922e6421 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -5075,10 +5075,10 @@ struct OpenMPBlockConstruct {
 struct OpenMPLoopConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPLoopConstruct);
   OpenMPLoopConstruct(OmpBeginLoopDirective &&a)
-    : t({std::move(a), std::nullopt, std::nullopt, std::nullopt}) {}
+      : t({std::move(a), std::nullopt, std::nullopt, std::nullopt}) {}
   std::tuple<OmpBeginLoopDirective, std::optional<DoConstruct>,
-             std::optional<common::Indirection<OpenMPLoopConstruct>>,
-             std::optional<OmpEndLoopDirective>>
+      std::optional<common::Indirection<OpenMPLoopConstruct>>,
+      std::optional<OmpEndLoopDirective>>
       t;
 };
 
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index b70021a52..fa28d3f67 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -477,9 +477,10 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
               if (innerOptional.has_value()) {
                 const auto &innerLoopDirective = innerOptional.value().value();
                 const auto &innerBegin =
-                  std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
+                    std::get<parser::OmpBeginLoopDirective>(
+                        innerLoopDirective.t);
                 const auto &innerDirective =
-                  std::get<parser::OmpLoopDirective>(innerBegin.t);
+                    std::get<parser::OmpLoopDirective>(innerBegin.t);
                 if (innerDirective.v == llvm::omp::Directive::OMPD_tile) {
                   middleClauseList =
                       &std::get<parser::OmpClauseList>(innerBegin.t);
@@ -2153,11 +2154,13 @@ genLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
   return loopOp;
 }
 
-static mlir::omp::LoopOp
-genTiledLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
-          semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
-          mlir::Location loc, const ConstructQueue &queue,
-          ConstructQueue::const_iterator item) {
+static mlir::omp::LoopOp genTiledLoopOp(lower::AbstractConverter &converter,
+                                        lower::SymMap &symTable,
+                                        semantics::SemanticsContext &semaCtx,
+                                        lower::pft::Evaluation &eval,
+                                        mlir::Location loc,
+                                        const ConstructQueue &queue,
+                                        ConstructQueue::const_iterator item) {
   mlir::omp::LoopOperands loopClauseOps;
   llvm::SmallVector<const semantics::Symbol *> loopReductionSyms;
   genLoopClauses(converter, semaCtx, item->clauses, loc, loopClauseOps,
@@ -4007,7 +4010,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
     break;
   case llvm::omp::Directive::OMPD_tile:
     newOp =
-      genTiledLoopOp(converter, symTable, semaCtx, eval, loc, queue, item);
+        genTiledLoopOp(converter, symTable, semaCtx, eval, loc, queue, item);
     break;
   case llvm::omp::Directive::OMPD_unroll: {
     unsigned version = semaCtx.langOptions().OpenMPVersion;
@@ -4461,13 +4464,15 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
   List<Clause> clauses = makeClauses(
       std::get<parser::OmpClauseList>(beginLoopDirective.t), semaCtx);
 
-  const auto &innerOptional = std::get<std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(loopConstruct.t);
+  const auto &innerOptional =
+      std::get<std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
+          loopConstruct.t);
   if (innerOptional.has_value()) {
     const auto &innerLoopDirective = innerOptional.value().value();
     const auto &innerBegin =
-      std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
+        std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
     const auto &innerDirective =
-      std::get<parser::OmpLoopDirective>(innerBegin.t);
+        std::get<parser::OmpLoopDirective>(innerBegin.t);
     if (innerDirective.v == llvm::omp::Directive::OMPD_tile) {
       clauses.append(
           makeClauses(std::get<parser::OmpClauseList>(innerBegin.t), semaCtx));
diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 453dec9fb..69b5672a2 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -51,8 +51,7 @@ int64_t getCollapseValue(const List<Clause> &clauses) {
   }
 
   collapseValue = collapseValue - numTileSizes;
-  int64_t result =
-    collapseValue > numTileSizes ? collapseValue : numTileSizes;
+  int64_t result = collapseValue > numTileSizes ? collapseValue : numTileSizes;
   return result;
 }
 
diff --git a/flang/lib/Semantics/canonicalize-omp.cpp b/flang/lib/Semantics/canonicalize-omp.cpp
index 67d2bbf31..e6b835a10 100644
--- a/flang/lib/Semantics/canonicalize-omp.cpp
+++ b/flang/lib/Semantics/canonicalize-omp.cpp
@@ -8,7 +8,7 @@
 
 #include "canonicalize-omp.h"
 #include "flang/Parser/parse-tree-visitor.h"
-# include <stack>
+#include <stack>
 // After Loop Canonicalization, rewrite OpenMP parse tree to make OpenMP
 // Constructs more structured which provide explicit scopes for later
 // structural checks and semantic analysis.
@@ -137,7 +137,7 @@ private:
       std::stack<parser::OpenMPLoopConstruct *> loops;
       loops.push(&x);
       if (auto *innerConstruct{
-          GetConstructIf<parser::OpenMPConstruct>(*nextIt)}) {
+              GetConstructIf<parser::OpenMPConstruct>(*nextIt)}) {
         if (auto *innerOmpLoop{
                 std::get_if<parser::OpenMPLoopConstruct>(&innerConstruct->u)}) {
           auto &innerBeginDir{
@@ -150,10 +150,10 @@ private:
             // Retrieveing the address so that DoConstruct or inner loop can be
             // set later.
             loops.push(&(std::get<std::optional<
-                             common::Indirection<parser::OpenMPLoopConstruct>>>(
+                    common::Indirection<parser::OpenMPLoopConstruct>>>(
                 loops.top()->t)
-                             .value()
-                             .value()));
+                    .value()
+                    .value()));
             nextIt = block.erase(nextIt);
           }
         }
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 98007d0de..e5a3efae8 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2061,7 +2061,8 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
     innerMostLoop = &innerLoop.value().value();
   }
 
-  const auto &outer{std::get<std::optional<parser::DoConstruct>>(innerMostLoop->t)};
+  const auto &outer{
+      std::get<std::optional<parser::DoConstruct>>(innerMostLoop->t)};
   if (outer.has_value()) {
     for (const parser::DoConstruct *loop{&*outer}; loop && level > 0; --level) {
       // go through all the nested do-loops and resolve index variables
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 53e3bf979..d6eb4e334 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2978,8 +2978,7 @@ ParseResult LoopNestOp::parse(OpAsmParser &parser, OperationState &result) {
   };
 
   if (!parser.parseOptionalKeyword("tiles") &&
-      (parser.parseLParen() ||
-      parser.parseCommaSeparatedList(parseTiles) ||
+      (parser.parseLParen() || parser.parseCommaSeparatedList(parseTiles) ||
        parser.parseRParen()))
     return failure();
 
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index d24ad7ff3..5e9ae2f22 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -2924,7 +2924,7 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
 /// Converts an OpenMP loop nest into LLVM IR using OpenMPIRBuilder.
 static LogicalResult
 convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
-                        LLVM::ModuleTranslation &moduleTranslation) {
+                   LLVM::ModuleTranslation &moduleTranslation) {
   llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
   auto loopOp = cast<omp::LoopNestOp>(opInst);
   // Set up the source location value for OpenMP runtime.
@@ -2994,7 +2994,7 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
 
   //  llvm::OpenMPIRBuilder::InsertPointTy afterIP = builder.saveIP();
   llvm::OpenMPIRBuilder::InsertPointTy afterIP =
-    loopInfos.front()->getAfterIP();
+      loopInfos.front()->getAfterIP();
 
   // Initialize the new loop info to the current one, in case there
   // are no loop transformations done.
@@ -3006,12 +3006,12 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
     SmallVector<llvm::Value *> TileSizes;
 
     for (auto tile : tiles.value()) {
-      llvm::Value *TileVal =  llvm::ConstantInt::get(IVType, tile);
+      llvm::Value *TileVal = llvm::ConstantInt::get(IVType, tile);
       TileSizes.push_back(TileVal);
     }
 
-    std::vector<llvm::CanonicalLoopInfo*> NewLoops =
-      ompBuilder->tileLoops(ompLoc.DL, loopInfos, TileSizes);
+    std::vector<llvm::CanonicalLoopInfo *> NewLoops =
+        ompBuilder->tileLoops(ompLoc.DL, loopInfos, TileSizes);
 
     // Collapse loops. Store the insertion point because LoopInfos may get
     // invalidated.
@@ -3022,7 +3022,7 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
 
     // Update the loop infos
     loopInfos.clear();
-    for (const auto& newLoop : NewLoops) {
+    for (const auto &newLoop : NewLoops) {
       loopInfos.push_back(newLoop);
     }
   } // Tiling done

``````````

</details>


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


More information about the flang-commits mailing list