From 66c18fa8a408d6ec0123f901566a03159d2eb593 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sat, 26 Jul 2025 09:47:03 -0500 Subject: [PATCH 1/6] [flang][OpenMP] Make OmpDirectiveNameModifier a distrinct type It was an alias for OmpDirectiveName, which could cause confusion in parse-tree visitors: a visitor for OmpDirectiveNameModifier could be executed for an OmpDirectiveName node, leading to unexpected results. --- flang/include/flang/Parser/parse-tree.h | 12 +++++++++++- flang/lib/Parser/openmp-parsers.cpp | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 3a28f6f9731c3..0fb66c9f683e4 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3469,6 +3469,12 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions +#define INHERITED_WRAPPER_CLASS_BOILERPLATE(classname, basename) \ + BOILERPLATE(classname); \ + classname(decltype(basename::v) &&x) : basename(std::move(x)) {} \ + classname(basename &&base) : basename(std::move(base)) {} \ + using WrapperTrait = std::true_type + struct OmpClause; struct OmpDirectiveSpecification; @@ -3476,6 +3482,7 @@ struct OmpDirectiveName { // No boilerplates: this class should be copyable, movable, etc. constexpr OmpDirectiveName() = default; constexpr OmpDirectiveName(const OmpDirectiveName &) = default; + constexpr OmpDirectiveName(llvm::omp::Directive x) : v(x) {} // Construct from an already parsed text. Use Verbatim for this because // Verbatim's source corresponds to an actual source location. // This allows "construct(Verbatim(""))". @@ -3848,7 +3855,10 @@ struct OmpDeviceModifier { // [*] The IF clause is allowed on CANCEL in OpenMP 4.5, but only without // the directive-name-modifier. For the sake of uniformity CANCEL can be // considered a valid value in 4.5 as well. -using OmpDirectiveNameModifier = OmpDirectiveName; +struct OmpDirectiveNameModifier : public OmpDirectiveName { + INHERITED_WRAPPER_CLASS_BOILERPLATE( + OmpDirectiveNameModifier, OmpDirectiveName); +}; // Ref: [5.1:205-209], [5.2:166-168] // diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 1c626148a03ae..9abec5aef8329 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -466,6 +466,8 @@ TYPE_PARSER(construct( "ANCESTOR" >> pure(OmpDeviceModifier::Value::Ancestor) || "DEVICE_NUM" >> pure(OmpDeviceModifier::Value::Device_Num))) +TYPE_PARSER(construct(OmpDirectiveNameParser{})) + TYPE_PARSER(construct( // "PRESENT" >> pure(OmpExpectation::Value::Present))) @@ -609,7 +611,8 @@ TYPE_PARSER(sourced(construct( TYPE_PARSER(sourced( construct(Parser{}))) -TYPE_PARSER(sourced(construct(OmpDirectiveNameParser{}))) +TYPE_PARSER(sourced( + construct(Parser{}))) TYPE_PARSER(sourced( construct( From 14dc21327817f681c7b62cb54fa5ceafb6ca9788 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sat, 26 Jul 2025 10:08:46 -0500 Subject: [PATCH 2/6] fix test --- flang/test/Examples/omp-atomic.f90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/test/Examples/omp-atomic.f90 b/flang/test/Examples/omp-atomic.f90 index 934f84f132484..5695b621e4bff 100644 --- a/flang/test/Examples/omp-atomic.f90 +++ b/flang/test/Examples/omp-atomic.f90 @@ -31,13 +31,13 @@ ! CHECK-NEXT: - clause: read ! CHECK-NEXT: details: '' ! CHECK-NEXT: - clause: seq_cst -! CHECK-NEXT: details: 'name_modifier=atomic;' +! CHECK-NEXT: details: '' ! CHECK-NEXT:- file: '{{[^"]*}}omp-atomic.f90' ! CHECK-NEXT: line: 12 ! CHECK-NEXT: construct: atomic ! CHECK-NEXT: clauses: ! CHECK-NEXT: - clause: seq_cst -! CHECK-NEXT: details: 'name_modifier=atomic;' +! CHECK-NEXT: details: '' ! CHECK-NEXT: - clause: write ! CHECK-NEXT: details: '' ! CHECK-NEXT:- file: '{{[^"]*}}omp-atomic.f90' @@ -45,7 +45,7 @@ ! CHECK-NEXT: construct: atomic ! CHECK-NEXT: clauses: ! CHECK-NEXT: - clause: capture -! CHECK-NEXT: details: 'name_modifier=atomic;name_modifier=atomic;' +! CHECK-NEXT: details: '' ! CHECK-NEXT: - clause: seq_cst ! CHECK-NEXT: details: '' ! CHECK-NEXT:- file: '{{[^"]*}}omp-atomic.f90' From 4f48c1cfef2a5e75055aaaa6a1a2bace5ae0c871 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 25 Jul 2025 13:30:31 -0500 Subject: [PATCH 3/6] [flang][OpenMP] Store directive information in OpenMPSectionConstruct The OpenMPSectionConstruct corresponds to `!$omp section` directive, but there is nothing in the AST node that stores the directive information. Even though the only possibility (at the moment) is "section" without any clauses, for improved generality it is helpful to have that information anyway. --- flang/examples/FeatureList/FeatureList.cpp | 1 - .../FlangOmpReport/FlangOmpReportVisitor.cpp | 57 +------ flang/include/flang/Parser/dump-parse-tree.h | 1 - flang/include/flang/Parser/openmp-utils.h | 8 + flang/include/flang/Parser/parse-tree.h | 13 +- flang/lib/Lower/OpenMP/OpenMP.cpp | 4 +- flang/lib/Parser/openmp-parsers.cpp | 54 +++++-- flang/lib/Parser/unparse.cpp | 14 +- flang/lib/Semantics/check-omp-structure.cpp | 9 +- flang/test/Examples/omp-sections.f90 | 4 +- flang/test/Parser/OpenMP/sections.f90 | 144 +++++++++++++----- 11 files changed, 183 insertions(+), 126 deletions(-) diff --git a/flang/examples/FeatureList/FeatureList.cpp b/flang/examples/FeatureList/FeatureList.cpp index e9aeed18ab0b7..64b57b633feaf 100644 --- a/flang/examples/FeatureList/FeatureList.cpp +++ b/flang/examples/FeatureList/FeatureList.cpp @@ -529,7 +529,6 @@ struct NodeVisitor { READ_FEATURE(OmpChunkModifier::Value) READ_FEATURE(OmpOrderingModifier) READ_FEATURE(OmpOrderingModifier::Value) - READ_FEATURE(OmpSectionBlocks) READ_FEATURE(OmpSectionsDirective) READ_FEATURE(Only) READ_FEATURE(OpenACCAtomicConstruct) diff --git a/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp b/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp index feb7b4eced9e9..5c64870b74be2 100644 --- a/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp +++ b/flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "FlangOmpReportVisitor.h" +#include "flang/Parser/openmp-utils.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Frontend/OpenMP/OMP.h" @@ -118,60 +119,8 @@ std::string OpenMPCounterVisitor::getName(const OpenMPDeclarativeConstruct &c) { c.u); } std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) { - return std::visit( - Fortran::common::visitors{ - [&](const OpenMPStandaloneConstruct &c) -> std::string { - return common::visit( - common::visitors{ - [&](const OmpMetadirectiveDirective &d) { - return normalize_construct_name(d.source.ToString()); - }, - [&](auto &&d) { - const CharBlock &source{ - std::get(d.v.t).source}; - return normalize_construct_name(source.ToString()); - }, - }, - c.u); - }, - [&](const OpenMPExecutableAllocate &c) -> std::string { - const CharBlock &source{std::get<0>(c.t).source}; - return normalize_construct_name(source.ToString()); - }, - [&](const OpenMPDeclarativeAllocate &c) -> std::string { - const CharBlock &source{std::get<0>(c.t).source}; - return normalize_construct_name(source.ToString()); - }, - [&](const OpenMPAssumeConstruct &c) -> std::string { - const CharBlock &source{std::get<0>(c.t).source}; - return normalize_construct_name(source.ToString()); - }, - [&](const OpenMPAllocatorsConstruct &c) -> std::string { - const CharBlock &source{std::get<0>(c.t).source}; - return normalize_construct_name(source.ToString()); - }, - [&](const OpenMPAtomicConstruct &c) -> std::string { - auto &dirSpec = std::get(c.t); - auto &dirName = std::get(dirSpec.t); - return normalize_construct_name(dirName.source.ToString()); - }, - [&](const OpenMPUtilityConstruct &c) -> std::string { - const CharBlock &source{c.source}; - return normalize_construct_name(source.ToString()); - }, - [&](const OpenMPSectionConstruct &c) -> std::string { - return "section"; - }, - // OpenMPSectionsConstruct, OpenMPLoopConstruct, - // OpenMPBlockConstruct, OpenMPCriticalConstruct Get the source from - // the directive field of the begin directive or from the verbatim - // field of the begin directive in Critical - [&](const auto &c) -> std::string { - const CharBlock &source{std::get<0>(std::get<0>(c.t).t).source}; - return normalize_construct_name(source.ToString()); - }, - }, - c.u); + return normalize_construct_name( + omp::GetOmpDirectiveName(c).source.ToString()); } bool OpenMPCounterVisitor::Pre(const OpenMPDeclarativeConstruct &c) { diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index 23e35d106c077..ebac54f6e29ba 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -681,7 +681,6 @@ class ParseTreeDumper { NODE_ENUM(OmpChunkModifier, Value) NODE(parser, OmpOrderingModifier) NODE_ENUM(OmpOrderingModifier, Value) - NODE(parser, OmpSectionBlocks) NODE(parser, OmpSectionsDirective) NODE(parser, OmpToClause) NODE(OmpToClause, Modifier) diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index 579ea7d74957f..41c04424e91c6 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -78,6 +78,14 @@ struct DirectiveNameScope { return MakeName(dir.source, dir.v); } + static OmpDirectiveName GetOmpDirectiveName(const OpenMPSectionConstruct &x) { + if (auto &spec{std::get>(x.t)}) { + return spec->DirName(); + } else { + return MakeName({}, llvm::omp::Directive::OMPD_section); + } + } + static OmpDirectiveName GetOmpDirectiveName( const OmpBeginSectionsDirective &x) { auto &dir{std::get(x.t)}; diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 0fb66c9f683e4..da0a3632b8a63 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4818,18 +4818,17 @@ struct OmpEndSectionsDirective { // structured-block] // ... struct OpenMPSectionConstruct { - WRAPPER_CLASS_BOILERPLATE(OpenMPSectionConstruct, Block); + TUPLE_CLASS_BOILERPLATE(OpenMPSectionConstruct); + std::tuple, Block> t; CharBlock source; }; -// `OmpSectionBlocks` is a list of section constructs. The parser guarentees -// that the `OpenMPConstruct` here always encapsulates an -// `OpenMPSectionConstruct` and not any other OpenMP construct. -WRAPPER_CLASS(OmpSectionBlocks, std::list); - struct OpenMPSectionsConstruct { TUPLE_CLASS_BOILERPLATE(OpenMPSectionsConstruct); - std::tuple, OmpEndSectionsDirective> t; }; diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 12089d6caa5fe..6dd4b16a1fb55 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -2329,7 +2329,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, assert(sectionsConstruct && "Missing additional parsing information"); const auto §ionBlocks = - std::get(sectionsConstruct->t); + std::get>(sectionsConstruct->t); mlir::omp::SectionsOperands clauseOps; llvm::SmallVector reductionSyms; genSectionsClauses(converter, semaCtx, item->clauses, loc, clauseOps, @@ -2382,7 +2382,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, // because we need to run genReductionVars on each omp.section so that the // reduction variable gets mapped to the private version for (auto [construct, nestedEval] : - llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) { + llvm::zip(sectionBlocks, eval.getNestedEvaluations())) { const auto *sectionConstruct = std::get_if(&construct.u); if (!sectionConstruct) { diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 9abec5aef8329..8c780388b9cb1 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -34,6 +34,39 @@ namespace Fortran::parser { constexpr auto startOmpLine = skipStuffBeforeStatement >> "!$OMP "_sptok; constexpr auto endOmpLine = space >> endOfLine; +// Given a parser for a single element, and a parser for a list of elements +// of the same type, create a parser that constructs the entire list by having +// the single element be the head of the list, and the rest be the tail. +template struct ConsParser { + static_assert(std::is_same_v, + typename ParserT::resultType>); + + using resultType = typename ParserT::resultType; + constexpr ConsParser(ParserH h, ParserT t) : head_(h), tail_(t) {} + + std::optional Parse(ParseState &state) const { + if (auto &&first{head_.Parse(state)}) { + if (auto rest{tail_.Parse(state)}) { + rest->push_front(std::move(*first)); + return std::move(*rest); + } + } + return std::nullopt; + } + +private: + const ParserH head_; + const ParserT tail_; +}; + +template , ValueT>>> +constexpr auto cons(ParserH head, ParserT tail) { + return ConsParser(head, tail); +} + // Given a parser P for a wrapper class, invoke P, and if it succeeds return // the wrapped object. template struct UnwrapParser { @@ -1831,19 +1864,20 @@ TYPE_PARSER( sourced("END"_tok >> Parser{}), Parser{}))) -// OMP SECTION-BLOCK - -TYPE_PARSER(construct(block)) - -TYPE_PARSER(maybe(startOmpLine >> "SECTION"_tok / endOmpLine) >> - construct(nonemptySeparated( - construct(sourced(Parser{})), - startOmpLine >> "SECTION"_tok / endOmpLine))) +static constexpr auto sectionDir{ + startOmpLine >> (predicated(OmpDirectiveNameParser{}, + IsDirective(llvm::omp::Directive::OMPD_section)) >= + Parser{})}; // OMP SECTIONS (OpenMP 5.0 - 2.8.1), PARALLEL SECTIONS (OpenMP 5.0 - 2.13.3) -TYPE_PARSER(construct( +TYPE_PARSER(sourced(construct( Parser{} / endOmpLine, - Parser{}, Parser{} / endOmpLine)) + cons( // + construct(sourced( + construct(maybe(sectionDir), block))), + many(construct( + sourced(construct(sectionDir, block))))), + Parser{} / endOmpLine))) static bool IsExecutionPart(const OmpDirectiveName &name) { return name.IsExecutionPart(); diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index fc15d46a8c727..1d4d53de1491d 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2801,16 +2801,16 @@ class UnparseVisitor { break; } } - void Unparse(const OmpSectionBlocks &x) { - for (const auto &y : x.v) { + void Unparse(const OpenMPSectionConstruct &x) { + if (auto &&dirSpec{ + std::get>(x.t)}) { BeginOpenMP(); - Word("!$OMP SECTION"); + Word("!$OMP "); + Walk(*dirSpec); Put("\n"); EndOpenMP(); - // y.u is an OpenMPSectionConstruct - // (y.u).v is Block - Walk(std::get(y.u).v, ""); } + Walk(std::get(x.t), ""); } void Unparse(const OpenMPSectionsConstruct &x) { BeginOpenMP(); @@ -2818,7 +2818,7 @@ class UnparseVisitor { Walk(std::get(x.t)); Put("\n"); EndOpenMP(); - Walk(std::get(x.t)); + Walk(std::get>(x.t), ""); BeginOpenMP(); Word("!$OMP END "); Walk(std::get(x.t)); diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index d214d222e7c90..c191ad8d088d3 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -1057,10 +1057,11 @@ void OmpStructureChecker::Enter(const parser::OpenMPSectionsConstruct &x) { PushContextAndClauseSets(beginDir.source, beginDir.v); AddEndDirectiveClauses(std::get(endSectionsDir.t)); - const auto §ionBlocks{std::get(x.t)}; - for (const parser::OpenMPConstruct &block : sectionBlocks.v) { - CheckNoBranching(std::get(block.u).v, - beginDir.v, beginDir.source); + const auto §ionBlocks{std::get>(x.t)}; + for (const parser::OpenMPConstruct &construct : sectionBlocks) { + auto §ion{std::get(construct.u)}; + CheckNoBranching( + std::get(section.t), beginDir.v, beginDir.source); } HasInvalidWorksharingNesting( beginDir.source, llvm::omp::nestedWorkshareErrSet); diff --git a/flang/test/Examples/omp-sections.f90 b/flang/test/Examples/omp-sections.f90 index 41e6e8fd9e5ab..a6d28065c8001 100644 --- a/flang/test/Examples/omp-sections.f90 +++ b/flang/test/Examples/omp-sections.f90 @@ -13,11 +13,11 @@ subroutine omp_sections() end subroutine omp_sections !CHECK: - file: {{.*}} -!CHECK: line: 9 +!CHECK: line: 8 !CHECK: construct: section !CHECK: clauses: [] !CHECK: - file: {{.*}} -!CHECK: line: 11 +!CHECK: line: 10 !CHECK: construct: section !CHECK: clauses: [] !CHECK: - file: {{.*}} diff --git a/flang/test/Parser/OpenMP/sections.f90 b/flang/test/Parser/OpenMP/sections.f90 index 3752cef624329..8ba2294fb0faa 100644 --- a/flang/test/Parser/OpenMP/sections.f90 +++ b/flang/test/Parser/OpenMP/sections.f90 @@ -10,32 +10,41 @@ subroutine openmp_sections(x, y) !============================================================================== !CHECK: !$omp sections !$omp sections - !CHECK: !$omp section !CHECK: !$omp end sections !$omp end sections -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionsConstruct -!PARSE-TREE: OmpBeginSectionsDirective -!PARSE-TREE-NOT: ExecutionPartConstruct -!PARSE-TREE: OmpEndSectionsDirective +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPSectionsConstruct +!PARSE-TREE: | OmpBeginSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | Block +!PARSE-TREE: | OmpEndSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> !============================================================================== ! single section, without `!$omp section` !============================================================================== !CHECK: !$omp sections !$omp sections - !CHECK: !$omp section !CHECK: CALL call F1() !CHECK: !$omp end sections !$omp end sections -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionsConstruct -!PARSE-TREE: OmpBeginSectionsDirective -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE-NOT: ExecutionPartConstruct -!PARSE-TREE: OmpEndSectionsDirective +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPSectionsConstruct +!PARSE-TREE: | OmpBeginSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f1()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f1' +!PARSE-TREE: | OmpEndSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> !============================================================================== ! single section with `!$omp section` @@ -49,12 +58,22 @@ subroutine openmp_sections(x, y) !CHECK: !$omp end sections !$omp end sections -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionsConstruct -!PARSE-TREE: OmpBeginSectionsDirective -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE-NOT: ExecutionPartConstruct -!PARSE-TREE: OmpEndSectionsDirective +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPSectionsConstruct +!PARSE-TREE: | OmpBeginSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f1()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f1' +!PARSE-TREE: | OmpEndSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> !============================================================================== ! multiple sections @@ -76,16 +95,40 @@ subroutine openmp_sections(x, y) !CHECK: !$omp end sections !$omp end sections -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionsConstruct -!PARSE-TREE: OmpBeginSectionsDirective -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE-NOT: ExecutionPartConstruct -!PARSE-TREE: OmpEndSectionsDirective +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPSectionsConstruct +!PARSE-TREE: | OmpBeginSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f1()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f1' +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f2()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f2' +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f3()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f3' +!PARSE-TREE: | OmpEndSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> !============================================================================== ! multiple sections with clauses @@ -107,15 +150,40 @@ subroutine openmp_sections(x, y) !CHECK: !$omp end sections NOWAIT !$omp end sections NOWAIT -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionsConstruct -!PARSE-TREE: OmpBeginSectionsDirective -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE: OpenMPConstruct -> OpenMPSectionConstruct -> Block -!PARSE-TREE: CallStmt -!PARSE-TREE-NOT: ExecutionPartConstruct -!PARSE-TREE: OmpEndSectionsDirective +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPSectionsConstruct +!PARSE-TREE: | OmpBeginSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> OmpClause -> Private -> OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' +!PARSE-TREE: | | OmpClause -> Firstprivate -> OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'y' +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f1()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f1' +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f2()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f2' +!PARSE-TREE: | OpenMPConstruct -> OpenMPSectionConstruct +!PARSE-TREE: | | OmpDirectiveSpecification +!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = section +!PARSE-TREE: | | | OmpClauseList -> +!PARSE-TREE: | | | Flags = None +!PARSE-TREE: | | Block +!PARSE-TREE: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL f3()' +!PARSE-TREE: | | | | Call +!PARSE-TREE: | | | | | ProcedureDesignator -> Name = 'f3' +!PARSE-TREE: | OmpEndSectionsDirective +!PARSE-TREE: | | OmpSectionsDirective -> llvm::omp::Directive = sections +!PARSE-TREE: | | OmpClauseList -> OmpClause -> Nowait END subroutine openmp_sections From 0d64559614272cdf5bfa021d7120a273567f1e2d Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 28 Jul 2025 08:58:06 -0500 Subject: [PATCH 4/6] [flang][OpenMP] Use GetOmpDirectiveName to find directive source location --- .../lib/Lower/OpenMP/DataSharingProcessor.cpp | 52 +++++-------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp index 2ac4d9548b65b..2c0cbb2b6168f 100644 --- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp +++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp @@ -389,42 +389,16 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) { } } -static const parser::CharBlock * -getSource(const semantics::SemanticsContext &semaCtx, - const lower::pft::Evaluation &eval) { - const parser::CharBlock *source = nullptr; - - auto ompConsVisit = [&](const parser::OpenMPConstruct &x) { - std::visit( - common::visitors{ - [&](const parser::OpenMPSectionsConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPLoopConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPBlockConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPCriticalConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPAtomicConstruct &x) { - source = &std::get(x.t).source; - }, - [&](const auto &x) { source = &x.source; }, - }, - x.u); - }; - - eval.visit(common::visitors{ - [&](const parser::OpenMPConstruct &x) { ompConsVisit(x); }, - [&](const parser::OpenMPDeclarativeConstruct &x) { source = &x.source; }, - [&](const parser::OmpEndLoopDirective &x) { source = &x.source; }, - [&](const auto &x) {}, +static parser::CharBlock getSource(const semantics::SemanticsContext &semaCtx, + const lower::pft::Evaluation &eval) { + return eval.visit(common::visitors{ + [&](const parser::OpenMPConstruct &x) { + return parser::omp::GetOmpDirectiveName(x).source; + }, + [&](const parser::OpenMPDeclarativeConstruct &x) { return x.source; }, + [&](const parser::OmpEndLoopDirective &x) { return x.source; }, + [&](const auto &x) { return parser::CharBlock{}; }, }); - - return source; } static void collectPrivatizingConstructs( @@ -518,11 +492,11 @@ void DataSharingProcessor::collectSymbols( for (const semantics::Scope &child : scope->children()) collectScopes(&child); }; - const parser::CharBlock *source = - clauses.empty() ? getSource(semaCtx, eval) : &clauses.front().source; + parser::CharBlock source = + clauses.empty() ? getSource(semaCtx, eval) : clauses.front().source; const semantics::Scope *curScope = nullptr; - if (source && !source->empty()) { - curScope = &semaCtx.FindScope(*source); + if (!source.empty()) { + curScope = &semaCtx.FindScope(source); collectScopes(curScope); } // Collect all symbols referenced in the evaluation being processed, From cd3a5b91a2715367a4fcd1b3a92c8fef72c6938f Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 17 Jul 2025 08:28:34 -0500 Subject: [PATCH 5/6] [flang][OpenMP] Make all block constructs share the same structure The structure is - OmpBeginDirective (aka OmpDirectiveSpecification) - Block - optional (aka optional) The OmpBeginDirective and OmpEndDirective are effectively different names for OmpDirectiveSpecification. They exist to allow the semantic analyses to distinguish between the beginning and the ending of a block construct without maintaining additional context. The actual changes are in the parser: parse-tree.h and openmp-parser.cpp in particular. The rest is simply changing the way the directive/clause information is accessed (typically for the simpler). All standalone and block constructs now use OmpDirectiveSpecification to store the directive/clause information. --- flang/examples/FeatureList/FeatureList.cpp | 5 +- flang/include/flang/Parser/dump-parse-tree.h | 5 +- flang/include/flang/Parser/openmp-utils.h | 11 +- flang/include/flang/Parser/parse-tree.h | 83 ++++---- flang/lib/Lower/OpenMP/Atomic.cpp | 2 +- flang/lib/Lower/OpenMP/OpenMP.cpp | 49 ++--- flang/lib/Parser/openmp-parsers.cpp | 192 +++++++++--------- flang/lib/Parser/parse-tree.cpp | 6 +- flang/lib/Parser/unparse.cpp | 100 ++------- flang/lib/Semantics/check-omp-atomic.cpp | 8 +- flang/lib/Semantics/check-omp-loop.cpp | 14 +- flang/lib/Semantics/check-omp-structure.cpp | 115 +++++------ flang/lib/Semantics/check-omp-structure.h | 6 +- flang/lib/Semantics/resolve-directives.cpp | 34 ++-- flang/lib/Semantics/resolve-names.cpp | 12 +- flang/test/Parser/OpenMP/affinity-clause.f90 | 12 +- .../test/Parser/OpenMP/allocators-unparse.f90 | 8 +- flang/test/Parser/OpenMP/atomic-compare.f90 | 18 +- flang/test/Parser/OpenMP/atomic-end.f90 | 8 +- flang/test/Parser/OpenMP/block-construct.f90 | 20 +- .../OpenMP/construct-prefix-conflict.f90 | 40 ++-- .../test/Parser/OpenMP/defaultmap-clause.f90 | 24 +-- .../test/Parser/OpenMP/defaultmap-unparse.f90 | 36 ++-- flang/test/Parser/OpenMP/dispatch.f90 | 8 +- flang/test/Parser/OpenMP/if-clause.f90 | 4 +- .../Parser/OpenMP/in-reduction-clause.f90 | 12 +- .../test/Parser/OpenMP/map-modifiers-v60.f90 | 20 +- flang/test/Parser/OpenMP/map-modifiers.f90 | 46 ++--- flang/test/Parser/OpenMP/masked-unparse.f90 | 12 +- flang/test/Parser/OpenMP/master-unparse.f90 | 8 +- .../OpenMP/openmp6-directive-spellings.f90 | 12 +- flang/test/Parser/OpenMP/proc-bind.f90 | 4 +- flang/test/Parser/OpenMP/scope.f90 | 8 +- .../Parser/OpenMP/target_device_parse.f90 | 64 +++--- .../Parser/OpenMP/task-reduction-clause.f90 | 4 +- flang/test/Parser/OpenMP/task.f90 | 2 +- .../Semantics/OpenMP/clause-validity01.f90 | 3 +- flang/test/Semantics/OpenMP/symbol08.f90 | 3 +- 38 files changed, 461 insertions(+), 557 deletions(-) diff --git a/flang/examples/FeatureList/FeatureList.cpp b/flang/examples/FeatureList/FeatureList.cpp index 64b57b633feaf..0b8066e36312b 100644 --- a/flang/examples/FeatureList/FeatureList.cpp +++ b/flang/examples/FeatureList/FeatureList.cpp @@ -445,10 +445,9 @@ struct NodeVisitor { READ_FEATURE(ObjectDecl) READ_FEATURE(OldParameterStmt) READ_FEATURE(OmpAlignedClause) - READ_FEATURE(OmpBeginBlockDirective) + READ_FEATURE(OmpBeginDirective) READ_FEATURE(OmpBeginLoopDirective) READ_FEATURE(OmpBeginSectionsDirective) - READ_FEATURE(OmpBlockDirective) READ_FEATURE(OmpClause) READ_FEATURE(OmpClauseList) READ_FEATURE(OmpCriticalDirective) @@ -472,7 +471,7 @@ struct NodeVisitor { READ_FEATURE(OmpIteration) READ_FEATURE(OmpIterationOffset) READ_FEATURE(OmpIterationVector) - READ_FEATURE(OmpEndBlockDirective) + READ_FEATURE(OmpEndDirective) READ_FEATURE(OmpEndCriticalDirective) READ_FEATURE(OmpEndLoopDirective) READ_FEATURE(OmpEndSectionsDirective) diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index ebac54f6e29ba..b09dd32a90b98 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -534,10 +534,8 @@ class ParseTreeDumper { NODE(parser, OmpAtClause) NODE_ENUM(OmpAtClause, ActionTime) NODE_ENUM(OmpSeverityClause, Severity) - NODE(parser, OmpBeginBlockDirective) NODE(parser, OmpBeginLoopDirective) NODE(parser, OmpBeginSectionsDirective) - NODE(parser, OmpBlockDirective) static std::string GetNodeName(const llvm::omp::Directive &x) { return llvm::Twine("llvm::omp::Directive = ", llvm::omp::getOpenMPDirectiveName(x, llvm::omp::FallbackVersion)) @@ -584,7 +582,6 @@ class ParseTreeDumper { NODE(parser, OmpDetachClause) NODE(parser, OmpDoacrossClause) NODE(parser, OmpDestroyClause) - NODE(parser, OmpEndBlockDirective) NODE(parser, OmpEndCriticalDirective) NODE(parser, OmpEndLoopDirective) NODE(parser, OmpEndSectionsDirective) @@ -704,6 +701,8 @@ class ParseTreeDumper { NODE(parser, OpenMPDeclarativeAssumes) NODE(parser, OmpAssumeDirective) NODE(parser, OmpEndAssumeDirective) + NODE(parser, OmpBeginDirective) + NODE(parser, OmpEndDirective) NODE(parser, OpenMPAtomicConstruct) NODE(parser, OpenMPBlockConstruct) NODE(parser, OpenMPCancelConstruct) diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index 41c04424e91c6..fa0f7656cd5d8 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -68,11 +68,6 @@ struct DirectiveNameScope { return MakeName(x.source, llvm::omp::Directive::OMPD_nothing); } - static OmpDirectiveName GetOmpDirectiveName(const OmpBeginBlockDirective &x) { - auto &dir{std::get(x.t)}; - return MakeName(dir.source, dir.v); - } - static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) { auto &dir{std::get(x.t)}; return MakeName(dir.source, dir.v); @@ -106,10 +101,8 @@ struct DirectiveNameScope { return GetOmpDirectiveName(x.v); } } else if constexpr (TupleTrait) { - if constexpr (std::is_same_v || - std::is_same_v || - std::is_same_v) { - return std::get(x.t).DirName(); + if constexpr (std::is_base_of_v) { + return std::get(x.t).DirName(); } else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v || diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index da0a3632b8a63..7ba5fe964f7a1 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3469,6 +3469,13 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions +#define INHERITED_TUPLE_CLASS_BOILERPLATE(classname, basename) \ + template > \ + classname(Ts &&...args) : basename(std::move(args)...) {} \ + classname(basename &&b) : basename(std::move(b)) {} \ + using TupleTrait = std::true_type; \ + BOILERPLATE(classname) + #define INHERITED_WRAPPER_CLASS_BOILERPLATE(classname, basename) \ BOILERPLATE(classname); \ classname(decltype(basename::v) &&x) : basename(std::move(x)) {} \ @@ -4729,6 +4736,33 @@ struct OmpDirectiveSpecification { t; }; +// OmpBeginDirective and OmpEndDirective are needed for semantic analysis, +// where some checks are done specifically for either the begin or the end +// directive. The structure of both is identical, but the diffent types +// allow to distinguish them in the type-based parse-tree visitor. +struct OmpBeginDirective : public OmpDirectiveSpecification { + INHERITED_TUPLE_CLASS_BOILERPLATE( + OmpBeginDirective, OmpDirectiveSpecification); +}; + +struct OmpEndDirective : public OmpDirectiveSpecification { + INHERITED_TUPLE_CLASS_BOILERPLATE(OmpEndDirective, OmpDirectiveSpecification); +}; + +// Common base class for block-associated constructs. +struct OmpBlockConstruct { + TUPLE_CLASS_BOILERPLATE(OmpBlockConstruct); + const OmpBeginDirective &BeginDir() const { + return std::get(t); + } + const std::optional &EndDir() const { + return std::get>(t); + } + + CharBlock source; + std::tuple> t; +}; + struct OmpMetadirectiveDirective { TUPLE_CLASS_BOILERPLATE(OmpMetadirectiveDirective); std::tuple t; @@ -4833,12 +4867,6 @@ struct OpenMPSectionsConstruct { t; }; -// OpenMP directive beginning or ending a block -struct OmpBlockDirective { - WRAPPER_CLASS_BOILERPLATE(OmpBlockDirective, llvm::omp::Directive); - CharBlock source; -}; - struct OmpDeclareVariantDirective { TUPLE_CLASS_BOILERPLATE(OmpDeclareVariantDirective); CharBlock source; @@ -4963,12 +4991,9 @@ struct OpenMPExecutableAllocate { // ALLOCATORS [allocate-clause...] // block // [END ALLOCATORS] -struct OpenMPAllocatorsConstruct { - TUPLE_CLASS_BOILERPLATE(OpenMPAllocatorsConstruct); - CharBlock source; - std::tuple> - t; +struct OpenMPAllocatorsConstruct : public OmpBlockConstruct { + INHERITED_TUPLE_CLASS_BOILERPLATE( + OpenMPAllocatorsConstruct, OmpBlockConstruct); }; // 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0] @@ -4982,15 +5007,11 @@ struct OmpMemoryOrderClause { CharBlock source; }; -struct OpenMPAtomicConstruct { +struct OpenMPAtomicConstruct : public OmpBlockConstruct { llvm::omp::Clause GetKind() const; bool IsCapture() const; bool IsCompare() const; - TUPLE_CLASS_BOILERPLATE(OpenMPAtomicConstruct); - CharBlock source; - std::tuple> - t; + INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPAtomicConstruct, OmpBlockConstruct); // Information filled out during semantic checks to avoid duplication // of analyses. @@ -5054,12 +5075,8 @@ struct OpenMPDepobjConstruct { // nocontext-clause | // novariants-clause | // nowait-clause -struct OpenMPDispatchConstruct { - TUPLE_CLASS_BOILERPLATE(OpenMPDispatchConstruct); - CharBlock source; - std::tuple> - t; +struct OpenMPDispatchConstruct : public OmpBlockConstruct { + INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPDispatchConstruct, OmpBlockConstruct); }; // [4.5:162-165], [5.0:242-246], [5.1:275-279], [5.2:315-316], [6.0:498-500] @@ -5114,22 +5131,8 @@ struct OmpEndLoopDirective { CharBlock source; }; -struct OmpBeginBlockDirective { - TUPLE_CLASS_BOILERPLATE(OmpBeginBlockDirective); - std::tuple t; - CharBlock source; -}; - -struct OmpEndBlockDirective { - TUPLE_CLASS_BOILERPLATE(OmpEndBlockDirective); - std::tuple t; - CharBlock source; -}; - -struct OpenMPBlockConstruct { - TUPLE_CLASS_BOILERPLATE(OpenMPBlockConstruct); - std::tuple> - t; +struct OpenMPBlockConstruct : public OmpBlockConstruct { + INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPBlockConstruct, OmpBlockConstruct); }; // OpenMP directives enclosing do loop diff --git a/flang/lib/Lower/OpenMP/Atomic.cpp b/flang/lib/Lower/OpenMP/Atomic.cpp index 9a233d2d8cb08..623a9370aa00d 100644 --- a/flang/lib/Lower/OpenMP/Atomic.cpp +++ b/flang/lib/Lower/OpenMP/Atomic.cpp @@ -699,7 +699,7 @@ void Fortran::lower::omp::lowerAtomic( }; fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - auto &dirSpec = std::get(construct.t); + const parser::OmpDirectiveSpecification &dirSpec = construct.BeginDir(); omp::List clauses = makeClauses(dirSpec.Clauses(), semaCtx); lower::StatementContext stmtCtx; diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 6dd4b16a1fb55..68ebb66309f99 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -407,16 +407,9 @@ static void processHostEvalClauses(lower::AbstractConverter &converter, common::visit( common::visitors{ [&](const parser::OpenMPBlockConstruct &ompConstruct) { - const auto &beginDirective = - std::get(ompConstruct.t); - beginClauseList = - &std::get(beginDirective.t); - if (auto &endDirective = - std::get>( - ompConstruct.t)) { - endClauseList = - &std::get(endDirective->t); - } + beginClauseList = &ompConstruct.BeginDir().Clauses(); + if (auto &endSpec = ompConstruct.EndDir()) + endClauseList = &endSpec->Clauses(); }, [&](const parser::OpenMPLoopConstruct &ompConstruct) { const auto &beginDirective = @@ -3716,25 +3709,16 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, const parser::OpenMPBlockConstruct &blockConstruct) { - const auto &beginBlockDirective = - std::get(blockConstruct.t); - mlir::Location currentLocation = - converter.genLocation(beginBlockDirective.source); - const auto origDirective = - std::get(beginBlockDirective.t).v; - List clauses = makeClauses( - std::get(beginBlockDirective.t), semaCtx); - - if (const auto &endBlockDirective = - std::get>( - blockConstruct.t)) { - clauses.append(makeClauses( - std::get(endBlockDirective->t), semaCtx)); - } - - assert(llvm::omp::blockConstructSet.test(origDirective) && + const parser::OmpDirectiveSpecification &beginSpec = + blockConstruct.BeginDir(); + List clauses = makeClauses(beginSpec.Clauses(), semaCtx); + if (auto &endSpec = blockConstruct.EndDir()) + clauses.append(makeClauses(endSpec->Clauses(), semaCtx)); + + llvm::omp::Directive directive = beginSpec.DirId(); + assert(llvm::omp::blockConstructSet.test(directive) && "Expected block construct"); - (void)origDirective; + mlir::Location currentLocation = converter.genLocation(beginSpec.source); for (const Clause &clause : clauses) { mlir::Location clauseLocation = converter.genLocation(clause.source); @@ -3777,13 +3761,9 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, } } - llvm::omp::Directive directive = - std::get(beginBlockDirective.t).v; - const parser::CharBlock &source = - std::get(beginBlockDirective.t).source; ConstructQueue queue{ buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx, - eval, source, directive, clauses)}; + eval, beginSpec.source, directive, clauses)}; genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue, queue.begin()); } @@ -4071,8 +4051,7 @@ bool Fortran::lower::isOpenMPTargetConstruct( const parser::OpenMPConstruct &omp) { llvm::omp::Directive dir = llvm::omp::Directive::OMPD_unknown; if (const auto *block = std::get_if(&omp.u)) { - const auto &begin = std::get(block->t); - dir = std::get(begin.t).v; + dir = block->BeginDir().DirId(); } else if (const auto *loop = std::get_if(&omp.u)) { const auto &begin = std::get(loop->t); diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 8c780388b9cb1..c2c1921f446c7 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -1371,16 +1371,41 @@ TYPE_PARSER(sourced(construct(first( TYPE_PARSER(sourced(construct( sourced(Parser{}), Parser{}))) +static inline constexpr auto IsDirective(llvm::omp::Directive dir) { + return [dir](const OmpDirectiveName &name) -> bool { return dir == name.v; }; +} + +struct OmpBeginDirectiveParser { + using resultType = OmpDirectiveSpecification; + + constexpr OmpBeginDirectiveParser(llvm::omp::Directive dir) : dir_(dir) {} + + std::optional Parse(ParseState &state) const { + auto &&p{predicated(Parser{}, IsDirective(dir_)) >= + Parser{}}; + return p.Parse(state); + } + +private: + llvm::omp::Directive dir_; +}; + struct OmpEndDirectiveParser { using resultType = OmpDirectiveSpecification; constexpr OmpEndDirectiveParser(llvm::omp::Directive dir) : dir_(dir) {} std::optional Parse(ParseState &state) const { - if ((startOmpLine >> "END"_sptok).Parse(state)) { - auto &&dirSpec{Parser{}.Parse(state)}; - if (dirSpec && dirSpec->DirId() == dir_) { - return std::move(dirSpec); + if (startOmpLine.Parse(state)) { + if (auto endToken{verbatim("END"_sptok).Parse(state)}) { + if (auto &&dirSpec{OmpBeginDirectiveParser(dir_).Parse(state)}) { + // Extend the "source" on both the OmpDirectiveName and the + // OmpDirectiveNameSpecification. + CharBlock &nameSource{std::get(dirSpec->t).source}; + nameSource.ExtendToCover(endToken->source); + dirSpec->source.ExtendToCover(endToken->source); + return std::move(*dirSpec); + } } } return std::nullopt; @@ -1390,57 +1415,67 @@ struct OmpEndDirectiveParser { llvm::omp::Directive dir_; }; -struct OmpAllocatorsConstructParser { - using resultType = OpenMPAllocatorsConstruct; +struct OmpStatementConstructParser { + using resultType = OmpBlockConstruct; + + constexpr OmpStatementConstructParser(llvm::omp::Directive dir) : dir_(dir) {} std::optional Parse(ParseState &state) const { - auto dirSpec{Parser{}.Parse(state)}; - if (!dirSpec || dirSpec->DirId() != llvm::omp::Directive::OMPD_allocators) { - return std::nullopt; - } + if (auto begin{OmpBeginDirectiveParser(dir_).Parse(state)}) { + Block body; + if (auto stmt{attempt(Parser{}).Parse(state)}) { + body.emplace_back(std::move(*stmt)); + } + // Allow empty block. Check for this in semantics. - // This should be an allocate-stmt. That will be checked in semantics. - Block block; - if (auto stmt{attempt(Parser{}).Parse(state)}) { - block.emplace_back(std::move(*stmt)); + auto end{maybe(OmpEndDirectiveParser{dir_}).Parse(state)}; + return OmpBlockConstruct{OmpBeginDirective(std::move(*begin)), + std::move(body), + llvm::transformOptional(std::move(*end), + [](auto &&s) { return OmpEndDirective(std::move(s)); })}; } - // Allow empty block. Check for this in semantics. - - auto end{OmpEndDirectiveParser{llvm::omp::Directive::OMPD_allocators}}; - return OpenMPAllocatorsConstruct{ - std::move(*dirSpec), std::move(block), *maybe(end).Parse(state)}; + return std::nullopt; } + +private: + llvm::omp::Directive dir_; }; -TYPE_PARSER(sourced( // - construct( - "ALLOCATORS"_tok >= OmpAllocatorsConstructParser{}))) +struct OmpBlockConstructParser { + using resultType = OmpBlockConstruct; -struct OmpDispatchConstructParser { - using resultType = OpenMPDispatchConstruct; + constexpr OmpBlockConstructParser(llvm::omp::Directive dir) : dir_(dir) {} std::optional Parse(ParseState &state) const { - auto dirSpec{Parser{}.Parse(state)}; - if (!dirSpec || dirSpec->DirId() != llvm::omp::Directive::OMPD_dispatch) { - return std::nullopt; - } - - // This should be a function call. That will be checked in semantics. - Block block; - if (auto stmt{attempt(Parser{}).Parse(state)}) { - block.emplace_back(std::move(*stmt)); + if (auto &&begin{OmpBeginDirectiveParser(dir_).Parse(state)}) { + if (auto &&body{attempt(StrictlyStructuredBlockParser{}).Parse(state)}) { + // Try strictly-structured block with an optional end-directive + auto end{maybe(OmpEndDirectiveParser{dir_}).Parse(state)}; + return OmpBlockConstruct{OmpBeginDirective(std::move(*begin)), + std::move(*body), + llvm::transformOptional(std::move(*end), + [](auto &&s) { return OmpEndDirective(std::move(s)); })}; + } else if (auto &&body{ + attempt(LooselyStructuredBlockParser{}).Parse(state)}) { + // Try loosely-structured block with a mandatory end-directive + if (auto end{OmpEndDirectiveParser{dir_}.Parse(state)}) { + return OmpBlockConstruct{OmpBeginDirective(std::move(*begin)), + std::move(*body), OmpEndDirective{std::move(*end)}}; + } + } } - // Allow empty block. Check for this in semantics. - - auto end{OmpEndDirectiveParser{llvm::omp::Directive::OMPD_dispatch}}; - return OpenMPDispatchConstruct{ - std::move(*dirSpec), std::move(block), *maybe(end).Parse(state)}; + return std::nullopt; } + +private: + llvm::omp::Directive dir_; }; -TYPE_PARSER(sourced( // - construct( - "DISPATCH"_tok >= OmpDispatchConstructParser{}))) +TYPE_PARSER(sourced(construct( + OmpStatementConstructParser{llvm::omp::Directive::OMPD_allocators}))) + +TYPE_PARSER(sourced(construct( + OmpStatementConstructParser{llvm::omp::Directive::OMPD_dispatch}))) // Parser for an arbitrary OpenMP ATOMIC construct. // @@ -1505,8 +1540,10 @@ struct OmpAtomicConstructParser { } } recursing_ = false; - return OpenMPAtomicConstruct{ - std::move(*dirSpec), std::move(tail.first), std::move(tail.second)}; + return OpenMPAtomicConstruct{OmpBeginDirective(std::move(*dirSpec)), + std::move(tail.first), + llvm::transformOptional(std::move(tail.second), + [](auto &&s) { return OmpEndDirective(std::move(s)); })}; } recursing_ = false; @@ -1607,10 +1644,6 @@ TYPE_PARSER(sourced( // predicated(OmpDirectiveNameParser{}, IsSimpleStandalone) >= Parser{}))) -static inline constexpr auto IsDirective(llvm::omp::Directive dir) { - return [dir](const OmpDirectiveName &name) -> bool { return dir == name.v; }; -} - TYPE_PARSER(sourced( // construct( predicated(OmpDirectiveNameParser{}, @@ -1661,40 +1694,6 @@ TYPE_PARSER( Parser{})) / endOfLine) -// Directive names (of non-block constructs) whose prefix is a name of -// a block-associated construct. We need to exclude them from the block -// directive parser below to avoid parsing parts of them. -static constexpr auto StandaloneDirectiveLookahead{// - "TARGET ENTER DATA"_sptok || "TARGET_ENTER_DATA"_sptok || // - "TARGET EXIT DATA"_sptok || "TARGET_EXIT"_sptok || // - "TARGET UPDATE"_sptok || "TARGET_UPDATE"_sptok}; - -// Directives enclosing structured-block -TYPE_PARSER((!StandaloneDirectiveLookahead) >= - construct(first( - "MASKED" >> pure(llvm::omp::Directive::OMPD_masked), - "MASTER" >> pure(llvm::omp::Directive::OMPD_master), - "ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), - "PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked), - "PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master), - "PARALLEL WORKSHARE" >> - pure(llvm::omp::Directive::OMPD_parallel_workshare), - "PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), - "SCOPE" >> pure(llvm::omp::Directive::OMPD_scope), - "SINGLE" >> pure(llvm::omp::Directive::OMPD_single), - "TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), - "TARGET_DATA" >> pure(llvm::omp::Directive::OMPD_target_data), - "TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), - "TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), - "TARGET" >> pure(llvm::omp::Directive::OMPD_target), - "TASK"_id >> pure(llvm::omp::Directive::OMPD_task), - "TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), - "TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), - "WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare)))) - -TYPE_PARSER(sourced(construct( - sourced(Parser{}), Parser{}))) - TYPE_PARSER(construct(Parser{}, parenthesized(many(maybe(","_tok) >> Parser{})))) @@ -1844,12 +1843,27 @@ TYPE_PARSER(sourced( block, maybe(Parser{} / endOmpLine)))) // Block Construct +#define MakeBlockConstruct(dir) \ + construct(OmpBlockConstructParser{dir}) TYPE_PARSER( // - construct(Parser{}, - StrictlyStructuredBlockParser{}, - maybe(Parser{})) || - construct(Parser{}, - LooselyStructuredBlockParser{}, Parser{})) + MakeBlockConstruct(llvm::omp::Directive::OMPD_masked) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_master) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_ordered) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_parallel_masked) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_parallel_master) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_parallel_workshare) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_parallel) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_scope) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_single) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_target_data) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_target_parallel) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_target_teams) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_target) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_task) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_taskgroup) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_teams) || + MakeBlockConstruct(llvm::omp::Directive::OMPD_workshare)) +#undef MakeBlockConstruct // OMP SECTIONS Directive TYPE_PARSER(construct(first( @@ -1904,12 +1918,6 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US, construct(Parser{}), construct(Parser{})))) -// END OMP Block directives -TYPE_PARSER( - startOmpLine >> sourced(construct( - sourced("END"_tok >> Parser{}), - Parser{}))) - // END OMP Loop directives TYPE_PARSER( startOmpLine >> sourced(construct( diff --git a/flang/lib/Parser/parse-tree.cpp b/flang/lib/Parser/parse-tree.cpp index 7b46c9f469b06..cb3093954cbe4 100644 --- a/flang/lib/Parser/parse-tree.cpp +++ b/flang/lib/Parser/parse-tree.cpp @@ -322,7 +322,7 @@ std::string OmpTraitSetSelectorName::ToString() const { } llvm::omp::Clause OpenMPAtomicConstruct::GetKind() const { - auto &dirSpec{std::get(t)}; + const OmpDirectiveSpecification &dirSpec{std::get(t)}; for (auto &clause : dirSpec.Clauses().v) { switch (clause.Id()) { case llvm::omp::Clause::OMPC_read: @@ -337,14 +337,14 @@ llvm::omp::Clause OpenMPAtomicConstruct::GetKind() const { } bool OpenMPAtomicConstruct::IsCapture() const { - auto &dirSpec{std::get(t)}; + const OmpDirectiveSpecification &dirSpec{std::get(t)}; return llvm::any_of(dirSpec.Clauses().v, [](auto &clause) { return clause.Id() == llvm::omp::Clause::OMPC_capture; }); } bool OpenMPAtomicConstruct::IsCompare() const { - auto &dirSpec{std::get(t)}; + const OmpDirectiveSpecification &dirSpec{std::get(t)}; return llvm::any_of(dirSpec.Clauses().v, [](auto &clause) { return clause.Id() == llvm::omp::Clause::OMPC_compare; }); diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index 1d4d53de1491d..029ca4e74c7a1 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2508,87 +2508,39 @@ class UnparseVisitor { } } void Unparse(const OmpObjectList &x) { Walk(x.v, ","); } - void Unparse(const OmpBlockDirective &x) { - switch (x.v) { - case llvm::omp::Directive::OMPD_masked: - Word("MASKED"); - break; - case llvm::omp::Directive::OMPD_master: - Word("MASTER"); - break; - case llvm::omp::Directive::OMPD_ordered: - Word("ORDERED "); - break; - case llvm::omp::Directive::OMPD_parallel_masked: - Word("PARALLEL MASKED"); - break; - case llvm::omp::Directive::OMPD_parallel_master: - Word("PARALLEL MASTER"); - break; - case llvm::omp::Directive::OMPD_parallel_workshare: - Word("PARALLEL WORKSHARE "); - break; - case llvm::omp::Directive::OMPD_parallel: - Word("PARALLEL "); - break; - case llvm::omp::Directive::OMPD_scope: - Word("SCOPE "); - break; - case llvm::omp::Directive::OMPD_single: - Word("SINGLE "); - break; - case llvm::omp::Directive::OMPD_target_data: - Word("TARGET DATA "); - break; - case llvm::omp::Directive::OMPD_target_parallel: - Word("TARGET PARALLEL "); - break; - case llvm::omp::Directive::OMPD_target_teams: - Word("TARGET TEAMS "); - break; - case llvm::omp::Directive::OMPD_target: - Word("TARGET "); - break; - case llvm::omp::Directive::OMPD_taskgroup: - Word("TASKGROUP "); - break; - case llvm::omp::Directive::OMPD_task: - Word("TASK "); - break; - case llvm::omp::Directive::OMPD_teams: - Word("TEAMS "); - break; - case llvm::omp::Directive::OMPD_workshare: - Word("WORKSHARE "); - break; - default: - // Nothing to be done - break; - } - } void Unparse(const common::OmpMemoryOrderType &x) { Word(ToUpperCaseLetters(common::EnumToString(x))); } - template void UnparseBlockConstruct(const Construct &x) { + void Unparse(const OmpBeginDirective &x) { BeginOpenMP(); Word("!$OMP "); - Walk(std::get(x.t)); + Walk(static_cast(x)); Put("\n"); EndOpenMP(); + } + + void Unparse(const OmpEndDirective &x) { + BeginOpenMP(); + Word("!$OMP END "); + Walk(static_cast(x)); + Put("\n"); + EndOpenMP(); + } + + void Unparse(const OmpBlockConstruct &x) { + Walk(std::get(x.t)); Walk(std::get(x.t), ""); - if (auto &end{std::get>(x.t)}) { - BeginOpenMP(); - Word("!$OMP END "); + if (auto &end{std::get>(x.t)}) { Walk(*end); + } else { Put("\n"); - EndOpenMP(); } } void Unparse(const OpenMPAtomicConstruct &x) { // - UnparseBlockConstruct(x); + Unparse(static_cast(x)); } void Unparse(const OpenMPExecutableAllocate &x) { @@ -2619,7 +2571,7 @@ class UnparseVisitor { EndOpenMP(); } void Unparse(const OpenMPAllocatorsConstruct &x) { // - UnparseBlockConstruct(x); + Unparse(static_cast(x)); } void Unparse(const OmpAssumeDirective &x) { BeginOpenMP(); @@ -2759,7 +2711,7 @@ class UnparseVisitor { EndOpenMP(); } void Unparse(const OpenMPDispatchConstruct &x) { // - UnparseBlockConstruct(x); + Unparse(static_cast(x)); } void Unparse(const OpenMPRequiresConstruct &y) { BeginOpenMP(); @@ -2892,19 +2844,7 @@ class UnparseVisitor { EndOpenMP(); } void Unparse(const OpenMPBlockConstruct &x) { - BeginOpenMP(); - Word("!$OMP "); - Walk(std::get(x.t)); - Put("\n"); - EndOpenMP(); - Walk(std::get(x.t), ""); - if (auto &&end{std::get>(x.t)}) { - BeginOpenMP(); - Word("!$OMP END "); - Walk(*end); - Put("\n"); - EndOpenMP(); - } + Unparse(static_cast(x)); } void Unparse(const OpenMPLoopConstruct &x) { BeginOpenMP(); diff --git a/flang/lib/Semantics/check-omp-atomic.cpp b/flang/lib/Semantics/check-omp-atomic.cpp index c5ed8796f0c34..fae38672ef396 100644 --- a/flang/lib/Semantics/check-omp-atomic.cpp +++ b/flang/lib/Semantics/check-omp-atomic.cpp @@ -1105,12 +1105,11 @@ void OmpStructureChecker::CheckAtomicRead( // of the following forms: // v = x // v => x - auto &dirSpec{std::get(x.t)}; auto &block{std::get(x.t)}; // Read cannot be conditional or have a capture statement. if (x.IsCompare() || x.IsCapture()) { - context_.Say(dirSpec.source, + context_.Say(x.BeginDir().source, "ATOMIC READ cannot have COMPARE or CAPTURE clauses"_err_en_US); return; } @@ -1141,12 +1140,11 @@ void OmpStructureChecker::CheckAtomicRead( void OmpStructureChecker::CheckAtomicWrite( const parser::OpenMPAtomicConstruct &x) { - auto &dirSpec{std::get(x.t)}; auto &block{std::get(x.t)}; // Write cannot be conditional or have a capture statement. if (x.IsCompare() || x.IsCapture()) { - context_.Say(dirSpec.source, + context_.Say(x.BeginDir().source, "ATOMIC WRITE cannot have COMPARE or CAPTURE clauses"_err_en_US); return; } @@ -1234,7 +1232,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPAtomicConstruct &x) { } }}; - auto &dirSpec{std::get(x.t)}; + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; auto &dir{std::get(dirSpec.t)}; PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_atomic); llvm::omp::Clause kind{x.GetKind()}; diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp index b82e2f7342d85..59d57a2ec7cfb 100644 --- a/flang/lib/Semantics/check-omp-loop.cpp +++ b/flang/lib/Semantics/check-omp-loop.cpp @@ -18,6 +18,7 @@ #include "flang/Common/idioms.h" #include "flang/Common/visit.h" #include "flang/Parser/char-block.h" +#include "flang/Parser/openmp-utils.h" #include "flang/Parser/parse-tree-visitor.h" #include "flang/Parser/parse-tree.h" #include "flang/Parser/tools.h" @@ -196,14 +197,9 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) { common::visitors{ // Allow `!$OMP ORDERED SIMD` [&](const parser::OpenMPBlockConstruct &c) { - const auto &beginBlockDir{ - std::get(c.t)}; - const auto &beginDir{ - std::get(beginBlockDir.t)}; - if (beginDir.v == llvm::omp::Directive::OMPD_ordered) { - const auto &clauses{ - std::get(beginBlockDir.t)}; - for (const auto &clause : clauses.v) { + const parser::OmpDirectiveSpecification &beginSpec{c.BeginDir()}; + if (beginSpec.DirId() == llvm::omp::Directive::OMPD_ordered) { + for (const auto &clause : beginSpec.Clauses().v) { if (std::get_if(&clause.u)) { eligibleSIMD = true; break; @@ -247,7 +243,7 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) { }, c.u); if (!eligibleSIMD) { - context_.Say(parser::FindSourceLocation(c), + context_.Say(parser::omp::GetOmpDirectiveName(c).source, "The only OpenMP constructs that can be encountered during execution " "of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, " "the `SIMD` construct, the `SCAN` construct and the `ORDERED` " diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index c191ad8d088d3..d45993e8edf2f 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -498,7 +498,7 @@ template struct DirectiveSpellingVisitor { template static const parser::OmpDirectiveName &GetDirName( const std::tuple &t) { - return std::get(t).DirName(); + return std::get(t).DirName(); } bool Pre(const parser::OmpSectionsDirective &x) { @@ -588,12 +588,14 @@ template struct DirectiveSpellingVisitor { checker_(std::get(x.t).source, Directive::OMPD_requires); return false; } - - bool Pre(const parser::OmpBlockDirective &x) { - checker_(x.source, x.v); + bool Pre(const parser::OmpBeginDirective &x) { + checker_(x.DirName().source, x.DirId()); + return false; + } + bool Pre(const parser::OmpEndDirective &x) { + checker_(x.DirName().source, x.DirId()); return false; } - bool Pre(const parser::OmpLoopDirective &x) { checker_(x.source, x.v); return false; @@ -726,22 +728,22 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) { // 2.12.5 Target Construct Restriction bool eligibleTarget{true}; llvm::omp::Directive ineligibleTargetDir; + parser::CharBlock source; common::visit( common::visitors{ [&](const parser::OpenMPBlockConstruct &c) { - const auto &beginBlockDir{ - std::get(c.t)}; - const auto &beginDir{ - std::get(beginBlockDir.t)}; - if (beginDir.v == llvm::omp::Directive::OMPD_target_data) { + const parser::OmpDirectiveSpecification &beginSpec{c.BeginDir()}; + source = beginSpec.DirName().source; + if (beginSpec.DirId() == llvm::omp::Directive::OMPD_target_data) { eligibleTarget = false; - ineligibleTargetDir = beginDir.v; + ineligibleTargetDir = beginSpec.DirId(); } }, [&](const parser::OpenMPStandaloneConstruct &c) { common::visit( common::visitors{ [&](const parser::OpenMPSimpleStandaloneConstruct &c) { + source = c.v.DirName().source; switch (llvm::omp::Directive dirId{c.v.DirId()}) { case llvm::omp::Directive::OMPD_target_update: case llvm::omp::Directive::OMPD_target_enter_data: @@ -762,6 +764,7 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) { std::get(c.t)}; const auto &beginDir{ std::get(beginLoopDir.t)}; + source = beginLoopDir.source; if (llvm::omp::allTargetSet.test(beginDir.v)) { eligibleTarget = false; ineligibleTargetDir = beginDir.v; @@ -771,8 +774,7 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) { }, c.u); if (!eligibleTarget) { - context_.Warn(common::UsageWarning::OpenMPUsage, - parser::FindSourceLocation(c), + context_.Warn(common::UsageWarning::OpenMPUsage, source, "If %s directive is nested inside TARGET region, the behaviour is unspecified"_port_en_US, parser::ToUpperCaseLetters( getDirectiveName(ineligibleTargetDir).str())); @@ -780,25 +782,18 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) { } void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { - const auto &beginBlockDir{std::get(x.t)}; - const auto &endBlockDir{ - std::get>(x.t)}; - const auto &beginDir{std::get(beginBlockDir.t)}; + const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()}; + const std::optional &endSpec{x.EndDir()}; const parser::Block &block{std::get(x.t)}; - if (endBlockDir) { - const auto &endDir{std::get(endBlockDir->t)}; - CheckMatching(beginDir, endDir); - } - - PushContextAndClauseSets(beginDir.source, beginDir.v); + PushContextAndClauseSets(beginSpec.DirName().source, beginSpec.DirId()); if (llvm::omp::allTargetSet.test(GetContext().directive)) { EnterDirectiveNest(TargetNest); } if (CurrentDirectiveIsNested()) { if (llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) { - HasInvalidTeamsNesting(beginDir.v, beginDir.source); + HasInvalidTeamsNesting(beginSpec.DirId(), beginSpec.source); } if (GetContext().directive == llvm::omp::Directive::OMPD_master) { CheckMasterNesting(x); @@ -807,7 +802,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { // region or a target region. if (GetContext().directive == llvm::omp::Directive::OMPD_teams && GetContextParent().directive != llvm::omp::Directive::OMPD_target) { - context_.Say(parser::FindSourceLocation(x), + context_.Say(x.BeginDir().DirName().source, "%s region can only be strictly nested within the implicit parallel " "region or TARGET region"_err_en_US, ContextDirectiveAsFortran()); @@ -824,12 +819,12 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { } } - CheckNoBranching(block, beginDir.v, beginDir.source); + CheckNoBranching(block, beginSpec.DirId(), beginSpec.source); // Target block constructs are target device constructs. Keep track of // whether any such construct has been visited to later check that REQUIRES // directives for target-related options don't appear after them. - if (llvm::omp::allTargetSet.test(beginDir.v)) { + if (llvm::omp::allTargetSet.test(beginSpec.DirId())) { deviceConstructFound_ = true; } @@ -839,8 +834,8 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { bool foundNowait{false}; parser::CharBlock NowaitSource; - auto catchCopyPrivateNowaitClauses = [&](const auto &dir, bool isEnd) { - for (auto &clause : std::get(dir.t).v) { + auto catchCopyPrivateNowaitClauses = [&](const auto &dirSpec, bool isEnd) { + for (auto &clause : dirSpec.Clauses().v) { if (clause.Id() == llvm::omp::Clause::OMPC_copyprivate) { for (const auto &ompObject : GetOmpObjectList(clause)->v) { const auto *name{parser::Unwrap(ompObject)}; @@ -881,9 +876,9 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { } } }; - catchCopyPrivateNowaitClauses(beginBlockDir, false); - if (endBlockDir) { - catchCopyPrivateNowaitClauses(*endBlockDir, true); + catchCopyPrivateNowaitClauses(beginSpec, false); + if (endSpec) { + catchCopyPrivateNowaitClauses(*endSpec, true); } unsigned version{context_.langOptions().OpenMPVersion}; if (version <= 52 && NowaitSource.ToString().size() && @@ -893,7 +888,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { } } - switch (beginDir.v) { + switch (beginSpec.DirId()) { case llvm::omp::Directive::OMPD_target: if (CheckTargetBlockOnlyTeams(block)) { EnterDirectiveNest(TargetBlockOnlyTeams); @@ -901,27 +896,25 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) { break; case llvm::omp::OMPD_workshare: case llvm::omp::OMPD_parallel_workshare: - CheckWorkshareBlockStmts(block, beginDir.source); + CheckWorkshareBlockStmts(block, beginSpec.source); HasInvalidWorksharingNesting( - beginDir.source, llvm::omp::nestedWorkshareErrSet); + beginSpec.source, llvm::omp::nestedWorkshareErrSet); break; case llvm::omp::Directive::OMPD_scope: case llvm::omp::Directive::OMPD_single: // TODO: This check needs to be extended while implementing nesting of // regions checks. HasInvalidWorksharingNesting( - beginDir.source, llvm::omp::nestedWorkshareErrSet); + beginSpec.source, llvm::omp::nestedWorkshareErrSet); break; - case llvm::omp::Directive::OMPD_task: { - const auto &clauses{std::get(beginBlockDir.t)}; - for (const auto &clause : clauses.v) { + case llvm::omp::Directive::OMPD_task: + for (const auto &clause : beginSpec.Clauses().v) { if (std::get_if(&clause.u)) { OmpUnitedTaskDesignatorChecker check{context_}; parser::Walk(block, check); } } break; - } default: break; } @@ -934,7 +927,7 @@ void OmpStructureChecker::CheckMasterNesting( // TODO: Expand the check to include `LOOP` construct as well when it is // supported. if (IsCloselyNestedRegion(llvm::omp::nestedMasterErrSet)) { - context_.Say(parser::FindSourceLocation(x), + context_.Say(x.BeginDir().source, "`MASTER` region may not be closely nested inside of `WORKSHARING`, " "`LOOP`, `TASK`, `TASKLOOP`," " or `ATOMIC` region."_err_en_US); @@ -1034,7 +1027,7 @@ void OmpStructureChecker::ChecksOnOrderedAsBlock() { } } -void OmpStructureChecker::Leave(const parser::OmpBeginBlockDirective &) { +void OmpStructureChecker::Leave(const parser::OmpBeginDirective &) { switch (GetContext().directive) { case llvm::omp::Directive::OMPD_ordered: // [5.1] 2.19.9 Ordered Construct Restriction @@ -1600,7 +1593,7 @@ void OmpStructureChecker::Enter(const parser::OmpErrorDirective &x) { } void OmpStructureChecker::Enter(const parser::OpenMPDispatchConstruct &x) { - auto &dirSpec{std::get(x.t)}; + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; const auto &block{std::get(x.t)}; PushContextAndClauseSets( dirSpec.DirName().source, llvm::omp::Directive::OMPD_dispatch); @@ -1671,7 +1664,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPExecutableAllocate &x) { void OmpStructureChecker::Enter(const parser::OpenMPAllocatorsConstruct &x) { isPredefinedAllocator = true; - auto &dirSpec{std::get(x.t)}; + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; auto &block{std::get(x.t)}; PushContextAndClauseSets( dirSpec.DirName().source, llvm::omp::Directive::OMPD_allocators); @@ -1702,7 +1695,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPAllocatorsConstruct &x) { } void OmpStructureChecker::Leave(const parser::OpenMPAllocatorsConstruct &x) { - auto &dirSpec{std::get(x.t)}; + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; for (const auto &clause : dirSpec.Clauses().v) { if (const auto *allocClause{ @@ -1736,7 +1729,7 @@ void OmpStructureChecker::CheckBarrierNesting( // TODO: Expand the check to include `LOOP` construct as well when it is // supported. if (IsCloselyNestedRegion(llvm::omp::nestedBarrierErrSet)) { - context_.Say(parser::FindSourceLocation(x), + context_.Say(x.v.DirName().source, "`BARRIER` region may not be closely nested inside of `WORKSHARING`, " "`LOOP`, `TASK`, `TASKLOOP`," "`CRITICAL`, `ORDERED`, `ATOMIC` or `MASTER` region."_err_en_US); @@ -2276,22 +2269,21 @@ void OmpStructureChecker::CheckCancellationNest( } } -void OmpStructureChecker::Enter(const parser::OmpEndBlockDirective &x) { - const auto &dir{std::get(x.t)}; - ResetPartialContext(dir.source); - switch (dir.v) { +void OmpStructureChecker::Enter(const parser::OmpEndDirective &x) { + parser::CharBlock source{x.DirName().source}; + ResetPartialContext(source); + switch (x.DirId()) { case llvm::omp::Directive::OMPD_scope: - PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_end_scope); + PushContextAndClauseSets(source, llvm::omp::Directive::OMPD_end_scope); break; // 2.7.3 end-single-clause -> copyprivate-clause | // nowait-clause case llvm::omp::Directive::OMPD_single: - PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_end_single); + PushContextAndClauseSets(source, llvm::omp::Directive::OMPD_end_single); break; // 2.7.4 end-workshare -> END WORKSHARE [nowait-clause] case llvm::omp::Directive::OMPD_workshare: - PushContextAndClauseSets( - dir.source, llvm::omp::Directive::OMPD_end_workshare); + PushContextAndClauseSets(source, llvm::omp::Directive::OMPD_end_workshare); break; default: // no clauses are allowed @@ -2304,7 +2296,7 @@ void OmpStructureChecker::Enter(const parser::OmpEndBlockDirective &x) { // constructs unless a nowait clause is specified. Only OMPD_end_single and // end_workshareare popped as they are pushed while entering the // EndBlockDirective. -void OmpStructureChecker::Leave(const parser::OmpEndBlockDirective &x) { +void OmpStructureChecker::Leave(const parser::OmpEndDirective &x) { if ((GetContext().directive == llvm::omp::Directive::OMPD_end_scope) || (GetContext().directive == llvm::omp::Directive::OMPD_end_single) || (GetContext().directive == llvm::omp::Directive::OMPD_end_workshare)) { @@ -4353,11 +4345,8 @@ bool OmpStructureChecker::CheckTargetBlockOnlyTeams( parser::Unwrap(*it)}) { if (const auto *ompBlockConstruct{ std::get_if(&ompConstruct->u)}) { - const auto &beginBlockDir{ - std::get(ompBlockConstruct->t)}; - const auto &beginDir{ - std::get(beginBlockDir.t)}; - if (beginDir.v == llvm::omp::Directive::OMPD_teams) { + llvm::omp::Directive dirId{ompBlockConstruct->BeginDir().DirId()}; + if (dirId == llvm::omp::Directive::OMPD_teams) { nestedTeams = true; } } @@ -4403,11 +4392,7 @@ void OmpStructureChecker::CheckWorkshareBlockStmts( auto currentDir{llvm::omp::Directive::OMPD_unknown}; if (const auto *ompBlockConstruct{ std::get_if(&ompConstruct->u)}) { - const auto &beginBlockDir{ - std::get(ompBlockConstruct->t)}; - const auto &beginDir{ - std::get(beginBlockDir.t)}; - currentDir = beginDir.v; + currentDir = ompBlockConstruct->BeginDir().DirId(); } else if (const auto *ompLoopConstruct{ std::get_if( &ompConstruct->u)}) { diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h index f4a291dc255c8..6b33ca6ab583f 100644 --- a/flang/lib/Semantics/check-omp-structure.h +++ b/flang/lib/Semantics/check-omp-structure.h @@ -90,9 +90,9 @@ class OmpStructureChecker void Leave(const parser::OpenMPDeclarativeAssumes &); void Enter(const parser::OpenMPBlockConstruct &); void Leave(const parser::OpenMPBlockConstruct &); - void Leave(const parser::OmpBeginBlockDirective &); - void Enter(const parser::OmpEndBlockDirective &); - void Leave(const parser::OmpEndBlockDirective &); + void Leave(const parser::OmpBeginDirective &); + void Enter(const parser::OmpEndDirective &); + void Leave(const parser::OmpEndDirective &); void Enter(const parser::OpenMPSectionsConstruct &); void Leave(const parser::OpenMPSectionsConstruct &); diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index 4c3e509b5a36d..580c9cdbfc695 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -378,7 +378,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor { bool Pre(const parser::OpenMPBlockConstruct &); void Post(const parser::OpenMPBlockConstruct &); - void Post(const parser::OmpBeginBlockDirective &) { + void Post(const parser::OmpBeginDirective &x) { GetContext().withinConstruct = true; } @@ -519,6 +519,9 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor { bool Pre(const parser::OpenMPDeclarativeAllocate &); void Post(const parser::OpenMPDeclarativeAllocate &) { PopContext(); } + bool Pre(const parser::OpenMPAtomicConstruct &); + void Post(const parser::OpenMPAtomicConstruct &) { PopContext(); } + bool Pre(const parser::OpenMPDispatchConstruct &); void Post(const parser::OpenMPDispatchConstruct &) { PopContext(); } @@ -1698,9 +1701,9 @@ static std::string ScopeSourcePos(const Fortran::semantics::Scope &scope); #endif bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) { - const auto &beginBlockDir{std::get(x.t)}; - const auto &beginDir{std::get(beginBlockDir.t)}; - switch (beginDir.v) { + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; + llvm::omp::Directive dirId{dirSpec.DirId()}; + switch (dirId) { case llvm::omp::Directive::OMPD_masked: case llvm::omp::Directive::OMPD_parallel_masked: case llvm::omp::Directive::OMPD_master: @@ -1718,15 +1721,15 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) { case llvm::omp::Directive::OMPD_parallel_workshare: case llvm::omp::Directive::OMPD_target_teams: case llvm::omp::Directive::OMPD_target_parallel: - PushContext(beginDir.source, beginDir.v); + PushContext(dirSpec.source, dirId); break; default: // TODO others break; } - if (beginDir.v == llvm::omp::Directive::OMPD_master || - beginDir.v == llvm::omp::Directive::OMPD_parallel_master) - IssueNonConformanceWarning(beginDir.v, beginDir.source, 52); + if (dirId == llvm::omp::Directive::OMPD_master || + dirId == llvm::omp::Directive::OMPD_parallel_master) + IssueNonConformanceWarning(dirId, dirSpec.source, 52); ClearDataSharingAttributeObjects(); ClearPrivateDataSharingAttributeObjects(); ClearAllocateNames(); @@ -1734,9 +1737,9 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) { } void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) { - const auto &beginBlockDir{std::get(x.t)}; - const auto &beginDir{std::get(beginBlockDir.t)}; - switch (beginDir.v) { + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; + llvm::omp::Directive dirId{dirSpec.DirId()}; + switch (dirId) { case llvm::omp::Directive::OMPD_masked: case llvm::omp::Directive::OMPD_master: case llvm::omp::Directive::OMPD_parallel_masked: @@ -2184,6 +2187,11 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDeclarativeAllocate &x) { return false; } +bool OmpAttributeVisitor::Pre(const parser::OpenMPAtomicConstruct &x) { + PushContext(x.source, llvm::omp::Directive::OMPD_atomic); + return true; +} + bool OmpAttributeVisitor::Pre(const parser::OpenMPDispatchConstruct &x) { PushContext(x.source, llvm::omp::Directive::OMPD_dispatch); return true; @@ -2201,7 +2209,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPExecutableAllocate &x) { } bool OmpAttributeVisitor::Pre(const parser::OpenMPAllocatorsConstruct &x) { - auto &dirSpec{std::get(x.t)}; + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; PushContext(x.source, dirSpec.DirId()); for (const auto &clause : dirSpec.Clauses().v) { @@ -2287,7 +2295,7 @@ void OmpAttributeVisitor::Post(const parser::OpenMPExecutableAllocate &x) { } void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) { - auto &dirSpec{std::get(x.t)}; + const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()}; auto &block{std::get(x.t)}; omp::SourcedActionStmt action{omp::GetActionStmt(block)}; diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index d08c669377cb2..6d3872c2198a5 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -1484,18 +1484,18 @@ class OmpVisitor : public virtual DeclarationVisitor { } bool Pre(const parser::OpenMPBlockConstruct &); void Post(const parser::OpenMPBlockConstruct &); - bool Pre(const parser::OmpBeginBlockDirective &x) { + bool Pre(const parser::OmpBeginDirective &x) { AddOmpSourceRange(x.source); return true; } - void Post(const parser::OmpBeginBlockDirective &) { + void Post(const parser::OmpBeginDirective &) { messageHandler().set_currStmtSource(std::nullopt); } - bool Pre(const parser::OmpEndBlockDirective &x) { + bool Pre(const parser::OmpEndDirective &x) { AddOmpSourceRange(x.source); return true; } - void Post(const parser::OmpEndBlockDirective &) { + void Post(const parser::OmpEndDirective &) { messageHandler().set_currStmtSource(std::nullopt); } @@ -1724,9 +1724,7 @@ class OmpVisitor : public virtual DeclarationVisitor { }; bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) { - const auto &beginBlockDir{std::get(x.t)}; - const auto &beginDir{std::get(beginBlockDir.t)}; - switch (beginDir.v) { + switch (x.BeginDir().DirId()) { case llvm::omp::Directive::OMPD_master: case llvm::omp::Directive::OMPD_ordered: return false; diff --git a/flang/test/Parser/OpenMP/affinity-clause.f90 b/flang/test/Parser/OpenMP/affinity-clause.f90 index 642af6aeb7e49..0b96cae9e74a8 100644 --- a/flang/test/Parser/OpenMP/affinity-clause.f90 +++ b/flang/test/Parser/OpenMP/affinity-clause.f90 @@ -15,8 +15,8 @@ subroutine f00(x) !UNPARSE: !$OMP END TASK !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = task +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task !PARSE-TREE: | OmpClauseList -> OmpClause -> Affinity -> OmpAffinityClause !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' @@ -34,8 +34,8 @@ subroutine f01(x) !UNPARSE: !$OMP END TASK !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = task +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task !PARSE-TREE: | OmpClauseList -> OmpClause -> Affinity -> OmpAffinityClause !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> ArrayElement !PARSE-TREE: | | | DataRef -> Name = 'x' @@ -60,8 +60,8 @@ subroutine f02(x) !UNPARSE: !$OMP END TASK !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = task +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task !PARSE-TREE: | OmpClauseList -> OmpClause -> Affinity -> OmpAffinityClause !PARSE-TREE: | | Modifier -> OmpIterator -> OmpIteratorSpecifier !PARSE-TREE: | | | TypeDeclarationStmt diff --git a/flang/test/Parser/OpenMP/allocators-unparse.f90 b/flang/test/Parser/OpenMP/allocators-unparse.f90 index 70feb7a6b527e..079d6acf114d5 100644 --- a/flang/test/Parser/OpenMP/allocators-unparse.f90 +++ b/flang/test/Parser/OpenMP/allocators-unparse.f90 @@ -28,7 +28,7 @@ end subroutine allocate !CHECK-NEXT: ALLOCATE(arr2(5,3)) !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAllocatorsConstruct -!PARSE-TREE-NEXT: | OmpDirectiveSpecification +!PARSE-TREE-NEXT: | OmpBeginDirective !PARSE-TREE-NEXT: | | OmpDirectiveName -> llvm::omp::Directive = allocators !PARSE-TREE-NEXT: | | OmpClauseList -> OmpClause -> Allocate -> OmpAllocateClause !PARSE-TREE-NEXT: | | | Modifier -> OmpAllocatorSimpleModifier -> Scalar -> Integer -> Expr -> Designator -> DataRef -> Name = 'omp_default_mem_alloc' @@ -40,7 +40,7 @@ end subroutine allocate !PARSE-TREE-NEXT: | | | | AllocateObject -> Name = 'arr1' !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAllocatorsConstruct -!PARSE-TREE-NEXT: | OmpDirectiveSpecification +!PARSE-TREE-NEXT: | OmpBeginDirective !PARSE-TREE-NEXT: | | OmpDirectiveName -> llvm::omp::Directive = allocators !PARSE-TREE-NEXT: | | OmpClauseList -> OmpClause -> Allocate -> OmpAllocateClause !PARSE-TREE-NEXT: | | | Modifier -> OmpAllocatorComplexModifier -> Scalar -> Integer -> Expr -> Designator -> DataRef -> Name = 'omp_default_mem_alloc' @@ -56,7 +56,7 @@ end subroutine allocate !PARSE-TREE-NEXT: | | | | AllocateObject -> Name = 'arr1' !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAllocatorsConstruct -!PARSE-TREE-NEXT: | OmpDirectiveSpecification +!PARSE-TREE-NEXT: | OmpBeginDirective !PARSE-TREE-NEXT: | | OmpDirectiveName -> llvm::omp::Directive = allocators !PARSE-TREE-NEXT: | | OmpClauseList -> OmpClause -> Allocate -> OmpAllocateClause !PARSE-TREE-NEXT: | | | Modifier -> OmpAlignModifier -> Scalar -> Integer -> Expr -> LiteralConstant -> IntLiteralConstant = '32' @@ -70,7 +70,7 @@ end subroutine allocate !PARSE-TREE-NEXT: | | | | | Scalar -> Integer -> Expr -> LiteralConstant -> IntLiteralConstant = '5' !PARSE-TREE-NEXT: | | | | AllocateShapeSpec !PARSE-TREE-NEXT: | | | | | Scalar -> Integer -> Expr -> LiteralConstant -> IntLiteralConstant = '3' -!PARSE-TREE-NEXT: | OmpDirectiveSpecification +!PARSE-TREE-NEXT: | OmpEndDirective !PARSE-TREE-NEXT: | | OmpDirectiveName -> llvm::omp::Directive = allocators !PARSE-TREE-NEXT: | | OmpClauseList -> !PARSE-TREE-NEXT: | | Flags = None diff --git a/flang/test/Parser/OpenMP/atomic-compare.f90 b/flang/test/Parser/OpenMP/atomic-compare.f90 index e09da4a359fcc..9b9c4f02df9c1 100644 --- a/flang/test/Parser/OpenMP/atomic-compare.f90 +++ b/flang/test/Parser/OpenMP/atomic-compare.f90 @@ -16,7 +16,7 @@ subroutine f00(a, b) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Update -> !PARSE-TREE: | | OmpClause -> Compare @@ -54,7 +54,7 @@ subroutine f01(a, b) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Update -> !PARSE-TREE: | | OmpClause -> Compare @@ -108,7 +108,7 @@ subroutine f02(a, b) !PARSE-TREE: | | | Expr = 'a' !PARSE-TREE: | | | | Designator -> DataRef -> Name = 'a' !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Update -> !PARSE-TREE: | | OmpClause -> Compare @@ -145,7 +145,7 @@ subroutine g00(a, b) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Update -> !PARSE-TREE: | | OmpClause -> Capture @@ -169,7 +169,7 @@ subroutine g00(a, b) !PARSE-TREE: | | | | | Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | | Expr = 'b' !PARSE-TREE: | | | | | Designator -> DataRef -> Name = 'b' -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpEndDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | | Flags = None @@ -197,7 +197,7 @@ subroutine g01(a, b) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Update -> !PARSE-TREE: | | OmpClause -> Capture @@ -224,7 +224,7 @@ subroutine g01(a, b) !PARSE-TREE: | | | | | Expr = 'b' !PARSE-TREE: | | | | | | Designator -> DataRef -> Name = 'b' !PARSE-TREE: | | | EndIfStmt -> -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpEndDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | | Flags = None @@ -254,7 +254,7 @@ subroutine g02(a, b) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Update -> !PARSE-TREE: | | OmpClause -> Capture @@ -284,7 +284,7 @@ subroutine g02(a, b) !PARSE-TREE: | | | | | | Expr = 'x' !PARSE-TREE: | | | | | | | Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | EndIfStmt -> -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpEndDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | | Flags = None diff --git a/flang/test/Parser/OpenMP/atomic-end.f90 b/flang/test/Parser/OpenMP/atomic-end.f90 index e5eac87517b1e..b971bb6f3d1da 100644 --- a/flang/test/Parser/OpenMP/atomic-end.f90 +++ b/flang/test/Parser/OpenMP/atomic-end.f90 @@ -16,7 +16,7 @@ subroutine f00 !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Read !PARSE-TREE: | | Flags = None @@ -26,7 +26,7 @@ subroutine f00 !PARSE-TREE: | | | | Designator -> DataRef -> Name = 'v' !PARSE-TREE: | | | Expr = 'x' !PARSE-TREE: | | | | Designator -> DataRef -> Name = 'x' -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpEndDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | | Flags = None @@ -47,7 +47,7 @@ subroutine f01 !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAtomicConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> OmpClause -> Read !PARSE-TREE: | | Flags = None @@ -57,7 +57,7 @@ subroutine f01 !PARSE-TREE: | | | | Designator -> DataRef -> Name = 'v' !PARSE-TREE: | | | Expr = 'x' !PARSE-TREE: | | | | Designator -> DataRef -> Name = 'x' -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpEndDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = atomic !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | | Flags = None diff --git a/flang/test/Parser/OpenMP/block-construct.f90 b/flang/test/Parser/OpenMP/block-construct.f90 index 83f0f7f276631..ea425544a5530 100644 --- a/flang/test/Parser/OpenMP/block-construct.f90 +++ b/flang/test/Parser/OpenMP/block-construct.f90 @@ -20,8 +20,8 @@ subroutine f00(x, y) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | OmpObject -> Designator -> DataRef -> Name = 'y' @@ -45,8 +45,8 @@ subroutine f00(x, y) !PARSE-TREE: | | | | | | LiteralConstant -> IntLiteralConstant = '2' !PARSE-TREE: | | | | | Expr = 'x' !PARSE-TREE: | | | | | | Designator -> DataRef -> Name = 'x' -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> @@ -72,8 +72,8 @@ subroutine f01(x, y) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | OmpObject -> Designator -> DataRef -> Name = 'y' @@ -129,8 +129,8 @@ subroutine f02(x, y) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | OmpObject -> Designator -> DataRef -> Name = 'y' @@ -160,6 +160,6 @@ subroutine f02(x, y) !PARSE-TREE: | | | | | | | Expr = 'x' !PARSE-TREE: | | | | | | | | Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | EndBlockStmt -> -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> diff --git a/flang/test/Parser/OpenMP/construct-prefix-conflict.f90 b/flang/test/Parser/OpenMP/construct-prefix-conflict.f90 index 678942afe1953..d6f5152b021f0 100644 --- a/flang/test/Parser/OpenMP/construct-prefix-conflict.f90 +++ b/flang/test/Parser/OpenMP/construct-prefix-conflict.f90 @@ -27,13 +27,13 @@ subroutine f00(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | Block !PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | | | OmpBeginBlockDirective -!PARSE-TREE: | | | | OmpBlockDirective -> llvm::omp::Directive = target data +!PARSE-TREE: | | | OmpBeginDirective +!PARSE-TREE: | | | | OmpDirectiveName -> llvm::omp::Directive = target data !PARSE-TREE: | | | | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | | | bool = 'true' @@ -43,11 +43,11 @@ subroutine f00(x) !PARSE-TREE: | | | | | Expr -> Add !PARSE-TREE: | | | | | | Expr -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | | | | Expr -> LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: | | | OmpEndBlockDirective -!PARSE-TREE: | | | | OmpBlockDirective -> llvm::omp::Directive = target data +!PARSE-TREE: | | | OmpEndDirective +!PARSE-TREE: | | | | OmpDirectiveName -> llvm::omp::Directive = target data !PARSE-TREE: | | | | OmpClauseList -> -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> @@ -70,8 +70,8 @@ subroutine f01(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | Block !PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPSimpleStandaloneConstruct -> OmpDirectiveSpecification @@ -85,8 +85,8 @@ subroutine f01(x) !PARSE-TREE: | | | Expr -> Add !PARSE-TREE: | | | | Expr -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | | Expr -> LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> @@ -109,8 +109,8 @@ subroutine f02(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | Block !PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPSimpleStandaloneConstruct -> OmpDirectiveSpecification @@ -124,8 +124,8 @@ subroutine f02(x) !PARSE-TREE: | | | Expr -> Add !PARSE-TREE: | | | | Expr -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | | Expr -> LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> @@ -148,8 +148,8 @@ subroutine f03(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | Block !PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPSimpleStandaloneConstruct -> OmpDirectiveSpecification @@ -163,6 +163,6 @@ subroutine f03(x) !PARSE-TREE: | | | Expr -> Add !PARSE-TREE: | | | | Expr -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | | | Expr -> LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | | OmpClauseList -> diff --git a/flang/test/Parser/OpenMP/defaultmap-clause.f90 b/flang/test/Parser/OpenMP/defaultmap-clause.f90 index d908258fac763..e7825e5b7a532 100644 --- a/flang/test/Parser/OpenMP/defaultmap-clause.f90 +++ b/flang/test/Parser/OpenMP/defaultmap-clause.f90 @@ -11,8 +11,8 @@ subroutine f00 !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: | | ImplicitBehavior = From !PARSE-TREE: Block @@ -27,8 +27,8 @@ subroutine f01 !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: | | ImplicitBehavior = Firstprivate !PARSE-TREE: | | Modifier -> OmpVariableCategory -> Value = Aggregate @@ -43,8 +43,8 @@ subroutine f02 !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: | | ImplicitBehavior = Alloc !PARSE-TREE: | | Modifier -> OmpVariableCategory -> Value = All @@ -61,8 +61,8 @@ subroutine f03 !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: | | ImplicitBehavior = Alloc !PARSE-TREE: | | Modifier -> OmpVariableCategory -> Value = Allocatable @@ -77,8 +77,8 @@ subroutine f04 !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: | | ImplicitBehavior = Tofrom !PARSE-TREE: | | Modifier -> OmpVariableCategory -> Value = Scalar @@ -93,8 +93,8 @@ subroutine f05 !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: | | ImplicitBehavior = Present !PARSE-TREE: | | Modifier -> OmpVariableCategory -> Value = Scalar diff --git a/flang/test/Parser/OpenMP/defaultmap-unparse.f90 b/flang/test/Parser/OpenMP/defaultmap-unparse.f90 index bbbb6fc938326..fa0578014071f 100644 --- a/flang/test/Parser/OpenMP/defaultmap-unparse.f90 +++ b/flang/test/Parser/OpenMP/defaultmap-unparse.f90 @@ -34,8 +34,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = Tofrom !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Scalar @@ -46,8 +46,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = Alloc !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Scalar @@ -58,8 +58,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = None @@ -69,8 +69,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = None !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Scalar @@ -81,8 +81,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = To !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Scalar @@ -93,8 +93,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = Firstprivate !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Scalar @@ -108,8 +108,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = Tofrom !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Aggregate @@ -120,8 +120,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = Tofrom !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Allocatable @@ -134,8 +134,8 @@ program main !CHECK: !$omp end target !$omp end target -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause !PARSE-TREE: ImplicitBehavior = Default !PARSE-TREE: Modifier -> OmpVariableCategory -> Value = Pointer diff --git a/flang/test/Parser/OpenMP/dispatch.f90 b/flang/test/Parser/OpenMP/dispatch.f90 index 4076c00331225..131b4d1f9ddb6 100644 --- a/flang/test/Parser/OpenMP/dispatch.f90 +++ b/flang/test/Parser/OpenMP/dispatch.f90 @@ -18,7 +18,7 @@ subroutine sub(x) !UNPARSE: !$OMP END DISPATCH !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPDispatchConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = dispatch !PARSE-TREE: | | OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: | | | Scalar -> Integer -> Expr = '3_4' @@ -37,7 +37,7 @@ subroutine sub(x) !PARSE-TREE: | Block !PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt ![...] -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpEndDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = dispatch !PARSE-TREE: | | OmpClauseList -> !PARSE-TREE: | | Flags = None @@ -51,7 +51,7 @@ subroutine sub(x) !UNPARSE: r=func(a+1_4,b+2_4,c+3_4) !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPDispatchConstruct -!PARSE-TREE: | OmpDirectiveSpecification +!PARSE-TREE: | OmpBeginDirective !PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = dispatch !PARSE-TREE: | | OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: | | | Scalar -> Integer -> Expr = '3_4' @@ -60,7 +60,7 @@ subroutine sub(x) !PARSE-TREE: | | Flags = None !PARSE-TREE: | Block !PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt -!PARSE-TREE-NOT: OmpDirectiveSpecification +!PARSE-TREE-NOT: OmpEndDirective !$omp dispatch device(3) is_device_ptr(x) r = func(a+1, b+2, c+3) diff --git a/flang/test/Parser/OpenMP/if-clause.f90 b/flang/test/Parser/OpenMP/if-clause.f90 index e47fbde2646d3..2bf80cb99f919 100644 --- a/flang/test/Parser/OpenMP/if-clause.f90 +++ b/flang/test/Parser/OpenMP/if-clause.f90 @@ -24,7 +24,7 @@ program openmp_parse_if ! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target exit data !$omp target exit data map(from: i) if(target exit data: cond) - ! CHECK: OmpBlockDirective -> llvm::omp::Directive = target data + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = target data ! CHECK: OmpClause -> If -> OmpIfClause ! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target data !$omp target data map(tofrom: i) if(target data: cond) @@ -45,7 +45,7 @@ program openmp_parse_if end do !$omp end target teams distribute parallel do simd - ! CHECK: OmpBlockDirective -> llvm::omp::Directive = task + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = task ! CHECK-NEXT: OmpClause -> If -> OmpIfClause ! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = task !$omp task if(task: cond) diff --git a/flang/test/Parser/OpenMP/in-reduction-clause.f90 b/flang/test/Parser/OpenMP/in-reduction-clause.f90 index bb3fadbc5088e..ee59069436a29 100644 --- a/flang/test/Parser/OpenMP/in-reduction-clause.f90 +++ b/flang/test/Parser/OpenMP/in-reduction-clause.f90 @@ -29,13 +29,13 @@ subroutine omp_in_reduction_taskgroup() end subroutine omp_in_reduction_taskgroup !PARSE-TREE: OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE-NEXT: OmpBeginBlockDirective -!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = taskgroup +!PARSE-TREE-NEXT: OmpBeginDirective +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskgroup !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> TaskReduction -> OmpTaskReductionClause !PARSE-TREE: OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE-NEXT: OmpBeginBlockDirective -!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = task +!PARSE-TREE-NEXT: OmpBeginDirective +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = task !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> InReduction -> OmpInReductionClause !PARSE-TREE-NEXT: OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add !PARSE-TREE-NEXT: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'z' @@ -66,8 +66,8 @@ subroutine omp_in_reduction_parallel() end subroutine omp_in_reduction_parallel !PARSE-TREE: OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE-NEXT: OmpBeginBlockDirective -!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel +!PARSE-TREE-NEXT: OmpBeginDirective +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct diff --git a/flang/test/Parser/OpenMP/map-modifiers-v60.f90 b/flang/test/Parser/OpenMP/map-modifiers-v60.f90 index bc80886780d46..46d57a0700390 100644 --- a/flang/test/Parser/OpenMP/map-modifiers-v60.f90 +++ b/flang/test/Parser/OpenMP/map-modifiers-v60.f90 @@ -15,8 +15,8 @@ subroutine f00(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpAlwaysModifier -> Value = Always !PARSE-TREE: | | Modifier -> OmpCloseModifier -> Value = Close @@ -38,8 +38,8 @@ subroutine f01(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpSelfModifier -> Value = Self !PARSE-TREE: | | Modifier -> OmpMapType -> Value = Storage @@ -60,8 +60,8 @@ subroutine f02(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpRefModifier -> Value = Ref_Ptr !PARSE-TREE: | | Modifier -> OmpMapType -> Value = To @@ -82,8 +82,8 @@ subroutine f03(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpRefModifier -> Value = Ref_Ptee !PARSE-TREE: | | Modifier -> OmpMapType -> Value = To @@ -104,8 +104,8 @@ subroutine f04(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpRefModifier -> Value = Ref_Ptr_Ptee !PARSE-TREE: | | Modifier -> OmpMapType -> Value = To diff --git a/flang/test/Parser/OpenMP/map-modifiers.f90 b/flang/test/Parser/OpenMP/map-modifiers.f90 index 4e034e51352e4..83662b70f08f5 100644 --- a/flang/test/Parser/OpenMP/map-modifiers.f90 +++ b/flang/test/Parser/OpenMP/map-modifiers.f90 @@ -15,8 +15,8 @@ subroutine f00(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Ompx_Hold !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Always @@ -40,8 +40,8 @@ subroutine f01(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Ompx_Hold !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Always @@ -64,8 +64,8 @@ subroutine f02(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapType -> Value = From !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' @@ -85,8 +85,8 @@ subroutine f03(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | bool = 'true' @@ -105,8 +105,8 @@ subroutine f04(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Ompx_Hold !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Always @@ -130,8 +130,8 @@ subroutine f05(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Ompx_Hold !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Always @@ -155,8 +155,8 @@ subroutine f10(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Present !PARSE-TREE: | | Modifier -> OmpIterator -> OmpIteratorSpecifier @@ -190,8 +190,8 @@ subroutine f11(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Present !PARSE-TREE: | | Modifier -> OmpIterator -> OmpIteratorSpecifier @@ -225,8 +225,8 @@ subroutine f12(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Present !PARSE-TREE: | | Modifier -> OmpIterator -> OmpIteratorSpecifier @@ -283,8 +283,8 @@ subroutine f20(x, y) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapTypeModifier -> Value = Present !PARSE-TREE: | | Modifier -> OmpIterator -> OmpIteratorSpecifier @@ -334,8 +334,8 @@ subroutine f21(x, y) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | Modifier -> OmpMapper -> Name = 'xx' !PARSE-TREE: | | Modifier -> OmpMapType -> Value = From @@ -355,7 +355,7 @@ subroutine f22(x) !UNPARSE: !$OMP END TARGET !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | Modifier -> OmpMapTypeModifier -> Value = Present !PARSE-TREE: | Modifier -> OmpIterator -> OmpIteratorSpecifier diff --git a/flang/test/Parser/OpenMP/masked-unparse.f90 b/flang/test/Parser/OpenMP/masked-unparse.f90 index 16d7ca68e3e18..46ddd3722216a 100644 --- a/flang/test/Parser/OpenMP/masked-unparse.f90 +++ b/flang/test/Parser/OpenMP/masked-unparse.f90 @@ -6,14 +6,14 @@ subroutine test_masked() integer :: c = 1 - !PARSE-TREE: OmpBeginBlockDirective - !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked + !PARSE-TREE: OmpBeginDirective + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = masked !CHECK: !$omp masked !$omp masked c = c + 1 !$omp end masked - !PARSE-TREE: OmpBeginBlockDirective - !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked + !PARSE-TREE: OmpBeginDirective + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = masked !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '1_4' !PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '1' !CHECK: !$omp masked filter(1_4) @@ -51,8 +51,8 @@ subroutine test_masked_taskloop subroutine test_parallel_masked integer, parameter :: i = 1, j = 1 integer :: c = 2 - !PARSE-TREE: OmpBeginBlockDirective - !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked + !PARSE-TREE: OmpBeginDirective + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel masked !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4' !PARSE-TREE-NEXT: Add !PARSE-TREE-NEXT: Expr = '1_4' diff --git a/flang/test/Parser/OpenMP/master-unparse.f90 b/flang/test/Parser/OpenMP/master-unparse.f90 index 30c293a521b5d..ec7a7d3845014 100644 --- a/flang/test/Parser/OpenMP/master-unparse.f90 +++ b/flang/test/Parser/OpenMP/master-unparse.f90 @@ -6,8 +6,8 @@ subroutine test_master() integer :: c = 1 - !PARSE-TREE: OmpBeginBlockDirective - !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = master + !PARSE-TREE: OmpBeginDirective + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = master !CHECK: !$omp master !$omp master c = c + 1 @@ -40,8 +40,8 @@ subroutine test_master_taskloop subroutine test_parallel_master integer :: c = 2 - !PARSE-TREE: OmpBeginBlockDirective - !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel master + !PARSE-TREE: OmpBeginDirective + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel master !CHECK: !$omp parallel master !$omp parallel master c = c + 2 diff --git a/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 b/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 index 6a1d565451220..69a0de656e4d5 100644 --- a/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 +++ b/flang/test/Parser/OpenMP/openmp6-directive-spellings.f90 @@ -170,14 +170,14 @@ subroutine f06 !UNPARSE: SUBROUTINE f06 !UNPARSE: IMPLICIT NONE !UNPARSE: INTEGER i -!UNPARSE: !$OMP TARGET DATA MAP(TOFROM: i) +!UNPARSE: !$OMP TARGET_DATA MAP(TOFROM: i) !UNPARSE: i=0_4 -!UNPARSE: !$OMP END TARGET DATA +!UNPARSE: !$OMP END TARGET_DATA !UNPARSE: END SUBROUTINE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: | OmpBeginBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target data +!PARSE-TREE: | OmpBeginDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target data !PARSE-TREE: | | OmpClauseList -> OmpClause -> Map -> OmpMapClause !PARSE-TREE: | | | Modifier -> OmpMapType -> Value = Tofrom !PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'i' @@ -188,8 +188,8 @@ subroutine f06 !PARSE-TREE: | | | | Designator -> DataRef -> Name = 'i' !PARSE-TREE: | | | Expr = '0_4' !PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '0' -!PARSE-TREE: | OmpEndBlockDirective -!PARSE-TREE: | | OmpBlockDirective -> llvm::omp::Directive = target data +!PARSE-TREE: | OmpEndDirective +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = target data !PARSE-TREE: | | OmpClauseList -> subroutine f07 diff --git a/flang/test/Parser/OpenMP/proc-bind.f90 b/flang/test/Parser/OpenMP/proc-bind.f90 index 3115b3771f27d..98ce39e4db911 100644 --- a/flang/test/Parser/OpenMP/proc-bind.f90 +++ b/flang/test/Parser/OpenMP/proc-bind.f90 @@ -4,8 +4,8 @@ ! CHECK: !$OMP PARALLEL PROC_BIND(PRIMARY) ! PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -! PARSE-TREE: OmpBeginBlockDirective -! PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = parallel +! PARSE-TREE: OmpBeginDirective +! PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel ! PARSE-TREE: OmpClauseList -> OmpClause -> ProcBind -> OmpProcBindClause -> AffinityPolicy = Primary subroutine sb1 !$omp parallel proc_bind(primary) diff --git a/flang/test/Parser/OpenMP/scope.f90 b/flang/test/Parser/OpenMP/scope.f90 index 6574136311e71..9e046d69f351e 100644 --- a/flang/test/Parser/OpenMP/scope.f90 +++ b/flang/test/Parser/OpenMP/scope.f90 @@ -9,13 +9,13 @@ program omp_scope !CHECK: !$OMP END SCOPE !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = scope +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = scope !PARSE-TREE: OmpClauseList -> OmpClause -> Private -> OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'i' !PARSE-TREE: Block !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = scope +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = scope !PARSE-TREE: OmpClauseList -> OmpClause -> Nowait !$omp scope private(i) diff --git a/flang/test/Parser/OpenMP/target_device_parse.f90 b/flang/test/Parser/OpenMP/target_device_parse.f90 index 7f5bee3793b2e..d3c9c692adcd4 100644 --- a/flang/test/Parser/OpenMP/target_device_parse.f90 +++ b/flang/test/Parser/OpenMP/target_device_parse.f90 @@ -20,13 +20,13 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: Scalar -> Integer -> Expr = '1_4' !PARSE-TREE: LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> !------------------------------------------------------ @@ -38,8 +38,8 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: Scalar -> Integer -> Expr = '1_4' !PARSE-TREE: Subtract @@ -47,8 +47,8 @@ PROGRAM main !PARSE-TREE: LiteralConstant -> IntLiteralConstant = '2' !PARSE-TREE: Expr = '1_4' !PARSE-TREE: LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> @@ -61,13 +61,13 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: Scalar -> Integer -> Expr = 'x' !PARSE-TREE: Designator -> DataRef -> Name = 'x' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> @@ -80,8 +80,8 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: Scalar -> Integer -> Expr = 'x+y' !PARSE-TREE: Add @@ -89,8 +89,8 @@ PROGRAM main !PARSE-TREE: Designator -> DataRef -> Name = 'x' !PARSE-TREE: Expr = 'y' !PARSE-TREE: Designator -> DataRef -> Name = 'y' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> !------------------------------------------------------ @@ -102,14 +102,14 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: OmpDeviceModifier -> Value = Ancestor !PARSE-TREE: Scalar -> Integer -> Expr = '1_4' !PARSE-TREE: LiteralConstant -> IntLiteralConstant = '1' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> @@ -122,14 +122,14 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: OmpDeviceModifier -> Value = Device_Num !PARSE-TREE: Scalar -> Integer -> Expr = '2_4' !PARSE-TREE: LiteralConstant -> IntLiteralConstant = '2' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> @@ -142,8 +142,8 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: OmpDeviceModifier -> Value = Ancestor !PARSE-TREE: Scalar -> Integer -> Expr = 'x+y' @@ -152,8 +152,8 @@ PROGRAM main !PARSE-TREE: Designator -> DataRef -> Name = 'x' !PARSE-TREE: Expr = 'y' !PARSE-TREE: Designator -> DataRef -> Name = 'y' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> @@ -166,8 +166,8 @@ PROGRAM main !CHECK: !$OMP END TARGET !$OMP END TARGET -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target !PARSE-TREE: OmpClauseList -> OmpClause -> Device -> OmpDeviceClause !PARSE-TREE: OmpDeviceModifier -> Value = Device_Num !PARSE-TREE: Scalar -> Integer -> Expr = 'x-y' @@ -176,6 +176,6 @@ PROGRAM main !PARSE-TREE: Designator -> DataRef -> Name = 'x' !PARSE-TREE: Expr = 'y' !PARSE-TREE: Designator -> DataRef -> Name = 'y' -!PARSE-TREE: OmpEndBlockDirective -!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpEndDirective +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = target END PROGRAM diff --git a/flang/test/Parser/OpenMP/task-reduction-clause.f90 b/flang/test/Parser/OpenMP/task-reduction-clause.f90 index 248ff7918dbe5..e3e6962462a63 100644 --- a/flang/test/Parser/OpenMP/task-reduction-clause.f90 +++ b/flang/test/Parser/OpenMP/task-reduction-clause.f90 @@ -15,8 +15,8 @@ subroutine f00 !UNPARSE: !$OMP END TASKGROUP !UNPARSE: END SUBROUTINE -!PARSE-TREE: OmpBeginBlockDirective -!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = taskgroup +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = taskgroup !PARSE-TREE: | OmpClauseList -> OmpClause -> TaskReduction -> OmpTaskReductionClause !PARSE-TREE: | | Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' diff --git a/flang/test/Parser/OpenMP/task.f90 b/flang/test/Parser/OpenMP/task.f90 index 706deb3451f98..d6508df9e978a 100644 --- a/flang/test/Parser/OpenMP/task.f90 +++ b/flang/test/Parser/OpenMP/task.f90 @@ -2,7 +2,7 @@ ! RUN: %flang_fc1 %openmp_flags -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case %s ! RUN: %flang_fc1 %openmp_flags -fdebug-unparse -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case --check-prefix="CHECK-UNPARSE" %s -!CHECK: OmpBlockDirective -> llvm::omp::Directive = task +!CHECK: OmpDirectiveName -> llvm::omp::Directive = task !CHECK: OmpClauseList -> OmpClause -> Detach -> OmpDetachClause -> OmpObject -> Designator -> DataRef -> Name = 'event' !CHECK-UNPARSE: INTEGER(KIND=8_4) event diff --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90 index bc1371847b792..e725e2670e8dc 100644 --- a/flang/test/Semantics/OpenMP/clause-validity01.f90 +++ b/flang/test/Semantics/OpenMP/clause-validity01.f90 @@ -163,8 +163,7 @@ !$omp parallel do i = 1, N enddo - !ERROR: Unmatched END TARGET directive - !$omp end target + !$omp end parallel ! OMP 5.0 - 2.6 Restriction point 1 outofparallel: do k =1, 10 diff --git a/flang/test/Semantics/OpenMP/symbol08.f90 b/flang/test/Semantics/OpenMP/symbol08.f90 index 545bccc86b068..bf0f724669fa2 100644 --- a/flang/test/Semantics/OpenMP/symbol08.f90 +++ b/flang/test/Semantics/OpenMP/symbol08.f90 @@ -130,8 +130,7 @@ subroutine dotprod (b, c, n, block_size, num_teams, block_threads) !REF: /dotprod/sum sum = 0.0e0 !$omp target map(to:b,c) map(tofrom:sum) -!$omp teams num_teams(num_teams) thread_limit(block_threads) reduction(+: sum& -!$OMP&) +!$omp teams num_teams(num_teams) thread_limit(block_threads) reduction(+: sum) !$omp distribute !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/i0 (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4) !REF: /dotprod/n From 8c3232c9159941c0959b9c21bac8768efae86b91 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 31 Jul 2025 08:50:04 -0500 Subject: [PATCH 6/6] Inherit constructors --- flang/include/flang/Parser/parse-tree.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 0429692012d52..b97e5f387d14f 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3470,8 +3470,7 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions #define INHERITED_TUPLE_CLASS_BOILERPLATE(classname, basename) \ - template > \ - classname(Ts &&...args) : basename(std::move(args)...) {} \ + using basename::basename; \ classname(basename &&b) : basename(std::move(b)) {} \ using TupleTrait = std::true_type; \ BOILERPLATE(classname)