[flang] Define and use OpenMPConstructDirective
authorpeter klausler <pklausler@nvidia.com>
Fri, 12 Jul 2019 17:11:01 +0000 (10:11 -0700)
committerpeter klausler <pklausler@nvidia.com>
Mon, 15 Jul 2019 20:05:24 +0000 (13:05 -0700)
Original-commit: flang-compiler/f18@cd716fa90702613fc1cd1596705dbe6e85b07d57
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false

flang/lib/parser/dump-parse-tree.h
flang/lib/parser/openmp-grammar.h
flang/lib/parser/parse-tree-visitor.h
flang/lib/parser/parse-tree.h
flang/lib/parser/token-parsers.h
flang/lib/parser/unparse.cc

index 4aeb620..f3213f6 100644 (file)
@@ -405,10 +405,7 @@ public:
   NODE(parser, ObjectDecl)
   NODE(parser, OldParameterStmt)
   NODE(parser, OmpAlignedClause)
-  NODE(parser, OpenMPAtomicConstruct)
   NODE(parser, OmpEndAtomic)
-  NODE(parser, OpenMPCriticalConstruct)
-  NODE(parser::OpenMPCriticalConstruct, Hint)
   NODE(parser, OmpEndCritical)
   NODE(parser, OmpAtomic)
   NODE(parser::OmpAtomic, SeqCst)
@@ -431,9 +428,7 @@ public:
   NODE(parser::OmpBlockDirective, Ordered)
   NODE(parser::OmpBlockDirective, Parallel)
   NODE(parser::OmpBlockDirective, ParallelWorkshare)
-  NODE(parser, OpenMPSingleConstruct)
   NODE(parser, OmpEndSingle)
-  NODE(parser, OpenMPWorkshareConstruct)
   NODE(parser, OmpEndDo)
   NODE(parser, OmpEndDoSimd)
   NODE(parser::OmpBlockDirective, Target)
@@ -496,20 +491,11 @@ public:
   NODE(parser::OmpLinearClause, WithoutModifier)
   NODE(parser, OmpLinearModifier)
   NODE_ENUM(parser::OmpLinearModifier, Type)
-  NODE(parser, OpenMPDeclareReductionConstruct)
   NODE(parser, OmpReductionInitializerClause)
   NODE(parser, OmpReductionCombiner)
   NODE(parser::OmpReductionCombiner, FunctionCombiner)
-  NODE(parser, OpenMPDeclareSimdConstruct)
   NODE(parser, OmpDeclareTargetMapType)
   NODE_ENUM(parser::OmpDeclareTargetMapType, Type)
-  NODE(parser, OpenMPEndLoopDirective)
-  NODE(parser, OpenMPDeclareTargetConstruct)
-  NODE(parser::OpenMPDeclareTargetConstruct, Implicit)
-  NODE(parser::OpenMPDeclareTargetConstruct, WithClause)
-  NODE(parser::OpenMPDeclareTargetConstruct, WithExtendedList)
-  NODE(parser::OpenMPDeclarativeConstruct, Threadprivate)
-  NODE(parser, OpenMPLoopConstruct)
   NODE(parser, OmpLoopDirective)
   NODE(parser::OmpLoopDirective, Distribute)
   NODE(parser::OmpLoopDirective, DistributeParallelDo)
@@ -553,28 +539,43 @@ public:
   NODE(parser, OmpReductionOperator)
   NODE(parser, OmpSection)
   NODE(parser, OmpStandaloneDirective)
-  NODE(parser, OpenMPCancellationPointConstruct)
-  NODE(parser, OpenMPCancelConstruct)
-  NODE(parser::OpenMPCancelConstruct, If)
   NODE(parser, OmpCancelType)
   NODE_ENUM(parser::OmpCancelType, Type)
-  NODE(parser, OpenMPFlushConstruct)
   NODE(parser::OmpStandaloneDirective, TargetEnterData)
   NODE(parser::OmpStandaloneDirective, TargetExitData)
   NODE(parser::OmpStandaloneDirective, TargetUpdate)
+  NODE(parser, OmpReductionClause)
+  NODE(parser, OmpEndSections)
+  NODE(parser, OmpEndParallelSections)
+  NODE(parser, Only)
+  NODE(parser, OpenMPAtomicConstruct)
   NODE(parser, OpenMPBarrierConstruct)
