[flang-commits] [flang] [flang][OpenMP] Make OmpDependenceKind be a common enum, NFC (PR #172871)

via flang-commits flang-commits at lists.llvm.org
Thu Dec 18 07:53:07 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-parser

Author: Krzysztof Parzyszek (kparzysz)

<details>
<summary>Changes</summary>

In OpenMP 6.0 a subset of the dependence types is also used in the `depinfo-modifier` on INIT clause. Make the enum be a common type to avoid defining separate enum types with mostly identical members.

Use the name `OmpDependenceKind` because the other obvious candidate, OmpDependenceType, used to be a modifier name in older OpenMP specs.

---
Full diff: https://github.com/llvm/llvm-project/pull/172871.diff


7 Files Affected:

- (modified) flang/include/flang/Parser/dump-parse-tree.h (+1-1) 
- (modified) flang/include/flang/Parser/parse-tree.h (+1-1) 
- (modified) flang/include/flang/Support/Fortran.h (+3) 
- (modified) flang/lib/Parser/unparse.cpp (+2-5) 
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+1-2) 
- (modified) flang/test/Parser/OpenMP/depobj-construct.f90 (+2-2) 
- (modified) flang/test/Parser/OpenMP/interop-construct.f90 (+2-2) 


``````````diff
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index dbc2b6541dd75..8527f0c545177 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -64,6 +64,7 @@ class ParseTreeDumper {
   NODE(std, uint64_t)
   NODE_ENUM(common, CUDADataAttr)
   NODE_ENUM(common, CUDASubprogramAttrs)
+  NODE_ENUM(common, OmpDependenceKind)
   NODE_ENUM(common, OmpMemoryOrderType)
   NODE_ENUM(common, OpenACCDeviceType)
   NODE(format, ControlEditDesc)
@@ -714,7 +715,6 @@ class ParseTreeDumper {
   NODE(parser, OmpStylizedInstance)
   NODE(OmpStylizedInstance, Instance)
   NODE(parser, OmpTaskDependenceType)
-  NODE_ENUM(OmpTaskDependenceType, Value)
   NODE(parser, OmpTaskReductionClause)
   NODE(OmpTaskReductionClause, Modifier)
   NODE(parser, OmpThreadLimitClause)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 0e108ccbe7ea9..a31eb542a50d0 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4256,7 +4256,7 @@ struct OmpStepSimpleModifier {
 //    MUTEXINOUTSET | DEPOBJ |                      // since 5.0
 //    INOUTSET                                      // since 5.2
 struct OmpTaskDependenceType {
-  ENUM_CLASS(Value, In, Out, Inout, Inoutset, Mutexinoutset, Depobj)
+  using Value = common::OmpDependenceKind;
   WRAPPER_CLASS_BOILERPLATE(OmpTaskDependenceType, Value);
 };
 
diff --git a/flang/include/flang/Support/Fortran.h b/flang/include/flang/Support/Fortran.h
index cf39781c1e8a7..5ca7882da32fd 100644
--- a/flang/include/flang/Support/Fortran.h
+++ b/flang/include/flang/Support/Fortran.h
@@ -72,6 +72,9 @@ ENUM_CLASS(
 ENUM_CLASS(
     OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)
 
+// OpenMP dependence kinds
+ENUM_CLASS(OmpDependenceKind, In, Out, Inout, Inoutset, Mutexinoutset, Depobj)
+
 // OpenMP memory-order types
 ENUM_CLASS(OmpMemoryOrderType, Acq_Rel, Acquire, Relaxed, Release, Seq_Cst)
 
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index a8d2c0b0df81a..19680dee7568d 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2518,10 +2518,6 @@ class UnparseVisitor {
 #include "llvm/Frontend/OpenMP/OMP.inc"
   void Unparse(const OmpObjectList &x) { Walk(x.v, ","); }
 
-  void Unparse(const common::OmpMemoryOrderType &x) {
-    Word(ToUpperCaseLetters(common::EnumToString(x)));
-  }
-
   void Unparse(const OmpBeginDirective &x) {
     BeginOpenMP();
     Word("!$OMP ");
@@ -2827,6 +2823,8 @@ class UnparseVisitor {
   WALK_NESTED_ENUM(common, TypeParamAttr) // R734
   WALK_NESTED_ENUM(common, CUDADataAttr) // CUDA
   WALK_NESTED_ENUM(common, CUDASubprogramAttrs) // CUDA
+  WALK_NESTED_ENUM(common, OmpDependenceKind)
+  WALK_NESTED_ENUM(common, OmpMemoryOrderType)
   WALK_NESTED_ENUM(IntentSpec, Intent) // R826
   WALK_NESTED_ENUM(ImplicitStmt, ImplicitNoneNameSpec) // R866
   WALK_NESTED_ENUM(ConnectSpec::CharExpr, Kind) // R1205
@@ -2848,7 +2846,6 @@ class UnparseVisitor {
   WALK_NESTED_ENUM(OmpChunkModifier, Value) // OMP chunk-modifier
   WALK_NESTED_ENUM(OmpLinearModifier, Value) // OMP linear-modifier
   WALK_NESTED_ENUM(OmpOrderingModifier, Value) // OMP ordering-modifier
-  WALK_NESTED_ENUM(OmpTaskDependenceType, Value) // OMP task-dependence-type
   WALK_NESTED_ENUM(OmpScheduleClause, Kind) // OMP schedule-kind
   WALK_NESTED_ENUM(OmpSeverityClause, SevLevel) // OMP severity
   WALK_NESTED_ENUM(OmpThreadsetClause, ThreadsetPolicy) // OMP threadset
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index c005894bbfacf..68c30d6b4f0e3 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2650,8 +2650,7 @@ void OmpStructureChecker::CheckTaskDependenceType(
   if (version < since) {
     context_.Say(GetContext().clauseSource,
         "%s task dependence type is not supported in %s, %s"_warn_en_US,
-        parser::ToUpperCaseLetters(
-            parser::OmpTaskDependenceType::EnumToString(x)),
+        parser::ToUpperCaseLetters(EnumToString(x)),
         ThisVersion(version), TryVersion(since));
   }
 }
diff --git a/flang/test/Parser/OpenMP/depobj-construct.f90 b/flang/test/Parser/OpenMP/depobj-construct.f90
index 55807195c5fbb..1497414125aac 100644
--- a/flang/test/Parser/OpenMP/depobj-construct.f90
+++ b/flang/test/Parser/OpenMP/depobj-construct.f90
@@ -15,7 +15,7 @@ subroutine f00
 !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = depobj
 !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'x'
 !PARSE-TREE: | OmpClauseList -> OmpClause -> Depend -> OmpDependClause -> TaskDep
-!PARSE-TREE: | | Modifier -> OmpTaskDependenceType -> Value = In
+!PARSE-TREE: | | Modifier -> OmpTaskDependenceType -> OmpDependenceKind = In
 !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'y'
 
 subroutine f01
@@ -31,7 +31,7 @@ subroutine f01
 !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPDepobjConstruct -> OmpDirectiveSpecification
 !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = depobj
 !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'x'
-!PARSE-TREE: | OmpClauseList -> OmpClause -> Update -> OmpUpdateClause -> OmpTaskDependenceType -> Value = Out
+!PARSE-TREE: | OmpClauseList -> OmpClause -> Update -> OmpUpdateClause -> OmpTaskDependenceType -> OmpDependenceKind = Out
 
 subroutine f02
   integer :: x
diff --git a/flang/test/Parser/OpenMP/interop-construct.f90 b/flang/test/Parser/OpenMP/interop-construct.f90
index a80d06ae4d627..c46d15cff8082 100644
--- a/flang/test/Parser/OpenMP/interop-construct.f90
+++ b/flang/test/Parser/OpenMP/interop-construct.f90
@@ -63,7 +63,7 @@ END SUBROUTINE test_interop_03
 !PARSE-TREE: | | Modifier -> OmpInteropType -> Value = Targetsync
 !PARSE-TREE: | | OmpObject -> Designator -> DataRef -> Name = 'obj'
 !PARSE-TREE: | OmpClause -> Depend -> OmpDependClause -> TaskDep
-!PARSE-TREE: | | Modifier -> OmpTaskDependenceType -> Value = Inout
+!PARSE-TREE: | | Modifier -> OmpTaskDependenceType -> OmpDependenceKind = Inout
 !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'obj'
 !PARSE-TREE: | Flags = {}
 
@@ -94,7 +94,7 @@ END SUBROUTINE test_interop_04
 !PARSE-TREE: | | Modifier -> OmpInteropType -> Value = Target
 !PARSE-TREE: | | OmpObject -> Designator -> DataRef -> Name = 'obj'
 !PARSE-TREE: | OmpClause -> Depend -> OmpDependClause -> TaskDep
-!PARSE-TREE: | | Modifier -> OmpTaskDependenceType -> Value = Inout
+!PARSE-TREE: | | Modifier -> OmpTaskDependenceType -> OmpDependenceKind = Inout
 !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'arr'
 !PARSE-TREE: | OmpClause -> Nowait
 !PARSE-TREE: | Flags = {}

``````````

</details>


https://github.com/llvm/llvm-project/pull/172871


More information about the flang-commits mailing list