From: Valentin Clement Date: Sat, 21 Nov 2020 19:31:17 +0000 (-0500) Subject: [flang][openmp] Separate memory-order-clause parser creating OmpClause node X-Git-Tag: llvmorg-13-init~5440 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa179d80990921486ec3e4f97d53522a4bb6cfad;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index e05c5d5..61c5bdd 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -548,7 +548,7 @@ public: 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 a64ca06..2dcb92b 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, + std::tuple, std::optional> t; }; diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp index 5b69800..780aea9 100644 --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -109,9 +109,9 @@ genOMP(Fortran::lower::AbstractConverter &converter, std::get>( flushConstruct.t)) genObjectList(*ompObjectList, converter, operandRange); - if (std::get>( + if (std::get>( flushConstruct.t)) - TODO("Handle OmpFlushMemoryClause"); + TODO("Handle OmpMemoryOrderClause"); converter.getFirOpBuilder().create( converter.getCurrentLocation(), operandRange); }, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 8ad13df..0af3137 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -302,18 +302,22 @@ TYPE_PARSER(sourced(construct( TYPE_PARSER(sourced(construct(verbatim("CANCEL"_tok), Parser{}, 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( - "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( + sourced("SEQ_CST" >> construct(construct()) || + "ACQ_REL" >> construct(construct()) || + "RELEASE" >> construct(construct()) || + "ACQUIRE" >> construct(construct()) || + "RELAXED" >> construct(construct()))))) TYPE_PARSER(sourced(construct(verbatim("FLUSH"_tok), - maybe(Parser{}), + maybe(Parser{}), maybe(parenthesized(Parser{}))))) // Simple Standalone Directives diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index 2a6b0a6..56f09f9 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2419,25 +2419,11 @@ public: 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>(x.t)); + Walk(std::get>(x.t)); Walk(" (", std::get>(x.t), ")"); Put("\n"); EndOpenMP(); diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 3cf7713..d3430d7 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 cf10608..8384efe 100644 --- a/flang/lib/Semantics/check-omp-structure.h +++ b/flang/lib/Semantics/check-omp-structure.h @@ -150,6 +150,12 @@ public: 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 5ff748e..601e3902 100644 --- a/flang/test/Semantics/omp-clause-validity01.f90 +++ b/flang/test/Semantics/omp-clause-validity01.f90 @@ -62,7 +62,7 @@ use omp_lib a = 3.14 enddo !$omp end parallel - + !$omp task private(b) allocate(b) do i = 1, N z = 2 @@ -80,7 +80,7 @@ use omp_lib 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 @@ use omp_lib !$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