-  NODE(parser, OpenMPTaskwaitConstruct)
-  NODE(parser, OpenMPTaskyieldConstruct)
-  NODE(parser, OpenMPConstruct)
   NODE(parser, OpenMPBlockConstruct)
+  NODE(parser, OpenMPCancelConstruct)
+  NODE(parser::OpenMPCancelConstruct, If)
+  NODE(parser, OpenMPCancellationPointConstruct)
+  NODE(parser, OpenMPConstruct)
+  NODE(parser, OpenMPConstructDirective)
+  NODE(parser, OpenMPCriticalConstruct)
+  NODE(parser::OpenMPCriticalConstruct, Hint)
   NODE(parser, OpenMPDeclarativeConstruct)
+  NODE(parser::OpenMPDeclarativeConstruct, Threadprivate)
+  NODE(parser, OpenMPDeclareReductionConstruct)
+  NODE(parser, OpenMPDeclareSimdConstruct)
+  NODE(parser, OpenMPDeclareTargetConstruct)
+  NODE(parser::OpenMPDeclareTargetConstruct, Implicit)
+  NODE(parser::OpenMPDeclareTargetConstruct, WithClause)
+  NODE(parser::OpenMPDeclareTargetConstruct, WithExtendedList)
+  NODE(parser, OpenMPEndLoopDirective)
+  NODE(parser, OpenMPFlushConstruct)
+  NODE(parser, OpenMPLoopConstruct)
   NODE(parser, OpenMPStandaloneConstruct)
-  NODE(parser, OmpReductionClause)
   NODE(parser, OpenMPSectionsConstruct)
+  NODE(parser, OpenMPSingleConstruct)
   NODE(parser, OpenMPParallelSectionsConstruct)
-  NODE(parser, OmpEndSections)
-  NODE(parser, OmpEndParallelSections)
-  NODE(parser, Only)
+  NODE(parser, OpenMPTaskwaitConstruct)
+  NODE(parser, OpenMPTaskyieldConstruct)
+  NODE(parser, OpenMPWorkshareConstruct)
   NODE(parser, OpenStmt)
   NODE(parser, Optional)
   NODE(parser, OptionalStmt)
index c499978..1a9decb 100644 (file)
@@ -61,12 +61,13 @@ TYPE_PARSER(construct<OmpProcBindClause>(
 // map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE
 TYPE_PARSER(construct<OmpMapType>(
     maybe("ALWAYS" >> construct<OmpMapType::Always>() / maybe(","_tok)),
-    "TO"_id >> pure(OmpMapType::Type::To) / ":"_tok ||
-        "FROM" >> pure(OmpMapType::Type::From) / ":"_tok ||
-        "TOFROM" >> pure(OmpMapType::Type::Tofrom) / ":"_tok ||
-        "ALLOC" >> pure(OmpMapType::Type::Alloc) / ":"_tok ||
-        "RELEASE" >> pure(OmpMapType::Type::Release) / ":"_tok ||
-        "DELETE" >> pure(OmpMapType::Type::Delete) / ":"_tok))
+    ("TO"_id >> pure(OmpMapType::Type::To) ||
+        "FROM" >> pure(OmpMapType::Type::From) ||
+        "TOFROM" >> pure(OmpMapType::Type::Tofrom) ||
+        "ALLOC" >> pure(OmpMapType::Type::Alloc) ||
+        "RELEASE" >> pure(OmpMapType::Type::Release) ||
+        "DELETE" >> pure(OmpMapType::Type::Delete)) /
+        ":"))
 
 TYPE_PARSER(construct<OmpMapClause>(
     maybe(Parser<OmpMapType>{}), Parser<OmpObjectList>{}))
@@ -514,10 +515,15 @@ TYPE_PARSER(startOmpLine >> "END SECTIONS"_tok >>
     construct<OmpEndSections>(
         maybe("NOWAIT" >> construct<OmpNowait>()) / endOmpLine))
 
+template<typename A> constexpr decltype(auto) OmpConstructDirective(A keyword) {
+  return sourced(construct<OpenMPConstructDirective>(
+             keyword >> Parser<OmpClauseList>{})) /
+      endOmpLine;
+}
+
 // OMP SECTIONS
