[flang-commits] [flang] c05b999 - [flang][OpenMP][NFC] Refactor code related to OpenMP atomic memory order clause semantics

Nimish Mishra via flang-commits flang-commits at lists.llvm.org
Sun Jun 19 10:06:30 PDT 2022


Author: Nimish Mishra
Date: 2022-06-19T22:36:40+05:30
New Revision: c05b99971fa042ae75c1848e6597c068392d693b

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

LOG: [flang][OpenMP][NFC] Refactor code related to OpenMP atomic memory order clause semantics

Reviewed By: peixin

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

Added: 
    

Modified: 
    flang/lib/Semantics/check-omp-structure.cpp
    flang/lib/Semantics/check-omp-structure.h

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 58ad55bde405f..ef68f77059b3c 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<Fortran::parser::OmpMemoryOrderClause>(&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<Fortran::parser::OmpMemoryOrderClause>(&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<Fortran::parser::OmpMemoryOrderClause>(&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<Fortran::parser::OmpMemoryOrderClause>(&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<parser::OmpAtomicClauseList>(atomicConstruct.t));
+                &std::get<parser::OmpAtomicClauseList>(atomicConstruct.t),
+                nullptr);
           },
-          [&](const parser::OmpAtomicUpdate &atomicConstruct) {
-            const auto &dir{std::get<parser::Verbatim>(atomicConstruct.t)};
+          [&](const parser::OmpAtomicUpdate &atomicUpdate) {
+            const auto &dir{std::get<parser::Verbatim>(atomicUpdate.t)};
             PushContextAndClauseSets(
                 dir.source, llvm::omp::Directive::OMPD_atomic);
             CheckAtomicUpdateAssignmentStmt(
                 std::get<parser::Statement<parser::AssignmentStmt>>(
-                    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<parser::Verbatim>(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 e959fb751cc99..a4748157d04fc 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -234,8 +234,7 @@ class OmpStructureChecker
   void CheckCycleConstraints(const parser::OpenMPLoopConstruct &x);
   template <typename T, typename D> 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);


        


More information about the flang-commits mailing list