[flang-commits] [flang] [flang][OpenMP] Order Unparse functions for OpenMP classes, NFC (PR #173391)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Tue Dec 23 07:57:45 PST 2025


https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/173391

None

>From 1437bd89fd8c0dcfcc7116845668c7b0081d7f37 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 22 Dec 2025 15:48:17 -0600
Subject: [PATCH] [flang][OpenMP] Order Unparse functions for OpenMP classes,
 NFC

---
 flang/lib/Parser/unparse.cpp | 742 +++++++++++++++++------------------
 1 file changed, 368 insertions(+), 374 deletions(-)

diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 19680dee7568d..1fb03c28d10a3 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2119,33 +2119,134 @@ class UnparseVisitor {
   }
 
   // OpenMP Clauses & Directives
+#define GEN_FLANG_CLAUSE_UNPARSE
+#include "llvm/Frontend/OpenMP/OMP.inc"
+  bool Pre(const OmpMessageClause &x) {
+    Walk(x.v);
+    return false;
+  }
+  void Unparse(const llvm::omp::Directive &x) {
+    unsigned ompVersion{langOpts_.OpenMPVersion};
+    Word(llvm::omp::getOpenMPDirectiveName(x, ompVersion).str());
+  }
+  void Unparse(const OmpAbsentClause &x) { Walk("", x.v, ","); }
+  void Unparse(const OmpAdjustArgsClause &x) {
+    Walk(std::get<OmpAdjustArgsClause::OmpAdjustOp>(x.t).v);
+    Put(":");
+    Walk(std::get<parser::OmpObjectList>(x.t));
+  }
+  void Unparse(const OmpAffinityClause &x) {
+    using Modifier = OmpAffinityClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<OmpObjectList>(x.t));
+  }
+  void Unparse(const OmpAlignedClause &x) {
+    using Modifier = OmpAlignedClause::Modifier;
+    Walk(std::get<OmpObjectList>(x.t));
+    Walk(": ", std::get<std::optional<std::list<Modifier>>>(x.t));
+  }
+  void Unparse(const OmpAlignModifier &x) {
+    Word("ALIGN(");
+    Walk(x.v);
+    Put(")");
+  }
+  void Unparse(const OmpAllocateClause &x) {
+    using Modifier = OmpAllocateClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<OmpObjectList>(x.t));
+  }
+  void Unparse(const OmpAllocateDirective &x) {
+    Unparse(static_cast<const OmpBlockConstruct &>(x));
+  }
+  void Unparse(const OmpAllocatorComplexModifier &x) {
+    Word("ALLOCATOR(");
+    Walk(x.v);
+    Put(")");
+  }
+  void Unparse(const OmpAllocatorSimpleModifier &x) { Walk(x.v); }
+  void Unparse(const OmpAppendArgsClause::OmpAppendOp &x) {
+    Put("INTEROP(");
+    Walk(x.v, ",");
+    Put(")");
+  }
+  void Unparse(const OmpAppendArgsClause &x) { Walk(x.v, ","); }
   void Unparse(const OmpArgumentList &x) { Walk(x.v, ", "); }
-  void Unparse(const OmpTypeNameList &x) { Walk(x.v, ", "); }
-
+  void Unparse(const OmpAttachModifier &x) {
+    Word("ATTACH(");
+    Walk(x.v);
+    Put(")");
+  }
   void Unparse(const OmpBaseVariantNames &x) {
     Walk(std::get<0>(x.t)); // OmpObject
     Put(":");
     Walk(std::get<1>(x.t)); // OmpObject
   }
