[flang] [llvm] [flang][OpenMP] Parse iterators, add to MAP clause, TODO for lowering (PR #113167)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 07:17:58 PDT 2024


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 89d8449a2900123c2e9bd7a11315381b2b70c155 e6c345a76cf2ac2653e04fb07d0ddd0f248908b3 --extensions cpp,h -- flang/include/flang/Parser/dump-parse-tree.h flang/include/flang/Parser/parse-tree.h flang/lib/Lower/OpenMP/ClauseProcessor.cpp flang/lib/Lower/OpenMP/Clauses.cpp flang/lib/Lower/OpenMP/Clauses.h flang/lib/Parser/openmp-parsers.cpp flang/lib/Parser/type-parsers.h flang/lib/Parser/unparse.cpp flang/lib/Semantics/check-omp-structure.cpp flang/lib/Semantics/check-omp-structure.h flang/lib/Semantics/resolve-directives.cpp flang/lib/Semantics/resolve-names.cpp llvm/include/llvm/Frontend/OpenMP/OMP.h llvm/lib/Frontend/OpenMP/OMP.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 3582128869..f20d6b0e85 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3475,10 +3475,10 @@ struct OmpMapClause {
   // In OpenMP 5.2 the non-comma syntax has been deprecated: keep the
   // information about separator presence to emit a diagnostic if needed.
   std::tuple<std::optional<std::list<TypeModifier>>,
-             std::optional<std::list<OmpIteratorModifier>>, // unique
-             std::optional<std::list<Type>>,                // unique
-             OmpObjectList,
-             bool> // were the modifiers comma-separated
+      std::optional<std::list<OmpIteratorModifier>>, // unique
+      std::optional<std::list<Type>>, // unique
+      OmpObjectList,
+      bool> // were the modifiers comma-separated
       t;
 };
 
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 26ee1653cc..4a1daed04f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -56,13 +56,13 @@ struct ConcatSeparated {
       if (auto first{firstParser.Parse(state)}) {
         if (attempt(std::get<0>(sepAndParsers_)).Parse(state)) {
           return std::tuple_cat(TupleFor<Parser>(std::move(*first)),
-                                std::move(*restParser.Parse(state)));
+              std::move(*restParser.Parse(state)));
         }
         return std::tuple_cat(TupleFor<Parser>{std::move(*first)},
-                              std::tuple<OptListOf<Parsers>...>{});
+            std::tuple<OptListOf<Parsers>...>{});
       }
-      return std::tuple_cat(TupleFor<Parser>{},
-                            std::move(*restParser.Parse(state)));
+      return std::tuple_cat(
+          TupleFor<Parser>{}, std::move(*restParser.Parse(state)));
     }
   }
 
@@ -90,8 +90,7 @@ private:
 // [1] Any of the commas are optional, but that syntax has been deprecated
 // in OpenMP 5.2, and the parsing code keeps a record of whether the commas
 // were present.
