From 603904fa193c5096bbbdec8e39b9e73c6719f396 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 18 Dec 2025 10:23:57 -0600 Subject: [PATCH] [flang][OpenMP] Make OmpDependenceKind be a common enum, NFC (#172871) 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. --- flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp | 3 +-- flang/include/flang/Parser/dump-parse-tree.h | 2 +- flang/include/flang/Parser/parse-tree.h | 2 +- flang/include/flang/Support/Fortran.h | 3 +++ flang/lib/Parser/unparse.cpp | 7 ++----- flang/lib/Semantics/check-omp-structure.cpp | 5 ++--- flang/test/Parser/OpenMP/depobj-construct.f90 | 4 ++-- flang/test/Parser/OpenMP/interop-construct.f90 | 4 ++-- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp b/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp index fa9926155b33..d9cb10a35270 100644 --- a/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp +++ b/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp @@ -164,8 +164,7 @@ void OpenMPCounterVisitor::Post(const OmpOrderingModifier::Value &c) { "modifier=" + std::string{OmpOrderingModifier::EnumToString(c)} + ";"; } void OpenMPCounterVisitor::Post(const OmpTaskDependenceType::Value &c) { - clauseDetails += - "type=" + std::string{OmpTaskDependenceType::EnumToString(c)} + ";"; + clauseDetails += "type=" + std::string{common::EnumToString(c)} + ";"; } void OpenMPCounterVisitor::Post(const OmpMapType::Value &c) { clauseDetails += "type=" + std::string{OmpMapType::EnumToString(c)} + ";"; diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index dbc2b6541dd7..8527f0c54517 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -64,6 +64,7 @@ public: 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 @@ public: 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 0e108ccbe7ea..a31eb542a50d 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 cf39781c1e8a..5ca7882da32f 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 a8d2c0b0df81..19680dee7568 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2518,10 +2518,6 @@ public: #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 @@ public: 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 @@ public: 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 c005894bbfac..831d901d421a 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -2650,9 +2650,8 @@ 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)), - ThisVersion(version), TryVersion(since)); + 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 55807195c5fb..1497414125aa 100644 --- a/flang/test/Parser/OpenMP/depobj-construct.f90 +++ b/flang/test/Parser/OpenMP/depobj-construct.f90 @@ -15,7 +15,7 @@ end !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 @@ end !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 a80d06ae4d62..c46d15cff808 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 = {}