Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ SourcePosition OpenMPCounterVisitor::getLocation(const OpenMPConstruct &c) {
const CharBlock &source{c.source};
return (parsing->allCooked().GetSourcePositionRange(source))->first;
},
[&](const OpenMPUtilityConstruct &c) -> SourcePosition {
const CharBlock &source{c.source};
return (parsing->allCooked().GetSourcePositionRange(source))->first;
},
},
c.u);
}
Expand All @@ -102,10 +106,16 @@ std::string OpenMPCounterVisitor::getName(const OmpWrapperType &w) {
return getName(*std::get<const OpenMPDeclarativeConstruct *>(w));
}
std::string OpenMPCounterVisitor::getName(const OpenMPDeclarativeConstruct &c) {
return std::visit(
[&](const auto &o) -> std::string {
const CharBlock &source{std::get<Verbatim>(o.t).source};
return normalize_construct_name(source.ToString());
return std::visit( //
Fortran::common::visitors{
[&](const OpenMPUtilityConstruct &o) -> std::string {
const CharBlock &source{o.source};
return normalize_construct_name(source.ToString());
},
[&](const auto &o) -> std::string {
const CharBlock &source{std::get<Verbatim>(o.t).source};
return normalize_construct_name(source.ToString());
},
},
c.u);
}
Expand Down Expand Up @@ -143,8 +153,8 @@ std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
},
c.u);
},
[&](const OpenMPErrorConstruct &c) -> std::string {
const CharBlock &source{std::get<0>(c.t).source};
[&](const OpenMPUtilityConstruct &c) -> std::string {
const CharBlock &source{c.source};
return normalize_construct_name(source.ToString());
},
[&](const OpenMPSectionConstruct &c) -> std::string {
Expand Down
4 changes: 3 additions & 1 deletion flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ class ParseTreeDumper {
#include "llvm/Frontend/OpenMP/OMP.inc"
NODE(parser, OmpClauseList)
NODE(parser, OmpCriticalDirective)
NODE(parser, OmpErrorDirective)
NODE(parser, OmpNothingDirective)
NODE(parser, OmpDeclareTargetSpecifier)
NODE(parser, OmpDeclareTargetWithClause)
NODE(parser, OmpDeclareTargetWithList)
Expand Down Expand Up @@ -662,7 +664,7 @@ class ParseTreeDumper {
NODE(parser, OmpAtomicDefaultMemOrderClause)
NODE_ENUM(common, OmpAtomicDefaultMemOrderType)
NODE(parser, OpenMPDepobjConstruct)
NODE(parser, OpenMPErrorConstruct)
NODE(parser, OpenMPUtilityConstruct)
NODE(parser, OpenMPFlushConstruct)
NODE(parser, OpenMPLoopConstruct)
NODE(parser, OpenMPExecutableAllocate)
Expand Down
36 changes: 26 additions & 10 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4182,6 +4182,30 @@ struct OmpClauseList {

// --- Directives and constructs

// Ref: [5.1:89-90], [5.2:216]
//
// nothing-directive ->
// NOTHING // since 5.1
struct OmpNothingDirective {
using EmptyTrait = std::true_type;
COPY_AND_ASSIGN_BOILERPLATE(OmpNothingDirective);
CharBlock source;
};

// Ref: OpenMP [5.2:216-218]
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
struct OmpErrorDirective {
TUPLE_CLASS_BOILERPLATE(OmpErrorDirective);
CharBlock source;
std::tuple<Verbatim, OmpClauseList> t;
};

struct OpenMPUtilityConstruct {
UNION_CLASS_BOILERPLATE(OpenMPUtilityConstruct);
CharBlock source;
std::variant<OmpErrorDirective, OmpNothingDirective> u;
};

// 2.7.2 SECTIONS
// 2.11.2 PARALLEL SECTIONS
struct OmpSectionsDirective {
Expand Down Expand Up @@ -4318,7 +4342,7 @@ struct OpenMPDeclarativeConstruct {
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
OpenMPDeclareTargetConstruct, OpenMPThreadprivate,
OpenMPRequiresConstruct>
OpenMPRequiresConstruct, OpenMPUtilityConstruct>
u;
};

Expand Down Expand Up @@ -4506,14 +4530,6 @@ struct OpenMPDepobjConstruct {
std::tuple<Verbatim, OmpObject, OmpClause> t;
};

// Ref: OpenMP [5.2:216-218]
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
struct OpenMPErrorConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPErrorConstruct);
CharBlock source;
std::tuple<Verbatim, OmpClauseList> t;
};

// 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
struct OpenMPFlushConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
Expand Down Expand Up @@ -4586,7 +4602,7 @@ struct OpenMPConstruct {
UNION_CLASS_BOILERPLATE(OpenMPConstruct);
std::variant<OpenMPStandaloneConstruct, OpenMPSectionsConstruct,
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPErrorConstruct,
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPUtilityConstruct,
OpenMPExecutableAllocate, OpenMPAllocatorsConstruct,
OpenMPCriticalConstruct>
u;
Expand Down
8 changes: 6 additions & 2 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,10 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
//===----------------------------------------------------------------------===//
// OpenMPDeclarativeConstruct visitors
//===----------------------------------------------------------------------===//
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPUtilityConstruct &);

static void
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
Expand Down Expand Up @@ -2907,8 +2911,8 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPErrorConstruct &) {
TODO(converter.getCurrentLocation(), "OpenMPErrorConstruct");
const parser::OpenMPUtilityConstruct &) {
TODO(converter.getCurrentLocation(), "OpenMPUtilityConstruct");
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
Expand Down
22 changes: 16 additions & 6 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,20 @@ TYPE_PARSER(
TYPE_PARSER(sourced(construct<OmpClauseList>(
many(maybe(","_tok) >> sourced(Parser<OmpClause>{})))))

// 2.1 (variable | /common-block | array-sections)
// 2.1 (variable | /common-block/ | array-sections)
TYPE_PARSER(construct<OmpObjectList>(nonemptyList(Parser<OmpObject>{})))

TYPE_PARSER(sourced(construct<OmpErrorDirective>(
verbatim("ERROR"_tok), Parser<OmpClauseList>{})))

TYPE_PARSER(sourced(construct<OmpNothingDirective>("NOTHING" >> ok)))

TYPE_PARSER(sourced(construct<OpenMPUtilityConstruct>(
sourced(construct<OpenMPUtilityConstruct>(
sourced(Parser<OmpErrorDirective>{}))) ||
sourced(construct<OpenMPUtilityConstruct>(
sourced(Parser<OmpNothingDirective>{}))))))

// Omp directives enclosing do loop
TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
"DISTRIBUTE PARALLEL DO SIMD" >>
Expand Down Expand Up @@ -1027,9 +1038,6 @@ TYPE_PARSER(sourced(construct<OmpCriticalDirective>(verbatim("CRITICAL"_tok),
TYPE_PARSER(construct<OpenMPCriticalConstruct>(
Parser<OmpCriticalDirective>{}, block, Parser<OmpEndCriticalDirective>{}))

TYPE_PARSER(sourced(construct<OpenMPErrorConstruct>(
verbatim("ERROR"_tok), Parser<OmpClauseList>{})))

// 2.11.3 Executable Allocate directive
TYPE_PARSER(
sourced(construct<OpenMPExecutableAllocate>(verbatim("ALLOCATE"_tok),
Expand Down Expand Up @@ -1082,7 +1090,9 @@ TYPE_PARSER(startOmpLine >>
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPRequiresConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPThreadprivate>{})) /
Parser<OpenMPThreadprivate>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPUtilityConstruct>{})) /
endOmpLine))

// Block Construct
Expand Down Expand Up @@ -1127,7 +1137,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPErrorConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPUtilityConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
Expand Down
107 changes: 47 additions & 60 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2631,90 +2631,77 @@ class UnparseVisitor {
}
}
void Unparse(const OpenMPDeclareReductionConstruct &x) {
BeginOpenMP();
Word("!$OMP DECLARE REDUCTION ");
Put("(");
Walk(std::get<OmpReductionIdentifier>(x.t)), Put(" : ");
Walk(std::get<std::list<DeclarationTypeSpec>>(x.t), ","), Put(" : ");
Walk(std::get<OmpReductionCombiner>(x.t));
Put(")");
Walk(std::get<std::optional<OmpReductionInitializerClause>>(x.t));
EndOpenMP();
}
bool Pre(const OpenMPDeclarativeConstruct &x) {

void Unparse(const OpenMPDeclareMapperConstruct &z) {
BeginOpenMP();
Word("!$OMP ");
return common::visit(
common::visitors{
[&](const OpenMPDeclarativeAllocate &z) {
Word("ALLOCATE (");
Walk(std::get<OmpObjectList>(z.t));
Put(")");
Walk(std::get<OmpClauseList>(z.t));
Put("\n");
EndOpenMP();
return false;
},
[&](const OpenMPDeclareMapperConstruct &z) {
Word("DECLARE MAPPER (");
const auto &spec{std::get<OmpDeclareMapperSpecifier>(z.t)};
if (auto mapname{std::get<std::optional<Name>>(spec.t)}) {
Walk(mapname);
Put(":");
}
Walk(std::get<TypeSpec>(spec.t));
Put("::");
Walk(std::get<Name>(spec.t));
Put(")");
Word("!$OMP DECLARE MAPPER (");
const auto &spec{std::get<OmpDeclareMapperSpecifier>(z.t)};
if (auto mapname{std::get<std::optional<Name>>(spec.t)}) {
Walk(mapname);
Put(":");
}
Walk(std::get<TypeSpec>(spec.t));
Put("::");
Walk(std::get<Name>(spec.t));
Put(")");

Walk(std::get<OmpClauseList>(z.t));
Put("\n");
return false;
},
[&](const OpenMPDeclareReductionConstruct &) {
Word("DECLARE REDUCTION ");
return true;
},
[&](const OpenMPDeclareSimdConstruct &y) {
Word("DECLARE SIMD ");
Walk("(", std::get<std::optional<Name>>(y.t), ")");
Walk(std::get<OmpClauseList>(y.t));
Put("\n");
EndOpenMP();
return false;
},
[&](const OpenMPDeclareTargetConstruct &) {
Word("DECLARE TARGET ");
return true;
},
[&](const OpenMPRequiresConstruct &y) {
Word("REQUIRES ");
Walk(std::get<OmpClauseList>(y.t));
Put("\n");
EndOpenMP();
return false;
},
[&](const OpenMPThreadprivate &) {
Word("THREADPRIVATE (");
return true;
},
},
x.u);
Walk(std::get<OmpClauseList>(z.t));
Put("\n");
EndOpenMP();
}
void Unparse(const OpenMPDeclareSimdConstruct &y) {
BeginOpenMP();
Word("!$OMP DECLARE SIMD ");
Walk("(", std::get<std::optional<Name>>(y.t), ")");
Walk(std::get<OmpClauseList>(y.t));
Put("\n");
EndOpenMP();
}
void Post(const OpenMPDeclarativeConstruct &) {
void Unparse(const OpenMPDeclareTargetConstruct &x) {
BeginOpenMP();
Word("!$OMP DECLARE TARGET ");
Walk(std::get<parser::OmpDeclareTargetSpecifier>(x.t));
Put("\n");
EndOpenMP();
}
void Post(const OpenMPThreadprivate &) {
void Unparse(const OpenMPRequiresConstruct &y) {
BeginOpenMP();
Word("!$OMP REQUIRES ");
Walk(std::get<OmpClauseList>(y.t));
Put("\n");
EndOpenMP();
}
void Unparse(const OpenMPThreadprivate &x) {
BeginOpenMP();
Word("!$OMP THREADPRIVATE (");
Walk(std::get<parser::OmpObjectList>(x.t));
Put(")\n");
EndOpenMP();
}

bool Pre(const OmpMessageClause &x) {
Walk(x.v);
return false;
}
void Unparse(const OpenMPErrorConstruct &x) {
void Unparse(const OmpErrorDirective &x) {
Word("!$OMP ERROR ");
Walk(x.t);
Put("\n");
}
void Unparse(const OmpNothingDirective &x) {
Word("!$OMP NOTHING");
Put("\n");
}
void Unparse(const OmpSectionsDirective &x) {
switch (x.v) {
case llvm::omp::Directive::OMPD_sections:
Expand Down
Loading
Loading