[flang-commits] [flang] cd50316 - [flang][OpenMP] Enhance parser support for flush construct to OpenMP 5.0

Kiran Kumar T P via flang-commits flang-commits at lists.llvm.org
Tue Jul 7 01:57:30 PDT 2020


Author: Kiran Kumar T P
Date: 2020-07-07T14:27:13+05:30
New Revision: cd503166fb74baf91c55f5f959ed9cd016cbd9f7

URL: https://github.com/llvm/llvm-project/commit/cd503166fb74baf91c55f5f959ed9cd016cbd9f7
DIFF: https://github.com/llvm/llvm-project/commit/cd503166fb74baf91c55f5f959ed9cd016cbd9f7.diff

LOG: [flang][OpenMP] Enhance parser support for flush construct to OpenMP 5.0

Summary:
This patch enhances parser support for flush construct to OpenMP 5.0 by including memory-order-clause.

2.18.8 flush Construct
        !$omp flush [memory-order-clause] [(list)]
                where memory-order-clause is
                acq_rel
                release
                acquire

The patch includes code changes and testcase modifications.

Reviewed By: klausler, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D82177

Added: 
    

Modified: 
    flang/include/flang/Parser/dump-parse-tree.h
    flang/include/flang/Parser/parse-tree.h
    flang/lib/Parser/openmp-parsers.cpp
    flang/lib/Parser/unparse.cpp
    flang/test/Semantics/omp-clause-validity01.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 80a1411db5dd..59333c7405ff 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -521,6 +521,8 @@ class ParseTreeDumper {
   NODE(parser, OpenMPDeclareReductionConstruct)
   NODE(parser, OpenMPDeclareSimdConstruct)
   NODE(parser, OpenMPDeclareTargetConstruct)
+  NODE(parser, OmpFlushMemoryClause)
+  NODE_ENUM(OmpFlushMemoryClause, FlushMemoryOrder)
   NODE(parser, OpenMPFlushConstruct)
   NODE(parser, OpenMPLoopConstruct)
   NODE(parser, OpenMPSimpleStandaloneConstruct)

diff  --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 1ca3b4967240..28a343c58c66 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3707,11 +3707,23 @@ struct OpenMPCancelConstruct {
   std::tuple<Verbatim, OmpCancelType, std::optional<If>> t;
 };
 
-// 2.13.7 flush -> FLUSH [(variable-name-list)]
+// 2.17.8 Flush Construct [OpenMP 5.0]
+// memory-order-clause -> acq_rel
+//                        release
+//                        acquire
+struct OmpFlushMemoryClause {
+  ENUM_CLASS(FlushMemoryOrder, AcqRel, Release, Acquire)
+  WRAPPER_CLASS_BOILERPLATE(OmpFlushMemoryClause, FlushMemoryOrder);
+  CharBlock source;
+};
+
+// 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
 struct OpenMPFlushConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
   CharBlock source;
-  std::tuple<Verbatim, std::optional<OmpObjectList>> t;
+  std::tuple<Verbatim, std::optional<OmpFlushMemoryClause>,
+      std::optional<OmpObjectList>>
+      t;
 };
 
 struct OmpSimpleStandaloneDirective {

diff  --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index b845d6573c65..41a97ff902d9 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -291,9 +291,19 @@ TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>(
 TYPE_PARSER(sourced(construct<OpenMPCancelConstruct>(verbatim("CANCEL"_tok),
     Parser<OmpCancelType>{}, maybe("IF" >> parenthesized(scalarLogicalExpr)))))
 
-// 2.13.7 Flush construct
-TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(
-    verbatim("FLUSH"_tok), maybe(parenthesized(Parser<OmpObjectList>{})))))
+// 2.17.8 Flush construct [OpenMP 5.0]
+//        flush -> FLUSH [memory-order-clause] [(variable-name-list)]
+//        memory-order-clause -> acq_rel
+//                               release
+//                               acquire
+TYPE_PARSER(sourced(construct<OmpFlushMemoryClause>(
+    "ACQ_REL" >> pure(OmpFlushMemoryClause::FlushMemoryOrder::AcqRel) ||
+    "RELEASE" >> pure(OmpFlushMemoryClause::FlushMemoryOrder::Release) ||
+    "ACQUIRE" >> pure(OmpFlushMemoryClause::FlushMemoryOrder::Acquire))))
+
+TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(verbatim("FLUSH"_tok),
+    maybe(Parser<OmpFlushMemoryClause>{}),
+    maybe(parenthesized(Parser<OmpObjectList>{})))))
 
 // Simple Standalone Directives
 TYPE_PARSER(sourced(construct<OmpSimpleStandaloneDirective>(first(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 19c5ba6d589a..09acaaa37076 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2369,10 +2369,24 @@ class UnparseVisitor {
     Put("\n");
     EndOpenMP();
   }
+  void Unparse(const OmpFlushMemoryClause &x) {
+    switch (x.v) {
+    case OmpFlushMemoryClause::FlushMemoryOrder::AcqRel:
+      Word("ACQ_REL ");
+      break;
+    case OmpFlushMemoryClause::FlushMemoryOrder::Release:
+      Word("RELEASE ");
+      break;
+    case OmpFlushMemoryClause::FlushMemoryOrder::Acquire:
+      Word("ACQUIRE ");
+      break;
+    }
+  }
   void Unparse(const OpenMPFlushConstruct &x) {
     BeginOpenMP();
-    Word("!$OMP FLUSH");
-    Walk("(", std::get<std::optional<OmpObjectList>>(x.t), ")");
+    Word("!$OMP FLUSH ");
+    Walk(std::get<std::optional<OmpFlushMemoryClause>>(x.t));
+    Walk(" (", std::get<std::optional<OmpObjectList>>(x.t), ")");
     Put("\n");
     EndOpenMP();
   }

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 b/flang/test/Semantics/omp-clause-validity01.f90
index 06fd7203763d..e3f43dc5445e 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -403,6 +403,10 @@
   !ERROR: Internal: no symbol found for 'i'
   !$omp ordered depend(sink:i-1)
   !$omp flush (c)
+  !$omp flush acq_rel
+  !$omp flush release
+  !$omp flush acquire
+  !$omp flush release (c)
   !$omp cancel DO
   !$omp cancellation point parallel
 


        


More information about the flang-commits mailing list