[flang-commits] [flang] f48969f - Revert "[Flang][Sema] Move directive sets to a shared location"

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Mon Aug 7 09:44:12 PDT 2023


Author: Kiran Chandramohan
Date: 2023-08-07T16:43:42Z
New Revision: f48969f90769f37e042025dba6c544eeddd6d3e6

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

LOG: Revert "[Flang][Sema] Move directive sets to a shared location"

This reverts commit ec70627dd17703a2a12ce0f28bd3794aa77d2058.

Reverting due to CI failure

Added: 
    

Modified: 
    clang/docs/tools/clang-formatted-files.txt
    flang/lib/Semantics/check-omp-structure.cpp
    flang/lib/Semantics/check-omp-structure.h
    flang/lib/Semantics/resolve-directives.cpp

Removed: 
    flang/include/flang/Semantics/openmp-directive-sets.h


################################################################################
diff  --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt
index e22f01e8c150e1..27aab1e1305245 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -2185,8 +2185,6 @@ flang/include/flang/Runtime/time-intrinsic.h
 flang/include/flang/Runtime/transformational.h
 flang/include/flang/Runtime/type-code.h
 flang/include/flang/Semantics/attr.h
-flang/include/flang/Semantics/expression.h
-flang/include/flang/Semantics/openmp-directive-sets.h
 flang/include/flang/Semantics/runtime-type-info.h
 flang/include/flang/Semantics/scope.h
 flang/include/flang/Semantics/semantics.h

