[flang] more progress
authorpeter klausler <pklausler@nvidia.com>
Fri, 12 Jul 2019 19:46:39 +0000 (12:46 -0700)
committerpeter klausler <pklausler@nvidia.com>
Mon, 15 Jul 2019 20:05:26 +0000 (13:05 -0700)
Original-commit: flang-compiler/f18@1a219e50732ab5bd8c79ec9e85609c0b64598c69
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.h
flang/lib/parser/unparse.cc

index fbeb0e6..a9c8990 100644 (file)
@@ -557,7 +557,8 @@ public:
   NODE(parser, OpenMPConstruct)
   NODE(parser, OpenMPConstructDirective)
   NODE(parser, OpenMPCriticalConstruct)
-  NODE(parser::OpenMPCriticalConstruct, Hint)
+  NODE(parser, OpenMPCriticalConstructDirective)
+  NODE(parser::OpenMPCriticalConstructDirective, Hint)
   NODE(parser, OpenMPDeclarativeConstruct)
   NODE(parser::OpenMPDeclarativeConstruct, Threadprivate)
   NODE(parser, OpenMPDeclareReductionConstruct)
index 826fd36..73ae1fe 100644 (file)
@@ -42,6 +42,12 @@ namespace Fortran::parser {
 constexpr auto startOmpLine = skipStuffBeforeStatement >> "!$OMP "_sptok;
 constexpr auto endOmpLine = space >> endOfLine;
 
+template<typename A> constexpr decltype(auto) OmpConstructDirective(A keyword) {
+  return sourced(construct<OpenMPConstructDirective>(
+             keyword >> Parser<OmpClauseList>{})) /
+      endOmpLine;
+}
+
 // OpenMP Clauses
 // DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE )
 TYPE_PARSER(construct<OmpDefaultClause>(
@@ -436,39 +442,40 @@ TYPE_PARSER("ATOMIC" >>
 
 // OMP CRITICAL
 TYPE_PARSER(startOmpLine >> "END CRITICAL"_tok >>
-    construct<OmpEndCritical>(maybe(parenthesized(name))))
+    construct<OmpEndCritical>(maybe(parenthesized(name))) / endOmpLine)
 
 TYPE_PARSER(
-    "CRITICAL" >> construct<OpenMPCriticalConstruct>(maybe(parenthesized(name)),
-                      maybe("HINT" >> construct<OpenMPCriticalConstruct::Hint>(
-                                          parenthesized(constantExpr))) /
-                          endOmpLine,
-                      block, Parser<OmpEndCritical>{} / endOmpLine))
+    sourced(construct<OpenMPCriticalConstructDirective>(
+        "CRITICAL" >> maybe(parenthesized(name)),
+        maybe("HINT" >> construct<OpenMPCriticalConstructDirective::Hint>(
+                            parenthesized(constantExpr))))) /
+    endOmpLine)
+TYPE_PARSER(construct<OpenMPCriticalConstruct>(
+    Parser<OpenMPCriticalConstructDirective>{}, block,
+    Parser<OmpEndCritical>{}))
 
 // Declare Simd construct
-TYPE_PARSER(construct<OpenMPDeclareSimdConstruct>(
-    maybe(parenthesized(name)), Parser<OmpClauseList>{}))
+TYPE_PARSER(sourced(construct<OpenMPDeclareSimdConstruct>(
+    maybe(parenthesized(name)), Parser<OmpClauseList>{})))
 
 // Declarative construct & Threadprivate directive
 TYPE_PARSER(startOmpLine >>
-    ("DECLARE REDUCTION" >>
+    sourced("DECLARE REDUCTION" >>
             construct<OpenMPDeclarativeConstruct>(
                 construct<OpenMPDeclarativeConstruct>(
-                    Parser<OpenMPDeclareReductionConstruct>{})) /
-                endOmpLine ||
+                    Parser<OpenMPDeclareReductionConstruct>{})) ||
         "DECLARE SIMD" >> construct<OpenMPDeclarativeConstruct>(
-                              Parser<OpenMPDeclareSimdConstruct>{}) /
-                endOmpLine ||
+                              Parser<OpenMPDeclareSimdConstruct>{}) ||
         "DECLARE TARGET" >> construct<OpenMPDeclarativeConstruct>(
                                 construct<OpenMPDeclarativeConstruct>(
-                                    Parser<OpenMPDeclareTargetConstruct>{})) /
-                endOmpLine ||
+                                    Parser<OpenMPDeclareTargetConstruct>{})) ||
         "THREADPRIVATE" >>
             construct<OpenMPDeclarativeConstruct>(
                 construct<OpenMPDeclarativeConstruct::Threadprivate>(
-                    parenthesized(Parser<OmpObjectList>{})) /
-                endOmpLine)))
+                    parenthesized(Parser<OmpObjectList>{}))) /
+                endOmpLine))
 
