From c05b99971fa042ae75c1848e6597c068392d693b Mon Sep 17 00:00:00 2001 From: Nimish Mishra Date: Wed, 15 Jun 2022 14:31:41 +0530 Subject: [PATCH] [flang][OpenMP][NFC] Refactor code related to OpenMP atomic memory order clause semantics Reviewed By: peixin Differential Revision: https://reviews.llvm.org/D127822 --- flang/lib/Semantics/check-omp-structure.cpp | 73 +++++++++++------------------ flang/lib/Semantics/check-omp-structure.h | 3 +- 2 files changed, 29 insertions(+), 47 deletions(-) diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 58ad55b..ef68f77 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -1543,46 +1543,28 @@ void OmpStructureChecker::CheckAtomicUpdateAssignmentStmt( } void OmpStructureChecker::CheckAtomicMemoryOrderClause( - const parser::OmpAtomicClauseList &clauseList) { + const parser::OmpAtomicClauseList *leftHandClauseList, + const parser::OmpAtomicClauseList *rightHandClauseList) { int numMemoryOrderClause = 0; - for (const auto &clause : clauseList.v) { - if (std::get_if(&clause.u)) { - numMemoryOrderClause++; - if (numMemoryOrderClause > 1) { - context_.Say(clause.source, - "More than one memory order clause not allowed on OpenMP " - "Atomic construct"_err_en_US); - return; - } - } - } -} - -void OmpStructureChecker::CheckAtomicMemoryOrderClause( - const parser::OmpAtomicClauseList &leftHandClauseList, - const parser::OmpAtomicClauseList &rightHandClauseList) { - int numMemoryOrderClause = 0; - for (const auto &clause : leftHandClauseList.v) { - if (std::get_if(&clause.u)) { - numMemoryOrderClause++; - if (numMemoryOrderClause > 1) { - context_.Say(clause.source, - "More than one memory order clause not allowed on " - "OpenMP Atomic construct"_err_en_US); - return; - } - } + auto checkForValidMemoryOrderClause = + [&](const parser::OmpAtomicClauseList *clauseList) { + for (const auto &clause : clauseList->v) { + if (std::get_if(&clause.u)) { + numMemoryOrderClause++; + if (numMemoryOrderClause > 1) { + context_.Say(clause.source, + "More than one memory order clause not allowed on " + "OpenMP Atomic construct"_err_en_US); + return; + } + } + } + }; + if (leftHandClauseList) { + checkForValidMemoryOrderClause(leftHandClauseList); } - for (const auto &clause : rightHandClauseList.v) { - if (std::get_if(&clause.u)) { - numMemoryOrderClause++; - if (numMemoryOrderClause > 1) { - context_.Say(clause.source, - "More than one memory order clause not " - "allowed on OpenMP Atomic construct"_err_en_US); - return; - } - } + if (rightHandClauseList) { + checkForValidMemoryOrderClause(rightHandClauseList); } } @@ -1598,25 +1580,26 @@ void OmpStructureChecker::Enter(const parser::OpenMPAtomicConstruct &x) { atomicConstruct.t) .statement); CheckAtomicMemoryOrderClause( - std::get(atomicConstruct.t)); + &std::get(atomicConstruct.t), + nullptr); }, - [&](const parser::OmpAtomicUpdate &atomicConstruct) { - const auto &dir{std::get(atomicConstruct.t)}; + [&](const parser::OmpAtomicUpdate &atomicUpdate) { + const auto &dir{std::get(atomicUpdate.t)}; PushContextAndClauseSets( dir.source, llvm::omp::Directive::OMPD_atomic); CheckAtomicUpdateAssignmentStmt( std::get>( - atomicConstruct.t) + atomicUpdate.t) .statement); CheckAtomicMemoryOrderClause( - std::get<0>(atomicConstruct.t), std::get<2>(atomicConstruct.t)); + &std::get<0>(atomicUpdate.t), &std::get<2>(atomicUpdate.t)); }, [&](const auto &atomicConstruct) { const auto &dir{std::get(atomicConstruct.t)}; PushContextAndClauseSets( dir.source, llvm::omp::Directive::OMPD_atomic); - CheckAtomicMemoryOrderClause( - std::get<0>(atomicConstruct.t), std::get<2>(atomicConstruct.t)); + CheckAtomicMemoryOrderClause(&std::get<0>(atomicConstruct.t), + &std::get<2>(atomicConstruct.t)); }, }, x.u); diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h index e959fb7..a474815 100644 --- a/flang/lib/Semantics/check-omp-structure.h +++ b/flang/lib/Semantics/check-omp-structure.h @@ -234,8 +234,7 @@ private: void CheckCycleConstraints(const parser::OpenMPLoopConstruct &x); template bool IsOperatorValid(const T &, const D &); void CheckAtomicMemoryOrderClause( - const parser::OmpAtomicClauseList &, const parser::OmpAtomicClauseList &); - void CheckAtomicMemoryOrderClause(const parser::OmpAtomicClauseList &); + const parser::OmpAtomicClauseList *, const parser::OmpAtomicClauseList *); void CheckAtomicUpdateAssignmentStmt(const parser::AssignmentStmt &); void CheckAtomicConstructStructure(const parser::OpenMPAtomicConstruct &); void CheckDistLinear(const parser::OpenMPLoopConstruct &x); -- 2.7.4