[llvm-branch-commits] [flang] aa179d8 - [flang][openmp] Separate memory-order-clause parser creating OmpClause node
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Nov 21 11:36:59 PST 2020
Author: Valentin Clement
Date: 2020-11-21T14:31:33-05:00
New Revision: aa179d80990921486ec3e4f97d53522a4bb6cfad
URL: https://github.com/llvm/llvm-project/commit/aa179d80990921486ec3e4f97d53522a4bb6cfad
DIFF: https://github.com/llvm/llvm-project/commit/aa179d80990921486ec3e4f97d53522a4bb6cfad.diff
LOG: [flang][openmp] Separate memory-order-clause parser creating OmpClause node
This patch introduce the separate parser for the memory-order-clause from the general
OmpClauseList. This parser still creates OmpClause node and therefore can use all the feature
from TableGen and the OmpStructureChecker.
This is applied only for the Flush construct in this patch and it should be applied for
atomic as well.
This is the approach we disscussed several time during the weekly call.
Reviewed By: kiranchandramohan, sameeranjoshi
Differential Revision: https://reviews.llvm.org/D91839
Added:
Modified:
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Lower/OpenMP.cpp
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
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 e05c5d5e527e..61c5bddc0afb 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -548,7 +548,7 @@ class ParseTreeDumper {
NODE(parser, OpenMPDeclareReductionConstruct)
NODE(parser, OpenMPDeclareSimdConstruct)
NODE(parser, OpenMPDeclareTargetConstruct)
- NODE(parser, OmpFlushMemoryClause)
+ NODE(parser, OmpMemoryOrderClause)
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 a64ca06f1b3b..2dcb92b4a725 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3701,8 +3701,8 @@ struct OpenMPCancelConstruct {
// memory-order-clause -> acq_rel
// release
// acquire
-struct OmpFlushMemoryClause {
- WRAPPER_CLASS_BOILERPLATE(OmpFlushMemoryClause, llvm::omp::Clause);
+struct OmpMemoryOrderClause {
+ WRAPPER_CLASS_BOILERPLATE(OmpMemoryOrderClause, OmpClause);
CharBlock source;
};
@@ -3710,7 +3710,7 @@ struct OmpFlushMemoryClause {
struct OpenMPFlushConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
CharBlock source;
- std::tuple<Verbatim, std::optional<OmpFlushMemoryClause>,
+ std::tuple<Verbatim, std::optional<OmpMemoryOrderClause>,
std::optional<OmpObjectList>>
t;
};
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 5b69800176ea..780aea9664fc 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -109,9 +109,9 @@ genOMP(Fortran::lower::AbstractConverter &converter,
std::get<std::optional<Fortran::parser::OmpObjectList>>(
flushConstruct.t))
genObjectList(*ompObjectList, converter, operandRange);
- if (std::get<std::optional<Fortran::parser::OmpFlushMemoryClause>>(
+ if (std::get<std::optional<Fortran::parser::OmpMemoryOrderClause>>(
flushConstruct.t))
- TODO("Handle OmpFlushMemoryClause");
+ TODO("Handle OmpMemoryOrderClause");
converter.getFirOpBuilder().create<mlir::omp::FlushOp>(
converter.getCurrentLocation(), operandRange);
},
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 8ad13dffea04..0af313743c0f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -302,18 +302,22 @@ TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>(
TYPE_PARSER(sourced(construct<OpenMPCancelConstruct>(verbatim("CANCEL"_tok),
Parser<OmpCancelType>{}, maybe("IF" >> parenthesized(scalarLogicalExpr)))))
-// 2.17.8 Flush construct [OpenMP 5.0]
-// flush -> FLUSH [memory-order-clause] [(variable-name-list)]
-// memory-order-clause -> acq_rel
+// 2.17.7 Atomtic construct/2.17.8 Flush construct [OpenMP 5.0]
+// memory-order-clause ->
+// seq_cst
+// acq_rel
// release
// acquire
-TYPE_PARSER(sourced(construct<OmpFlushMemoryClause>(
- "ACQ_REL" >> pure(llvm::omp::Clause::OMPC_acq_rel) ||
- "RELEASE" >> pure(llvm::omp::Clause::OMPC_release) ||
- "ACQUIRE" >> pure(llvm::omp::Clause::OMPC_acquire))))
+// relaxed
+TYPE_PARSER(sourced(construct<OmpMemoryOrderClause>(
+ sourced("SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) ||
+ "ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
+ "RELEASE" >> construct<OmpClause>(construct<OmpClause::Release>()) ||
+ "ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
+ "RELAXED" >> construct<OmpClause>(construct<OmpClause::Relaxed>())))))
TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(verbatim("FLUSH"_tok),
- maybe(Parser<OmpFlushMemoryClause>{}),
+ maybe(Parser<OmpMemoryOrderClause>{}),
maybe(parenthesized(Parser<OmpObjectList>{})))))
// Simple Standalone Directives
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 2a6b0a6490e4..56f09f97d98e 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2419,25 +2419,11 @@ class UnparseVisitor {
Put("\n");
EndOpenMP();
}
- void Unparse(const OmpFlushMemoryClause &x) {
- switch (x.v) {
- case llvm::omp::Clause::OMPC_acq_rel:
- Word("ACQ_REL ");
- break;
- case llvm::omp::Clause::OMPC_release:
- Word("RELEASE ");
- break;
- case llvm::omp::Clause::OMPC_acquire:
- Word("ACQUIRE ");
- break;
- default:
- break;
- }
- }
+ void Unparse(const OmpMemoryOrderClause &x) { Walk(x.v); }
void Unparse(const OpenMPFlushConstruct &x) {
BeginOpenMP();
Word("!$OMP FLUSH ");
- Walk(std::get<std::optional<OmpFlushMemoryClause>>(x.t));
+ Walk(std::get<std::optional<OmpMemoryOrderClause>>(x.t));
Walk(" (", std::get<std::optional<OmpObjectList>>(x.t), ")");
Put("\n");
EndOpenMP();
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 3cf77137ec12..d3430d724651 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -378,6 +378,11 @@ CHECK_SIMPLE_CLAUSE(To, OMPC_to)
CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)
CHECK_SIMPLE_CLAUSE(UseDevicePtr, OMPC_use_device_ptr)
+CHECK_SIMPLE_CLAUSE(AcqRel, OMPC_acq_rel)
+CHECK_SIMPLE_CLAUSE(Acquire, OMPC_acquire)
+CHECK_SIMPLE_CLAUSE(SeqCst, OMPC_seq_cst)
+CHECK_SIMPLE_CLAUSE(Release, OMPC_release)
+CHECK_SIMPLE_CLAUSE(Relaxed, OMPC_relaxed)
CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index cf10608efa72..8384efecb840 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -150,6 +150,12 @@ class OmpStructureChecker
void Enter(const parser::OmpClause::Uniform &);
void Enter(const parser::OmpClause::UseDevicePtr &);
void Enter(const parser::OmpClause::IsDevicePtr &);
+ // Memory-order-clause
+ void Enter(const parser::OmpClause::SeqCst &);
+ void Enter(const parser::OmpClause::AcqRel &);
+ void Enter(const parser::OmpClause::Release &);
+ void Enter(const parser::OmpClause::Acquire &);
+ void Enter(const parser::OmpClause::Relaxed &);
void Enter(const parser::OmpAlignedClause &);
void Enter(const parser::OmpAllocateClause &);
diff --git a/flang/test/Semantics/omp-clause-validity01.f90 b/flang/test/Semantics/omp-clause-validity01.f90
index 5ff748ec33c6..601e39021e44 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -62,7 +62,7 @@
a = 3.14
enddo
!$omp end parallel
-
+
!$omp task private(b) allocate(b)
do i = 1, N
z = 2
@@ -80,7 +80,7 @@
z = 2
end do
!$omp end target
-
+
!ERROR: ALLOCATE clause is not allowed on the TARGET DATA directive
!$omp target data map(from: b) allocate(b)
do i = 1, N
@@ -488,6 +488,11 @@
!$omp flush release
!$omp flush acquire
!$omp flush release (c)
+ !ERROR: SEQ_CST clause is not allowed on the FLUSH directive
+ !$omp flush seq_cst
+ !ERROR: RELAXED clause is not allowed on the FLUSH directive
+ !$omp flush relaxed
+
!$omp cancel DO
!$omp cancellation point parallel
More information about the llvm-branch-commits
mailing list