+// TODO pmk
 // Block Construct
 TYPE_PARSER(construct<OpenMPBlockConstruct>(
     sourced(Parser<OmpBlockDirective>{}), Parser<OmpClauseList>{} / endOmpLine,
@@ -488,20 +495,19 @@ TYPE_PARSER("TASKYIELD" >> construct<OpenMPTaskyieldConstruct>() / endOmpLine)
 
 // OMP SINGLE
 TYPE_PARSER(startOmpLine >> "END"_tok >>
-    construct<OmpEndSingle>("SINGLE" >> Parser<OmpClauseList>{}))
+    construct<OmpEndSingle>("SINGLE" >> Parser<OmpClauseList>{}) / endOmpLine)
 
 TYPE_PARSER("SINGLE" >>
-    construct<OpenMPSingleConstruct>(Parser<OmpClauseList>{} / endOmpLine,
-        block, Parser<OmpEndSingle>{} / endOmpLine))
+    construct<OpenMPSingleConstruct>(
+        OmpConstructDirective("SINGLE"_tok), block, Parser<OmpEndSingle>{}))
 
-TYPE_PARSER(
-    startOmpLine >> "END"_tok >> construct<OmpEndWorkshare>("WORKSHARE"_tok))
+TYPE_PARSER(startOmpLine >> "END"_tok >>
+    construct<OmpEndWorkshare>("WORKSHARE"_tok) / endOmpLine)
 
 // OMP WORKSHARE
 TYPE_PARSER("WORKSHARE" >>
     construct<OpenMPWorkshareConstruct>(endOmpLine >> block,
-        Parser<OmpEndWorkshare>{} >>
-            maybe(construct<OmpNowait>("NOWAIT"_tok)) / endOmpLine))
+        Parser<OmpEndWorkshare>{} >> maybe(construct<OmpNowait>("NOWAIT"_tok))))
 
 // OMP END DO SIMD [NOWAIT]
 TYPE_PARSER(construct<OmpEndDoSimd>(maybe(construct<OmpNowait>("NOWAIT"_tok))))
@@ -514,12 +520,6 @@ 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(construct<OpenMPSectionsConstruct>(
     OmpConstructDirective("SECTIONS"_tok), block, Parser<OmpEndSections>{}))
index 2b7699b..e587ac0 100644 (file)
@@ -3494,7 +3494,7 @@ struct OpenMPWorkshareConstruct {
 WRAPPER_CLASS(OmpEndSingle, OmpClauseList);
 struct OpenMPSingleConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPSingleConstruct);
-  std::tuple<OmpClauseList, Block, OmpEndSingle> t;
+  std::tuple<OpenMPConstructDirective, Block, OmpEndSingle> t;
 };
 
 // OpenMP directive beginning a block
@@ -3557,12 +3557,14 @@ struct OpenMPDeclareReductionConstruct {
 
 struct OpenMPDeclareSimdConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPDeclareSimdConstruct);
+  CharBlock source;
   std::tuple<std::optional<Name>, OmpClauseList> t;
 };
 
 struct OpenMPDeclarativeConstruct {
   UNION_CLASS_BOILERPLATE(OpenMPDeclarativeConstruct);
   WRAPPER_CLASS(Threadprivate, OmpObjectList);
+  CharBlock source;
   std::variant<OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
       OpenMPDeclareTargetConstruct, Threadprivate>
       u;
@@ -3570,10 +3572,15 @@ struct OpenMPDeclarativeConstruct {
 
 // CRITICAL [Name] <block> END CRITICAL [Name]
 WRAPPER_CLASS(OmpEndCritical, std::optional<Name>);
+struct OpenMPCriticalConstructDirective {
+  TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstructDirective);
+  WRAPPER_CLASS(Hint, ConstantExpr);
+  CharBlock source;
+  std::tuple<std::optional<Name>, std::optional<Hint>> t;
+};
 struct OpenMPCriticalConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct);
