[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 10:39:50 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,c,cpp -- clang/test/OpenMP/fuse_ast_print.cpp clang/test/OpenMP/fuse_codegen.cpp clang/test/OpenMP/fuse_messages.cpp openmp/runtime/test/transform/fuse/foreach.cpp openmp/runtime/test/transform/fuse/intfor.c openmp/runtime/test/transform/fuse/iterfor.cpp openmp/runtime/test/transform/fuse/parallel-wsloop-collapse-foreach.cpp openmp/runtime/test/transform/fuse/parallel-wsloop-collapse-intfor.c clang/include/clang-c/Index.h clang/include/clang/AST/OpenMPClause.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/AST/StmtOpenMP.h clang/include/clang/Parse/Parser.h clang/include/clang/Sema/SemaOpenMP.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/OpenMPClause.cpp clang/lib/AST/StmtOpenMP.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp clang/lib/Basic/OpenMPKinds.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/tools/libclang/CIndex.cpp clang/tools/libclang/CXCursor.cpp flang/include/flang/Parser/dump-parse-tree.h flang/include/flang/Parser/parse-tree.h flang/lib/Lower/OpenMP/Clauses.cpp flang/lib/Lower/OpenMP/Clauses.h flang/lib/Parser/openmp-parsers.cpp flang/lib/Parser/unparse.cpp flang/lib/Semantics/check-omp-structure.cpp llvm/include/llvm/Frontend/OpenMP/ClauseT.h
``````````

</details>

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

``````````diff
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 08bee0078..9364007f3 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -6737,7 +6737,7 @@ private:
 
   /// Parses the 'looprange' clause of a '#pragma omp fuse' directive.
   OMPClause *ParseOpenMPLoopRangeClause();
-  
+
   /// Parses the 'sizes' clause of a '#pragma omp tile' directive.
   OMPClause *ParseOpenMPSizesClause();
 
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index f527e6361..1f49e9f2a 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -522,15 +522,15 @@ OMPFuseDirective *OMPFuseDirective::Create(
       NumLoops);
   Dir->setTransformedStmt(TransformedStmt);
   Dir->setPreInits(PreInits);
-  // The number of top level canonical nests could 
+  // The number of top level canonical nests could
   // not match the total number of generated loops
   // Example:
   // Before fusion:
-  //   for (int i = 0; i < N; ++i)   
-  //     for (int j = 0; j < M; ++j) 
+  //   for (int i = 0; i < N; ++i)
+  //     for (int j = 0; j < M; ++j)
   //       A[i][j] = i + j;
-  //   
-  //   for (int k = 0; k < P; ++k) 
+  //
+  //   for (int k = 0; k < P; ++k)
   //     B[k] = k * 2;
   // Here, NumLoopNests = 2, but NumLoops = 3.
   Dir->setNumGeneratedLoopNests(NumLoopNests);
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 2d6d624c1..48d9c1841 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3520,7 +3520,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
     break;
   case OMPC_looprange:
     Clause = ParseOpenMPLoopRangeClause();
-    break;  
+    break;
   default:
     break;
   }
diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp
index a38249bf2..c94d56cb5 100644
--- a/flang/lib/Lower/OpenMP/Clauses.cpp
+++ b/flang/lib/Lower/OpenMP/Clauses.cpp
@@ -998,7 +998,7 @@ Link make(const parser::OmpClause::Link &inp,
 }
 
 LoopRange make(const parser::OmpClause::Looprange &inp,
-            semantics::SemanticsContext &semaCtx) {
+               semantics::SemanticsContext &semaCtx) {
   llvm_unreachable("Unimplemented: looprange");
 }
 
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index d53389746..39978e402 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -847,10 +847,8 @@ TYPE_PARSER(
         maybe(":"_tok >> nonemptyList(Parser<OmpLinearClause::Modifier>{})),
         /*PostModified=*/pure(true)))
 
-TYPE_PARSER(
-  construct<OmpLoopRangeClause>(scalarIntConstantExpr,
-                                "," >> scalarIntConstantExpr)
-)
+TYPE_PARSER(construct<OmpLoopRangeClause>(
+    scalarIntConstantExpr, "," >> scalarIntConstantExpr))
 
 // OpenMPv5.2 12.5.2 detach-clause -> DETACH (event-handle)
 TYPE_PARSER(construct<OmpDetachClause>(Parser<OmpObject>{}))
@@ -1026,7 +1024,7 @@ TYPE_PARSER( //
     "LINK" >> construct<OmpClause>(construct<OmpClause::Link>(
                   parenthesized(Parser<OmpObjectList>{}))) ||
     "LOOPRANGE" >> construct<OmpClause>(construct<OmpClause::Looprange>(
-                  parenthesized(Parser<OmpLoopRangeClause>{}))) ||
+                       parenthesized(Parser<OmpLoopRangeClause>{}))) ||
     "MAP" >> construct<OmpClause>(construct<OmpClause::Map>(
                  parenthesized(Parser<OmpMapClause>{}))) ||
     "MATCH" >> construct<OmpClause>(construct<OmpClause::Match>(
diff --git a/openmp/runtime/test/transform/fuse/foreach.cpp b/openmp/runtime/test/transform/fuse/foreach.cpp
index cabf4bf8a..176465b20 100644
--- a/openmp/runtime/test/transform/fuse/foreach.cpp
+++ b/openmp/runtime/test/transform/fuse/foreach.cpp
@@ -188,5 +188,4 @@ int main() {
 // CHECK-NEXT: [C] dtor
 // CHECK-NEXT: done
 
-
 #endif
diff --git a/openmp/runtime/test/transform/fuse/parallel-wsloop-collapse-foreach.cpp b/openmp/runtime/test/transform/fuse/parallel-wsloop-collapse-foreach.cpp
index e9f76713f..dcbbdf1b6 100644
--- a/openmp/runtime/test/transform/fuse/parallel-wsloop-collapse-foreach.cpp
+++ b/openmp/runtime/test/transform/fuse/parallel-wsloop-collapse-foreach.cpp
@@ -205,4 +205,3 @@ int main() {
 // CHECK-NEXT: [range] dtor
 // CHECK-NEXT: [init-stmt] dtor
 // CHECK-NEXT: done
-

``````````

</details>


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


More information about the llvm-commits mailing list