From 0599bff45f1d80a8b3bad3eb2d9eee8e3fad0c27 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 15 Sep 2025 11:30:29 -0500 Subject: [PATCH 1/2] [flang][OpenMP] Use OmpDirectiveSpecification in Omp[Begin|End]LoopDirective This makes accessing directive components, such as directive name or the list of clauses simpler and more uniform across different directives. It also makes the parser simpler, since it reuses existing parsing functionality. --- flang/include/flang/Parser/openmp-utils.h | 3 +- flang/include/flang/Parser/parse-tree.h | 19 ++- flang/lib/Lower/OpenMP/OpenMP.cpp | 56 ++----- flang/lib/Lower/OpenMP/Utils.cpp | 13 +- flang/lib/Parser/openmp-parsers.cpp | 157 ++++++++++-------- flang/lib/Parser/unparse.cpp | 128 +------------- flang/lib/Semantics/canonicalize-omp.cpp | 76 ++++----- flang/lib/Semantics/check-omp-loop.cpp | 76 ++++----- flang/lib/Semantics/check-omp-structure.cpp | 40 ++--- flang/lib/Semantics/resolve-directives.cpp | 40 ++--- flang/lib/Semantics/rewrite-parse-tree.cpp | 4 +- flang/test/Parser/OpenMP/bind-clause.f90 | 3 +- .../Parser/OpenMP/declare-reduction-multi.f90 | 12 +- .../OpenMP/declare-reduction-unparse.f90 | 2 +- flang/test/Parser/OpenMP/do-tile-size.f90 | 2 +- flang/test/Parser/OpenMP/doacross-clause.f90 | 4 +- flang/test/Parser/OpenMP/if-clause.f90 | 4 +- .../Parser/OpenMP/in-reduction-clause.f90 | 6 +- .../test/Parser/OpenMP/lastprivate-clause.f90 | 4 +- flang/test/Parser/OpenMP/linear-clause.f90 | 9 +- .../loop-transformation-construct01.f90 | 12 +- .../loop-transformation-construct02.f90 | 18 +- .../loop-transformation-construct03.f90 | 3 +- flang/test/Parser/OpenMP/masked-unparse.f90 | 8 +- flang/test/Parser/OpenMP/master-unparse.f90 | 8 +- flang/test/Parser/OpenMP/order-clause01.f90 | 45 +++-- flang/test/Parser/OpenMP/ordered-depend.f90 | 4 +- .../test/Parser/OpenMP/reduction-modifier.f90 | 2 +- .../Parser/OpenMP/target-loop-unparse.f90 | 10 +- flang/test/Parser/OpenMP/taskloop.f90 | 6 +- flang/test/Parser/OpenMP/tile-size.f90 | 2 +- flang/test/Parser/OpenMP/tile.f90 | 2 +- .../test/Parser/OpenMP/transparent-clause.f90 | 3 +- flang/test/Parser/OpenMP/unroll-full.f90 | 2 +- flang/test/Parser/OpenMP/unroll-heuristic.f90 | 6 +- flang/test/Parser/OpenMP/unroll-partial.f90 | 2 +- flang/test/Semantics/OpenMP/simd-only.f90 | 38 ++--- 37 files changed, 351 insertions(+), 478 deletions(-) diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index 8205d25647916..032fb8996fe48 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -67,8 +67,7 @@ struct DirectiveNameScope { } static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) { - auto &dir{std::get(x.t)}; - return MakeName(dir.source, dir.v); + return x.DirName(); } static OmpDirectiveName GetOmpDirectiveName(const OpenMPSectionConstruct &x) { diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 951c96b974141..7307283eb91ec 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -5158,16 +5158,12 @@ struct OpenMPStandaloneConstruct { u; }; -struct OmpBeginLoopDirective { - TUPLE_CLASS_BOILERPLATE(OmpBeginLoopDirective); - std::tuple t; - CharBlock source; +struct OmpBeginLoopDirective : public OmpBeginDirective { + INHERITED_TUPLE_CLASS_BOILERPLATE(OmpBeginLoopDirective, OmpBeginDirective); }; -struct OmpEndLoopDirective { - TUPLE_CLASS_BOILERPLATE(OmpEndLoopDirective); - std::tuple t; - CharBlock source; +struct OmpEndLoopDirective : public OmpEndDirective { + INHERITED_TUPLE_CLASS_BOILERPLATE(OmpEndLoopDirective, OmpEndDirective); }; // OpenMP directives enclosing do loop @@ -5177,6 +5173,13 @@ struct OpenMPLoopConstruct { TUPLE_CLASS_BOILERPLATE(OpenMPLoopConstruct); OpenMPLoopConstruct(OmpBeginLoopDirective &&a) : t({std::move(a), std::nullopt, std::nullopt}) {} + + const OmpBeginLoopDirective &BeginDir() const { + return std::get(t); + } + const std::optional &EndDir() const { + return std::get>(t); + } std::tuple, std::optional> t; diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 0ec33e6b24dbf..3a59c0f5f5a90 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -408,26 +408,15 @@ static void processHostEvalClauses(lower::AbstractConverter &converter, const parser::OmpClauseList *beginClauseList = nullptr; const parser::OmpClauseList *endClauseList = nullptr; common::visit( - common::visitors{ - [&](const parser::OmpBlockConstruct &ompConstruct) { - beginClauseList = &ompConstruct.BeginDir().Clauses(); - if (auto &endSpec = ompConstruct.EndDir()) - endClauseList = &endSpec->Clauses(); - }, - [&](const parser::OpenMPLoopConstruct &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); - } - }, - [&](const auto &) {}}, + [&](const auto &construct) { + using Type = llvm::remove_cvref_t; + if constexpr (std::is_same_v || + std::is_same_v) { + beginClauseList = &construct.BeginDir().Clauses(); + if (auto &endSpec = construct.EndDir()) + endClauseList = &endSpec->Clauses(); + } + }, ompEval->u); assert(beginClauseList && "expected begin directive"); @@ -3820,19 +3809,12 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, const parser::OpenMPLoopConstruct &loopConstruct) { - const auto &beginLoopDirective = - std::get(loopConstruct.t); - List clauses = makeClauses( - std::get(beginLoopDirective.t), semaCtx); - if (auto &endLoopDirective = - std::get>( - loopConstruct.t)) { - clauses.append(makeClauses( - std::get(endLoopDirective->t), semaCtx)); - } + const parser::OmpDirectiveSpecification &beginSpec = loopConstruct.BeginDir(); + List clauses = makeClauses(beginSpec.Clauses(), semaCtx); + if (auto &endSpec = loopConstruct.EndDir()) + clauses.append(makeClauses(endSpec->Clauses(), semaCtx)); - mlir::Location currentLocation = - converter.genLocation(beginLoopDirective.source); + mlir::Location currentLocation = converter.genLocation(beginSpec.source); auto &optLoopCons = std::get>(loopConstruct.t); @@ -3858,13 +3840,10 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, } } - llvm::omp::Directive directive = - parser::omp::GetOmpDirectiveName(beginLoopDirective).v; - const parser::CharBlock &source = - std::get(beginLoopDirective.t).source; + const parser::OmpDirectiveName &beginName = beginSpec.DirName(); ConstructQueue queue{ buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx, - eval, source, directive, clauses)}; + eval, beginName.source, beginName.v, clauses)}; genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue, queue.begin()); } @@ -4047,8 +4026,7 @@ bool Fortran::lower::isOpenMPTargetConstruct( dir = block->BeginDir().DirId(); } else if (const auto *loop = std::get_if(&omp.u)) { - const auto &begin = std::get(loop->t); - dir = std::get(begin.t).v; + dir = loop->BeginDir().DirId(); } return llvm::omp::allTargetSet.test(dir); } diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index d1d1cd68a5b44..83b7ccb1ce0ee 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -616,16 +616,11 @@ static void processTileSizesFromOpenMPConstruct( &(nestedOptional.value())); if (innerConstruct) { const auto &innerLoopDirective = innerConstruct->value(); - const auto &innerBegin = - std::get(innerLoopDirective.t); - const auto &innerDirective = - std::get(innerBegin.t).v; - - if (innerDirective == llvm::omp::Directive::OMPD_tile) { + const parser::OmpDirectiveSpecification &innerBeginSpec = + innerLoopDirective.BeginDir(); + if (innerBeginSpec.DirId() == llvm::omp::Directive::OMPD_tile) { // Get the size values from parse tree and convert to a vector. - const auto &innerClauseList{ - std::get(innerBegin.t)}; - for (const auto &clause : innerClauseList.v) { + for (const auto &clause : innerBeginSpec.Clauses().v) { if (const auto tclause{ std::get_if(&clause.u)}) { processFun(tclause); diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 519bce64321d4..0c466b91d0845 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -18,15 +18,34 @@ #include "flang/Parser/openmp-utils.h" #include "flang/Parser/parse-tree.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Bitset.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Frontend/OpenMP/OMP.h" +#include "llvm/Support/MathExtras.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // OpenMP Directives and Clauses namespace Fortran::parser { using namespace Fortran::parser::omp; +static constexpr size_t DirectiveCount{ + static_cast(llvm::omp::Directive::Last_) - + static_cast(llvm::omp::Directive::First_) + 1}; +using DirectiveSet = llvm::Bitset; + // Helper function to print the buffer contents starting at the current point. [[maybe_unused]] static std::string ahead(const ParseState &state) { return std::string( @@ -1349,95 +1368,46 @@ TYPE_PARSER(sourced(construct( TYPE_PARSER(sourced(construct( verbatim("METADIRECTIVE"_tok), Parser{}))) -// Omp directives enclosing do loop -TYPE_PARSER(sourced(construct(first( - "DISTRIBUTE PARALLEL DO SIMD" >> - pure(llvm::omp::Directive::OMPD_distribute_parallel_do_simd), - "DISTRIBUTE PARALLEL DO" >> - pure(llvm::omp::Directive::OMPD_distribute_parallel_do), - "DISTRIBUTE SIMD" >> pure(llvm::omp::Directive::OMPD_distribute_simd), - "DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_distribute), - "DO SIMD" >> pure(llvm::omp::Directive::OMPD_do_simd), - "DO" >> pure(llvm::omp::Directive::OMPD_do), - "LOOP" >> pure(llvm::omp::Directive::OMPD_loop), - "MASKED TASKLOOP SIMD" >> - pure(llvm::omp::Directive::OMPD_masked_taskloop_simd), - "MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop), - "MASTER TASKLOOP SIMD" >> - pure(llvm::omp::Directive::OMPD_master_taskloop_simd), - "MASTER TASKLOOP" >> pure(llvm::omp::Directive::OMPD_master_taskloop), - "PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd), - "PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do), - "PARALLEL MASKED TASKLOOP SIMD" >> - pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd), - "PARALLEL MASKED TASKLOOP" >> - pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop), - "PARALLEL MASTER TASKLOOP SIMD" >> - pure(llvm::omp::Directive::OMPD_parallel_master_taskloop_simd), - "PARALLEL MASTER TASKLOOP" >> - pure(llvm::omp::Directive::OMPD_parallel_master_taskloop), - "SIMD" >> pure(llvm::omp::Directive::OMPD_simd), - "TARGET LOOP" >> pure(llvm::omp::Directive::OMPD_target_loop), - "TARGET PARALLEL DO SIMD" >> - pure(llvm::omp::Directive::OMPD_target_parallel_do_simd), - "TARGET PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_target_parallel_do), - "TARGET PARALLEL LOOP" >> - pure(llvm::omp::Directive::OMPD_target_parallel_loop), - "TARGET SIMD" >> pure(llvm::omp::Directive::OMPD_target_simd), - "TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD" >> - pure(llvm::omp::Directive:: - OMPD_target_teams_distribute_parallel_do_simd), - "TARGET TEAMS DISTRIBUTE PARALLEL DO" >> - pure(llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do), - "TARGET TEAMS DISTRIBUTE SIMD" >> - pure(llvm::omp::Directive::OMPD_target_teams_distribute_simd), - "TARGET TEAMS DISTRIBUTE" >> - pure(llvm::omp::Directive::OMPD_target_teams_distribute), - "TARGET TEAMS LOOP" >> pure(llvm::omp::Directive::OMPD_target_teams_loop), - "TASKLOOP SIMD" >> pure(llvm::omp::Directive::OMPD_taskloop_simd), - "TASKLOOP" >> pure(llvm::omp::Directive::OMPD_taskloop), - "TEAMS DISTRIBUTE PARALLEL DO SIMD" >> - pure(llvm::omp::Directive::OMPD_teams_distribute_parallel_do_simd), - "TEAMS DISTRIBUTE PARALLEL DO" >> - pure(llvm::omp::Directive::OMPD_teams_distribute_parallel_do), - "TEAMS DISTRIBUTE SIMD" >> - pure(llvm::omp::Directive::OMPD_teams_distribute_simd), - "TEAMS DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_teams_distribute), - "TEAMS LOOP" >> pure(llvm::omp::Directive::OMPD_teams_loop), - "TILE" >> pure(llvm::omp::Directive::OMPD_tile), - "UNROLL" >> pure(llvm::omp::Directive::OMPD_unroll))))) - -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; }; } +static inline constexpr auto IsMemberOf(const DirectiveSet &dirs) { + return [&dirs](const OmpDirectiveName &name) -> bool { + return dirs.test(llvm::to_underlying(name.v)); + }; +} + struct OmpBeginDirectiveParser { using resultType = OmpDirectiveSpecification; - constexpr OmpBeginDirectiveParser(llvm::omp::Directive dir) : dir_(dir) {} + constexpr OmpBeginDirectiveParser(DirectiveSet dirs) : dirs_(dirs) {} + constexpr OmpBeginDirectiveParser(llvm::omp::Directive dir) { + dirs_.set(llvm::to_underlying(dir)); + } std::optional Parse(ParseState &state) const { - auto &&p{predicated(Parser{}, IsDirective(dir_)) >= + auto &&p{predicated(Parser{}, IsMemberOf(dirs_)) >= Parser{}}; return p.Parse(state); } private: - llvm::omp::Directive dir_; + DirectiveSet dirs_; }; struct OmpEndDirectiveParser { using resultType = OmpDirectiveSpecification; - constexpr OmpEndDirectiveParser(llvm::omp::Directive dir) : dir_(dir) {} + constexpr OmpEndDirectiveParser(DirectiveSet dirs) : dirs_(dirs) {} + constexpr OmpEndDirectiveParser(llvm::omp::Directive dir) { + dirs_.set(llvm::to_underlying(dir)); + } std::optional Parse(ParseState &state) const { if (startOmpLine.Parse(state)) { if (auto endToken{verbatim("END"_sptok).Parse(state)}) { - if (auto &&dirSpec{OmpBeginDirectiveParser(dir_).Parse(state)}) { + if (auto &&dirSpec{OmpBeginDirectiveParser(dirs_).Parse(state)}) { // Extend the "source" on both the OmpDirectiveName and the // OmpDirectiveNameSpecification. CharBlock &nameSource{std::get(dirSpec->t).source}; @@ -1451,7 +1421,7 @@ struct OmpEndDirectiveParser { } private: - llvm::omp::Directive dir_; + DirectiveSet dirs_; }; struct OmpStatementConstructParser { @@ -1946,11 +1916,56 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US, construct(Parser{}), construct(Parser{})))) +static constexpr DirectiveSet GetLoopDirectives() { + using Directive = llvm::omp::Directive; + constexpr DirectiveSet loopDirectives{ + unsigned(Directive::OMPD_distribute), + unsigned(Directive::OMPD_distribute_parallel_do), + unsigned(Directive::OMPD_distribute_parallel_do_simd), + unsigned(Directive::OMPD_distribute_simd), + unsigned(Directive::OMPD_do), + unsigned(Directive::OMPD_do_simd), + unsigned(Directive::OMPD_loop), + unsigned(Directive::OMPD_masked_taskloop), + unsigned(Directive::OMPD_masked_taskloop_simd), + unsigned(Directive::OMPD_master_taskloop), + unsigned(Directive::OMPD_master_taskloop_simd), + unsigned(Directive::OMPD_parallel_do), + unsigned(Directive::OMPD_parallel_do_simd), + unsigned(Directive::OMPD_parallel_masked_taskloop), + unsigned(Directive::OMPD_parallel_masked_taskloop_simd), + unsigned(Directive::OMPD_parallel_master_taskloop), + unsigned(Directive::OMPD_parallel_master_taskloop_simd), + unsigned(Directive::OMPD_simd), + unsigned(Directive::OMPD_target_loop), + unsigned(Directive::OMPD_target_parallel_do), + unsigned(Directive::OMPD_target_parallel_do_simd), + unsigned(Directive::OMPD_target_parallel_loop), + unsigned(Directive::OMPD_target_simd), + unsigned(Directive::OMPD_target_teams_distribute), + unsigned(Directive::OMPD_target_teams_distribute_parallel_do), + unsigned(Directive::OMPD_target_teams_distribute_parallel_do_simd), + unsigned(Directive::OMPD_target_teams_distribute_simd), + unsigned(Directive::OMPD_target_teams_loop), + unsigned(Directive::OMPD_taskloop), + unsigned(Directive::OMPD_taskloop_simd), + unsigned(Directive::OMPD_teams_distribute), + unsigned(Directive::OMPD_teams_distribute_parallel_do), + unsigned(Directive::OMPD_teams_distribute_parallel_do_simd), + unsigned(Directive::OMPD_teams_distribute_simd), + unsigned(Directive::OMPD_teams_loop), + unsigned(Directive::OMPD_tile), + unsigned(Directive::OMPD_unroll), + }; + return loopDirectives; +} + +TYPE_PARSER(sourced(construct( + sourced(OmpBeginDirectiveParser(GetLoopDirectives()))))) + // END OMP Loop directives -TYPE_PARSER( - startOmpLine >> sourced(construct( - sourced("END"_tok >> Parser{}), - Parser{}))) +TYPE_PARSER(sourced(construct( + sourced(OmpEndDirectiveParser(GetLoopDirectives()))))) TYPE_PARSER(construct( Parser{} / endOmpLine)) diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index dc6d33607146b..73bbbc04f46b1 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2403,120 +2403,6 @@ class UnparseVisitor { } #define GEN_FLANG_CLAUSE_UNPARSE #include "llvm/Frontend/OpenMP/OMP.inc" - void Unparse(const OmpLoopDirective &x) { - switch (x.v) { - case llvm::omp::Directive::OMPD_distribute: - Word("DISTRIBUTE "); - break; - case llvm::omp::Directive::OMPD_distribute_parallel_do: - Word("DISTRIBUTE PARALLEL DO "); - break; - case llvm::omp::Directive::OMPD_distribute_parallel_do_simd: - Word("DISTRIBUTE PARALLEL DO SIMD "); - break; - case llvm::omp::Directive::OMPD_distribute_simd: - Word("DISTRIBUTE SIMD "); - break; - case llvm::omp::Directive::OMPD_do: - Word("DO "); - break; - case llvm::omp::Directive::OMPD_do_simd: - Word("DO SIMD "); - break; - case llvm::omp::Directive::OMPD_loop: - Word("LOOP "); - break; - case llvm::omp::Directive::OMPD_masked_taskloop_simd: - Word("MASKED TASKLOOP SIMD"); - break; - case llvm::omp::Directive::OMPD_masked_taskloop: - Word("MASKED TASKLOOP"); - break; - case llvm::omp::Directive::OMPD_master_taskloop_simd: - Word("MASTER TASKLOOP SIMD"); - break; - case llvm::omp::Directive::OMPD_master_taskloop: - Word("MASTER TASKLOOP"); - break; - case llvm::omp::Directive::OMPD_parallel_do: - Word("PARALLEL DO "); - break; - case llvm::omp::Directive::OMPD_parallel_do_simd: - Word("PARALLEL DO SIMD "); - break; - case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd: - Word("PARALLEL MASKED TASKLOOP SIMD"); - break; - case llvm::omp::Directive::OMPD_parallel_masked_taskloop: - Word("PARALLEL MASKED TASKLOOP"); - break; - case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd: - Word("PARALLEL MASTER TASKLOOP SIMD"); - break; - case llvm::omp::Directive::OMPD_parallel_master_taskloop: - Word("PARALLEL MASTER TASKLOOP"); - break; - case llvm::omp::Directive::OMPD_simd: - Word("SIMD "); - break; - case llvm::omp::Directive::OMPD_target_loop: - Word("TARGET LOOP "); - break; - case llvm::omp::Directive::OMPD_target_parallel_do: - Word("TARGET PARALLEL DO "); - break; - case llvm::omp::Directive::OMPD_target_parallel_do_simd: - Word("TARGET PARALLEL DO SIMD "); - break; - case llvm::omp::Directive::OMPD_target_parallel_loop: - Word("TARGET PARALLEL LOOP "); - break; - case llvm::omp::Directive::OMPD_target_teams_distribute: - Word("TARGET TEAMS DISTRIBUTE "); - break; - case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do: - Word("TARGET TEAMS DISTRIBUTE PARALLEL DO "); - break; - case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do_simd: - Word("TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD "); - break; - case llvm::omp::Directive::OMPD_target_teams_distribute_simd: - Word("TARGET TEAMS DISTRIBUTE SIMD "); - break; - case llvm::omp::Directive::OMPD_target_teams_loop: - Word("TARGET TEAMS LOOP "); - break; - case llvm::omp::Directive::OMPD_target_simd: - Word("TARGET SIMD "); - break; - case llvm::omp::Directive::OMPD_taskloop: - Word("TASKLOOP "); - break; - case llvm::omp::Directive::OMPD_taskloop_simd: - Word("TASKLOOP SIMD "); - break; - case llvm::omp::Directive::OMPD_teams_distribute: - Word("TEAMS DISTRIBUTE "); - break; - case llvm::omp::Directive::OMPD_teams_distribute_parallel_do: - Word("TEAMS DISTRIBUTE PARALLEL DO "); - break; - case llvm::omp::Directive::OMPD_teams_distribute_parallel_do_simd: - Word("TEAMS DISTRIBUTE PARALLEL DO SIMD "); - break; - case llvm::omp::Directive::OMPD_teams_distribute_simd: - Word("TEAMS DISTRIBUTE SIMD "); - break; - case llvm::omp::Directive::OMPD_tile: - Word("TILE "); - break; - case llvm::omp::Directive::OMPD_unroll: - Word("UNROLL "); - break; - default: - break; - } - } void Unparse(const OmpObjectList &x) { Walk(x.v, ","); } void Unparse(const common::OmpMemoryOrderType &x) { @@ -2815,13 +2701,11 @@ class UnparseVisitor { Put("\n"); EndOpenMP(); } + void Unparse(const OmpBeginLoopDirective &x) { + Unparse(static_cast(x)); + } void Unparse(const OmpEndLoopDirective &x) { - BeginOpenMP(); - Word("!$OMP END "); - Walk(std::get(x.t)); - Walk(std::get(x.t)); - Put("\n"); - EndOpenMP(); + Unparse(static_cast(x)); } void Unparse(const OmpClauseList &x, const char *sep = " ") { Walk(" ", x.v, sep); @@ -2834,11 +2718,7 @@ class UnparseVisitor { EndOpenMP(); } void Unparse(const OpenMPLoopConstruct &x) { - BeginOpenMP(); - Word("!$OMP "); Walk(std::get(x.t)); - Put("\n"); - EndOpenMP(); Walk(std::get>>>(x.t)); Walk(std::get>(x.t)); diff --git a/flang/lib/Semantics/canonicalize-omp.cpp b/flang/lib/Semantics/canonicalize-omp.cpp index 9722eca19447d..c884658bf464a 100644 --- a/flang/lib/Semantics/canonicalize-omp.cpp +++ b/flang/lib/Semantics/canonicalize-omp.cpp @@ -42,11 +42,11 @@ class CanonicalizationOfOmp { } else if (auto *endDir{ GetConstructIf(*it)}) { // Unmatched OmpEndLoopDirective - auto &dir{std::get(endDir->t)}; - messages_.Say(dir.source, + const parser::OmpDirectiveName &endName{endDir->DirName()}; + messages_.Say(endName.source, "The %s directive must follow the DO loop associated with the " "loop construct"_err_en_US, - parser::ToUpperCaseLetters(dir.source.ToString())); + parser::ToUpperCaseLetters(endName.source.ToString())); } } // Block list } @@ -128,17 +128,20 @@ class CanonicalizationOfOmp { // DoConstruct // OmpEndLoopDirective (if available) parser::Block::iterator nextIt; - auto &beginDir{std::get(x.t)}; - auto &dir{std::get(beginDir.t)}; - auto missingDoConstruct = [](auto &dir, auto &messages) { - messages.Say(dir.source, + const parser::OmpDirectiveSpecification &beginDir{x.BeginDir()}; + const parser::OmpDirectiveName &beginName{beginDir.DirName()}; + + auto missingDoConstruct = [](const parser::OmpDirectiveName &dirName, + parser::Messages &messages) { + messages.Say(dirName.source, "A DO loop must follow the %s directive"_err_en_US, - parser::ToUpperCaseLetters(dir.source.ToString())); + parser::ToUpperCaseLetters(dirName.source.ToString())); }; - auto tileUnrollError = [](auto &dir, auto &messages) { - messages.Say(dir.source, + auto tileUnrollError = [](const parser::OmpDirectiveName &dirName, + parser::Messages &messages) { + messages.Say(dirName.source, "If a loop construct has been fully unrolled, it cannot then be tiled"_err_en_US, - parser::ToUpperCaseLetters(dir.source.ToString())); + parser::ToUpperCaseLetters(dirName.source.ToString())); }; nextIt = it; @@ -164,23 +167,20 @@ class CanonicalizationOfOmp { } } } else { - messages_.Say(dir.source, + messages_.Say(beginName.source, "DO loop after the %s directive must have loop control"_err_en_US, - parser::ToUpperCaseLetters(dir.source.ToString())); + parser::ToUpperCaseLetters(beginName.source.ToString())); } } else if (auto *ompLoopCons{ GetOmpIf(*nextIt)}) { // We should allow UNROLL and TILE constructs to be inserted between an // OpenMP Loop Construct and the DO loop itself - auto &nestedBeginDirective = - std::get(ompLoopCons->t); - auto &nestedBeginLoopDirective = - std::get(nestedBeginDirective.t); - if ((nestedBeginLoopDirective.v == llvm::omp::Directive::OMPD_unroll || - nestedBeginLoopDirective.v == - llvm::omp::Directive::OMPD_tile) && - !(nestedBeginLoopDirective.v == llvm::omp::Directive::OMPD_unroll && - dir.v == llvm::omp::Directive::OMPD_tile)) { + auto &nestedBeginDirective = ompLoopCons->BeginDir(); + auto &nestedBeginName = nestedBeginDirective.DirName(); + if ((nestedBeginName.v == llvm::omp::Directive::OMPD_unroll || + nestedBeginName.v == llvm::omp::Directive::OMPD_tile) && + !(nestedBeginName.v == llvm::omp::Directive::OMPD_unroll && + beginName.v == llvm::omp::Directive::OMPD_tile)) { // iterate through the remaining block items to find the end directive // for the unroll/tile directive. parser::Block::iterator endIt; @@ -188,9 +188,8 @@ class CanonicalizationOfOmp { while (endIt != block.end()) { if (auto *endDir{ GetConstructIf(*endIt)}) { - auto &endLoopDirective = - std::get(endDir->t); - if (endLoopDirective.v == dir.v) { + auto &endDirName = endDir->DirName(); + if (endDirName.v == beginName.v) { std::get>(x.t) = std::move(*endDir); endIt = block.erase(endIt); @@ -205,41 +204,38 @@ class CanonicalizationOfOmp { std::optional{parser::NestedConstruct{ common::Indirection{std::move(*ompLoopCons)}}}; nextIt = block.erase(nextIt); - } else if (nestedBeginLoopDirective.v == - llvm::omp::Directive::OMPD_unroll && - dir.v == llvm::omp::Directive::OMPD_tile) { + } else if (nestedBeginName.v == llvm::omp::Directive::OMPD_unroll && + beginName.v == llvm::omp::Directive::OMPD_tile) { // if a loop has been unrolled, the user can not then tile that loop // as it has been unrolled - parser::OmpClauseList &unrollClauseList{ - std::get(nestedBeginDirective.t)}; + const parser::OmpClauseList &unrollClauseList{ + nestedBeginDirective.Clauses()}; if (unrollClauseList.v.empty()) { // if the clause list is empty for an unroll construct, we assume // the loop is being fully unrolled - tileUnrollError(dir, messages_); + tileUnrollError(beginName, messages_); } else { // parse the clauses for the unroll directive to find the full // clause - for (auto clause{unrollClauseList.v.begin()}; - clause != unrollClauseList.v.end(); ++clause) { - if (clause->Id() == llvm::omp::OMPC_full) { - tileUnrollError(dir, messages_); + for (auto &clause : unrollClauseList.v) { + if (clause.Id() == llvm::omp::OMPC_full) { + tileUnrollError(beginName, messages_); } } } } else { - messages_.Say(nestedBeginLoopDirective.source, + messages_.Say(nestedBeginName.source, "Only Loop Transformation Constructs or Loop Nests can be nested within Loop Constructs"_err_en_US, - parser::ToUpperCaseLetters( - nestedBeginLoopDirective.source.ToString())); + parser::ToUpperCaseLetters(nestedBeginName.source.ToString())); } } else { - missingDoConstruct(dir, messages_); + missingDoConstruct(beginName, messages_); } // If we get here, we either found a loop, or issued an error message. return; } if (nextIt == block.end()) { - missingDoConstruct(dir, messages_); + missingDoConstruct(beginName, messages_); } } diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp index 9384e039cf3f3..562bd1b4e79a4 100644 --- a/flang/lib/Semantics/check-omp-loop.cpp +++ b/flang/lib/Semantics/check-omp-loop.cpp @@ -128,9 +128,8 @@ using namespace Fortran::semantics::omp; void OmpStructureChecker::HasInvalidDistributeNesting( const parser::OpenMPLoopConstruct &x) { bool violation{false}; - const auto &beginLoopDir{std::get(x.t)}; - const auto &beginDir{std::get(beginLoopDir.t)}; - if (llvm::omp::topDistributeSet.test(beginDir.v)) { + const parser::OmpDirectiveName &beginName{x.BeginDir().DirName()}; + if (llvm::omp::topDistributeSet.test(beginName.v)) { // `distribute` region has to be nested if (!CurrentDirectiveIsNested()) { violation = true; @@ -142,29 +141,28 @@ void OmpStructureChecker::HasInvalidDistributeNesting( } } if (violation) { - context_.Say(beginDir.source, + context_.Say(beginName.source, "`DISTRIBUTE` region has to be strictly nested inside `TEAMS` " "region."_err_en_US); } } void OmpStructureChecker::HasInvalidLoopBinding( const parser::OpenMPLoopConstruct &x) { - const auto &beginLoopDir{std::get(x.t)}; - const auto &beginDir{std::get(beginLoopDir.t)}; + const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()}; + const parser::OmpDirectiveName &beginName{beginSpec.DirName()}; auto teamsBindingChecker = [&](parser::MessageFixedText msg) { - const auto &clauseList{std::get(beginLoopDir.t)}; - for (const auto &clause : clauseList.v) { + for (const auto &clause : beginSpec.Clauses().v) { if (const auto *bindClause{ std::get_if(&clause.u)}) { if (bindClause->v.v != parser::OmpBindClause::Binding::Teams) { - context_.Say(beginDir.source, msg); + context_.Say(beginName.source, msg); } } } }; - if (llvm::omp::Directive::OMPD_loop == beginDir.v && + if (llvm::omp::Directive::OMPD_loop == beginName.v && CurrentDirectiveIsNested() && llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) { teamsBindingChecker( @@ -174,7 +172,7 @@ void OmpStructureChecker::HasInvalidLoopBinding( if (OmpDirectiveSet{ llvm::omp::OMPD_teams_loop, llvm::omp::OMPD_target_teams_loop} - .test(beginDir.v)) { + .test(beginName.v)) { teamsBindingChecker( "`BIND(TEAMS)` must be specified since the `LOOP` directive is " "combined with a `TEAMS` construct."_err_en_US); @@ -225,13 +223,10 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) { }, // Allowing SIMD and loop construct [&](const parser::OpenMPLoopConstruct &c) { - const auto &beginLoopDir{ - std::get(c.t)}; - const auto &beginDir{ - std::get(beginLoopDir.t)}; - if ((beginDir.v == llvm::omp::Directive::OMPD_simd) || - (beginDir.v == llvm::omp::Directive::OMPD_do_simd) || - (beginDir.v == llvm::omp::Directive::OMPD_loop)) { + const auto &beginName{c.BeginDir().DirName()}; + if (beginName.v == llvm::omp::Directive::OMPD_simd || + beginName.v == llvm::omp::Directive::OMPD_do_simd || + beginName.v == llvm::omp::Directive::OMPD_loop) { eligibleSIMD = true; } }, @@ -253,20 +248,15 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) { void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) { loopStack_.push_back(&x); - const auto &beginLoopDir{std::get(x.t)}; - const auto &beginDir{std::get(beginLoopDir.t)}; - PushContextAndClauseSets(beginDir.source, beginDir.v); + const parser::OmpDirectiveName &beginName{x.BeginDir().DirName()}; + PushContextAndClauseSets(beginName.source, beginName.v); - // check matching, End directive is optional - if (const auto &endLoopDir{ - std::get>(x.t)}) { - const auto &endDir{ - std::get(endLoopDir.value().t)}; + // Check matching, end directive is optional + if (auto &endSpec{x.EndDir()}) { + CheckMatching(beginName, endSpec->DirName()); - CheckMatching(beginDir, endDir); - - AddEndDirectiveClauses(std::get(endLoopDir->t)); + AddEndDirectiveClauses(endSpec->Clauses()); } if (llvm::omp::allSimdSet.test(GetContext().directive)) { @@ -276,11 +266,11 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) { // Combined target loop 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(beginName.v)) { deviceConstructFound_ = true; } - if (beginDir.v == llvm::omp::Directive::OMPD_do) { + if (beginName.v == llvm::omp::Directive::OMPD_do) { // 2.7.1 do-clause -> private-clause | // firstprivate-clause | // lastprivate-clause | @@ -292,7 +282,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) { // nesting check HasInvalidWorksharingNesting( - beginDir.source, llvm::omp::nestedWorkshareErrSet); + beginName.source, llvm::omp::nestedWorkshareErrSet); } SetLoopInfo(x); @@ -301,7 +291,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) { if (const auto &doConstruct{ std::get_if(&*optLoopCons)}) { const auto &doBlock{std::get(doConstruct->t)}; - CheckNoBranching(doBlock, beginDir.v, beginDir.source); + CheckNoBranching(doBlock, beginName.v, beginName.source); } } CheckLoopItrVariableIsInt(x); @@ -310,10 +300,10 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) { HasInvalidLoopBinding(x); if (CurrentDirectiveIsNested() && llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) { - HasInvalidTeamsNesting(beginDir.v, beginDir.source); + HasInvalidTeamsNesting(beginName.v, beginName.source); } - if ((beginDir.v == llvm::omp::Directive::OMPD_distribute_parallel_do_simd) || - (beginDir.v == llvm::omp::Directive::OMPD_distribute_simd)) { + if (beginName.v == llvm::omp::Directive::OMPD_distribute_parallel_do_simd || + beginName.v == llvm::omp::Directive::OMPD_distribute_simd) { CheckDistLinear(x); } } @@ -370,13 +360,12 @@ void OmpStructureChecker::CheckLoopItrVariableIsInt( std::int64_t OmpStructureChecker::GetOrdCollapseLevel( const parser::OpenMPLoopConstruct &x) { - const auto &beginLoopDir{std::get(x.t)}; - const auto &clauseList{std::get(beginLoopDir.t)}; + const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()}; std::int64_t orderedCollapseLevel{1}; std::int64_t orderedLevel{1}; std::int64_t collapseLevel{1}; - for (const auto &clause : clauseList.v) { + for (const auto &clause : beginSpec.Clauses().v) { if (const auto *collapseClause{ std::get_if(&clause.u)}) { if (const auto v{GetIntValue(collapseClause->v)}) { @@ -407,9 +396,7 @@ void OmpStructureChecker::CheckAssociatedLoopConstraints( void OmpStructureChecker::CheckDistLinear( const parser::OpenMPLoopConstruct &x) { - - const auto &beginLoopDir{std::get(x.t)}; - const auto &clauses{std::get(beginLoopDir.t)}; + const parser::OmpClauseList &clauses{x.BeginDir().Clauses()}; SymbolSourceMap indexVars; @@ -467,8 +454,7 @@ void OmpStructureChecker::CheckDistLinear( } void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) { - const auto &beginLoopDir{std::get(x.t)}; - const auto &clauseList{std::get(beginLoopDir.t)}; + const parser::OmpClauseList &clauseList{x.BeginDir().Clauses()}; // A few semantic checks for InScan reduction are performed below as SCAN // constructs inside LOOP may add the relevant information. Scan reduction is @@ -527,7 +513,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) { } void OmpStructureChecker::Enter(const parser::OmpEndLoopDirective &x) { - const auto &dir{std::get(x.t)}; + const parser::OmpDirectiveName &dir{x.DirName()}; ResetPartialContext(dir.source); switch (dir.v) { // 2.7.1 end-do -> END DO [nowait-clause] diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 6bc9f9955fe24..7d3fd7a699ff5 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -815,11 +815,11 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) { common::visit( common::visitors{ [&](const parser::OmpBlockConstruct &c) { - const parser::OmpDirectiveSpecification &beginSpec{c.BeginDir()}; - source = beginSpec.DirName().source; - if (beginSpec.DirId() == llvm::omp::Directive::OMPD_target_data) { + const parser::OmpDirectiveName &beginName{c.BeginDir().DirName()}; + source = beginName.source; + if (beginName.v == llvm::omp::Directive::OMPD_target_data) { eligibleTarget = false; - ineligibleTargetDir = beginSpec.DirId(); + ineligibleTargetDir = beginName.v; } }, [&](const parser::OpenMPStandaloneConstruct &c) { @@ -843,14 +843,11 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) { c.u); }, [&](const parser::OpenMPLoopConstruct &c) { - const auto &beginLoopDir{ - std::get(c.t)}; - const auto &beginDir{ - std::get(beginLoopDir.t)}; - source = beginLoopDir.source; - if (llvm::omp::allTargetSet.test(beginDir.v)) { + const parser::OmpDirectiveName &beginName{c.BeginDir().DirName()}; + source = beginName.source; + if (llvm::omp::allTargetSet.test(beginName.v)) { eligibleTarget = false; - ineligibleTargetDir = beginDir.v; + ineligibleTargetDir = beginName.v; } }, [&](const auto &c) {}, @@ -3968,16 +3965,6 @@ void OmpStructureChecker::CheckDoacross(const parser::OmpDoacross &doa) { // Ignore any mismatch between the size of the iteration vector and the // number of DO constructs on the stack. This is checked elsewhere. - auto GetLoopDirective{[](const parser::OpenMPLoopConstruct &x) { - auto &begin{std::get(x.t)}; - return std::get(begin.t).v; - }}; - auto GetLoopClauses{[](const parser::OpenMPLoopConstruct &x) - -> const std::list & { - auto &begin{std::get(x.t)}; - return std::get(begin.t).v; - }}; - std::set inductionVars; for (const LoopConstruct &loop : llvm::reverse(loopStack_)) { if (auto *doc{std::get_if(&loop)}) { @@ -3991,13 +3978,14 @@ void OmpStructureChecker::CheckDoacross(const parser::OmpDoacross &doa) { // Omp-loop-construct, check if it's do/simd with an ORDERED clause. auto *loopc{std::get_if(&loop)}; assert(loopc && "Expecting OpenMPLoopConstruct"); - llvm::omp::Directive loopDir{GetLoopDirective(**loopc)}; + const parser::OmpDirectiveSpecification &beginSpec{(*loopc)->BeginDir()}; + llvm::omp::Directive loopDir{beginSpec.DirId()}; if (loopDir == llvm::omp::OMPD_do || loopDir == llvm::omp::OMPD_simd) { auto IsOrdered{[](const parser::OmpClause &c) { return c.Id() == llvm::omp::OMPC_ordered; }}; // If it has ORDERED clause, stop the traversal. - if (llvm::any_of(GetLoopClauses(**loopc), IsOrdered)) { + if (llvm::any_of(beginSpec.Clauses().v, IsOrdered)) { break; } } @@ -4655,11 +4643,7 @@ void OmpStructureChecker::CheckWorkshareBlockStmts( } else if (const auto *ompLoopConstruct{ std::get_if( &ompConstruct->u)}) { - const auto &beginLoopDir{ - std::get(ompLoopConstruct->t)}; - const auto &beginDir{ - std::get(beginLoopDir.t)}; - currentDir = beginDir.v; + currentDir = ompLoopConstruct->BeginDir().DirId(); } else if (const auto *ompSectionsConstruct{ std::get_if( &ompConstruct->u)}) { diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index 16b895d8259dd..abb8f6430b29b 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -1890,9 +1890,9 @@ bool OmpAttributeVisitor::Pre( } bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) { - const auto &beginLoopDir{std::get(x.t)}; - const auto &beginDir{std::get(beginLoopDir.t)}; - switch (beginDir.v) { + const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()}; + const parser::OmpDirectiveName &beginName{beginSpec.DirName()}; + switch (beginName.v) { case llvm::omp::Directive::OMPD_distribute: case llvm::omp::Directive::OMPD_distribute_parallel_do: case llvm::omp::Directive::OMPD_distribute_parallel_do_simd: @@ -1930,21 +1930,23 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) { case llvm::omp::Directive::OMPD_teams_loop: case llvm::omp::Directive::OMPD_tile: case llvm::omp::Directive::OMPD_unroll: - PushContext(beginDir.source, beginDir.v); + PushContext(beginName.source, beginName.v); break; default: break; } - if (beginDir.v == llvm::omp::OMPD_master_taskloop || - beginDir.v == llvm::omp::OMPD_master_taskloop_simd || - beginDir.v == llvm::omp::OMPD_parallel_master_taskloop || - beginDir.v == llvm::omp::OMPD_parallel_master_taskloop_simd || - beginDir.v == llvm::omp::Directive::OMPD_target_loop) - IssueNonConformanceWarning(beginDir.v, beginDir.source, 52); + if (beginName.v == llvm::omp::OMPD_master_taskloop || + beginName.v == llvm::omp::OMPD_master_taskloop_simd || + beginName.v == llvm::omp::OMPD_parallel_master_taskloop || + beginName.v == llvm::omp::OMPD_parallel_master_taskloop_simd || + beginName.v == llvm::omp::Directive::OMPD_target_loop) { + unsigned version{context_.langOptions().OpenMPVersion}; + IssueNonConformanceWarning(beginName.v, beginName.source, version); + } ClearDataSharingAttributeObjects(); SetContextAssociatedLoopLevel(GetNumAffectedLoopsFromLoopConstruct(x)); - if (beginDir.v == llvm::omp::Directive::OMPD_do) { + if (beginName.v == llvm::omp::Directive::OMPD_do) { auto &optLoopCons = std::get>(x.t); if (optLoopCons.has_value()) { if (const auto &doConstruct{ @@ -2094,8 +2096,7 @@ void OmpAttributeVisitor::CollectNumAffectedLoopsFromLoopConstruct( const parser::OpenMPLoopConstruct &x, llvm::SmallVector &levels, llvm::SmallVector &clauses) { - const auto &beginLoopDir{std::get(x.t)}; - const auto &clauseList{std::get(beginLoopDir.t)}; + const auto &clauseList{x.BeginDir().Clauses()}; CollectNumAffectedLoopsFromClauses(clauseList, levels, clauses); CollectNumAffectedLoopsFromInnerLoopContruct(x, levels, clauses); @@ -2228,15 +2229,14 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel( } } CheckAssocLoopLevel(level, GetAssociatedClause()); - } else if (const auto &loop{std::get_if< + } else if (const auto *loop{std::get_if< common::Indirection>( innerMostNest)}) { - auto &beginDirective = - std::get(loop->value().t); - auto &beginLoopDirective = - std::get(beginDirective.t); - if (beginLoopDirective.v != llvm::omp::Directive::OMPD_unroll && - beginLoopDirective.v != llvm::omp::Directive::OMPD_tile) { + const parser::OmpDirectiveSpecification &beginSpec{ + loop->value().BeginDir()}; + const parser::OmpDirectiveName &beginName{beginSpec.DirName()}; + if (beginName.v != llvm::omp::Directive::OMPD_unroll && + beginName.v != llvm::omp::Directive::OMPD_tile) { context_.Say(GetContext().directiveSource, "Only UNROLL or TILE constructs are allowed between an OpenMP Loop Construct and a DO construct"_err_en_US, parser::ToUpperCaseLetters(llvm::omp::getOpenMPDirectiveName( diff --git a/flang/lib/Semantics/rewrite-parse-tree.cpp b/flang/lib/Semantics/rewrite-parse-tree.cpp index eae22dc257fa7..5b7dab309eda7 100644 --- a/flang/lib/Semantics/rewrite-parse-tree.cpp +++ b/flang/lib/Semantics/rewrite-parse-tree.cpp @@ -117,9 +117,7 @@ static bool ReturnsDataPointer(const Symbol &symbol) { } static bool LoopConstructIsSIMD(parser::OpenMPLoopConstruct *ompLoop) { - auto &begin = std::get(ompLoop->t); - auto directive = std::get(begin.t).v; - return llvm::omp::allSimdSet.test(directive); + return llvm::omp::allSimdSet.test(ompLoop->BeginDir().DirName().v); } // Remove non-SIMD OpenMPConstructs once they are parsed. diff --git a/flang/test/Parser/OpenMP/bind-clause.f90 b/flang/test/Parser/OpenMP/bind-clause.f90 index 5f1e6b47f1c8d..a4fb3aa66c1c8 100644 --- a/flang/test/Parser/OpenMP/bind-clause.f90 +++ b/flang/test/Parser/OpenMP/bind-clause.f90 @@ -19,7 +19,8 @@ subroutine f00 !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: | OmpBeginLoopDirective -!PARSE-TREE: | | OmpLoopDirective -> llvm::omp::Directive = loop +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = loop !PARSE-TREE: | | OmpClauseList -> OmpClause -> Bind -> OmpBindClause -> Binding = Parallel +!PARSE-TREE: | | Flags = None !PARSE-TREE: | DoConstruct diff --git a/flang/test/Parser/OpenMP/declare-reduction-multi.f90 b/flang/test/Parser/OpenMP/declare-reduction-multi.f90 index 0e1adcc9958d7..693e69d8896be 100644 --- a/flang/test/Parser/OpenMP/declare-reduction-multi.f90 +++ b/flang/test/Parser/OpenMP/declare-reduction-multi.f90 @@ -76,10 +76,11 @@ program omp_examples !CHECK: !$OMP PARALLEL DO REDUCTION(+: sum) !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = parallel do +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel do !PARSE-TREE: OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause !PARSE-TREE: Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add !PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'sum +!PARSE-TREE: Flags = None !PARSE-TREE: DoConstruct do i = 1, n sum%r = sum%r + values(i)%r @@ -90,10 +91,11 @@ program omp_examples !CHECK: !$OMP PARALLEL DO REDUCTION(*: prod) !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = parallel do +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel do !PARSE-TREE: OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause !PARSE-TREE: Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Multiply !PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'prod' +!PARSE-TREE: Flags = None !PARSE-TREE: DoConstruct do i = 1, n prod%r = prod%r * (values(i)%r+0.6) @@ -104,10 +106,11 @@ program omp_examples !CHECK: $OMP PARALLEL DO REDUCTION(max: big) !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = parallel do +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel do !PARSE-TREE: OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause !PARSE-TREE: Modifier -> OmpReductionIdentifier -> ProcedureDesignator -> Name = 'max' !PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'big' +!PARSE-TREE: Flags = None !PARSE-TREE: DoConstruct do i = 1, n big = mymax(values(i), big) @@ -118,10 +121,11 @@ program omp_examples !CHECK: !$OMP PARALLEL DO REDUCTION(min: small) !CHECK-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !CHECK-TREE: OmpBeginLoopDirective -!CHECK-TREE: OmpLoopDirective -> llvm::omp::Directive = parallel do +!CHECK-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel do !CHECK-TREE: OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause !CHECK-TREE: Modifier -> OmpReductionIdentifier -> ProcedureDesignator -> Name = 'min' !CHECK-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'small' +!PARSE-TREE: Flags = None !CHECK-TREE: DoConstruct do i = 1, n small%r = min(values(i)%r, small%r) diff --git a/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 b/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 index 7b1b569d87f78..0ed693e5821d6 100644 --- a/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 +++ b/flang/test/Parser/OpenMP/declare-reduction-unparse.f90 @@ -30,7 +30,7 @@ end subroutine initme !CHECK: !$OMP SIMD REDUCTION(red_add: res) !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = simd +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = simd !PARSE-TREE: OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause !PARSE-TREE: Modifier -> OmpReductionIdentifier -> ProcedureDesignator -> Name = 'red_add do i=1,n diff --git a/flang/test/Parser/OpenMP/do-tile-size.f90 b/flang/test/Parser/OpenMP/do-tile-size.f90 index 886ee4a2a680c..9ba6a3a6c2c41 100644 --- a/flang/test/Parser/OpenMP/do-tile-size.f90 +++ b/flang/test/Parser/OpenMP/do-tile-size.f90 @@ -23,7 +23,7 @@ subroutine openmp_do_tiles(x) !PARSE-TREE:| | | OmpBeginLoopDirective !PARSE-TREE:| | | OpenMPLoopConstruct !PARSE-TREE:| | | | OmpBeginLoopDirective -!PARSE-TREE:| | | | | OmpLoopDirective -> llvm::omp::Directive = tile +!PARSE-TREE:| | | | | OmpDirectiveName -> llvm::omp::Directive = tile !PARSE-TREE:| | | | | OmpClauseList -> OmpClause -> Sizes -> Scalar -> Integer -> Expr = '2_4' !PARSE-TREE: | | | | DoConstruct END subroutine openmp_do_tiles diff --git a/flang/test/Parser/OpenMP/doacross-clause.f90 b/flang/test/Parser/OpenMP/doacross-clause.f90 index 8686e1f13a7ab..d2a52c59cc1a0 100644 --- a/flang/test/Parser/OpenMP/doacross-clause.f90 +++ b/flang/test/Parser/OpenMP/doacross-clause.f90 @@ -27,7 +27,7 @@ subroutine f00(x) !PARSE-TREE-LABEL: ProgramUnit -> SubroutineSubprogram !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Ordered -> Scalar -> Integer -> Constant -> Expr = '2_4' !PARSE-TREE: | | LiteralConstant -> IntLiteralConstant = '2' ![...] @@ -61,7 +61,7 @@ subroutine f01(x) !PARSE-TREE-LABEL: ProgramUnit -> SubroutineSubprogram !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Ordered -> Scalar -> Integer -> Constant -> Expr = '2_4' !PARSE-TREE: | | LiteralConstant -> IntLiteralConstant = '2' ![...] diff --git a/flang/test/Parser/OpenMP/if-clause.f90 b/flang/test/Parser/OpenMP/if-clause.f90 index 2bf80cb99f919..3c422ef15918c 100644 --- a/flang/test/Parser/OpenMP/if-clause.f90 +++ b/flang/test/Parser/OpenMP/if-clause.f90 @@ -30,7 +30,7 @@ program openmp_parse_if !$omp target data map(tofrom: i) if(target data: cond) !$omp end target data - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = target teams distribute parallel do simd + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = target teams distribute parallel do simd ! CHECK: OmpClause -> If -> OmpIfClause ! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target ! CHECK: OmpClause -> If -> OmpIfClause @@ -51,7 +51,7 @@ program openmp_parse_if !$omp task if(task: cond) !$omp end task - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = taskloop + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = taskloop ! CHECK-NEXT: OmpClause -> If -> OmpIfClause ! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop !$omp taskloop if(taskloop: cond) diff --git a/flang/test/Parser/OpenMP/in-reduction-clause.f90 b/flang/test/Parser/OpenMP/in-reduction-clause.f90 index 611068e83900e..6059fb27d5be3 100644 --- a/flang/test/Parser/OpenMP/in-reduction-clause.f90 +++ b/flang/test/Parser/OpenMP/in-reduction-clause.f90 @@ -42,10 +42,11 @@ end subroutine omp_in_reduction_taskgroup !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = taskloop +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> InReduction -> OmpInReductionClause !PARSE-TREE-NEXT: OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add !PARSE-TREE-NEXT: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'z' +!PARSE-TREE-NEXT: Flags = None subroutine omp_in_reduction_parallel() integer :: z @@ -72,8 +73,9 @@ end subroutine omp_in_reduction_parallel !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = taskloop simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> InReduction -> OmpInReductionClause !PARSE-TREE-NEXT: OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add !PARSE-TREE-NEXT: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'z' +!PARSE-TREE-NEXT: Flags = None diff --git a/flang/test/Parser/OpenMP/lastprivate-clause.f90 b/flang/test/Parser/OpenMP/lastprivate-clause.f90 index ac25174f3cc42..6364b74255521 100644 --- a/flang/test/Parser/OpenMP/lastprivate-clause.f90 +++ b/flang/test/Parser/OpenMP/lastprivate-clause.f90 @@ -21,7 +21,7 @@ subroutine foo1() !PARSE-TREE: SubroutineStmt !PARSE-TREE: Name = 'foo1' -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = parallel do +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel do !PARSE-TREE: OmpClauseList -> OmpClause -> Lastprivate -> OmpLastprivateClause !PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: EndSubroutineStmt @@ -47,7 +47,7 @@ subroutine foo2() !PARSE-TREE: SubroutineStmt !PARSE-TREE: Name = 'foo2' -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = parallel do +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = parallel do !PARSE-TREE: OmpClauseList -> OmpClause -> Lastprivate -> OmpLastprivateClause !PARSE-TREE: Modifier -> OmpLastprivateModifier -> Value = Conditional !PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' diff --git a/flang/test/Parser/OpenMP/linear-clause.f90 b/flang/test/Parser/OpenMP/linear-clause.f90 index 5f031b0694149..5ea31ce58fc5a 100644 --- a/flang/test/Parser/OpenMP/linear-clause.f90 +++ b/flang/test/Parser/OpenMP/linear-clause.f90 @@ -18,10 +18,11 @@ subroutine f00(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | bool = 'true' +!PARSE-TREE: | Flags = None !PARSE-TREE: DoConstruct subroutine f01(x) @@ -41,12 +42,13 @@ subroutine f01(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | Modifier -> OmpStepSimpleModifier -> Scalar -> Integer -> Expr = '2_4' !PARSE-TREE: | | | LiteralConstant -> IntLiteralConstant = '2' !PARSE-TREE: | | bool = 'true' +!PARSE-TREE: | Flags = None !PARSE-TREE: DoConstruct subroutine f02(x) @@ -66,12 +68,13 @@ subroutine f02(x) !UNPARSE: END SUBROUTINE !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause !PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' !PARSE-TREE: | | Modifier -> OmpStepComplexModifier -> Scalar -> Integer -> Expr = '3_4' !PARSE-TREE: | | | LiteralConstant -> IntLiteralConstant = '3' !PARSE-TREE: | | bool = 'true' +!PARSE-TREE: | Flags = None !PARSE-TREE: DoConstruct subroutine f03(x) diff --git a/flang/test/Parser/OpenMP/loop-transformation-construct01.f90 b/flang/test/Parser/OpenMP/loop-transformation-construct01.f90 index baffc2f6e2f1e..9595889b1bf98 100644 --- a/flang/test/Parser/OpenMP/loop-transformation-construct01.f90 +++ b/flang/test/Parser/OpenMP/loop-transformation-construct01.f90 @@ -21,12 +21,14 @@ subroutine loop_transformation_construct !CHECK-PARSE: | ExecutionPart -> Block !CHECK-PARSE-NEXT: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !CHECK-PARSE-NEXT: | | | OmpBeginLoopDirective -!CHECK-PARSE-NEXT: | | | | OmpLoopDirective -> llvm::omp::Directive = do +!CHECK-PARSE-NEXT: | | | | OmpDirectiveName -> llvm::omp::Directive = do !CHECK-PARSE-NEXT: | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | Flags = None !CHECK-PARSE-NEXT: | | | OpenMPLoopConstruct !CHECK-PARSE-NEXT: | | | | OmpBeginLoopDirective -!CHECK-PARSE-NEXT: | | | | | OmpLoopDirective -> llvm::omp::Directive = unroll +!CHECK-PARSE-NEXT: | | | | | OmpDirectiveName -> llvm::omp::Directive = unroll !CHECK-PARSE-NEXT: | | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | | Flags = None !CHECK-PARSE-NEXT: | | | | DoConstruct !CHECK-PARSE-NEXT: | | | | | NonLabelDoStmt !CHECK-PARSE-NEXT: | | | | | | LoopControl -> LoopBounds @@ -53,11 +55,13 @@ subroutine loop_transformation_construct !CHECK-PARSE-NEXT: | | | | | | | | | | LiteralConstant -> IntLiteralConstant = '5' !CHECK-PARSE-NEXT: | | | | | EndDoStmt -> !CHECK-PARSE-NEXT: | | | | OmpEndLoopDirective -!CHECK-PARSE-NEXT: | | | | | OmpLoopDirective -> llvm::omp::Directive = unroll +!CHECK-PARSE-NEXT: | | | | | OmpDirectiveName -> llvm::omp::Directive = unroll !CHECK-PARSE-NEXT: | | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | | Flags = None !CHECK-PARSE-NEXT: | | | OmpEndLoopDirective -!CHECK-PARSE-NEXT: | | | | OmpLoopDirective -> llvm::omp::Directive = do +!CHECK-PARSE-NEXT: | | | | OmpDirectiveName -> llvm::omp::Directive = do !CHECK-PARSE-NEXT: | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | Flags = None !CHECK-UNPARSE: SUBROUTINE loop_transformation_construct !CHECK-UNPARSE-NEXT: IMPLICIT NONE diff --git a/flang/test/Parser/OpenMP/loop-transformation-construct02.f90 b/flang/test/Parser/OpenMP/loop-transformation-construct02.f90 index b50e7183841cc..a6af35a0111a3 100644 --- a/flang/test/Parser/OpenMP/loop-transformation-construct02.f90 +++ b/flang/test/Parser/OpenMP/loop-transformation-construct02.f90 @@ -23,16 +23,19 @@ subroutine loop_transformation_construct !CHECK-PARSE: | ExecutionPart -> Block !CHECK-PARSE-NEXT: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !CHECK-PARSE-NEXT: | | | OmpBeginLoopDirective -!CHECK-PARSE-NEXT: | | | | OmpLoopDirective -> llvm::omp::Directive = do +!CHECK-PARSE-NEXT: | | | | OmpDirectiveName -> llvm::omp::Directive = do !CHECK-PARSE-NEXT: | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | Flags = None !CHECK-PARSE-NEXT: | | | OpenMPLoopConstruct !CHECK-PARSE-NEXT: | | | | OmpBeginLoopDirective -!CHECK-PARSE-NEXT: | | | | | OmpLoopDirective -> llvm::omp::Directive = unroll +!CHECK-PARSE-NEXT: | | | | | OmpDirectiveName -> llvm::omp::Directive = unroll !CHECK-PARSE-NEXT: | | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | | Flags = None !CHECK-PARSE-NEXT: | | | | OpenMPLoopConstruct !CHECK-PARSE-NEXT: | | | | | OmpBeginLoopDirective -!CHECK-PARSE-NEXT: | | | | | | OmpLoopDirective -> llvm::omp::Directive = tile +!CHECK-PARSE-NEXT: | | | | | | OmpDirectiveName -> llvm::omp::Directive = tile !CHECK-PARSE-NEXT: | | | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | | | Flags = None !CHECK-PARSE-NEXT: | | | | | DoConstruct !CHECK-PARSE-NEXT: | | | | | | NonLabelDoStmt !CHECK-PARSE-NEXT: | | | | | | | LoopControl -> LoopBounds @@ -59,14 +62,17 @@ subroutine loop_transformation_construct !CHECK-PARSE-NEXT: | | | | | | | | | | | LiteralConstant -> IntLiteralConstant = '5' !CHECK-PARSE-NEXT: | | | | | | EndDoStmt -> !CHECK-PARSE-NEXT: | | | | | OmpEndLoopDirective -!CHECK-PARSE-NEXT: | | | | | | OmpLoopDirective -> llvm::omp::Directive = tile +!CHECK-PARSE-NEXT: | | | | | | OmpDirectiveName -> llvm::omp::Directive = tile !CHECK-PARSE-NEXT: | | | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | | | Flags = None !CHECK-PARSE-NEXT: | | | | OmpEndLoopDirective -!CHECK-PARSE-NEXT: | | | | | OmpLoopDirective -> llvm::omp::Directive = unroll +!CHECK-PARSE-NEXT: | | | | | OmpDirectiveName -> llvm::omp::Directive = unroll !CHECK-PARSE-NEXT: | | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | | Flags = None !CHECK-PARSE-NEXT: | | | OmpEndLoopDirective -!CHECK-PARSE-NEXT: | | | | OmpLoopDirective -> llvm::omp::Directive = do +!CHECK-PARSE-NEXT: | | | | OmpDirectiveName -> llvm::omp::Directive = do !CHECK-PARSE-NEXT: | | | | OmpClauseList -> +!CHECK-PARSE-NEXT: | | | | Flags = None !CHECK-UNPARSE: SUBROUTINE loop_transformation_construct !CHECK-UNPARSE-NEXT: IMPLICIT NONE diff --git a/flang/test/Parser/OpenMP/loop-transformation-construct03.f90 b/flang/test/Parser/OpenMP/loop-transformation-construct03.f90 index 81f0de1b76263..8725025a51321 100644 --- a/flang/test/Parser/OpenMP/loop-transformation-construct03.f90 +++ b/flang/test/Parser/OpenMP/loop-transformation-construct03.f90 @@ -21,10 +21,11 @@ subroutine loop_transformation_construct7 !CHECK-PARSE: | ExecutionPart -> Block !CHECK-PARSE-NEXT: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !CHECK-PARSE-NEXT: | | | OmpBeginLoopDirective -!CHECK-PARSE-NEXT: | | | | OmpLoopDirective -> llvm::omp::Directive = target teams distribute parallel do +!CHECK-PARSE-NEXT: | | | | OmpDirectiveName -> llvm::omp::Directive = target teams distribute parallel do !CHECK-PARSE-NEXT: | | | | OmpClauseList -> OmpClause -> Collapse -> Scalar -> Integer -> Constant -> Expr = '2_4' !CHECK-PARSE-NEXT: | | | | | LiteralConstant -> IntLiteralConstant = '2' !CHECK-PARSE-NEXT: | | | | OmpClause -> Private -> OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'b' +!CHECK-PARSE-NEXT: | | | | Flags = None !CHECK-PARSE-NEXT: | | | DoConstruct !CHECK-PARSE-NEXT: | | | | NonLabelDoStmt !CHECK-PARSE-NEXT: | | | | | LoopControl -> LoopBounds diff --git a/flang/test/Parser/OpenMP/masked-unparse.f90 b/flang/test/Parser/OpenMP/masked-unparse.f90 index 46ddd3722216a..786b60416846f 100644 --- a/flang/test/Parser/OpenMP/masked-unparse.f90 +++ b/flang/test/Parser/OpenMP/masked-unparse.f90 @@ -25,7 +25,7 @@ subroutine test_masked() subroutine test_masked_taskloop_simd() integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = masked taskloop simd + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = masked taskloop simd !CHECK: !$omp masked taskloop simd !$omp masked taskloop simd do i=1,10 @@ -37,7 +37,7 @@ subroutine test_masked_taskloop_simd() subroutine test_masked_taskloop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = masked taskloop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = masked taskloop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4' !PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2' !CHECK: !$omp masked taskloop filter(2_4) @@ -68,7 +68,7 @@ subroutine test_parallel_masked subroutine test_parallel_masked_taskloop_simd integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel masked taskloop simd + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel masked taskloop simd !CHECK: !$omp parallel masked taskloop simd !$omp parallel masked taskloop simd do i=1,10 @@ -80,7 +80,7 @@ subroutine test_parallel_masked_taskloop_simd subroutine test_parallel_masked_taskloop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel masked taskloop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel masked taskloop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4' !PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2' !CHECK: !$omp parallel masked taskloop filter(2_4) diff --git a/flang/test/Parser/OpenMP/master-unparse.f90 b/flang/test/Parser/OpenMP/master-unparse.f90 index ec7a7d3845014..36935d4fe1a7d 100644 --- a/flang/test/Parser/OpenMP/master-unparse.f90 +++ b/flang/test/Parser/OpenMP/master-unparse.f90 @@ -17,7 +17,7 @@ subroutine test_master() subroutine test_master_taskloop_simd() integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = master taskloop simd + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = master taskloop simd !CHECK: !$omp master taskloop simd !$omp master taskloop simd do i=1,10 @@ -29,7 +29,7 @@ subroutine test_master_taskloop_simd() subroutine test_master_taskloop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = master taskloop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = master taskloop !CHECK: !$omp master taskloop !$omp master taskloop do i=1,10 @@ -51,7 +51,7 @@ subroutine test_parallel_master subroutine test_parallel_master_taskloop_simd integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel master taskloop simd + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel master taskloop simd !CHECK: !$omp parallel master taskloop simd !$omp parallel master taskloop simd do i=1,10 @@ -63,7 +63,7 @@ subroutine test_parallel_master_taskloop_simd subroutine test_parallel_master_taskloop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel master taskloop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel master taskloop !CHECK: !$omp parallel master taskloop !$omp parallel master taskloop do i=1,10 diff --git a/flang/test/Parser/OpenMP/order-clause01.f90 b/flang/test/Parser/OpenMP/order-clause01.f90 index f810eb74ee29d..087e400934de5 100644 --- a/flang/test/Parser/OpenMP/order-clause01.f90 +++ b/flang/test/Parser/OpenMP/order-clause01.f90 @@ -15,9 +15,10 @@ subroutine test_do_order() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_simd_order_reproducible() integer :: i, j = 1 @@ -31,10 +32,11 @@ subroutine test_simd_order_reproducible() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Reproducible !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_do_simd_order_unconstrained() integer :: i, j = 1 @@ -48,10 +50,11 @@ subroutine test_do_simd_order_unconstrained() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = do simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = do simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Unconstrained !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_parallel_do_order() integer :: i, j = 1 @@ -65,9 +68,10 @@ subroutine test_parallel_do_order() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel do +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel do !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_parallel_do_simd_order_reproducible() integer :: i, j = 1 @@ -81,10 +85,11 @@ subroutine test_parallel_do_simd_order_reproducible() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel do simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel do simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Reproducible !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_target_simd_order_unconstrained() integer :: i, j = 1 @@ -98,10 +103,11 @@ subroutine test_target_simd_order_unconstrained() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Unconstrained !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_target_parallel_do_order() integer :: i, j = 1 @@ -115,9 +121,10 @@ subroutine test_target_parallel_do_order() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target parallel do +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target parallel do !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_target_parallel_do_simd_order_reproducible() integer :: i, j = 1 @@ -131,10 +138,11 @@ subroutine test_target_parallel_do_simd_order_reproducible() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target parallel do simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target parallel do simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Reproducible !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_teams_distribute_simd_order_unconstrained() integer :: i, j = 1 @@ -148,10 +156,11 @@ subroutine test_teams_distribute_simd_order_unconstrained() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = teams distribute simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = teams distribute simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Unconstrained !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_teams_distribute_parallel_do_order() integer :: i, j = 1 @@ -165,9 +174,10 @@ subroutine test_teams_distribute_parallel_do_order() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = teams distribute parallel do +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = teams distribute parallel do !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_teams_distribute_parallel_do_simd_order_reproducible() integer :: i, j = 1 @@ -181,10 +191,11 @@ subroutine test_teams_distribute_parallel_do_simd_order_reproducible() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = teams distribute parallel do simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = teams distribute parallel do simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Reproducible !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_target_teams_distribute_simd_order_unconstrained() integer :: i, j = 1 @@ -198,10 +209,11 @@ subroutine test_target_teams_distribute_simd_order_unconstrained() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target teams distribute simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target teams distribute simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Unconstrained !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_target_teams_distribute_parallel_do_order() integer :: i, j = 1 @@ -215,9 +227,10 @@ subroutine test_target_teams_distribute_parallel_do_order() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target teams distribute parallel do +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target teams distribute parallel do !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_target_teams_distribute_parallel_do_simd_order_reproducible() integer :: i, j = 1 @@ -231,10 +244,11 @@ subroutine test_target_teams_distribute_parallel_do_simd_order_reproducible() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target teams distribute parallel do simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target teams distribute parallel do simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Reproducible !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None subroutine test_taskloop_simd_order_unconstrained() integer :: i, j = 1 @@ -248,7 +262,8 @@ subroutine test_taskloop_simd_order_unconstrained() !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE-NEXT: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = taskloop simd +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop simd !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Order -> OmpOrderClause !PARSE-TREE-NEXT: OmpOrderModifier -> Value = Unconstrained !PARSE-TREE-NEXT: Ordering = Concurrent +!PARSE-TREE-NEXT: Flags = None diff --git a/flang/test/Parser/OpenMP/ordered-depend.f90 b/flang/test/Parser/OpenMP/ordered-depend.f90 index 71eff105e03c6..4826d134362c8 100644 --- a/flang/test/Parser/OpenMP/ordered-depend.f90 +++ b/flang/test/Parser/OpenMP/ordered-depend.f90 @@ -27,7 +27,7 @@ subroutine f00(x) !PARSE-TREE-LABEL: ProgramUnit -> SubroutineSubprogram !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Ordered -> Scalar -> Integer -> Constant -> Expr = '2_4' !PARSE-TREE: | | LiteralConstant -> IntLiteralConstant = '2' ![...] @@ -61,7 +61,7 @@ subroutine f01(x) !PARSE-TREE-LABEL: ProgramUnit -> SubroutineSubprogram !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: | OmpLoopDirective -> llvm::omp::Directive = do +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = do !PARSE-TREE: | OmpClauseList -> OmpClause -> Ordered -> Scalar -> Integer -> Constant -> Expr = '2_4' !PARSE-TREE: | | LiteralConstant -> IntLiteralConstant = '2' ![...] diff --git a/flang/test/Parser/OpenMP/reduction-modifier.f90 b/flang/test/Parser/OpenMP/reduction-modifier.f90 index 56303af66395e..8c7d5b1472018 100644 --- a/flang/test/Parser/OpenMP/reduction-modifier.f90 +++ b/flang/test/Parser/OpenMP/reduction-modifier.f90 @@ -7,7 +7,7 @@ subroutine foo() ! CHECK: !$OMP DO REDUCTION(TASK, *: j) ! PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct ! PARSE-TREE: | | | OmpBeginLoopDirective -! PARSE-TREE: | | | | OmpLoopDirective -> llvm::omp::Directive = do +! PARSE-TREE: | | | | OmpDirectiveName -> llvm::omp::Directive = do ! PARSE-TREE: | | | | OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause ! PARSE-TREE: | | | | | Modifier -> OmpReductionModifier -> Value = Task ! PARSE-TREE: | | | | | Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Multiply diff --git a/flang/test/Parser/OpenMP/target-loop-unparse.f90 b/flang/test/Parser/OpenMP/target-loop-unparse.f90 index ee0013f613403..142bcabf0894b 100644 --- a/flang/test/Parser/OpenMP/target-loop-unparse.f90 +++ b/flang/test/Parser/OpenMP/target-loop-unparse.f90 @@ -9,7 +9,7 @@ subroutine test_loop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = loop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = loop !CHECK: !$omp loop !$omp loop do i=1,10 @@ -18,7 +18,7 @@ subroutine test_loop !$omp end loop !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = loop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = loop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Bind -> OmpBindClause -> Binding = Thread !CHECK: !$omp loop !$omp loop bind(thread) @@ -31,7 +31,7 @@ subroutine test_loop subroutine test_target_loop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target loop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target loop !CHECK: !$omp target loop !$omp target loop do i=1,10 @@ -43,7 +43,7 @@ subroutine test_target_loop subroutine test_target_teams_loop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target teams loop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target teams loop !CHECK: !$omp target teams loop !$omp target teams loop do i=1,10 @@ -55,7 +55,7 @@ subroutine test_target_teams_loop subroutine test_target_parallel_loop integer :: i, j = 1 !PARSE-TREE: OmpBeginLoopDirective - !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target parallel loop + !PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = target parallel loop !CHECK: !$omp target parallel loop !$omp target parallel loop do i=1,10 diff --git a/flang/test/Parser/OpenMP/taskloop.f90 b/flang/test/Parser/OpenMP/taskloop.f90 index f053aa7f0cff3..3ea91daae160e 100644 --- a/flang/test/Parser/OpenMP/taskloop.f90 +++ b/flang/test/Parser/OpenMP/taskloop.f90 @@ -6,7 +6,7 @@ subroutine parallel_work !CHECK: !$OMP TASKLOOP GRAINSIZE(STRICT: 500_4) !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = taskloop +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Grainsize -> OmpGrainsizeClause !PARSE-TREE-NEXT: Modifier -> OmpPrescriptiveness -> Value = Strict !PARSE-TREE-NEXT: Scalar -> Integer -> Expr = '500_4' @@ -18,7 +18,7 @@ subroutine parallel_work !CHECK: !$OMP TASKLOOP GRAINSIZE(500_4) !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = taskloop +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Grainsize -> OmpGrainsizeClause !PARSE-TREE-NEXT: Scalar -> Integer -> Expr = '500_4' !$omp taskloop grainsize(500) @@ -29,7 +29,7 @@ subroutine parallel_work !CHECK: !$OMP TASKLOOP NUM_TASKS(STRICT: 500_4) !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = taskloop +!PARSE-TREE-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> NumTasks -> OmpNumTasksClause !PARSE-TREE-NEXT: Modifier -> OmpPrescriptiveness -> Value = Strict !PARSE-TREE-NEXT: Scalar -> Integer -> Expr = '500_4' diff --git a/flang/test/Parser/OpenMP/tile-size.f90 b/flang/test/Parser/OpenMP/tile-size.f90 index 64bc3c5319e88..5110493de4a0c 100644 --- a/flang/test/Parser/OpenMP/tile-size.f90 +++ b/flang/test/Parser/OpenMP/tile-size.f90 @@ -18,6 +18,6 @@ subroutine openmp_tiles(x) !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = tile +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = tile !PARSE-TREE: OmpClauseList -> OmpClause -> Sizes -> Scalar -> Integer -> Expr = '2_4' END subroutine openmp_tiles diff --git a/flang/test/Parser/OpenMP/tile.f90 b/flang/test/Parser/OpenMP/tile.f90 index ee9b6aa5c84ca..2ea17471866a4 100644 --- a/flang/test/Parser/OpenMP/tile.f90 +++ b/flang/test/Parser/OpenMP/tile.f90 @@ -17,7 +17,7 @@ subroutine openmp_tiles(x) !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = tile +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = tile END subroutine openmp_tiles diff --git a/flang/test/Parser/OpenMP/transparent-clause.f90 b/flang/test/Parser/OpenMP/transparent-clause.f90 index 01f49f5e8a15d..8f669546f2dea 100644 --- a/flang/test/Parser/OpenMP/transparent-clause.f90 +++ b/flang/test/Parser/OpenMP/transparent-clause.f90 @@ -70,7 +70,8 @@ subroutine f02 !PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: | OmpBeginLoopDirective -!PARSE-TREE: | | OmpLoopDirective -> llvm::omp::Directive = taskloop +!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = taskloop !PARSE-TREE: | | OmpClauseList -> OmpClause -> Transparent -> OmpTransparentClause -> Scalar -> Integer -> Expr = '2_4' !PARSE-TREE: | | | LiteralConstant -> IntLiteralConstant = '2' +!PARSE-TREE: | | Flags = None !PARSE-TREE: | DoConstruct diff --git a/flang/test/Parser/OpenMP/unroll-full.f90 b/flang/test/Parser/OpenMP/unroll-full.f90 index 30d2f46624991..80b2cac296fee 100644 --- a/flang/test/Parser/OpenMP/unroll-full.f90 +++ b/flang/test/Parser/OpenMP/unroll-full.f90 @@ -17,6 +17,6 @@ subroutine openmp_parse_unroll(x) !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = unroll +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = unroll !PARSE-TREE: OmpClauseList -> OmpClause -> Full END subroutine openmp_parse_unroll diff --git a/flang/test/Parser/OpenMP/unroll-heuristic.f90 b/flang/test/Parser/OpenMP/unroll-heuristic.f90 index 2f589af0c83ca..bbc2df3b57df6 100644 --- a/flang/test/Parser/OpenMP/unroll-heuristic.f90 +++ b/flang/test/Parser/OpenMP/unroll-heuristic.f90 @@ -20,8 +20,9 @@ END subroutine openmp_parse_unroll_heuristic !PTREE: OpenMPConstruct -> OpenMPLoopConstruct !PTREE-NEXT: | OmpBeginLoopDirective -!PTREE-NEXT: | | OmpLoopDirective -> llvm::omp::Directive = unroll +!PTREE-NEXT: | | OmpDirectiveName -> llvm::omp::Directive = unroll !PTREE-NEXT: | | OmpClauseList -> +!PTREE-NEXT: | | Flags = None !PTREE-NEXT: | DoConstruct !PTREE-NEXT: | | NonLabelDoStmt !PTREE-NEXT: | | | LoopControl -> LoopBounds @@ -39,5 +40,6 @@ END subroutine openmp_parse_unroll_heuristic !PTREE-NEXT: | | | | | | | Designator -> DataRef -> Name = 'i' !PTREE-NEXT: | | EndDoStmt -> !PTREE-NEXT: | OmpEndLoopDirective -!PTREE-NEXT: | | OmpLoopDirective -> llvm::omp::Directive = unroll +!PTREE-NEXT: | | OmpDirectiveName -> llvm::omp::Directive = unroll !PTREE-NEXT: | | OmpClauseList -> +!PTREE-NEXT: | | Flags = None diff --git a/flang/test/Parser/OpenMP/unroll-partial.f90 b/flang/test/Parser/OpenMP/unroll-partial.f90 index 8ac2a74166773..59dffb63cee6c 100644 --- a/flang/test/Parser/OpenMP/unroll-partial.f90 +++ b/flang/test/Parser/OpenMP/unroll-partial.f90 @@ -17,7 +17,7 @@ subroutine openmp_parse_unroll(x) !PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct !PARSE-TREE: OmpBeginLoopDirective -!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = unroll +!PARSE-TREE: OmpDirectiveName -> llvm::omp::Directive = unroll !PARSE-TREE: OmpClauseList -> OmpClause -> Partial -> Scalar -> Integer -> Constant -> Expr = '3_4' !PARSE-TREE: LiteralConstant -> IntLiteralConstant = '3' diff --git a/flang/test/Semantics/OpenMP/simd-only.f90 b/flang/test/Semantics/OpenMP/simd-only.f90 index 33ab3d62c98e9..e137ef7d82929 100644 --- a/flang/test/Semantics/OpenMP/simd-only.f90 +++ b/flang/test/Semantics/OpenMP/simd-only.f90 @@ -9,7 +9,7 @@ subroutine test_simd() integer :: i ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = simd + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = simd ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp simd do i = 1, 100 @@ -21,7 +21,7 @@ subroutine test_do_simd() integer :: i ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = do simd + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = do simd ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp do simd do i = 1, 100 @@ -34,7 +34,7 @@ subroutine test_parallel_do_simd() integer :: i ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = parallel do simd + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = parallel do simd ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp parallel do simd do i = 1, 100 @@ -47,7 +47,7 @@ subroutine test_simd_scan() real :: sum ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = simd + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = simd !$omp simd reduction(inscan,+:sum) do i = 1, N sum = sum + a(i) @@ -64,7 +64,7 @@ subroutine test_simd_atomic() integer :: i, x ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK: OmpLoopDirective -> llvm::omp::Directive = simd + ! CHECK: OmpDirectiveName -> llvm::omp::Directive = simd ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp simd do i = 1, 100 @@ -80,7 +80,7 @@ subroutine test_do() integer :: i ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = do + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = do ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp parallel do do i = 1, 100 @@ -92,7 +92,7 @@ subroutine test_do_nested() integer :: i ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = parallel do + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = parallel do ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp parallel do @@ -107,7 +107,7 @@ subroutine test_target() integer :: i ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = target + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = target ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp target do i = 1, 100 @@ -120,7 +120,7 @@ subroutine test_target_teams_distribute() integer :: i ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = target teams distribute + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = target teams distribute ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp target teams distribute do i = 1, 100 @@ -132,7 +132,7 @@ subroutine test_target_teams_distribute() ! CHECK-LABEL: Name = 'test_target_data' subroutine test_target_data() ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = target data + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = target data ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp target data map(to: A) map(tofrom: B) do i = 1, 100 @@ -145,7 +145,7 @@ subroutine test_loop() integer :: i ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = loop + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = loop ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp loop bind(thread) do i = 1, 100 @@ -157,7 +157,7 @@ subroutine test_unroll() integer :: i ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = unroll + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = unroll ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp unroll do i = 1, 100 @@ -170,12 +170,12 @@ subroutine test_do_ordered() x = 0 ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = do + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = do ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp do ordered do i = 1, 100 ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = ordered + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = ordered !$omp ordered x = x + 1 !$omp end ordered @@ -188,17 +188,17 @@ subroutine test_cancel() x = 0 ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = parallel do + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = parallel do ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp parallel do do i = 1, 100 if (i == 10) then ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPCancelConstruct -> OmpDirectiveSpecification - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = cancel + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = cancel !$omp cancel do end if ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPCancellationPointConstruct -> OmpDirectiveSpecification - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = cancellation point + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = cancellation point !$omp cancellation point do end do end subroutine @@ -208,7 +208,7 @@ subroutine test_scan() integer :: i, sum ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = parallel do + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = parallel do ! CHECK: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct !$omp parallel do reduction(inscan, +: sum) do i = 1, n @@ -225,7 +225,7 @@ subroutine test_target_map() integer :: array(10) ! CHECK-NOT: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct - ! CHECK-NOT: OmpLoopDirective -> llvm::omp::Directive = target + ! CHECK-NOT: OmpDirectiveName -> llvm::omp::Directive = target !$omp target map(tofrom: array(2:10)) array(2) = array(2) * 2 !$omp end target From 1708e712e295eb2e673b76e73c84a14358f1cd7e Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Sep 2025 08:36:10 -0500 Subject: [PATCH 2/2] Use existing constant --- flang/lib/Parser/openmp-parsers.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 0c466b91d0845..c6d4de108fb59 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -41,10 +41,8 @@ namespace Fortran::parser { using namespace Fortran::parser::omp; -static constexpr size_t DirectiveCount{ - static_cast(llvm::omp::Directive::Last_) - - static_cast(llvm::omp::Directive::First_) + 1}; -using DirectiveSet = llvm::Bitset; +using DirectiveSet = + llvm::Bitset; // Helper function to print the buffer contents starting at the current point. [[maybe_unused]] static std::string ahead(const ParseState &state) {