-  WRAPPER_CLASS(Hint, ConstantExpr);
-  std::tuple<std::optional<Name>, std::optional<Hint>, Block, OmpEndCritical> t;
+  std::tuple<OpenMPCriticalConstructDirective, Block, OmpEndCritical> t;
 };
 
 // END ATOMIC
@@ -3639,28 +3646,28 @@ struct OpenMPAtomicConstruct {
 
 struct OmpLoopDirective {
   UNION_CLASS_BOILERPLATE(OmpLoopDirective);
+  EMPTY_CLASS(Distribute);
   EMPTY_CLASS(DistributeParallelDoSimd);
   EMPTY_CLASS(DistributeParallelDo);
   EMPTY_CLASS(DistributeSimd);
-  EMPTY_CLASS(Distribute);
-  EMPTY_CLASS(ParallelDoSimd);
   EMPTY_CLASS(ParallelDo);
+  EMPTY_CLASS(ParallelDoSimd);
   EMPTY_CLASS(Do);
   EMPTY_CLASS(DoSimd);
   EMPTY_CLASS(Simd);
-  EMPTY_CLASS(TargetParallelDoSimd);
   EMPTY_CLASS(TargetParallelDo);
-  EMPTY_CLASS(TargetTeamsDistributeParallelDoSimd);
+  EMPTY_CLASS(TargetParallelDoSimd);
+  EMPTY_CLASS(TargetTeamsDistribute);
   EMPTY_CLASS(TargetTeamsDistributeParallelDo);
+  EMPTY_CLASS(TargetTeamsDistributeParallelDoSimd);
   EMPTY_CLASS(TargetTeamsDistributeSimd);
-  EMPTY_CLASS(TargetTeamsDistribute);
   EMPTY_CLASS(TargetSimd);
-  EMPTY_CLASS(TaskloopSimd);
   EMPTY_CLASS(Taskloop);
+  EMPTY_CLASS(TaskloopSimd);
+  EMPTY_CLASS(TeamsDistribute);
   EMPTY_CLASS(TeamsDistributeParallelDoSimd);
   EMPTY_CLASS(TeamsDistributeParallelDo);
   EMPTY_CLASS(TeamsDistributeSimd);
-  EMPTY_CLASS(TeamsDistribute);
   CharBlock source;
   std::variant<DistributeParallelDoSimd, DistributeParallelDo, DistributeSimd,
       Distribute, ParallelDoSimd, ParallelDo, Do, DoSimd, Simd,
index 8fe84d8..1fa436b 100644 (file)
@@ -2156,14 +2156,18 @@ public:
     Walk(" (", x.v, ")");
     EndOpenMP();
   }
-  void Unparse(const OpenMPCriticalConstruct &x) {
+  void Unparse(const OpenMPCriticalConstructDirective &x) {
     BeginOpenMP();
     Word("!$OMP CRITICAL");
     Walk(" (", std::get<std::optional<Name>>(x.t), ")");
-    Walk(" HINT(", std::get<std::optional<OpenMPCriticalConstruct::Hint>>(x.t),
+    Walk(" HINT(",
+        std::get<std::optional<OpenMPCriticalConstructDirective::Hint>>(x.t),
         ")");
     Put("\n");
     EndOpenMP();
+  }
+  void Unparse(const OpenMPCriticalConstruct &x) {
+    Walk(std::get<OpenMPCriticalConstructDirective>(x.t));
     Walk(std::get<Block>(x.t), "");
     BeginOpenMP();
     Word("!$OMP END CRITICAL");
@@ -2260,7 +2264,7 @@ public:
   void Unparse(const OpenMPSingleConstruct &x) {
     BeginOpenMP();
     Word("!$OMP SINGLE");
-    Walk(std::get<OmpClauseList>(x.t));
+    Walk(std::get<OpenMPConstructDirective>(x.t));
     EndOpenMP();
     Put("\n");
     Walk(std::get<Block>(x.t), "");