diff  --git a/flang/include/flang/Semantics/openmp-directive-sets.h b/flang/include/flang/Semantics/openmp-directive-sets.h
deleted file mode 100644
index 5ccd75842b878e..00000000000000
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ /dev/null
@@ -1,283 +0,0 @@
-//===-- include/flang/Semantics/openmp-directive-sets.h ---------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef FORTRAN_SEMANTICS_OPENMP_DIRECTIVE_SETS_H_
-#define FORTRAN_SEMANTICS_OPENMP_DIRECTIVE_SETS_H_
-
-#include "flang/Common/enum-set.h"
-#include "llvm/Frontend/OpenMP/OMPConstants.h"
-
-using OmpDirectiveSet = Fortran::common::EnumSet<llvm::omp::Directive,
-    llvm::omp::Directive_enumSize>;
-
-namespace llvm::omp {
-//===----------------------------------------------------------------------===//
-// Directive sets for single directives
-//===----------------------------------------------------------------------===//
-// - top<Directive>Set: The directive appears alone or as the first in a
-//   combined construct.
-// - all<Directive>Set: All standalone or combined uses of the directive.
-
-const inline OmpDirectiveSet topParallelSet{
-    Directive::OMPD_parallel,
-    Directive::OMPD_parallel_do,
-    Directive::OMPD_parallel_do_simd,
-    Directive::OMPD_parallel_sections,
-    Directive::OMPD_parallel_workshare,
-};
-
-const inline OmpDirectiveSet allParallelSet{
-    Directive::OMPD_distribute_parallel_do,
-    Directive::OMPD_distribute_parallel_do_simd,
-    Directive::OMPD_parallel,
-    Directive::OMPD_parallel_do,
-    Directive::OMPD_parallel_do_simd,
-    Directive::OMPD_parallel_sections,
-    Directive::OMPD_parallel_workshare,
-    Directive::OMPD_target_parallel,
-    Directive::OMPD_target_parallel_do,
-    Directive::OMPD_target_parallel_do_simd,
-    Directive::OMPD_target_teams_distribute_parallel_do,
-    Directive::OMPD_target_teams_distribute_parallel_do_simd,
-    Directive::OMPD_teams_distribute_parallel_do,
-    Directive::OMPD_teams_distribute_parallel_do_simd,
-};
-
-const inline OmpDirectiveSet topDoSet{
-    Directive::OMPD_do,
-    Directive::OMPD_do_simd,
-};
-
-const inline OmpDirectiveSet allDoSet{
-    Directive::OMPD_distribute_parallel_do,
-    Directive::OMPD_distribute_parallel_do_simd,
-    Directive::OMPD_parallel_do,
-    Directive::OMPD_parallel_do_simd,
-    Directive::OMPD_do,
-    Directive::OMPD_do_simd,
-    Directive::OMPD_target_parallel_do,
-    Directive::OMPD_target_parallel_do_simd,
-    Directive::OMPD_target_teams_distribute_parallel_do,
-    Directive::OMPD_target_teams_distribute_parallel_do_simd,
-    Directive::OMPD_teams_distribute_parallel_do,
-    Directive::OMPD_teams_distribute_parallel_do_simd,
-};
-
-const inline OmpDirectiveSet topTaskloopSet{
-    Directive::OMPD_taskloop,
-    Directive::OMPD_taskloop_simd,
-};
-
-const inline OmpDirectiveSet allTaskloopSet = topTaskloopSet;
-
-const inline OmpDirectiveSet topTargetSet{
-    Directive::OMPD_target,
-    Directive::OMPD_target_parallel,
-    Directive::OMPD_target_parallel_do,
-    Directive::OMPD_target_parallel_do_simd,
-    Directive::OMPD_target_simd,
-    Directive::OMPD_target_teams,
-    Directive::OMPD_target_teams_distribute,
-    Directive::OMPD_target_teams_distribute_parallel_do,
-    Directive::OMPD_target_teams_distribute_parallel_do_simd,
-    Directive::OMPD_target_teams_distribute_simd,
-};
-
-const inline OmpDirectiveSet allTargetSet = topTargetSet;
-
-const inline OmpDirectiveSet topSimdSet{
-    Directive::OMPD_simd,
-};
-
-const inline OmpDirectiveSet allSimdSet{
-    Directive::OMPD_distribute_parallel_do_simd,
-    Directive::OMPD_distribute_simd,
-    Directive::OMPD_do_simd,
-    Directive::OMPD_parallel_do_simd,
-    Directive::OMPD_simd,
-    Directive::OMPD_target_parallel_do_simd,
-    Directive::OMPD_target_simd,
-    Directive::OMPD_target_teams_distribute_parallel_do_simd,
-    Directive::OMPD_target_teams_distribute_simd,
-    Directive::OMPD_taskloop_simd,
-    Directive::OMPD_teams_distribute_parallel_do_simd,
-    Directive::OMPD_teams_distribute_simd,
-};
-
-const inline OmpDirectiveSet topTeamsSet{
-    Directive::OMPD_teams,
-    Directive::OMPD_teams_distribute,
-    Directive::OMPD_teams_distribute_parallel_do,
-    Directive::OMPD_teams_distribute_parallel_do_simd,
-    Directive::OMPD_teams_distribute_simd,
-};
-
-const inline OmpDirectiveSet allTeamsSet{
-    llvm::omp::OMPD_target_teams,
-    llvm::omp::OMPD_target_teams_distribute,
-    llvm::omp::OMPD_target_teams_distribute_parallel_do,
-    llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
-    llvm::omp::OMPD_target_teams_distribute_simd,
-    llvm::omp::OMPD_teams,
-    llvm::omp::OMPD_teams_distribute,
-    llvm::omp::OMPD_teams_distribute_parallel_do,
-    llvm::omp::OMPD_teams_distribute_parallel_do_simd,
-    llvm::omp::OMPD_teams_distribute_simd,
-};
-
-const inline OmpDirectiveSet topDistributeSet{
-    Directive::OMPD_distribute,
-    Directive::OMPD_distribute_parallel_do,
-    Directive::OMPD_distribute_parallel_do_simd,
-    Directive::OMPD_distribute_simd,
-};
-
-const inline OmpDirectiveSet allDistributeSet{
-    llvm::omp::OMPD_distribute,
-    llvm::omp::OMPD_distribute_parallel_do,
-    llvm::omp::OMPD_distribute_parallel_do_simd,
-    llvm::omp::OMPD_distribute_simd,
-    llvm::omp::OMPD_target_teams_distribute,
-    llvm::omp::OMPD_target_teams_distribute_parallel_do,
-    llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
-    llvm::omp::OMPD_target_teams_distribute_simd,
-    llvm::omp::OMPD_teams_distribute,
-    llvm::omp::OMPD_teams_distribute_parallel_do,
-    llvm::omp::OMPD_teams_distribute_parallel_do_simd,
-    llvm::omp::OMPD_teams_distribute_simd,
-};
-
-//===----------------------------------------------------------------------===//
-// Directive sets for groups of multiple directives
-//===----------------------------------------------------------------------===//
-
-const inline OmpDirectiveSet allDoSimdSet = allDoSet & allSimdSet;
-
-const inline OmpDirectiveSet workShareSet{
-    OmpDirectiveSet{
-        Directive::OMPD_workshare,
-        Directive::OMPD_parallel_workshare,
-        Directive::OMPD_parallel_sections,
-        Directive::OMPD_sections,
-        Directive::OMPD_single,
-    } | allDoSet,
-};
-
-const inline OmpDirectiveSet taskGeneratingSet{
-    OmpDirectiveSet{
-        Directive::OMPD_task,
-    } | allTaskloopSet,
-};
-
-const inline OmpDirectiveSet nonPartialVarSet{
-    Directive::OMPD_allocate,
-    Directive::OMPD_allocators,
-    Directive::OMPD_threadprivate,
-    Directive::OMPD_declare_target,
-};
-
-//===----------------------------------------------------------------------===//
-// Directive sets for allowed/not allowed nested directives
-//===----------------------------------------------------------------------===//
-
-const inline OmpDirectiveSet nestedOrderedErrSet{
-    Directive::OMPD_critical,
-    Directive::OMPD_ordered,
-    Directive::OMPD_atomic,
-    Directive::OMPD_task,
-    Directive::OMPD_taskloop,
-};
-
-const inline OmpDirectiveSet nestedWorkshareErrSet{
-    OmpDirectiveSet{
-        Directive::OMPD_task,
-        Directive::OMPD_taskloop,
-        Directive::OMPD_critical,
-        Directive::OMPD_ordered,
-        Directive::OMPD_atomic,
-        Directive::OMPD_master,
-    } | workShareSet,
-};
-
-const inline OmpDirectiveSet nestedMasterErrSet{
-    OmpDirectiveSet{
-        Directive::OMPD_atomic,
-    } | taskGeneratingSet |
-        workShareSet,
-};
-
-const inline OmpDirectiveSet nestedBarrierErrSet{
-    OmpDirectiveSet{
-        Directive::OMPD_critical,
-        Directive::OMPD_ordered,
-        Directive::OMPD_atomic,
-        Directive::OMPD_master,
-    } | taskGeneratingSet |
-        workShareSet,
-};
-
-const inline OmpDirectiveSet nestedTeamsAllowedSet{
-    Directive::OMPD_parallel,
-    Directive::OMPD_parallel_do,
-    Directive::OMPD_parallel_do_simd,
-    Directive::OMPD_parallel_master,
-    Directive::OMPD_parallel_master_taskloop,
-    Directive::OMPD_parallel_master_taskloop_simd,
-    Directive::OMPD_parallel_sections,
-    Directive::OMPD_parallel_workshare,
-    Directive::OMPD_distribute,
-    Directive::OMPD_distribute_parallel_do,
-    Directive::OMPD_distribute_parallel_do_simd,
-    Directive::OMPD_distribute_simd,
-};
-
-const inline OmpDirectiveSet nestedOrderedParallelErrSet{
-    Directive::OMPD_parallel,
-    Directive::OMPD_target_parallel,
-    Directive::OMPD_parallel_sections,
-    Directive::OMPD_parallel_workshare,
-};
-
-const inline OmpDirectiveSet nestedOrderedDoAllowedSet{
-    Directive::OMPD_do,
-    Directive::OMPD_parallel_do,
-    Directive::OMPD_target_parallel_do,
-};
-
-const inline OmpDirectiveSet nestedCancelTaskgroupAllowedSet{
-    Directive::OMPD_task,
-    Directive::OMPD_taskloop,
-};
-
-const inline OmpDirectiveSet nestedCancelSectionsAllowedSet{
-    Directive::OMPD_sections,
-    Directive::OMPD_parallel_sections,
-};
-
-const inline OmpDirectiveSet nestedCancelDoAllowedSet{
-    Directive::OMPD_do,
-    Directive::OMPD_distribute_parallel_do,
-    Directive::OMPD_parallel_do,
-    Directive::OMPD_target_parallel_do,
-    Directive::OMPD_target_teams_distribute_parallel_do,
-    Directive::OMPD_teams_distribute_parallel_do,
-};
-
-const inline OmpDirectiveSet nestedCancelParallelAllowedSet{
-    Directive::OMPD_parallel,
-    Directive::OMPD_target_parallel,
-};
-
-const inline OmpDirectiveSet nestedReduceWorkshareAllowedSet{
-    Directive::OMPD_do,
-    Directive::OMPD_sections,
-    Directive::OMPD_do_simd,
-};
-} // namespace llvm::omp
-
-#endif // FORTRAN_SEMANTICS_OPENMP_DIRECTIVE_SETS_H_

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 7a04d28bfa8ad1..0accfa5083a9d6 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -161,7 +161,7 @@ bool OmpStructureChecker::IsCloselyNestedRegion(const OmpDirectiveSet &set) {
     while (index != -1) {
       if (set.test(dirContext_[index].directive)) {
         return true;
-      } else if (llvm::omp::allParallelSet.test(dirContext_[index].directive)) {
+      } else if (llvm::omp::parallelSet.test(dirContext_[index].directive)) {
         return false;
       }
       index--;
@@ -251,15 +251,23 @@ bool OmpStructureChecker::HasInvalidWorksharingNesting(
 void OmpStructureChecker::HasInvalidDistributeNesting(
     const parser::OpenMPLoopConstruct &x) {
   bool violation{false};
+
+  OmpDirectiveSet distributeSet{llvm::omp::Directive::OMPD_distribute,
+      llvm::omp::Directive::OMPD_distribute_parallel_do,
+      llvm::omp::Directive::OMPD_distribute_parallel_do_simd,
+      llvm::omp::Directive::OMPD_distribute_parallel_for,
+      llvm::omp::Directive::OMPD_distribute_parallel_for_simd,
+      llvm::omp::Directive::OMPD_distribute_simd};
+
   const auto &beginLoopDir{std::get<parser::OmpBeginLoopDirective>(x.t)};
   const auto &beginDir{std::get<parser::OmpLoopDirective>(beginLoopDir.t)};
-  if (llvm::omp::topDistributeSet.test(beginDir.v)) {
+  if (distributeSet.test(beginDir.v)) {
     // `distribute` region has to be nested
     if (!CurrentDirectiveIsNested()) {
       violation = true;
     } else {
       // `distribute` region has to be strictly nested inside `teams`
-      if (!llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
+      if (!llvm::omp::teamSet.test(GetContextParent().directive)) {
         violation = true;
       }
     }
@@ -273,7 +281,24 @@ void OmpStructureChecker::HasInvalidDistributeNesting(
 
 void OmpStructureChecker::HasInvalidTeamsNesting(
     const llvm::omp::Directive &dir, const parser::CharBlock &source) {
-  if (!llvm::omp::nestedTeamsAllowedSet.test(dir)) {
+  OmpDirectiveSet allowedSet{llvm::omp::Directive::OMPD_parallel,
+      llvm::omp::Directive::OMPD_parallel_do,
+      llvm::omp::Directive::OMPD_parallel_do_simd,
+      llvm::omp::Directive::OMPD_parallel_for,
+      llvm::omp::Directive::OMPD_parallel_for_simd,
+      llvm::omp::Directive::OMPD_parallel_master,
+      llvm::omp::Directive::OMPD_parallel_master_taskloop,
+      llvm::omp::Directive::OMPD_parallel_master_taskloop_simd,
+      llvm::omp::Directive::OMPD_parallel_sections,
+      llvm::omp::Directive::OMPD_parallel_workshare,
+      llvm::omp::Directive::OMPD_distribute,
+      llvm::omp::Directive::OMPD_distribute_parallel_do,
+      llvm::omp::Directive::OMPD_distribute_parallel_do_simd,
+      llvm::omp::Directive::OMPD_distribute_parallel_for,
+      llvm::omp::Directive::OMPD_distribute_parallel_for_simd,
+      llvm::omp::Directive::OMPD_distribute_simd};
+
+  if (!allowedSet.test(dir)) {
     context_.Say(source,
         "Only `DISTRIBUTE` or `PARALLEL` regions are allowed to be strictly "
         "nested inside `TEAMS` region."_err_en_US);
@@ -396,7 +421,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
   }
 
   PushContextAndClauseSets(beginDir.source, beginDir.v);
-  if (llvm::omp::allSimdSet.test(GetContext().directive)) {
+  if (llvm::omp::simdSet.test(GetContext().directive)) {
     EnterDirectiveNest(SIMDNest);
   }
 
@@ -426,7 +451,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
   CheckCycleConstraints(x);
   HasInvalidDistributeNesting(x);
   if (CurrentDirectiveIsNested() &&
-      llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
+      llvm::omp::teamSet.test(GetContextParent().directive)) {
     HasInvalidTeamsNesting(beginDir.v, beginDir.source);
   }
   if ((beginDir.v == llvm::omp::Directive::OMPD_distribute_parallel_do_simd) ||
@@ -725,7 +750,7 @@ void OmpStructureChecker::CheckDistLinear(
 }
 
 void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &) {
-  if (llvm::omp::allSimdSet.test(GetContext().directive)) {
+  if (llvm::omp::simdSet.test(GetContext().directive)) {
     ExitDirectiveNest(SIMDNest);
   }
   dirContext_.pop_back();
@@ -762,7 +787,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
   }
 
   if (CurrentDirectiveIsNested()) {
-    if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
+    if (llvm::omp::teamSet.test(GetContextParent().directive)) {
       HasInvalidTeamsNesting(beginDir.v, beginDir.source);
     }
     if (GetContext().directive == llvm::omp::Directive::OMPD_master) {
@@ -846,6 +871,10 @@ void OmpStructureChecker::ChecksOnOrderedAsBlock() {
     return;
   }
 
+  OmpDirectiveSet notAllowedParallelSet{llvm::omp::Directive::OMPD_parallel,
+      llvm::omp::Directive::OMPD_target_parallel,
+      llvm::omp::Directive::OMPD_parallel_sections,
+      llvm::omp::Directive::OMPD_parallel_workshare};
   bool isNestedInDo{false};
   bool isNestedInDoSIMD{false};
   bool isNestedInSIMD{false};
@@ -859,10 +888,9 @@ void OmpStructureChecker::ChecksOnOrderedAsBlock() {
             "`ORDERED` region may not be closely nested inside of `CRITICAL`, "
             "`ORDERED`, explicit `TASK` or `TASKLOOP` region."_err_en_US);
         break;
-      } else if (llvm::omp::allDoSet.test(dirContext_[i].directive)) {
+      } else if (llvm::omp::doSet.test(dirContext_[i].directive)) {
         isNestedInDo = true;
-        isNestedInDoSIMD =
-            llvm::omp::allDoSimdSet.test(dirContext_[i].directive);
+        isNestedInDoSIMD = llvm::omp::doSimdSet.test(dirContext_[i].directive);
         if (const auto *clause{
                 FindClause(dirContext_[i], llvm::omp::Clause::OMPC_ordered)}) {
           const auto &orderedClause{
@@ -873,11 +901,10 @@ void OmpStructureChecker::ChecksOnOrderedAsBlock() {
           noOrderedClause = true;
         }
         break;
-      } else if (llvm::omp::allSimdSet.test(dirContext_[i].directive)) {
+      } else if (llvm::omp::simdSet.test(dirContext_[i].directive)) {
         isNestedInSIMD = true;
         break;
-      } else if (llvm::omp::nestedOrderedParallelErrSet.test(
-                     dirContext_[i].directive)) {
+      } else if (notAllowedParallelSet.test(dirContext_[i].directive)) {
         isCloselyNestedRegion = false;
         break;
       }
@@ -1313,9 +1340,12 @@ void OmpStructureChecker::ChecksOnOrderedAsStandalone() {
     }
   }
 
+  OmpDirectiveSet allowedDoSet{llvm::omp::Directive::OMPD_do,
+      llvm::omp::Directive::OMPD_parallel_do,
+      llvm::omp::Directive::OMPD_target_parallel_do};
   bool isNestedInDoOrderedWithPara{false};
   if (CurrentDirectiveIsNested() &&
-      llvm::omp::nestedOrderedDoAllowedSet.test(GetContextParent().directive)) {
+      allowedDoSet.test(GetContextParent().directive)) {
     if (const auto *clause{
             FindClause(GetContextParent(), llvm::omp::Clause::OMPC_ordered)}) {
       const auto &orderedClause{
@@ -1473,11 +1503,24 @@ void OmpStructureChecker::CheckCancellationNest(
     // cancellation construct must be closely nested inside an OpenMP construct
     // that matches the type specified in construct-type-clause of the
     // cancellation construct.
+
+    OmpDirectiveSet allowedTaskgroupSet{
+        llvm::omp::Directive::OMPD_task, llvm::omp::Directive::OMPD_taskloop};
+    OmpDirectiveSet allowedSectionsSet{llvm::omp::Directive::OMPD_sections,
+        llvm::omp::Directive::OMPD_parallel_sections};
+    OmpDirectiveSet allowedDoSet{llvm::omp::Directive::OMPD_do,
+        llvm::omp::Directive::OMPD_distribute_parallel_do,
+        llvm::omp::Directive::OMPD_parallel_do,
+        llvm::omp::Directive::OMPD_target_parallel_do,
+        llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do,
+        llvm::omp::Directive::OMPD_teams_distribute_parallel_do};
+    OmpDirectiveSet allowedParallelSet{llvm::omp::Directive::OMPD_parallel,
+        llvm::omp::Directive::OMPD_target_parallel};
+
     bool eligibleCancellation{false};
     switch (type) {
     case parser::OmpCancelType::Type::Taskgroup:
-      if (llvm::omp::nestedCancelTaskgroupAllowedSet.test(
-              GetContextParent().directive)) {
+      if (allowedTaskgroupSet.test(GetContextParent().directive)) {
         eligibleCancellation = true;
         if (dirContext_.size() >= 3) {
           // Check if the cancellation region is closely nested inside a
@@ -1490,8 +1533,7 @@ void OmpStructureChecker::CheckCancellationNest(
                   llvm::omp::Directive::OMPD_taskgroup) {
                 break;
               }
-              if (llvm::omp::nestedCancelParallelAllowedSet.test(
-                      dirContext_[i].directive)) {
+              if (allowedParallelSet.test(dirContext_[i].directive)) {
                 eligibleCancellation = false;
                 break;
               }
@@ -1510,20 +1552,17 @@ void OmpStructureChecker::CheckCancellationNest(
       }
       return;
     case parser::OmpCancelType::Type::Sections:
-      if (llvm::omp::nestedCancelSectionsAllowedSet.test(
-              GetContextParent().directive)) {
+      if (allowedSectionsSet.test(GetContextParent().directive)) {
         eligibleCancellation = true;
       }
       break;
     case Fortran::parser::OmpCancelType::Type::Do:
-      if (llvm::omp::nestedCancelDoAllowedSet.test(
-              GetContextParent().directive)) {
+      if (allowedDoSet.test(GetContextParent().directive)) {
         eligibleCancellation = true;
       }
       break;
     case parser::OmpCancelType::Type::Parallel:
-      if (llvm::omp::nestedCancelParallelAllowedSet.test(
-              GetContextParent().directive)) {
+      if (allowedParallelSet.test(GetContextParent().directive)) {
         eligibleCancellation = true;
       }
       break;
@@ -1780,7 +1819,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPAtomicConstruct &) {
 
 void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
   // 2.7.1 Loop Construct Restriction
-  if (llvm::omp::allDoSet.test(GetContext().directive)) {
+  if (llvm::omp::doSet.test(GetContext().directive)) {
     if (auto *clause{FindClause(llvm::omp::Clause::OMPC_schedule)}) {
       // only one schedule clause is allowed
       const auto &schedClause{std::get<parser::OmpClause::Schedule>(clause->u)};
@@ -1831,7 +1870,7 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
   } // doSet
 
   // 2.8.1 Simd Construct Restriction
-  if (llvm::omp::allSimdSet.test(GetContext().directive)) {
+  if (llvm::omp::simdSet.test(GetContext().directive)) {
     if (auto *clause{FindClause(llvm::omp::Clause::OMPC_simdlen)}) {
       if (auto *clause2{FindClause(llvm::omp::Clause::OMPC_safelen)}) {
         const auto &simdlenClause{
@@ -2072,7 +2111,9 @@ void OmpStructureChecker::CheckReductionTypeList(
   CheckReductionArraySection(ompObjectList);
   // If this is a worksharing construct then ensure the reduction variable
   // is not private in the parallel region that it binds to.
-  if (llvm::omp::nestedReduceWorkshareAllowedSet.test(GetContext().directive)) {
+  OmpDirectiveSet workshareSet{llvm::omp::Directive::OMPD_do,
+      llvm::omp::Directive::OMPD_sections, llvm::omp::Directive::OMPD_do_simd};
+  if (workshareSet.test(GetContext().directive)) {
     CheckSharedBindingInOuterContext(ompObjectList);
   }
 }
@@ -2168,7 +2209,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
   if (const auto &expr{x.v}) {
     RequiresConstantPositiveParameter(llvm::omp::Clause::OMPC_ordered, *expr);
     // 2.8.3 Loop SIMD Construct Restriction
-    if (llvm::omp::allDoSimdSet.test(GetContext().directive)) {
+    if (llvm::omp::doSimdSet.test(GetContext().directive)) {
       context_.Say(GetContext().clauseSource,
           "No ORDERED clause with a parameter can be specified "
           "on the %s directive"_err_en_US,
@@ -2209,6 +2250,10 @@ bool OmpStructureChecker::IsDataRefTypeParamInquiry(
 
 void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
     const parser::CharBlock &source, const parser::OmpObjectList &objList) {
+  OmpDirectiveSet nonPartialVarSet{llvm::omp::Directive::OMPD_allocate,
+      llvm::omp::Directive::OMPD_allocators,
+      llvm::omp::Directive::OMPD_threadprivate,
+      llvm::omp::Directive::OMPD_declare_target};
   for (const auto &ompObject : objList.v) {
     common::visit(
         common::visitors{
@@ -2223,8 +2268,7 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
                 } else if (parser::Unwrap<parser::StructureComponent>(
                                ompObject) ||
                     parser::Unwrap<parser::ArrayElement>(ompObject)) {
-                  if (llvm::omp::nonPartialVarSet.test(
-                          GetContext().directive)) {
+                  if (nonPartialVarSet.test(GetContext().directive)) {
                     context_.Say(source,
                         "A variable that is part of another variable (as an "
                         "array or structure element) cannot appear on the %s "
@@ -2353,10 +2397,22 @@ void OmpStructureChecker::Enter(const parser::OmpClause::If &x) {
   using dirNameModifier = parser::OmpIfClause::DirectiveNameModifier;
   // TODO Check that, when multiple 'if' clauses are applied to a combined
   // construct, at most one of them applies to each directive.
+  // Need to define set here because llvm::omp::teamSet does not include target
+  // teams combined constructs.
+  OmpDirectiveSet teamSet{llvm::omp::Directive::OMPD_target_teams,
+      llvm::omp::Directive::OMPD_target_teams_distribute,
+      llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do,
+      llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do_simd,
+      llvm::omp::Directive::OMPD_target_teams_distribute_simd,
+      llvm::omp::Directive::OMPD_teams,
+      llvm::omp::Directive::OMPD_teams_distribute,
+      llvm::omp::Directive::OMPD_teams_distribute_parallel_do,
+      llvm::omp::Directive::OMPD_teams_distribute_parallel_do_simd,
+      llvm::omp::Directive::OMPD_teams_distribute_simd};
   static std::unordered_map<dirNameModifier, OmpDirectiveSet>
-      dirNameModifierMap{{dirNameModifier::Parallel, llvm::omp::allParallelSet},
-          {dirNameModifier::Simd, llvm::omp::allSimdSet},
-          {dirNameModifier::Target, llvm::omp::allTargetSet},
+      dirNameModifierMap{{dirNameModifier::Parallel, llvm::omp::parallelSet},
+          {dirNameModifier::Simd, llvm::omp::simdSet},
+          {dirNameModifier::Target, llvm::omp::targetSet},
           {dirNameModifier::TargetData,
               {llvm::omp::Directive::OMPD_target_data}},
           {dirNameModifier::TargetEnterData,
@@ -2366,8 +2422,8 @@ void OmpStructureChecker::Enter(const parser::OmpClause::If &x) {
           {dirNameModifier::TargetUpdate,
               {llvm::omp::Directive::OMPD_target_update}},
           {dirNameModifier::Task, {llvm::omp::Directive::OMPD_task}},
-          {dirNameModifier::Taskloop, llvm::omp::allTaskloopSet},
-          {dirNameModifier::Teams, llvm::omp::allTeamsSet}};
+          {dirNameModifier::Taskloop, llvm::omp::taskloopSet},
+          {dirNameModifier::Teams, teamSet}};
   if (const auto &directiveName{
           std::get<std::optional<dirNameModifier>>(x.v.t)}) {
     auto search{dirNameModifierMap.find(*directiveName)};
@@ -2388,8 +2444,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
   CheckAllowed(llvm::omp::Clause::OMPC_linear);
 
   // 2.7 Loop Construct Restriction
-  if ((llvm::omp::allDoSet | llvm::omp::allSimdSet)
-          .test(GetContext().directive)) {
+  if ((llvm::omp::doSet | llvm::omp::simdSet).test(GetContext().directive)) {
     if (std::holds_alternative<parser::OmpLinearClause::WithModifier>(x.v.u)) {
       context_.Say(GetContext().clauseSource,
           "A modifier may not be specified in a LINEAR clause "
@@ -2469,7 +2524,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Schedule &x) {
   const parser::OmpScheduleClause &scheduleClause = x.v;
 
   // 2.7 Loop Construct Restriction
-  if (llvm::omp::allDoSet.test(GetContext().directive)) {
+  if (llvm::omp::doSet.test(GetContext().directive)) {
     const auto &kind{std::get<1>(scheduleClause.t)};
     const auto &chunk{std::get<2>(scheduleClause.t)};
     if (chunk) {
@@ -2886,6 +2941,13 @@ void OmpStructureChecker::CheckWorkshareBlockStmts(
         // Check if OpenMP constructs enclosed in the Workshare construct are
         // 'Parallel' constructs
         auto currentDir{llvm::omp::Directive::OMPD_unknown};
+        const OmpDirectiveSet parallelDirSet{
+            llvm::omp::Directive::OMPD_parallel,
+            llvm::omp::Directive::OMPD_parallel_do,
+            llvm::omp::Directive::OMPD_parallel_sections,
+            llvm::omp::Directive::OMPD_parallel_workshare,
+            llvm::omp::Directive::OMPD_parallel_do_simd};
+
         if (const auto *ompBlockConstruct{
                 std::get_if<parser::OpenMPBlockConstruct>(&ompConstruct->u)}) {
           const auto &beginBlockDir{
@@ -2912,7 +2974,7 @@ void OmpStructureChecker::CheckWorkshareBlockStmts(
           currentDir = beginDir.v;
         }
 
-        if (!llvm::omp::topParallelSet.test(currentDir)) {
+        if (!parallelDirSet.test(currentDir)) {
           context_.Say(source,
               "OpenMP constructs enclosed in WORKSHARE construct may consist "
               "of ATOMIC, CRITICAL or PARALLEL constructs only"_err_en_US);

diff  --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index d165834196aefc..3b5de101fe0793 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -17,10 +17,12 @@
 #include "check-directive-structure.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Parser/parse-tree.h"
-#include "flang/Semantics/openmp-directive-sets.h"
 #include "flang/Semantics/semantics.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
+using OmpDirectiveSet = Fortran::common::EnumSet<llvm::omp::Directive,
+    llvm::omp::Directive_enumSize>;
+
 using OmpClauseSet =
     Fortran::common::EnumSet<llvm::omp::Clause, llvm::omp::Clause_enumSize>;
 
@@ -29,6 +31,74 @@ using OmpClauseSet =
 
 namespace llvm {
 namespace omp {
+static OmpDirectiveSet parallelSet{Directive::OMPD_distribute_parallel_do,
+    Directive::OMPD_distribute_parallel_do_simd, Directive::OMPD_parallel,
+    Directive::OMPD_parallel_do, Directive::OMPD_parallel_do_simd,
+    Directive::OMPD_parallel_sections, Directive::OMPD_parallel_workshare,
+    Directive::OMPD_target_parallel, Directive::OMPD_target_parallel_do,
+    Directive::OMPD_target_parallel_do_simd,
+    Directive::OMPD_target_teams_distribute_parallel_do,
+    Directive::OMPD_target_teams_distribute_parallel_do_simd,
+    Directive::OMPD_teams_distribute_parallel_do,
+    Directive::OMPD_teams_distribute_parallel_do_simd};
+static OmpDirectiveSet doSet{Directive::OMPD_distribute_parallel_do,
+    Directive::OMPD_distribute_parallel_do_simd, Directive::OMPD_parallel_do,
+    Directive::OMPD_parallel_do_simd, Directive::OMPD_do,
+    Directive::OMPD_do_simd, Directive::OMPD_target_parallel_do,
+    Directive::OMPD_target_parallel_do_simd,
+    Directive::OMPD_target_teams_distribute_parallel_do,
+    Directive::OMPD_target_teams_distribute_parallel_do_simd,
+    Directive::OMPD_teams_distribute_parallel_do,
+    Directive::OMPD_teams_distribute_parallel_do_simd};
+static OmpDirectiveSet doSimdSet{Directive::OMPD_distribute_parallel_do_simd,
+    Directive::OMPD_parallel_do_simd, Directive::OMPD_do_simd,
+    Directive::OMPD_target_parallel_do_simd,
+    Directive::OMPD_target_teams_distribute_parallel_do_simd,
+    Directive::OMPD_teams_distribute_parallel_do_simd};
+static OmpDirectiveSet workShareSet{
+    OmpDirectiveSet{Directive::OMPD_workshare,
+        Directive::OMPD_parallel_workshare, Directive::OMPD_parallel_sections,
+        Directive::OMPD_sections, Directive::OMPD_single} |
+    doSet};
+static OmpDirectiveSet taskloopSet{
+    Directive::OMPD_taskloop, Directive::OMPD_taskloop_simd};
+static OmpDirectiveSet targetSet{Directive::OMPD_target,
+    Directive::OMPD_target_parallel, Directive::OMPD_target_parallel_do,
+    Directive::OMPD_target_parallel_do_simd, Directive::OMPD_target_simd,
+    Directive::OMPD_target_teams, Directive::OMPD_target_teams_distribute,
+    Directive::OMPD_target_teams_distribute_parallel_do,
+    Directive::OMPD_target_teams_distribute_parallel_do_simd,
+    Directive::OMPD_target_teams_distribute_simd};
+static OmpDirectiveSet simdSet{Directive::OMPD_distribute_parallel_do_simd,
+    Directive::OMPD_distribute_simd, Directive::OMPD_do_simd,
+    Directive::OMPD_parallel_do_simd, Directive::OMPD_simd,
+    Directive::OMPD_target_parallel_do_simd, Directive::OMPD_target_simd,
+    Directive::OMPD_target_teams_distribute_parallel_do_simd,
+    Directive::OMPD_target_teams_distribute_simd, Directive::OMPD_taskloop_simd,
+    Directive::OMPD_teams_distribute_parallel_do_simd,
+    Directive::OMPD_teams_distribute_simd};
+static OmpDirectiveSet teamSet{Directive::OMPD_teams,
+    Directive::OMPD_teams_distribute,
+    Directive::OMPD_teams_distribute_parallel_do,
+    Directive::OMPD_teams_distribute_parallel_do_simd,
+    Directive::OMPD_teams_distribute_simd};
+static OmpDirectiveSet taskGeneratingSet{
+    OmpDirectiveSet{Directive::OMPD_task} | taskloopSet};
+static OmpDirectiveSet nestedOrderedErrSet{Directive::OMPD_critical,
+    Directive::OMPD_ordered, Directive::OMPD_atomic, Directive::OMPD_task,
+    Directive::OMPD_taskloop};
+static OmpDirectiveSet nestedWorkshareErrSet{
+    OmpDirectiveSet{Directive::OMPD_task, Directive::OMPD_taskloop,
+        Directive::OMPD_critical, Directive::OMPD_ordered,
+        Directive::OMPD_atomic, Directive::OMPD_master} |
+    workShareSet};
+static OmpDirectiveSet nestedMasterErrSet{
+    OmpDirectiveSet{llvm::omp::Directive::OMPD_atomic} | taskGeneratingSet |
+    workShareSet};
+static OmpDirectiveSet nestedBarrierErrSet{
+    OmpDirectiveSet{Directive::OMPD_critical, Directive::OMPD_ordered,
+        Directive::OMPD_atomic, Directive::OMPD_master} |
+    taskGeneratingSet | workShareSet};
 static OmpClauseSet privateSet{
     Clause::OMPC_private, Clause::OMPC_firstprivate, Clause::OMPC_lastprivate};
 static OmpClauseSet privateReductionSet{

diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9146d0cbb8320f..f317b27f7b1eaa 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1362,7 +1362,7 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
     if (targetIt == dirContext_.rend()) {
       return;
     }
-    if (llvm::omp::allParallelSet.test(targetIt->directive) ||
+    if (llvm::omp::parallelSet.test(targetIt->directive) ||
         llvm::omp::taskGeneratingSet.test(targetIt->directive)) {
       break;
     }
@@ -1463,7 +1463,7 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
     return;
   }
   Symbol::Flag ivDSA;
-  if (!llvm::omp::allSimdSet.test(GetContext().directive)) {
+  if (!llvm::omp::simdSet.test(GetContext().directive)) {
     ivDSA = Symbol::Flag::OmpPrivate;
   } else if (level == 1) {
     ivDSA = Symbol::Flag::OmpLinear;


        


More information about the flang-commits mailing list