-  void Unparse(const OmpMapperSpecifier &x) {
-    const auto &mapperName{std::get<std::string>(x.t)};
-    if (mapperName.find(llvm::omp::OmpDefaultMapperName) == std::string::npos) {
-      Walk(mapperName);
-      Put(":");
+  void Unparse(const OmpBeginDirective &x) {
+    BeginOpenMP();
+    Word("!$OMP ");
+    Walk(static_cast<const OmpDirectiveSpecification &>(x));
+    Put("\n");
+    EndOpenMP();
+  }
+  void Unparse(const OmpBeginLoopDirective &x) {
+    Unparse(static_cast<const OmpBeginDirective &>(x));
+  }
+  void Unparse(const OmpBeginSectionsDirective &x) {
+    Unparse(static_cast<const OmpBeginDirective &>(x));
+  }
+  void Unparse(const OmpBlockConstruct &x) {
+    Walk(std::get<OmpBeginDirective>(x.t));
+    Walk(std::get<Block>(x.t), "");
+    if (auto &end{std::get<std::optional<OmpEndDirective>>(x.t)}) {
+      Walk(*end);
+    } else {
+      Put("\n");
     }
-    Walk(std::get<TypeSpec>(x.t));
-    Put("::");
-    Walk(std::get<Name>(x.t));
   }
-  void Unparse(const OmpReductionSpecifier &x) {
-    Walk(std::get<OmpReductionIdentifier>(x.t));
-    Put(":");
-    Walk(std::get<OmpTypeNameList>(x.t));
-    Walk(": ", std::get<std::optional<OmpCombinerExpression>>(x.t));
+  // Clause unparsers are usually generated by tablegen in the form
+  // CLAUSE(VALUE). Here we only want to print VALUE so a custom unparser is
+  // needed.
+  void Unparse(const OmpClause::CancellationConstructType &x) { Walk(x.v); }
+  void Unparse(const OmpClauseList &x, const char *sep = " ") {
+    Walk(" ", x.v, sep);
   }
-  void Unparse(const llvm::omp::Directive &x) {
+  void Unparse(const OmpCombinerExpression &x) {
+    Unparse(static_cast<const OmpStylizedExpression &>(x));
+  }
+  void Unparse(const OmpContainsClause &x) { Walk("", x.v, ","); }
+  void Unparse(const OmpContextSelectorSpecification &x) { Walk(x.v, ", "); }
+  void Unparse(const OmpDeclareVariantDirective &x) {
+    BeginOpenMP();
+    Word("!$OMP ");
+    Walk(x.v);
+    Put("\n");
+    EndOpenMP();
+  }
+  void Unparse(const OmpDefaultmapClause &x) {
+    using Modifier = OmpDefaultmapClause::Modifier;
+    Walk(std::get<OmpDefaultmapClause::ImplicitBehavior>(x.t));
+    Walk(":", std::get<std::optional<std::list<Modifier>>>(x.t));
+  }
+  void Unparse(const OmpDependClause::TaskDep &x) {
+    using Modifier = OmpDependClause::TaskDep::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<OmpObjectList>(x.t));
+  }
+  void Unparse(const OmpDetachClause &x) { Walk(x.v); }
+  void Unparse(const OmpDeviceClause &x) {
+    using Modifier = OmpDeviceClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<ScalarIntExpr>(x.t));
+  }
+  void Unparse(const OmpDimsModifier &x) {
+    Word("DIMS");
+    Put("(");
+    Walk(x.v);
+    Put(")");
+  }
+  void Unparse(const OmpDirectiveNameModifier &x) {
     unsigned ompVersion{langOpts_.OpenMPVersion};
-    Word(llvm::omp::getOpenMPDirectiveName(x, ompVersion).str());
+    Word(llvm::omp::getOpenMPDirectiveName(x.v, ompVersion));
   }
   void Unparse(const OmpDirectiveSpecification &x) {
     auto unparseArgs{[&]() {
@@ -2172,196 +2273,90 @@ class UnparseVisitor {
       unparseClauses();
     }
   }
-  void Unparse(const OmpTraitScore &x) {
-    Word("SCORE(");
-    Walk(x.v);
-    Put(")");
-  }
-  void Unparse(const OmpTraitPropertyExtension::Complex &x) {
-    using PropList = std::list<common::Indirection<OmpTraitPropertyExtension>>;
-    Walk(std::get<OmpTraitPropertyName>(x.t));
-    Put("(");
-    Walk(std::get<PropList>(x.t), ",");
-    Put(")");
-  }
-  void Unparse(const OmpTraitSelector &x) {
-    Walk(std::get<OmpTraitSelectorName>(x.t));
-    Walk(std::get<std::optional<OmpTraitSelector::Properties>>(x.t));
-  }
-  void Unparse(const OmpTraitSelector::Properties &x) {
-    Put("(");
-    Walk(std::get<std::optional<OmpTraitScore>>(x.t), ": ");
-    Walk(std::get<std::list<OmpTraitProperty>>(x.t));
-    Put(")");
-  }
-  void Unparse(const OmpTraitSetSelector &x) {
-    Walk(std::get<OmpTraitSetSelectorName>(x.t));
-    Put("={");
-    Walk(std::get<std::list<OmpTraitSelector>>(x.t));
-    Put("}");
-  }
-  void Unparse(const OmpContextSelectorSpecification &x) { Walk(x.v, ", "); }
-
-  void Unparse(const OmpObject &x) {
-    common::visit( //
-        common::visitors{
-            [&](const Designator &y) { Walk(y); },
-            [&](const Name &y) {
-              Put("/");
-              Walk(y);
-              Put("/");
-            },
-            [&](const OmpObject::Invalid &y) {
-              switch (y.v) {
-              case OmpObject::Invalid::Kind::BlankCommonBlock:
-                Put("//");
-                break;
-              }
-            },
-        },
-        x.u);
-  }
-  void Unparse(const OmpDirectiveNameModifier &x) {
-    unsigned ompVersion{langOpts_.OpenMPVersion};
-    Word(llvm::omp::getOpenMPDirectiveName(x.v, ompVersion));
+  void Unparse(const OmpDoacross::Sink &x) {
+    Word("SINK: ");
+    Walk(x.v.v);
   }
-  void Unparse(const OmpDimsModifier &x) {
-    Word("DIMS");
-    Put("(");
-    Walk(x.v);
-    Put(")");
+  void Unparse(const OmpDoacross::Source &) { Word("SOURCE"); }
+  void Unparse(const OmpDynGroupprivateClause &x) {
+    using Modifier = OmpDynGroupprivateClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<ScalarIntExpr>(x.t));
   }
-  void Unparse(const OmpStylizedDeclaration &x) {
-    // empty
+  void Unparse(const OmpEndDirective &x) {
+    BeginOpenMP();
+    Word("!$OMP END ");
+    Walk(static_cast<const OmpDirectiveSpecification &>(x));
+    Put("\n");
+    EndOpenMP();
   }
-  void Unparse(const OmpStylizedExpression &x) { //
-    Put(x.source.ToString());
+  void Unparse(const OmpEndLoopDirective &x) {
+    Unparse(static_cast<const OmpEndDirective &>(x));
   }
-  void Unparse(const OmpStylizedInstance &x) {
-    // empty
+  void Unparse(const OmpEndSectionsDirective &x) {
+    Unparse(static_cast<const OmpEndDirective &>(x));
   }
-  void Unparse(const OmpIteratorSpecifier &x) {
-    Walk(std::get<TypeDeclarationStmt>(x.t));
-    Put(" = ");
-    Walk(std::get<SubscriptTriplet>(x.t));
+  void Unparse(const OmpEnterClause &x) {
+    using Modifier = OmpEnterClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<OmpObjectList>(x.t));
   }
-  void Unparse(const OmpIterator &x) {
-    Word("ITERATOR(");
+  void Unparse(const OmpErrorDirective &x) {
+    BeginOpenMP();
+    Word("!$OMP ");
     Walk(x.v);
-    Put(")");
+    Put("\n");
+    EndOpenMP();
   }
-  void Unparse(const OmpMapper &x) {
-    Word("MAPPER(");
+  void Unparse(const OmpFailClause &x) { Walk(x.v); }
+  void Unparse(const OmpFallbackModifier &x) {
+    Word("FALLBACK(");
     Walk(x.v);
     Put(")");
   }
-  void Unparse(const OmpLastprivateClause &x) {
-    using Modifier = OmpLastprivateClause::Modifier;
+  void Unparse(const OmpFromClause &x) {
+    using Modifier = OmpFromClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObjectList>(x.t));
   }
-  void Unparse(const OmpPreferenceSelector &x) {
-    common::visit( //
-        common::visitors{
-            [&](const OmpPreferenceSelector::ForeignRuntimeIdentifier &s) {
-              Word("FR");
-              Put("(");
-              Walk(s);
-              Put(")");
-            },
-            [&](const OmpPreferenceSelector::Extensions &s) {
-              Word("ATTR");
-              Put("(");
-              Walk(s, ", ");
-              Put(")");
-            },
-        },
-        x.u);
-  }
-  void Unparse(const OmpPreferenceSpecification &x) {
-    common::visit( //
-        common::visitors{
-            [&](const std::list<OmpPreferenceSelector> &s) {
-              Put("{");
-              Walk(s, ", ");
-              Put("}");
-            },
-            [&](const OmpPreferenceSelector::ForeignRuntimeIdentifier &s) {
-              Walk(s);
-            },
-        },
-        x.u);
+  void Unparse(const OmpGrainsizeClause &x) {
+    using Modifier = OmpGrainsizeClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<ScalarIntExpr>(x.t));
   }
-  void Unparse(const OmpPreferType &x) {
-    Word("PREFER_TYPE");
-    Put("(");
-    Walk(x.v, ", ");
-    Put(")");
+  void Unparse(const OmpIfClause &x) {
+    using Modifier = OmpIfClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<ScalarLogicalExpr>(x.t));
   }
   void Unparse(const OmpInitClause &x) {
     using Modifier = OmpInitClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObject>(x.t));
   }
-  void Unparse(const OmpMapClause &x) {
-    using Modifier = OmpMapClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<OmpObjectList>(x.t));
-  }
-  void Unparse(const OmpScheduleClause &x) {
-    using Modifier = OmpScheduleClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
-    Walk(std::get<OmpScheduleClause::Kind>(x.t));
-    Walk(",", std::get<std::optional<ScalarIntExpr>>(x.t));
-  }
-  void Unparse(const OmpDeviceClause &x) {
-    using Modifier = OmpDeviceClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<ScalarIntExpr>(x.t));
+  void Unparse(const OmpInitializerExpression &x) {
+    Unparse(static_cast<const OmpStylizedExpression &>(x));
   }
-  void Unparse(const OmpAbsentClause &x) { Walk("", x.v, ","); }
-  void Unparse(const OmpContainsClause &x) { Walk("", x.v, ","); }
-  void Unparse(const OmpAffinityClause &x) {
-    using Modifier = OmpAffinityClause::Modifier;
+  void Unparse(const OmpInReductionClause &x) {
+    using Modifier = OmpInReductionClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObjectList>(x.t));
   }
-  void Unparse(const OmpAlignedClause &x) {
-    using Modifier = OmpAlignedClause::Modifier;
-    Walk(std::get<OmpObjectList>(x.t));
-    Walk(": ", std::get<std::optional<std::list<Modifier>>>(x.t));
+  void Unparse(const OmpIteratorSpecifier &x) {
+    Walk(std::get<TypeDeclarationStmt>(x.t));
+    Put(" = ");
+    Walk(std::get<SubscriptTriplet>(x.t));
   }
-  void Unparse(const OmpFallbackModifier &x) {
-    Word("FALLBACK(");
+  void Unparse(const OmpIterator &x) {
+    Word("ITERATOR(");
     Walk(x.v);
     Put(")");
   }
-  void Unparse(const OmpDynGroupprivateClause &x) {
-    using Modifier = OmpDynGroupprivateClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<ScalarIntExpr>(x.t));
-  }
-  void Unparse(const OmpEnterClause &x) {
-    using Modifier = OmpEnterClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<OmpObjectList>(x.t));
-  }
-  void Unparse(const OmpFromClause &x) {
-    using Modifier = OmpFromClause::Modifier;
+  void Unparse(const OmpLastprivateClause &x) {
+    using Modifier = OmpLastprivateClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObjectList>(x.t));
   }
-  void Unparse(const OmpIfClause &x) {
-    using Modifier = OmpIfClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<ScalarLogicalExpr>(x.t));
-  }
-  void Unparse(const OmpStepSimpleModifier &x) { Walk(x.v); }
-  void Unparse(const OmpStepComplexModifier &x) {
-    Word("STEP(");
-    Walk(x.v);
-    Put(")");
-  }
   void Unparse(const OmpLinearClause &x) {
     using Modifier = OmpLinearClause::Modifier;
     auto &modifiers{std::get<std::optional<std::list<Modifier>>>(x.t)};
@@ -2421,192 +2416,242 @@ class UnparseVisitor {
     Walk(std::get<1>(x.t));
     Put(")");
   }
-  void Unparse(const OmpReductionClause &x) {
-    using Modifier = OmpReductionClause::Modifier;
+  void Unparse(const OmpMapClause &x) {
+    using Modifier = OmpMapClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObjectList>(x.t));
   }
-  void Unparse(const OmpDetachClause &x) { Walk(x.v); }
-  void Unparse(const OmpInReductionClause &x) {
-    using Modifier = OmpInReductionClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<OmpObjectList>(x.t));
+  void Unparse(const OmpMapperSpecifier &x) {
+    const auto &mapperName{std::get<std::string>(x.t)};
+    if (mapperName.find(llvm::omp::OmpDefaultMapperName) == std::string::npos) {
+      Walk(mapperName);
+      Put(":");
+    }
+    Walk(std::get<TypeSpec>(x.t));
+    Put("::");
+    Walk(std::get<Name>(x.t));
   }
-  void Unparse(const OmpTaskReductionClause &x) {
-    using Modifier = OmpTaskReductionClause::Modifier;
+  void Unparse(const OmpMapper &x) {
+    Word("MAPPER(");
+    Walk(x.v);
+    Put(")");
+  }
+  void Unparse(const OmpMetadirectiveDirective &x) {
+    BeginOpenMP();
+    Word("!$OMP ");
+    Walk(x.v);
+    Put("\n");
+    EndOpenMP();
+  }
+  void Unparse(const OmpNothingDirective &x) {
+    BeginOpenMP();
+    Word("!$OMP ");
+    Walk(x.v);
+    Put("\n");
+    EndOpenMP();
+  }
+  void Unparse(const OmpNumTasksClause &x) {
+    using Modifier = OmpNumTasksClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<OmpObjectList>(x.t));
+    Walk(std::get<ScalarIntExpr>(x.t));
   }
-  void Unparse(const OmpAllocateClause &x) {
-    using Modifier = OmpAllocateClause::Modifier;
+  void Unparse(const OmpNumTeamsClause &x) {
+    using Modifier = OmpNumTeamsClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
+    Walk(std::get<std::list<ScalarIntExpr>>(x.t));
+  }
+  void Unparse(const OmpNumThreadsClause &x) {
+    using Modifier = OmpNumThreadsClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
+    Walk(std::get<std::list<ScalarIntExpr>>(x.t));
+  }
+  void Unparse(const OmpObjectList &x) { Walk(x.v, ","); }
+  void Unparse(const OmpObject &x) {
+    common::visit( //
+        common::visitors{
+            [&](const Designator &y) { Walk(y); },
+            [&](const Name &y) {
+              Put("/");
+              Walk(y);
+              Put("/");
+            },
+            [&](const OmpObject::Invalid &y) {
+              switch (y.v) {
+              case OmpObject::Invalid::Kind::BlankCommonBlock:
+                Put("//");
+                break;
+              }
+            },
+        },
+        x.u);
+  }
+  void Unparse(const OmpOrderClause &x) {
+    using Modifier = OmpOrderClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
+    Walk(std::get<OmpOrderClause::Ordering>(x.t));
+  }
+  void Unparse(const OmpPreferenceSelector &x) {
+    common::visit( //
+        common::visitors{
+            [&](const OmpPreferenceSelector::ForeignRuntimeIdentifier &s) {
+              Word("FR");
+              Put("(");
+              Walk(s);
+              Put(")");
+            },
+            [&](const OmpPreferenceSelector::Extensions &s) {
+              Word("ATTR");
+              Put("(");
+              Walk(s, ", ");
+              Put(")");
+            },
+        },
+        x.u);
+  }
+  void Unparse(const OmpPreferenceSpecification &x) {
+    common::visit( //
+        common::visitors{
+            [&](const std::list<OmpPreferenceSelector> &s) {
+              Put("{");
+              Walk(s, ", ");
+              Put("}");
+            },
+            [&](const OmpPreferenceSelector::ForeignRuntimeIdentifier &s) {
+              Walk(s);
+            },
+        },
+        x.u);
+  }
+  void Unparse(const OmpPreferType &x) {
+    Word("PREFER_TYPE");
+    Put("(");
+    Walk(x.v, ", ");
+    Put(")");
+  }
+  void Unparse(const OmpReductionClause &x) {
+    using Modifier = OmpReductionClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObjectList>(x.t));
   }
-  void Unparse(const OmpAlignModifier &x) {
-    Word("ALIGN(");
-    Walk(x.v);
-    Put(")");
+  void Unparse(const OmpReductionSpecifier &x) {
+    Walk(std::get<OmpReductionIdentifier>(x.t));
+    Put(":");
+    Walk(std::get<OmpTypeNameList>(x.t));
+    Walk(": ", std::get<std::optional<OmpCombinerExpression>>(x.t));
   }
-  void Unparse(const OmpAllocatorSimpleModifier &x) { Walk(x.v); }
-  void Unparse(const OmpAllocatorComplexModifier &x) {
-    Word("ALLOCATOR(");
-    Walk(x.v);
-    Put(")");
+  void Unparse(const OmpScheduleClause &x) {
+    using Modifier = OmpScheduleClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
+    Walk(std::get<OmpScheduleClause::Kind>(x.t));
+    Walk(",", std::get<std::optional<ScalarIntExpr>>(x.t));
   }
-  void Unparse(const OmpAttachModifier &x) {
-    Word("ATTACH(");
+  void Unparse(const OmpStepComplexModifier &x) {
+    Word("STEP(");
     Walk(x.v);
     Put(")");
   }
-  void Unparse(const OmpOrderClause &x) {
-    using Modifier = OmpOrderClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
-    Walk(std::get<OmpOrderClause::Ordering>(x.t));
-  }
-  void Unparse(const OmpGrainsizeClause &x) {
-    using Modifier = OmpGrainsizeClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<ScalarIntExpr>(x.t));
+  void Unparse(const OmpStepSimpleModifier &x) { Walk(x.v); }
+  void Unparse(const OmpStylizedDeclaration &x) {
+    // empty
   }
-  void Unparse(const OmpNumTasksClause &x) {
-    using Modifier = OmpNumTasksClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<ScalarIntExpr>(x.t));
+  void Unparse(const OmpStylizedExpression &x) { //
+    Put(x.source.ToString());
   }
-  void Unparse(const OmpNumTeamsClause &x) {
-    using Modifier = OmpNumTeamsClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
-    Walk(std::get<std::list<ScalarIntExpr>>(x.t));
+  void Unparse(const OmpStylizedInstance &x) {
+    // empty
   }
-  void Unparse(const OmpNumThreadsClause &x) {
-    using Modifier = OmpNumThreadsClause::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
-    Walk(std::get<std::list<ScalarIntExpr>>(x.t));
+  void Unparse(const OmpTaskReductionClause &x) {
+    using Modifier = OmpTaskReductionClause::Modifier;
+    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
+    Walk(std::get<OmpObjectList>(x.t));
   }
   void Unparse(const OmpThreadLimitClause &x) {
     using Modifier = OmpThreadLimitClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ":");
     Walk(std::get<std::list<ScalarIntExpr>>(x.t));
   }
-  void Unparse(const OmpDoacross::Sink &x) {
-    Word("SINK: ");
-    Walk(x.v.v);
-  }
-  void Unparse(const OmpDoacross::Source &) { Word("SOURCE"); }
-  void Unparse(const OmpDependClause::TaskDep &x) {
-    using Modifier = OmpDependClause::TaskDep::Modifier;
-    Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
-    Walk(std::get<OmpObjectList>(x.t));
-  }
-  void Unparse(const OmpDefaultmapClause &x) {
-    using Modifier = OmpDefaultmapClause::Modifier;
-    Walk(std::get<OmpDefaultmapClause::ImplicitBehavior>(x.t));
-    Walk(":", std::get<std::optional<std::list<Modifier>>>(x.t));
-  }
   void Unparse(const OmpToClause &x) {
     using Modifier = OmpToClause::Modifier;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<OmpObjectList>(x.t));
   }
+  void Unparse(const OmpTraitPropertyExtension::Complex &x) {
+    using PropList = std::list<common::Indirection<OmpTraitPropertyExtension>>;
+    Walk(std::get<OmpTraitPropertyName>(x.t));
+    Put("(");
+    Walk(std::get<PropList>(x.t), ",");
+    Put(")");
+  }
+  void Unparse(const OmpTraitScore &x) {
+    Word("SCORE(");
+    Walk(x.v);
+    Put(")");
+  }
+  void Unparse(const OmpTraitSelector::Properties &x) {
+    Put("(");
+    Walk(std::get<std::optional<OmpTraitScore>>(x.t), ": ");
+    Walk(std::get<std::list<OmpTraitProperty>>(x.t));
+    Put(")");
+  }
+  void Unparse(const OmpTraitSelector &x) {
+    Walk(std::get<OmpTraitSelectorName>(x.t));
+    Walk(std::get<std::optional<OmpTraitSelector::Properties>>(x.t));
+  }
+  void Unparse(const OmpTraitSetSelector &x) {
+    Walk(std::get<OmpTraitSetSelectorName>(x.t));
+    Put("={");
+    Walk(std::get<std::list<OmpTraitSelector>>(x.t));
+    Put("}");
+  }
+  void Unparse(const OmpTypeNameList &x) { Walk(x.v, ", "); }
   void Unparse(const OmpWhenClause &x) {
     using Modifier = OmpWhenClause::Modifier;
     using Directive = common::Indirection<OmpDirectiveSpecification>;
     Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
     Walk(std::get<std::optional<Directive>>(x.t));
   }
-#define GEN_FLANG_CLAUSE_UNPARSE
-#include "llvm/Frontend/OpenMP/OMP.inc"
-  void Unparse(const OmpObjectList &x) { Walk(x.v, ","); }
-
-  void Unparse(const OmpBeginDirective &x) {
-    BeginOpenMP();
-    Word("!$OMP ");
-    Walk(static_cast<const OmpDirectiveSpecification &>(x));
-    Put("\n");
-    EndOpenMP();
-  }
-
-  void Unparse(const OmpEndDirective &x) {
-    BeginOpenMP();
-    Word("!$OMP END ");
-    Walk(static_cast<const OmpDirectiveSpecification &>(x));
-    Put("\n");
-    EndOpenMP();
-  }
-
-  void Unparse(const OmpBlockConstruct &x) {
-    Walk(std::get<OmpBeginDirective>(x.t));
-    Walk(std::get<Block>(x.t), "");
-    if (auto &end{std::get<std::optional<OmpEndDirective>>(x.t)}) {
-      Walk(*end);
-    } else {
-      Put("\n");
-    }
-  }
-
-  void Unparse(const OpenMPAtomicConstruct &x) { //
-    Unparse(static_cast<const OmpBlockConstruct &>(x));
-  }
 
-  void Unparse(const OmpAllocateDirective &x) {
-    Unparse(static_cast<const OmpBlockConstruct &>(x));
-  }
   void Unparse(const OpenMPAllocatorsConstruct &x) {
     Unparse(static_cast<const OmpBlockConstruct &>(x));
   }
   void Unparse(const OpenMPAssumeConstruct &x) {
     Unparse(static_cast<const OmpBlockConstruct &>(x));
   }
-  void Unparse(const OpenMPCriticalConstruct &x) {
+  void Unparse(const OpenMPAtomicConstruct &x) {
     Unparse(static_cast<const OmpBlockConstruct &>(x));
   }
-  void Unparse(const OmpInitializerExpression &x) {
-    Unparse(static_cast<const OmpStylizedExpression &>(x));
-  }
-  void Unparse(const OmpCombinerExpression &x) {
-    Unparse(static_cast<const OmpStylizedExpression &>(x));
-  }
-  void Unparse(const OpenMPDeclareReductionConstruct &x) {
+  void Unparse(const OpenMPCancelConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OmpAppendArgsClause::OmpAppendOp &x) {
-    Put("INTEROP(");
-    Walk(x.v, ",");
-    Put(")");
-  }
-  void Unparse(const OmpAppendArgsClause &x) { Walk(x.v, ","); }
-  void Unparse(const OmpAdjustArgsClause &x) {
-    Walk(std::get<OmpAdjustArgsClause::OmpAdjustOp>(x.t).v);
-    Put(":");
-    Walk(std::get<parser::OmpObjectList>(x.t));
-  }
-  void Unparse(const OmpDeclareVariantDirective &x) {
+  void Unparse(const OpenMPCancellationPointConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OpenMPInteropConstruct &x) {
+  void Unparse(const OpenMPCriticalConstruct &x) {
+    Unparse(static_cast<const OmpBlockConstruct &>(x));
+  }
+  void Unparse(const OpenMPDeclarativeAssumes &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
-
-  void Unparse(const OpenMPDeclarativeAssumes &x) {
+  void Unparse(const OpenMPDeclareMapperConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OpenMPDeclareMapperConstruct &x) {
+  void Unparse(const OpenMPDeclareReductionConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
@@ -2627,42 +2672,55 @@ class UnparseVisitor {
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OpenMPDispatchConstruct &x) { //
-    Unparse(static_cast<const OmpBlockConstruct &>(x));
-  }
-  void Unparse(const OpenMPGroupprivate &x) {
+  void Unparse(const OpenMPDepobjConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OpenMPRequiresConstruct &x) {
+  void Unparse(const OpenMPDispatchConstruct &x) {
+    Unparse(static_cast<const OmpBlockConstruct &>(x));
+  }
+  void Unparse(const OpenMPFlushConstruct &x) {
     BeginOpenMP();
-    Word("!$OMP ");
-    Walk(x.v);
+    Word("!$OMP FLUSH");
+    auto flags{std::get<OmpDirectiveSpecification::Flags>(x.v.t)};
+    if (flags.test(OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
+      Walk("(", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
+      Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
+    } else {
+      Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
+      Walk(" (", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
+    }
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OpenMPThreadprivate &x) {
+  void Unparse(const OpenMPGroupprivate &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
-  bool Pre(const OmpMessageClause &x) {
+  void Unparse(const OpenMPInteropConstruct &x) {
+    BeginOpenMP();
+    Word("!$OMP ");
     Walk(x.v);
-    return false;
+    Put("\n");
+    EndOpenMP();
   }
-  void Unparse(const OmpErrorDirective &x) {
+  void Unparse(const OpenMPInvalidDirective &x) {
     BeginOpenMP();
     Word("!$OMP ");
-    Walk(x.v);
+    Put(parser::ToUpperCaseLetters(x.source.ToString()));
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OmpNothingDirective &x) {
+  void Unparse(const OpenMPMisplacedEndDirective &x) {
+    Unparse(static_cast<const OmpEndDirective &>(x));
+  }
+  void Unparse(const OpenMPRequiresConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
     Walk(x.v);
@@ -2680,73 +2738,11 @@ class UnparseVisitor {
     }
     Walk(std::get<Block>(x.t), "");
   }
-  void Unparse(const OmpBeginSectionsDirective &x) {
-    Unparse(static_cast<const OmpBeginDirective &>(x));
-  }
-  void Unparse(const OmpEndSectionsDirective &x) {
-    Unparse(static_cast<const OmpEndDirective &>(x));
-  }
   void Unparse(const OpenMPSectionsConstruct &x) {
     Walk(std::get<OmpBeginSectionsDirective>(x.t));
     Walk(std::get<std::list<OpenMPConstruct>>(x.t), "");
     Walk(std::get<std::optional<OmpEndSectionsDirective>>(x.t));
   }
-  // Clause unparsers are usually generated by tablegen in the form
-  // CLAUSE(VALUE). Here we only want to print VALUE so a custom unparser is
-  // needed.
-  void Unparse(const OmpClause::CancellationConstructType &x) { Walk(x.v); }
-  void Unparse(const OpenMPCancellationPointConstruct &x) {
-    BeginOpenMP();
-    Word("!$OMP ");
-    Walk(x.v);
-    Put("\n");
-    EndOpenMP();
-  }
-  void Unparse(const OpenMPCancelConstruct &x) {
-    BeginOpenMP();
-    Word("!$OMP ");
-    Walk(x.v);
-    Put("\n");
-    EndOpenMP();
-  }
-  void Unparse(const OmpFailClause &x) { Walk(x.v); }
-  void Unparse(const OmpMetadirectiveDirective &x) {
-    BeginOpenMP();
-    Word("!$OMP ");
-    Walk(x.v);
-    Put("\n");
-    EndOpenMP();
-  }
-  void Unparse(const OpenMPDepobjConstruct &x) {
-    BeginOpenMP();
-    Word("!$OMP ");
-    Walk(x.v);
-    Put("\n");
-    EndOpenMP();
-  }
-  void Unparse(const OpenMPFlushConstruct &x) {
-    BeginOpenMP();
-    Word("!$OMP FLUSH");
-    auto flags{std::get<OmpDirectiveSpecification::Flags>(x.v.t)};
-    if (flags.test(OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
-      Walk("(", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
-      Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
-    } else {
-      Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
-      Walk(" (", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
-    }
-    Put("\n");
-    EndOpenMP();
-  }
-  void Unparse(const OmpBeginLoopDirective &x) {
-    Unparse(static_cast<const OmpBeginDirective &>(x));
-  }
-  void Unparse(const OmpEndLoopDirective &x) {
-    Unparse(static_cast<const OmpEndDirective &>(x));
-  }
-  void Unparse(const OmpClauseList &x, const char *sep = " ") {
-    Walk(" ", x.v, sep);
-  }
   void Unparse(const OpenMPSimpleStandaloneConstruct &x) {
     BeginOpenMP();
     Word("!$OMP ");
@@ -2754,16 +2750,14 @@ class UnparseVisitor {
     Put("\n");
     EndOpenMP();
   }
-  void Unparse(const OpenMPMisplacedEndDirective &x) {
-    Unparse(static_cast<const OmpEndDirective &>(x));
-  }
-  void Unparse(const OpenMPInvalidDirective &x) {
+  void Unparse(const OpenMPThreadprivate &x) {
     BeginOpenMP();
     Word("!$OMP ");
-    Put(parser::ToUpperCaseLetters(x.source.ToString()));
+    Walk(x.v);
     Put("\n");
     EndOpenMP();
   }
+
   void Unparse(const BasedPointer &x) {
     Put('('), Walk(std::get<0>(x.t)), Put(","), Walk(std::get<1>(x.t));
     Walk("(", std::get<std::optional<ArraySpec>>(x.t), ")"), Put(')');



More information about the flang-commits mailing list