From 47ea37fe5360fc090669a745267f90601c82c40c Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 21 Oct 2025 13:31:16 -0500 Subject: [PATCH] [flang][OpenMP] Rename some AST classes to follow spec naming, NFC Rename OmpTypeSpecifier to OmpTypeName, since it represents a type-name list item. Also, OpenMP 6.0 introduced type-specifier with a different meaning. Rename OmpReductionCombiner to OmpCombinerExpression. --- flang/examples/FeatureList/FeatureList.cpp | 2 +- flang/include/flang/Parser/dump-parse-tree.h | 4 +-- flang/include/flang/Parser/parse-tree.h | 25 ++++++++++--------- flang/lib/Parser/openmp-parsers.cpp | 12 ++++----- flang/lib/Parser/unparse.cpp | 4 +-- flang/lib/Semantics/resolve-names.cpp | 6 ++--- .../Parser/OpenMP/declare-reduction-multi.f90 | 16 ++++++------ .../OpenMP/declare-reduction-operator.f90 | 8 +++--- .../OpenMP/declare-reduction-unparse.f90 | 8 +++--- .../Parser/OpenMP/metadirective-dirspec.f90 | 6 ++--- .../OpenMP/openmp6-directive-spellings.f90 | 4 +-- 11 files changed, 48 insertions(+), 47 deletions(-) diff --git a/flang/examples/FeatureList/FeatureList.cpp b/flang/examples/FeatureList/FeatureList.cpp index daa012e3eb08b..225a6558ef956 100644 --- a/flang/examples/FeatureList/FeatureList.cpp +++ b/flang/examples/FeatureList/FeatureList.cpp @@ -451,6 +451,7 @@ struct NodeVisitor { READ_FEATURE(OmpBlockConstruct) READ_FEATURE(OmpClause) READ_FEATURE(OmpClauseList) + READ_FEATURE(OmpCombinerExpression) READ_FEATURE(OmpDefaultClause) READ_FEATURE(OmpDefaultClause::DataSharingAttribute) READ_FEATURE(OmpDefaultmapClause) @@ -496,7 +497,6 @@ struct NodeVisitor { READ_FEATURE(OmpProcBindClause::AffinityPolicy) READ_FEATURE(OmpReductionClause) READ_FEATURE(OmpInReductionClause) - READ_FEATURE(OmpReductionCombiner) READ_FEATURE(OmpInitializerClause) READ_FEATURE(OmpReductionIdentifier) READ_FEATURE(OmpAllocateClause) diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index 5677277a9b381..af8152deb8a52 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -538,6 +538,7 @@ class ParseTreeDumper { NODE(parser, OmpClauseList) NODE(parser, OmpCloseModifier) NODE_ENUM(OmpCloseModifier, Value) + NODE(parser, OmpCombinerExpression) NODE(parser, OmpContainsClause) NODE(parser, OmpContextSelectorSpecification) NODE(parser, OmpDeclareVariantDirective) @@ -655,7 +656,6 @@ class ParseTreeDumper { NODE_ENUM(OmpProcBindClause, AffinityPolicy) NODE(parser, OmpReductionClause) NODE(OmpReductionClause, Modifier) - NODE(parser, OmpReductionCombiner) NODE(parser, OmpReductionIdentifier) NODE(parser, OmpReductionModifier) NODE_ENUM(OmpReductionModifier, Value) @@ -693,8 +693,8 @@ class ParseTreeDumper { NODE(parser, OmpTraitSetSelectorName) NODE_ENUM(OmpTraitSetSelectorName, Value) NODE(parser, OmpTransparentClause) + NODE(parser, OmpTypeName) NODE(parser, OmpTypeNameList) - NODE(parser, OmpTypeSpecifier) NODE(parser, OmpUnifiedAddressClause) NODE(parser, OmpUnifiedSharedMemoryClause) NODE(parser, OmpUpdateClause) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 6dd4f2492cf22..be64ef3770c60 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3502,6 +3502,16 @@ struct OmpDirectiveName { llvm::omp::Directive v{llvm::omp::Directive::OMPD_unknown}; }; +// type-name list item +struct OmpTypeName { + UNION_CLASS_BOILERPLATE(OmpTypeName); + std::variant u; +}; + +struct OmpTypeNameList { + WRAPPER_CLASS_BOILERPLATE(OmpTypeNameList, std::list); +}; + // 2.1 Directives or clauses may accept a list or extended-list. // A list item is a variable, array section or common block name (enclosed // in slashes). An extended list item is a list item or a procedure Name. @@ -3539,21 +3549,12 @@ struct OmpReductionIdentifier { // combiner-expression -> // since 4.5 // assignment-statement | // function-reference -struct OmpReductionCombiner { - UNION_CLASS_BOILERPLATE(OmpReductionCombiner); +struct OmpCombinerExpression { + UNION_CLASS_BOILERPLATE(OmpCombinerExpression); std::variant u; }; inline namespace arguments { -struct OmpTypeSpecifier { - UNION_CLASS_BOILERPLATE(OmpTypeSpecifier); - std::variant u; -}; - -struct OmpTypeNameList { - WRAPPER_CLASS_BOILERPLATE(OmpTypeNameList, std::list); -}; - struct OmpLocator { UNION_CLASS_BOILERPLATE(OmpLocator); std::variant u; @@ -3596,7 +3597,7 @@ struct OmpMapperSpecifier { struct OmpReductionSpecifier { TUPLE_CLASS_BOILERPLATE(OmpReductionSpecifier); std::tuple> + std::optional> t; }; diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index c0472ad3c0692..d1e081cfd1b41 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -367,8 +367,8 @@ struct OmpArgumentListParser { }; TYPE_PARSER( // - construct(Parser{}) || - construct(Parser{})) + construct(Parser{}) || + construct(Parser{})) // 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list) TYPE_PARSER(construct(Parser{}) || @@ -376,8 +376,8 @@ TYPE_PARSER(construct(Parser{}) || TYPE_PARSER(construct( // Parser{}, - ":"_tok >> nonemptyList(Parser{}), - maybe(":"_tok >> Parser{}))) + ":"_tok >> nonemptyList(Parser{}), + maybe(":"_tok >> Parser{}))) // --- Parsers for context traits ------------------------------------- @@ -1832,8 +1832,8 @@ TYPE_PARSER(sourced(construct( IsDirective(llvm::omp::Directive::OMPD_declare_mapper)) >= Parser{}))) -TYPE_PARSER(construct(Parser{}) || - construct(Parser{})) +TYPE_PARSER(construct(Parser{}) || + construct(Parser{})) TYPE_PARSER(sourced(construct( OmpBlockConstructParser{llvm::omp::Directive::OMPD_critical}))) diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index b172e429c84e8..2f86c76c5fe03 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2111,7 +2111,7 @@ class UnparseVisitor { Walk(std::get(x.t)); Put(":"); Walk(std::get(x.t)); - Walk(": ", std::get>(x.t)); + Walk(": ", std::get>(x.t)); } void Unparse(const llvm::omp::Directive &x) { unsigned ompVersion{langOpts_.OpenMPVersion}; @@ -2519,7 +2519,7 @@ class UnparseVisitor { Walk(x.u); } } - void Unparse(const OmpReductionCombiner &x) { + void Unparse(const OmpCombinerExpression &x) { // Don't let the visitor go to the normal AssignmentStmt Unparse function, // it adds an extra newline that we don't want. if (const auto *assignment{std::get_if(&x.u)}) { diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index db75437708a6c..4af6cf6a91239 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -1772,11 +1772,11 @@ class OmpVisitor : public virtual DeclarationVisitor { messageHandler().set_currStmtSource(std::nullopt); } - bool Pre(const parser::OmpTypeSpecifier &x) { + bool Pre(const parser::OmpTypeName &x) { BeginDeclTypeSpec(); return true; } - void Post(const parser::OmpTypeSpecifier &x) { // + void Post(const parser::OmpTypeName &x) { // EndDeclTypeSpec(); } @@ -2007,7 +2007,7 @@ void OmpVisitor::ProcessReductionSpecifier( } } EndDeclTypeSpec(); - Walk(std::get>(spec.t)); + Walk(std::get>(spec.t)); Walk(clauses); PopScope(); } diff --git a/flang/test/Parser/OpenMP/declare-reduction-multi.f90 b/flang/test/Parser/OpenMP/declare-reduction-multi.f90 index 0af3ed6e78571..a682958eb9128 100644 --- a/flang/test/Parser/OpenMP/declare-reduction-multi.f90 +++ b/flang/test/Parser/OpenMP/declare-reduction-multi.f90 @@ -32,9 +32,9 @@ program omp_examples !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 'tt' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out%r=omp_out%r+omp_in%r' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out%r=omp_out%r+omp_in%r' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=0._4' !$omp declare reduction(*:tt:omp_out%r = omp_out%r * omp_in%r) initializer(omp_priv%r = 1) @@ -44,9 +44,9 @@ program omp_examples !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Multiply -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 'tt' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out%r=omp_out%r*omp_in%r' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out%r=omp_out%r*omp_in%r' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=1._4' !$omp declare reduction(max:tt:omp_out = mymax(omp_out, omp_in)) initializer(omp_priv%r = 0) @@ -56,9 +56,9 @@ program omp_examples !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> ProcedureDesignator -> Name = 'max' -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 'tt' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out=mymax(omp_out,omp_in)' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out=mymax(omp_out,omp_in)' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=0._4' !$omp declare reduction(min:tt:omp_out%r = min(omp_out%r, omp_in%r)) initializer(omp_priv%r = 1) @@ -68,9 +68,9 @@ program omp_examples !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> ProcedureDesignator -> Name = 'min' -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 'tt' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out%r=min(omp_out%r,omp_in%r)' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out%r=min(omp_out%r,omp_in%r)' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=1._4' call random_number(values%r) diff --git a/flang/test/Parser/OpenMP/declare-reduction-operator.f90 b/flang/test/Parser/OpenMP/declare-reduction-operator.f90 index 347588468617b..e4d07c8265b1e 100644 --- a/flang/test/Parser/OpenMP/declare-reduction-operator.f90 +++ b/flang/test/Parser/OpenMP/declare-reduction-operator.f90 @@ -22,9 +22,9 @@ subroutine reduce_1 ( n, tts ) !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 'tt' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out=tt(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out=tt(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv=tt(x=0_4,y=0_4)' !$omp declare reduction(+ : tt : omp_out = tt(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = tt(0,0)) @@ -36,9 +36,9 @@ subroutine reduce_1 ( n, tts ) !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 'tt2' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out=tt2(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out=tt2(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv=tt2(x=0._8,y=0._8)' !$omp declare reduction(+ :tt2 : omp_out = tt2(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = tt2(0,0)) diff --git a/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 b/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 index 7514f0cf83877..73d7ccf489f01 100644 --- a/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 +++ b/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 @@ -25,9 +25,9 @@ end subroutine initme !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> ProcedureDesignator -> Name = 'red_add' -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec -> KindSelector -> Scalar -> Integer -> Constant -> Expr = '4_4' +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec -> KindSelector -> Scalar -> Integer -> Constant -> Expr = '4_4' !PARSE-TREE: | | | LiteralConstant -> IntLiteralConstant = '4' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out=omp_out+omp_in' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out=omp_out+omp_in' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> OmpInitializerProc !PARSE-TREE: | | ProcedureDesignator -> Name = 'initme' @@ -73,6 +73,6 @@ end program main !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> ProcedureDesignator -> Name = 'my_add_red' -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec -> -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out=omp_out+omp_in' +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec -> +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out=omp_out+omp_in' !PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv=0_4' diff --git a/flang/test/Parser/OpenMP/metadirective-dirspec.f90 b/flang/test/Parser/OpenMP/metadirective-dirspec.f90 index baf969317c18f..c373001be8963 100644 --- a/flang/test/Parser/OpenMP/metadirective-dirspec.f90 +++ b/flang/test/Parser/OpenMP/metadirective-dirspec.f90 @@ -123,11 +123,11 @@ subroutine f03 !PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | | | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add -!PARSE-TREE: | | | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | | | Name = 'tt1' -!PARSE-TREE: | | | | OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | | | OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | | | Name = 'tt2' -!PARSE-TREE: | | | | OmpReductionCombiner -> AssignmentStmt = 'omp_out%x=omp_in%x+omp_out%x' +!PARSE-TREE: | | | | OmpCombinerExpression -> AssignmentStmt = 'omp_out%x=omp_in%x+omp_out%x' !PARSE-TREE: | | | | | | Designator -> DataRef -> StructureComponent !PARSE-TREE: | | | | | | | DataRef -> Name = 'omp_out' !PARSE-TREE: | | | | | | | Name = 'x' diff --git a/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 b/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 index f4cdd556bd4e5..39e8f059bbb24 100644 --- a/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 +++ b/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 @@ -86,9 +86,9 @@ subroutine f02 !PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction !PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier !PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add -!PARSE-TREE: | | OmpTypeNameList -> OmpTypeSpecifier -> TypeSpec -> DerivedTypeSpec +!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec !PARSE-TREE: | | | Name = 't' -!PARSE-TREE: | | OmpReductionCombiner -> AssignmentStmt = 'omp_out%x=omp_out%x+omp_in%x' +!PARSE-TREE: | | OmpCombinerExpression -> AssignmentStmt = 'omp_out%x=omp_out%x+omp_in%x' !PARSE-TREE: | | | Variable = 'omp_out%x' !PARSE-TREE: | | | | Designator -> DataRef -> StructureComponent !PARSE-TREE: | | | | | DataRef -> Name = 'omp_out'