-template <typename Separator>
-struct MapModifiers {
+template <typename Separator> struct MapModifiers {
   constexpr MapModifiers(Separator sep) : sep_(sep) {}
   constexpr MapModifiers(const MapModifiers &) = default;
   constexpr MapModifiers(MapModifiers &&) = default;
@@ -143,10 +142,10 @@ static std::list<EntityDecl> makeEntityList(std::list<ObjectName> &&names) {
   return entities;
 }
 
-static TypeDeclarationStmt makeIterSpecDecl(DeclarationTypeSpec &&spec,
-                                            std::list<ObjectName> &&names) {
-  return TypeDeclarationStmt(std::move(spec), std::list<AttrSpec>{},
-                             makeEntityList(std::move(names)));
+static TypeDeclarationStmt makeIterSpecDecl(
+    DeclarationTypeSpec &&spec, std::list<ObjectName> &&names) {
+  return TypeDeclarationStmt(
+      std::move(spec), std::list<AttrSpec>{}, makeEntityList(std::move(names)));
 }
 
 static TypeDeclarationStmt makeIterSpecDecl(std::list<ObjectName> &&names) {
@@ -155,7 +154,7 @@ static TypeDeclarationStmt makeIterSpecDecl(std::list<ObjectName> &&names) {
       IntrinsicTypeSpec{IntegerTypeSpec{std::nullopt}});
 
   return TypeDeclarationStmt(std::move(typeSpec), std::list<AttrSpec>{},
-                             makeEntityList(std::move(names)));
+      makeEntityList(std::move(names)));
 }
 
 TYPE_PARSER(construct<OmpIteratorSpecifier>(
@@ -167,16 +166,15 @@ TYPE_PARSER(construct<OmpIteratorSpecifier>(
     // 2. integer :: j = i:10 will be flagged as an error because the
     // initializer 'i' must be constant (in declarations). In an iterator
     // specifier the 'j' is not an initializer and can be a variable.
-    (applyFunction<TypeDeclarationStmt>(
-         makeIterSpecDecl, Parser<DeclarationTypeSpec>{} / maybe("::"_tok),
+    (applyFunction<TypeDeclarationStmt>(makeIterSpecDecl,
+         Parser<DeclarationTypeSpec>{} / maybe("::"_tok),
          nonemptyList(Parser<ObjectName>{}) / "="_tok) ||
-     applyFunction<TypeDeclarationStmt>(
-         makeIterSpecDecl, nonemptyList(Parser<ObjectName>{}) / "="_tok)),
+        applyFunction<TypeDeclarationStmt>(
+            makeIterSpecDecl, nonemptyList(Parser<ObjectName>{}) / "="_tok)),
     subscriptTriplet))
 
 // [5.0] 2.1.6 iterator -> iterator-specifier-list
-TYPE_PARSER(construct<OmpIteratorModifier>(
-    "ITERATOR" >>
+TYPE_PARSER(construct<OmpIteratorModifier>("ITERATOR" >>
     parenthesized(nonemptyList(sourced(Parser<OmpIteratorSpecifier>{})))))
 
 // 2.15.3.1 DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE)
@@ -213,22 +211,21 @@ TYPE_PARSER(
         "TOFROM" >> pure(OmpMapClause::Type::Tofrom)))
 
 template <bool CommasEverywhere>
-static inline OmpMapClause
-makeMapClause(std::tuple<std::optional<std::list<OmpMapClause::TypeModifier>>,
-                         std::optional<std::list<OmpIteratorModifier>>,
-                         std::optional<std::list<OmpMapClause::Type>>> &&mods,
-              OmpObjectList &&objs) {
+static inline OmpMapClause makeMapClause(
+    std::tuple<std::optional<std::list<OmpMapClause::TypeModifier>>,
+        std::optional<std::list<OmpIteratorModifier>>,
+        std::optional<std::list<OmpMapClause::Type>>> &&mods,
+    OmpObjectList &&objs) {
   auto &&[tm, it, ty] = std::move(mods);
   return OmpMapClause{std::move(tm), std::move(it), std::move(ty),
-                      std::move(objs), CommasEverywhere};
+      std::move(objs), CommasEverywhere};
 }
 
 TYPE_PARSER(construct<OmpMapClause>(
-    applyFunction<OmpMapClause>(makeMapClause<true>, MapModifiers(","_tok),
-                                Parser<OmpObjectList>{}) ||
+    applyFunction<OmpMapClause>(
+        makeMapClause<true>, MapModifiers(","_tok), Parser<OmpObjectList>{}) ||
     applyFunction<OmpMapClause>(makeMapClause<false>,
-                                MapModifiers(maybe(","_tok)),
-                                Parser<OmpObjectList>{})))
+        MapModifiers(maybe(","_tok)), Parser<OmpObjectList>{})))
 
 // [OpenMP 5.0]
 // 2.19.7.2 defaultmap(implicit-behavior[:variable-category])
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 68da0669c1..c3b711f04f 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -566,8 +566,7 @@ void OmpStructureChecker::CheckIteratorRange(
   // a proper interval.
   const auto &[begin, end, step]{std::get<parser::SubscriptTriplet>(x.t).t};
   if (!begin || !end) {
-    context_.Say(
-        x.source,
+    context_.Say(x.source,
         "The begin and end expressions in iterator range-specification are "
         "mandatory"_err_en_US);
   }
@@ -575,20 +574,20 @@ void OmpStructureChecker::CheckIteratorRange(
   // value is implicitly defined to be 1.
   if (auto stepv{step ? GetIntValue(*step) : std::optional<int64_t>{1}}) {
     if (*stepv == 0) {
-      context_.Say(x.source,
-                   "The step value in the iterator range is 0"_warn_en_US);
+      context_.Say(
+          x.source, "The step value in the iterator range is 0"_warn_en_US);
     } else if (begin && end) {
       std::optional<int64_t> beginv{GetIntValue(*begin)};
       std::optional<int64_t> endv{GetIntValue(*end)};
       if (beginv && endv) {
         if (*stepv > 0 && *beginv > *endv) {
           context_.Say(x.source,
-            "The begin value is greater than the end value in iterator "
-            "range-specification with a positive step"_warn_en_US);
+              "The begin value is greater than the end value in iterator "
+              "range-specification with a positive step"_warn_en_US);
         } else if (*stepv < 0 && *beginv < *endv) {
           context_.Say(x.source,
-            "The begin value is less than the end value in iterator "
-            "range-specification with a negative step"_warn_en_US);
+              "The begin value is less than the end value in iterator "
+              "range-specification with a negative step"_warn_en_US);
         }
       }
     }
@@ -612,7 +611,7 @@ void OmpStructureChecker::CheckIteratorModifier(
     }
     if (!isInteger) {
       context_.Say(iterSpec.source,
-                   "The iterator variable must be of integer type"_err_en_US);
+          "The iterator variable must be of integer type"_err_en_US);
     }
     CheckIteratorRange(iterSpec);
   }

``````````

</details>


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


More information about the llvm-commits mailing list