-TYPE_PARSER("SECTIONS" >>
-    construct<OpenMPSectionsConstruct>(
-        Parser<OmpClauseList>{} / endOmpLine, block, Parser<OmpEndSections>{}))
+TYPE_PARSER(construct<OpenMPSectionsConstruct>(
+    OmpConstructDirective("SECTIONS"_tok), block, Parser<OmpEndSections>{}))
 
 // OMP END PARALLEL SECTIONS [NOWAIT]
 TYPE_PARSER(startOmpLine >> "END PARALLEL SECTIONS"_tok >>
index 96d8a3c..051d44b 100644 (file)
@@ -784,6 +784,18 @@ template<typename M> void Walk(CompilerDirective &x, M &mutator) {
     mutator.Post(x);
   }
 }
+template<typename V> void Walk(const OpenMPConstructDirective &x, V &visitor) {
+  if (visitor.Pre(x)) {
+    Walk(x.clauses, visitor);
+    visitor.Post(x);
+  }
+}
+template<typename M> void Walk(OpenMPConstructDirective &x, M &mutator) {
+  if (mutator.Pre(x)) {
+    Walk(x.clauses, mutator);
+    mutator.Post(x);
+  }
+}
 template<typename V>
 void Walk(const OmpLinearClause::WithModifier &x, V &visitor) {
   if (visitor.Pre(x)) {
index be12995..3d3066b 100644 (file)
@@ -3459,6 +3459,15 @@ struct OmpClause {
 
 WRAPPER_CLASS(OmpClauseList, std::list<OmpClause>);
 
+// Common representation for construct-starting directives
+struct OpenMPConstructDirective {
+  BOILERPLATE(OpenMPConstructDirective);
+  explicit OpenMPConstructDirective(OmpClauseList &&list)
+    : clauses{std::move(list)} {}
+  CharBlock source;
+  OmpClauseList clauses;
+};
+
 // SECTIONS, PARALLEL SECTIONS
 WRAPPER_CLASS(OmpEndSections, std::optional<OmpNowait>);
 WRAPPER_CLASS(OmpEndParallelSections, std::optional<OmpNowait>);
@@ -3466,7 +3475,7 @@ EMPTY_CLASS(OmpSection);
 
 struct OpenMPSectionsConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPSectionsConstruct);
-  std::tuple<OmpClauseList, Block, OmpEndSections> t;
+  std::tuple<OpenMPConstructDirective, Block, OmpEndSections> t;
 };
 
 struct OpenMPParallelSectionsConstruct {
index dd00443..dfc08cb 100644 (file)
@@ -118,7 +118,8 @@ constexpr struct SpaceCheck {
 // Token strings appear in the grammar as C++ user-defined literals
 // like "BIND ( C )"_tok and "SYNC ALL"_sptok.  The _tok suffix is implied
 // when a string literal appears before the sequencing operator >> or
-// after the sequencing operator /.
+// after the sequencing operator /.  The literal "..."_id parses a
+// token that cannot be a prefix of a longer identifier.
 template<bool MandatoryFreeFormSpace = false, bool MustBeComplete = false>
 class TokenStringMatch {
 public:
@@ -187,11 +188,13 @@ constexpr TokenStringMatch<> operator""_tok(const char str[], std::size_t n) {
   return {str, n};
 }
 
-constexpr TokenStringMatch<true> operator""_sptok(const char str[], std::size_t n) {
+constexpr TokenStringMatch<true> operator""_sptok(
+    const char str[], std::size_t n) {
   return {str, n};
 }
 
-constexpr TokenStringMatch<false, true> operator""_id(const char str[], std::size_t n) {
+constexpr TokenStringMatch<false, true> operator""_id(
+    const char str[], std::size_t n) {
   return {str, n};
 }
 
index 70482f3..ba07ae2 100644 (file)
@@ -2276,10 +2276,11 @@ public:
     Put("\n");
     EndOpenMP();
   }
+  void Unparse(const OpenMPConstructDirective &x) { Walk(x.clauses); }
   void Unparse(const OpenMPSectionsConstruct &x) {
     BeginOpenMP();
     Word("!$OMP SECTIONS");
-    Walk(std::get<OmpClauseList>(x.t));
+    Walk(std::get<OpenMPConstructDirective>(x.t));
     Put("\n");
     EndOpenMP();
     Walk(std::get<Block>(x.t), "");