[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Allow UPDATE clause to not have any arguments (PR #137521)
https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/137521 The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that. >From 637d237b9d904cfea6dc40eefb303f59641f545e Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sun, 27 Apr 2025 09:51:21 -0500 Subject: [PATCH] [flang][OpenMP] Allow UPDATE clause to not have any arguments The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that. --- flang/include/flang/Parser/parse-tree.h | 5 +++ flang/lib/Lower/OpenMP/Clauses.cpp | 10 +++-- flang/lib/Parser/openmp-parsers.cpp | 50 - flang/lib/Semantics/check-omp-structure.cpp | 16 +-- llvm/include/llvm/Frontend/OpenMP/OMP.td| 1 + 5 files changed, 53 insertions(+), 29 deletions(-) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index ca8473c6f9674..e39ecc13f4eec 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4501,6 +4501,11 @@ struct OmpToClause { // Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322] // +// In ATOMIC construct +// update-clause -> +//UPDATE// Since 4.5 +// +// In DEPOBJ construct // update-clause -> //UPDATE(dependence-type) // since 5.0, until 5.1 // update-clause -> diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index f1330b8d1909f..c258bef2e4427 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -1400,9 +1400,13 @@ Uniform make(const parser::OmpClause::Uniform &inp, Update make(const parser::OmpClause::Update &inp, semantics::SemanticsContext &semaCtx) { // inp.v -> parser::OmpUpdateClause - auto depType = - common::visit([](auto &&s) { return makeDepType(s); }, inp.v.u); - return Update{/*DependenceType=*/depType}; + if (inp.v) { +return common::visit( +[](auto &&s) { return Update{/*DependenceType=*/makeDepType(s)}; }, +inp.v->u); + } else { +return Update{/*DependenceType=*/std::nullopt}; + } } Use make(const parser::OmpClause::Use &inp, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e631922a354c4..bfca4e3f1730a 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -836,9 +836,9 @@ TYPE_PARSER(construct( TYPE_PARSER(construct(Parser{}, maybe(":" >> nonemptyList(Parser{} -TYPE_PARSER(construct( -construct(Parser{}) || -construct(Parser{}))) +TYPE_PARSER( // +construct(parenthesized(Parser{})) || +construct(parenthesized(Parser{}))) TYPE_PARSER(construct( maybe(nonemptyList(Parser{}) / ":"), @@ -1079,7 +1079,7 @@ TYPE_PARSER( // parenthesized(nonemptyList(name || "UNTIED" >> construct(construct()) || "UPDATE" >> construct(construct( -parenthesized(Parser{}))) || +maybe(Parser{}))) || "WHEN" >> construct(construct( parenthesized(Parser{}))) || // Cancellable constructs @@ -1313,24 +1313,30 @@ TYPE_PARSER( endOfLine) // Directives enclosing structured-block -TYPE_PARSER(construct(first( -"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), -"MASTER" >> pure(llvm::omp::Directive::OMPD_master), -"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), -"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked), -"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master), -"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), -"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), -"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope), -"SINGLE" >> pure(llvm::omp::Directive::OMPD_single), -"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), -"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), -"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), -"TARGET" >> pure(llvm::omp::Direct
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Allow UPDATE clause to not have any arguments (PR #137521)
llvmbot wrote: @llvm/pr-subscribers-flang-fir-hlfir Author: Krzysztof Parzyszek (kparzysz) Changes The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that. --- Full diff: https://github.com/llvm/llvm-project/pull/137521.diff 5 Files Affected: - (modified) flang/include/flang/Parser/parse-tree.h (+5) - (modified) flang/lib/Lower/OpenMP/Clauses.cpp (+7-3) - (modified) flang/lib/Parser/openmp-parsers.cpp (+28-22) - (modified) flang/lib/Semantics/check-omp-structure.cpp (+12-4) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+1) ``diff diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index ca8473c6f9674..e39ecc13f4eec 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4501,6 +4501,11 @@ struct OmpToClause { // Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322] // +// In ATOMIC construct +// update-clause -> +//UPDATE// Since 4.5 +// +// In DEPOBJ construct // update-clause -> //UPDATE(dependence-type) // since 5.0, until 5.1 // update-clause -> diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index f1330b8d1909f..c258bef2e4427 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -1400,9 +1400,13 @@ Uniform make(const parser::OmpClause::Uniform &inp, Update make(const parser::OmpClause::Update &inp, semantics::SemanticsContext &semaCtx) { // inp.v -> parser::OmpUpdateClause - auto depType = - common::visit([](auto &&s) { return makeDepType(s); }, inp.v.u); - return Update{/*DependenceType=*/depType}; + if (inp.v) { +return common::visit( +[](auto &&s) { return Update{/*DependenceType=*/makeDepType(s)}; }, +inp.v->u); + } else { +return Update{/*DependenceType=*/std::nullopt}; + } } Use make(const parser::OmpClause::Use &inp, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e631922a354c4..bfca4e3f1730a 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -836,9 +836,9 @@ TYPE_PARSER(construct( TYPE_PARSER(construct(Parser{}, maybe(":" >> nonemptyList(Parser{} -TYPE_PARSER(construct( -construct(Parser{}) || -construct(Parser{}))) +TYPE_PARSER( // +construct(parenthesized(Parser{})) || +construct(parenthesized(Parser{}))) TYPE_PARSER(construct( maybe(nonemptyList(Parser{}) / ":"), @@ -1079,7 +1079,7 @@ TYPE_PARSER( // parenthesized(nonemptyList(name || "UNTIED" >> construct(construct()) || "UPDATE" >> construct(construct( -parenthesized(Parser{}))) || +maybe(Parser{}))) || "WHEN" >> construct(construct( parenthesized(Parser{}))) || // Cancellable constructs @@ -1313,24 +1313,30 @@ TYPE_PARSER( endOfLine) // Directives enclosing structured-block -TYPE_PARSER(construct(first( -"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), -"MASTER" >> pure(llvm::omp::Directive::OMPD_master), -"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), -"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked), -"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master), -"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), -"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), -"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope), -"SINGLE" >> pure(llvm::omp::Directive::OMPD_single), -"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), -"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), -"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), -"TARGET" >> pure(llvm::omp::Directive::OMPD_target), -"TASK"_id >> pure(llvm::omp::Directive::OMPD_task), -"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), -"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), -"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare +TYPE_PARSER( +// In this context "TARGET UPDATE" can be parsed as a TARGET directive +// followed by an UPDATE clause. This is the only combination at the +// moment, exclude it explicitly. +(!"TARGET UPDATE"_sptok) >= +construct(first( +"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), +"MASTER" >> pure(llvm::omp::Directive::OM
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Allow UPDATE clause to not have any arguments (PR #137521)
llvmbot wrote: @llvm/pr-subscribers-flang-openmp Author: Krzysztof Parzyszek (kparzysz) Changes The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that. --- Full diff: https://github.com/llvm/llvm-project/pull/137521.diff 5 Files Affected: - (modified) flang/include/flang/Parser/parse-tree.h (+5) - (modified) flang/lib/Lower/OpenMP/Clauses.cpp (+7-3) - (modified) flang/lib/Parser/openmp-parsers.cpp (+28-22) - (modified) flang/lib/Semantics/check-omp-structure.cpp (+12-4) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+1) ``diff diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index ca8473c6f9674..e39ecc13f4eec 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4501,6 +4501,11 @@ struct OmpToClause { // Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322] // +// In ATOMIC construct +// update-clause -> +//UPDATE// Since 4.5 +// +// In DEPOBJ construct // update-clause -> //UPDATE(dependence-type) // since 5.0, until 5.1 // update-clause -> diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index f1330b8d1909f..c258bef2e4427 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -1400,9 +1400,13 @@ Uniform make(const parser::OmpClause::Uniform &inp, Update make(const parser::OmpClause::Update &inp, semantics::SemanticsContext &semaCtx) { // inp.v -> parser::OmpUpdateClause - auto depType = - common::visit([](auto &&s) { return makeDepType(s); }, inp.v.u); - return Update{/*DependenceType=*/depType}; + if (inp.v) { +return common::visit( +[](auto &&s) { return Update{/*DependenceType=*/makeDepType(s)}; }, +inp.v->u); + } else { +return Update{/*DependenceType=*/std::nullopt}; + } } Use make(const parser::OmpClause::Use &inp, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e631922a354c4..bfca4e3f1730a 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -836,9 +836,9 @@ TYPE_PARSER(construct( TYPE_PARSER(construct(Parser{}, maybe(":" >> nonemptyList(Parser{} -TYPE_PARSER(construct( -construct(Parser{}) || -construct(Parser{}))) +TYPE_PARSER( // +construct(parenthesized(Parser{})) || +construct(parenthesized(Parser{}))) TYPE_PARSER(construct( maybe(nonemptyList(Parser{}) / ":"), @@ -1079,7 +1079,7 @@ TYPE_PARSER( // parenthesized(nonemptyList(name || "UNTIED" >> construct(construct()) || "UPDATE" >> construct(construct( -parenthesized(Parser{}))) || +maybe(Parser{}))) || "WHEN" >> construct(construct( parenthesized(Parser{}))) || // Cancellable constructs @@ -1313,24 +1313,30 @@ TYPE_PARSER( endOfLine) // Directives enclosing structured-block -TYPE_PARSER(construct(first( -"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), -"MASTER" >> pure(llvm::omp::Directive::OMPD_master), -"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), -"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked), -"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master), -"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), -"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), -"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope), -"SINGLE" >> pure(llvm::omp::Directive::OMPD_single), -"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), -"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), -"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), -"TARGET" >> pure(llvm::omp::Directive::OMPD_target), -"TASK"_id >> pure(llvm::omp::Directive::OMPD_task), -"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), -"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), -"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare +TYPE_PARSER( +// In this context "TARGET UPDATE" can be parsed as a TARGET directive +// followed by an UPDATE clause. This is the only combination at the +// moment, exclude it explicitly. +(!"TARGET UPDATE"_sptok) >= +construct(first( +"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), +"MASTER" >> pure(llvm::omp::Directive::OMPD_
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Allow UPDATE clause to not have any arguments (PR #137521)
llvmbot wrote: @llvm/pr-subscribers-flang-semantics Author: Krzysztof Parzyszek (kparzysz) Changes The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that. --- Full diff: https://github.com/llvm/llvm-project/pull/137521.diff 5 Files Affected: - (modified) flang/include/flang/Parser/parse-tree.h (+5) - (modified) flang/lib/Lower/OpenMP/Clauses.cpp (+7-3) - (modified) flang/lib/Parser/openmp-parsers.cpp (+28-22) - (modified) flang/lib/Semantics/check-omp-structure.cpp (+12-4) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+1) ``diff diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index ca8473c6f9674..e39ecc13f4eec 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4501,6 +4501,11 @@ struct OmpToClause { // Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322] // +// In ATOMIC construct +// update-clause -> +//UPDATE// Since 4.5 +// +// In DEPOBJ construct // update-clause -> //UPDATE(dependence-type) // since 5.0, until 5.1 // update-clause -> diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index f1330b8d1909f..c258bef2e4427 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -1400,9 +1400,13 @@ Uniform make(const parser::OmpClause::Uniform &inp, Update make(const parser::OmpClause::Update &inp, semantics::SemanticsContext &semaCtx) { // inp.v -> parser::OmpUpdateClause - auto depType = - common::visit([](auto &&s) { return makeDepType(s); }, inp.v.u); - return Update{/*DependenceType=*/depType}; + if (inp.v) { +return common::visit( +[](auto &&s) { return Update{/*DependenceType=*/makeDepType(s)}; }, +inp.v->u); + } else { +return Update{/*DependenceType=*/std::nullopt}; + } } Use make(const parser::OmpClause::Use &inp, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e631922a354c4..bfca4e3f1730a 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -836,9 +836,9 @@ TYPE_PARSER(construct( TYPE_PARSER(construct(Parser{}, maybe(":" >> nonemptyList(Parser{} -TYPE_PARSER(construct( -construct(Parser{}) || -construct(Parser{}))) +TYPE_PARSER( // +construct(parenthesized(Parser{})) || +construct(parenthesized(Parser{}))) TYPE_PARSER(construct( maybe(nonemptyList(Parser{}) / ":"), @@ -1079,7 +1079,7 @@ TYPE_PARSER( // parenthesized(nonemptyList(name || "UNTIED" >> construct(construct()) || "UPDATE" >> construct(construct( -parenthesized(Parser{}))) || +maybe(Parser{}))) || "WHEN" >> construct(construct( parenthesized(Parser{}))) || // Cancellable constructs @@ -1313,24 +1313,30 @@ TYPE_PARSER( endOfLine) // Directives enclosing structured-block -TYPE_PARSER(construct(first( -"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), -"MASTER" >> pure(llvm::omp::Directive::OMPD_master), -"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), -"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked), -"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master), -"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), -"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), -"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope), -"SINGLE" >> pure(llvm::omp::Directive::OMPD_single), -"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), -"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), -"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), -"TARGET" >> pure(llvm::omp::Directive::OMPD_target), -"TASK"_id >> pure(llvm::omp::Directive::OMPD_task), -"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), -"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), -"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare +TYPE_PARSER( +// In this context "TARGET UPDATE" can be parsed as a TARGET directive +// followed by an UPDATE clause. This is the only combination at the +// moment, exclude it explicitly. +(!"TARGET UPDATE"_sptok) >= +construct(first( +"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), +"MASTER" >> pure(llvm::omp::Directive::OM
[llvm-branch-commits] [flang] [flang][OpenACC][OpenMP] Separate implementations of ATOMIC constructs (PR #137517)
kparzysz wrote: Previous PR: https://github.com/llvm/llvm-project/pull/137460 Next PR: https://github.com/llvm/llvm-project/pull/137521 https://github.com/llvm/llvm-project/pull/137517 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Allow UPDATE clause to not have any arguments (PR #137521)
kparzysz wrote: Previous PR: https://github.com/llvm/llvm-project/pull/137517 https://github.com/llvm/llvm-project/pull/137521 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenACC][OpenMP] Separate implementations of ATOMIC constructs (PR #137517)
https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/137517 The OpenMP implementation of the ATOMIC construct will change in the near future to accommodate OpenMP 6.0. This patch separates the shared implementations to avoid interfering with OpenACC. >From 69869a7673c62a5b47e20c532b6e438e929d212c Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sat, 26 Apr 2025 10:08:58 -0500 Subject: [PATCH] [flang][OpenACC][OpenMP] Separate implementations of ATOMIC constructs The OpenMP implementation of the ATOMIC construct will change in the near future to accommodate OpenMP 6.0. This patch separates the shared implementations to avoid interfering with OpenACC. --- flang/include/flang/Lower/DirectivesCommon.h | 514 --- flang/lib/Lower/OpenACC.cpp | 320 +++- flang/lib/Lower/OpenMP/OpenMP.cpp| 473 - 3 files changed, 767 insertions(+), 540 deletions(-) diff --git a/flang/include/flang/Lower/DirectivesCommon.h b/flang/include/flang/Lower/DirectivesCommon.h index d1dbaefcd81d0..93ab2e350d035 100644 --- a/flang/include/flang/Lower/DirectivesCommon.h +++ b/flang/include/flang/Lower/DirectivesCommon.h @@ -46,520 +46,6 @@ namespace Fortran { namespace lower { -/// Populates \p hint and \p memoryOrder with appropriate clause information -/// if present on atomic construct. -static inline void genOmpAtomicHintAndMemoryOrderClauses( -Fortran::lower::AbstractConverter &converter, -const Fortran::parser::OmpAtomicClauseList &clauseList, -mlir::IntegerAttr &hint, -mlir::omp::ClauseMemoryOrderKindAttr &memoryOrder) { - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - for (const Fortran::parser::OmpAtomicClause &clause : clauseList.v) { -common::visit( -common::visitors{ -[&](const parser::OmpMemoryOrderClause &s) { - auto kind = common::visit( - common::visitors{ - [&](const parser::OmpClause::AcqRel &) { -return mlir::omp::ClauseMemoryOrderKind::Acq_rel; - }, - [&](const parser::OmpClause::Acquire &) { -return mlir::omp::ClauseMemoryOrderKind::Acquire; - }, - [&](const parser::OmpClause::Relaxed &) { -return mlir::omp::ClauseMemoryOrderKind::Relaxed; - }, - [&](const parser::OmpClause::Release &) { -return mlir::omp::ClauseMemoryOrderKind::Release; - }, - [&](const parser::OmpClause::SeqCst &) { -return mlir::omp::ClauseMemoryOrderKind::Seq_cst; - }, - [&](auto &&) -> mlir::omp::ClauseMemoryOrderKind { -llvm_unreachable("Unexpected clause"); - }, - }, - s.v.u); - memoryOrder = mlir::omp::ClauseMemoryOrderKindAttr::get( - firOpBuilder.getContext(), kind); -}, -[&](const parser::OmpHintClause &s) { - const auto *expr = Fortran::semantics::GetExpr(s.v); - uint64_t hintExprValue = *Fortran::evaluate::ToInt64(*expr); - hint = firOpBuilder.getI64IntegerAttr(hintExprValue); -}, -[&](const parser::OmpFailClause &) {}, -}, -clause.u); - } -} - -template -static void processOmpAtomicTODO(mlir::Type elementType, - [[maybe_unused]] mlir::Location loc) { - if (!elementType) -return; - if constexpr (std::is_same()) { -assert(fir::isa_trivial(fir::unwrapRefType(elementType)) && - "is supported type for omp atomic"); - } -} - -/// Used to generate atomic.read operation which is created in existing -/// location set by builder. -template -static inline void genOmpAccAtomicCaptureStatement( -Fortran::lower::AbstractConverter &converter, mlir::Value fromAddress, -mlir::Value toAddress, -[[maybe_unused]] const AtomicListT *leftHandClauseList, -[[maybe_unused]] const AtomicListT *rightHandClauseList, -mlir::Type elementType, mlir::Location loc) { - // Generate `atomic.read` operation for atomic assigment statements - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - - processOmpAtomicTODO(elementType, loc); - - if constexpr (std::is_same()) { -// If no hint clause is specified, the effect is as if -// hint(omp_sync_hint_none) had been specified. -mlir::IntegerAttr hint = nullptr; - -mlir::omp::ClauseMemoryOrderKindAttr memoryOrder = nullptr; -if (leftHandClauseList) - genOmpAtomicHintAndMemoryOrderClauses(converter, *leftHandClauseList, -hint, memoryOrder); -if (rightHandClauseList) - genOmpAtomicHintAndMemoryOrderClauses(conv
[llvm-branch-commits] [flang] [flang][OpenACC][OpenMP] Separate implementations of ATOMIC constructs (PR #137517)
llvmbot wrote: @llvm/pr-subscribers-openacc Author: Krzysztof Parzyszek (kparzysz) Changes The OpenMP implementation of the ATOMIC construct will change in the near future to accommodate OpenMP 6.0. This patch separates the shared implementations to avoid interfering with OpenACC. --- Patch is 64.93 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137517.diff 3 Files Affected: - (modified) flang/include/flang/Lower/DirectivesCommon.h (-514) - (modified) flang/lib/Lower/OpenACC.cpp (+308-12) - (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+459-14) ``diff diff --git a/flang/include/flang/Lower/DirectivesCommon.h b/flang/include/flang/Lower/DirectivesCommon.h index d1dbaefcd81d0..93ab2e350d035 100644 --- a/flang/include/flang/Lower/DirectivesCommon.h +++ b/flang/include/flang/Lower/DirectivesCommon.h @@ -46,520 +46,6 @@ namespace Fortran { namespace lower { -/// Populates \p hint and \p memoryOrder with appropriate clause information -/// if present on atomic construct. -static inline void genOmpAtomicHintAndMemoryOrderClauses( -Fortran::lower::AbstractConverter &converter, -const Fortran::parser::OmpAtomicClauseList &clauseList, -mlir::IntegerAttr &hint, -mlir::omp::ClauseMemoryOrderKindAttr &memoryOrder) { - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - for (const Fortran::parser::OmpAtomicClause &clause : clauseList.v) { -common::visit( -common::visitors{ -[&](const parser::OmpMemoryOrderClause &s) { - auto kind = common::visit( - common::visitors{ - [&](const parser::OmpClause::AcqRel &) { -return mlir::omp::ClauseMemoryOrderKind::Acq_rel; - }, - [&](const parser::OmpClause::Acquire &) { -return mlir::omp::ClauseMemoryOrderKind::Acquire; - }, - [&](const parser::OmpClause::Relaxed &) { -return mlir::omp::ClauseMemoryOrderKind::Relaxed; - }, - [&](const parser::OmpClause::Release &) { -return mlir::omp::ClauseMemoryOrderKind::Release; - }, - [&](const parser::OmpClause::SeqCst &) { -return mlir::omp::ClauseMemoryOrderKind::Seq_cst; - }, - [&](auto &&) -> mlir::omp::ClauseMemoryOrderKind { -llvm_unreachable("Unexpected clause"); - }, - }, - s.v.u); - memoryOrder = mlir::omp::ClauseMemoryOrderKindAttr::get( - firOpBuilder.getContext(), kind); -}, -[&](const parser::OmpHintClause &s) { - const auto *expr = Fortran::semantics::GetExpr(s.v); - uint64_t hintExprValue = *Fortran::evaluate::ToInt64(*expr); - hint = firOpBuilder.getI64IntegerAttr(hintExprValue); -}, -[&](const parser::OmpFailClause &) {}, -}, -clause.u); - } -} - -template -static void processOmpAtomicTODO(mlir::Type elementType, - [[maybe_unused]] mlir::Location loc) { - if (!elementType) -return; - if constexpr (std::is_same()) { -assert(fir::isa_trivial(fir::unwrapRefType(elementType)) && - "is supported type for omp atomic"); - } -} - -/// Used to generate atomic.read operation which is created in existing -/// location set by builder. -template -static inline void genOmpAccAtomicCaptureStatement( -Fortran::lower::AbstractConverter &converter, mlir::Value fromAddress, -mlir::Value toAddress, -[[maybe_unused]] const AtomicListT *leftHandClauseList, -[[maybe_unused]] const AtomicListT *rightHandClauseList, -mlir::Type elementType, mlir::Location loc) { - // Generate `atomic.read` operation for atomic assigment statements - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - - processOmpAtomicTODO(elementType, loc); - - if constexpr (std::is_same()) { -// If no hint clause is specified, the effect is as if -// hint(omp_sync_hint_none) had been specified. -mlir::IntegerAttr hint = nullptr; - -mlir::omp::ClauseMemoryOrderKindAttr memoryOrder = nullptr; -if (leftHandClauseList) - genOmpAtomicHintAndMemoryOrderClauses(converter, *leftHandClauseList, -hint, memoryOrder); -if (rightHandClauseList) - genOmpAtomicHintAndMemoryOrderClauses(converter, *rightHandClauseList, -hint, memoryOrder); -firOpBuilder.create( -loc, fromAddress, toAddress, mlir::TypeAttr::get(elementType), hint, -memoryOrder); - } else { -firOpBuilder.create( -loc, fromAddress, toAddress, mlir::TypeAttr::get(elementType)); -
[llvm-branch-commits] [flang] [flang][OpenACC][OpenMP] Separate implementations of ATOMIC constructs (PR #137517)
llvmbot wrote: @llvm/pr-subscribers-flang-fir-hlfir Author: Krzysztof Parzyszek (kparzysz) Changes The OpenMP implementation of the ATOMIC construct will change in the near future to accommodate OpenMP 6.0. This patch separates the shared implementations to avoid interfering with OpenACC. --- Patch is 64.93 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137517.diff 3 Files Affected: - (modified) flang/include/flang/Lower/DirectivesCommon.h (-514) - (modified) flang/lib/Lower/OpenACC.cpp (+308-12) - (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+459-14) ``diff diff --git a/flang/include/flang/Lower/DirectivesCommon.h b/flang/include/flang/Lower/DirectivesCommon.h index d1dbaefcd81d0..93ab2e350d035 100644 --- a/flang/include/flang/Lower/DirectivesCommon.h +++ b/flang/include/flang/Lower/DirectivesCommon.h @@ -46,520 +46,6 @@ namespace Fortran { namespace lower { -/// Populates \p hint and \p memoryOrder with appropriate clause information -/// if present on atomic construct. -static inline void genOmpAtomicHintAndMemoryOrderClauses( -Fortran::lower::AbstractConverter &converter, -const Fortran::parser::OmpAtomicClauseList &clauseList, -mlir::IntegerAttr &hint, -mlir::omp::ClauseMemoryOrderKindAttr &memoryOrder) { - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - for (const Fortran::parser::OmpAtomicClause &clause : clauseList.v) { -common::visit( -common::visitors{ -[&](const parser::OmpMemoryOrderClause &s) { - auto kind = common::visit( - common::visitors{ - [&](const parser::OmpClause::AcqRel &) { -return mlir::omp::ClauseMemoryOrderKind::Acq_rel; - }, - [&](const parser::OmpClause::Acquire &) { -return mlir::omp::ClauseMemoryOrderKind::Acquire; - }, - [&](const parser::OmpClause::Relaxed &) { -return mlir::omp::ClauseMemoryOrderKind::Relaxed; - }, - [&](const parser::OmpClause::Release &) { -return mlir::omp::ClauseMemoryOrderKind::Release; - }, - [&](const parser::OmpClause::SeqCst &) { -return mlir::omp::ClauseMemoryOrderKind::Seq_cst; - }, - [&](auto &&) -> mlir::omp::ClauseMemoryOrderKind { -llvm_unreachable("Unexpected clause"); - }, - }, - s.v.u); - memoryOrder = mlir::omp::ClauseMemoryOrderKindAttr::get( - firOpBuilder.getContext(), kind); -}, -[&](const parser::OmpHintClause &s) { - const auto *expr = Fortran::semantics::GetExpr(s.v); - uint64_t hintExprValue = *Fortran::evaluate::ToInt64(*expr); - hint = firOpBuilder.getI64IntegerAttr(hintExprValue); -}, -[&](const parser::OmpFailClause &) {}, -}, -clause.u); - } -} - -template -static void processOmpAtomicTODO(mlir::Type elementType, - [[maybe_unused]] mlir::Location loc) { - if (!elementType) -return; - if constexpr (std::is_same()) { -assert(fir::isa_trivial(fir::unwrapRefType(elementType)) && - "is supported type for omp atomic"); - } -} - -/// Used to generate atomic.read operation which is created in existing -/// location set by builder. -template -static inline void genOmpAccAtomicCaptureStatement( -Fortran::lower::AbstractConverter &converter, mlir::Value fromAddress, -mlir::Value toAddress, -[[maybe_unused]] const AtomicListT *leftHandClauseList, -[[maybe_unused]] const AtomicListT *rightHandClauseList, -mlir::Type elementType, mlir::Location loc) { - // Generate `atomic.read` operation for atomic assigment statements - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - - processOmpAtomicTODO(elementType, loc); - - if constexpr (std::is_same()) { -// If no hint clause is specified, the effect is as if -// hint(omp_sync_hint_none) had been specified. -mlir::IntegerAttr hint = nullptr; - -mlir::omp::ClauseMemoryOrderKindAttr memoryOrder = nullptr; -if (leftHandClauseList) - genOmpAtomicHintAndMemoryOrderClauses(converter, *leftHandClauseList, -hint, memoryOrder); -if (rightHandClauseList) - genOmpAtomicHintAndMemoryOrderClauses(converter, *rightHandClauseList, -hint, memoryOrder); -firOpBuilder.create( -loc, fromAddress, toAddress, mlir::TypeAttr::get(elementType), hint, -memoryOrder); - } else { -firOpBuilder.create( -loc, fromAddress, toAddress, mlir::TypeAttr::get(elementTy
[llvm-branch-commits] [llvm] [SelectionDAG][X86] Widen <2 x T> vector types for atomic load (PR #120598)
arsenm wrote: Can you stop making no-op updates to these PRs? If there is an update, there should be some reviewable change. Right now this is just spamming everyones notifications https://github.com/llvm/llvm-project/pull/120598 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [lldb] Fix SBTarget::ReadInstruction with flavor (PR #136034)
da-viper wrote: Fix crash when calling `SBTarget::GetInstruction()` with the flavor parameter. https://github.com/llvm/llvm-project/pull/136034 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Allow UPDATE clause to not have any arguments (PR #137521)
llvmbot wrote: @llvm/pr-subscribers-flang-parser Author: Krzysztof Parzyszek (kparzysz) Changes The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that. --- Full diff: https://github.com/llvm/llvm-project/pull/137521.diff 5 Files Affected: - (modified) flang/include/flang/Parser/parse-tree.h (+5) - (modified) flang/lib/Lower/OpenMP/Clauses.cpp (+7-3) - (modified) flang/lib/Parser/openmp-parsers.cpp (+28-22) - (modified) flang/lib/Semantics/check-omp-structure.cpp (+12-4) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+1) ``diff diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index ca8473c6f9674..e39ecc13f4eec 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4501,6 +4501,11 @@ struct OmpToClause { // Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322] // +// In ATOMIC construct +// update-clause -> +//UPDATE// Since 4.5 +// +// In DEPOBJ construct // update-clause -> //UPDATE(dependence-type) // since 5.0, until 5.1 // update-clause -> diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index f1330b8d1909f..c258bef2e4427 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -1400,9 +1400,13 @@ Uniform make(const parser::OmpClause::Uniform &inp, Update make(const parser::OmpClause::Update &inp, semantics::SemanticsContext &semaCtx) { // inp.v -> parser::OmpUpdateClause - auto depType = - common::visit([](auto &&s) { return makeDepType(s); }, inp.v.u); - return Update{/*DependenceType=*/depType}; + if (inp.v) { +return common::visit( +[](auto &&s) { return Update{/*DependenceType=*/makeDepType(s)}; }, +inp.v->u); + } else { +return Update{/*DependenceType=*/std::nullopt}; + } } Use make(const parser::OmpClause::Use &inp, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e631922a354c4..bfca4e3f1730a 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -836,9 +836,9 @@ TYPE_PARSER(construct( TYPE_PARSER(construct(Parser{}, maybe(":" >> nonemptyList(Parser{} -TYPE_PARSER(construct( -construct(Parser{}) || -construct(Parser{}))) +TYPE_PARSER( // +construct(parenthesized(Parser{})) || +construct(parenthesized(Parser{}))) TYPE_PARSER(construct( maybe(nonemptyList(Parser{}) / ":"), @@ -1079,7 +1079,7 @@ TYPE_PARSER( // parenthesized(nonemptyList(name || "UNTIED" >> construct(construct()) || "UPDATE" >> construct(construct( -parenthesized(Parser{}))) || +maybe(Parser{}))) || "WHEN" >> construct(construct( parenthesized(Parser{}))) || // Cancellable constructs @@ -1313,24 +1313,30 @@ TYPE_PARSER( endOfLine) // Directives enclosing structured-block -TYPE_PARSER(construct(first( -"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), -"MASTER" >> pure(llvm::omp::Directive::OMPD_master), -"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), -"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked), -"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master), -"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), -"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), -"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope), -"SINGLE" >> pure(llvm::omp::Directive::OMPD_single), -"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), -"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), -"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), -"TARGET" >> pure(llvm::omp::Directive::OMPD_target), -"TASK"_id >> pure(llvm::omp::Directive::OMPD_task), -"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), -"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), -"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare +TYPE_PARSER( +// In this context "TARGET UPDATE" can be parsed as a TARGET directive +// followed by an UPDATE clause. This is the only combination at the +// moment, exclude it explicitly. +(!"TARGET UPDATE"_sptok) >= +construct(first( +"MASKED" >> pure(llvm::omp::Directive::OMPD_masked), +"MASTER" >> pure(llvm::omp::Directive::OMPD_