Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
const CharBlock &source{std::get<0>(c.t).source};
return normalize_construct_name(source.ToString());
},
[&](const OpenMPAssumeConstruct &c) -> std::string {
const CharBlock &source{std::get<0>(c.t).source};
return normalize_construct_name(source.ToString());
},
[&](const OpenMPAllocatorsConstruct &c) -> std::string {
const CharBlock &source{std::get<0>(c.t).source};
return normalize_construct_name(source.ToString());
Expand Down
10 changes: 10 additions & 0 deletions flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ class ParseTreeDumper {
NODE_ENUM(OmpMapTypeModifier, Value)
NODE(parser, OmpIteratorSpecifier)
NODE(parser, OmpIterator)
NODE(parser, OmpAbsentClause)
NODE(parser, OmpAffinityClause)
NODE(OmpAffinityClause, Modifier)
NODE(parser, OmpAlignment)
Expand Down Expand Up @@ -536,6 +537,7 @@ class ParseTreeDumper {
#define GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
#include "llvm/Frontend/OpenMP/OMP.inc"
NODE(parser, OmpClauseList)
NODE(parser, OmpContainsClause)
NODE(parser, OmpCriticalDirective)
NODE(parser, OmpErrorDirective)
NODE(parser, OmpNothingDirective)
Expand Down Expand Up @@ -578,6 +580,7 @@ class ParseTreeDumper {
NODE(parser, OmpExpectation)
NODE_ENUM(OmpExpectation, Value)
NODE(parser, OmpDirectiveNameModifier)
NODE(parser, OmpHoldsClause)
NODE(parser, OmpIfClause)
NODE(OmpIfClause, Modifier)
NODE(parser, OmpLastprivateClause)
Expand All @@ -601,6 +604,9 @@ class ParseTreeDumper {
}
NODE(parser, OmpObject)
NODE(parser, OmpObjectList)
NODE(parser, OmpNoOpenMPClause)
NODE(parser, OmpNoOpenMPRoutinesClause)
NODE(parser, OmpNoParallelismClause)
NODE(parser, OmpOrderClause)
NODE(OmpOrderClause, Modifier)
NODE_ENUM(OmpOrderClause, Ordering)
Expand Down Expand Up @@ -666,6 +672,10 @@ class ParseTreeDumper {
NODE(parser, OpenACCStandaloneDeclarativeConstruct)
NODE(parser, OpenACCStandaloneConstruct)
NODE(parser, OpenACCWaitConstruct)
NODE(parser, OpenMPAssumeConstruct)
NODE(parser, OpenMPDeclarativeAssumes)
NODE(parser, OmpAssumeDirective)
NODE(parser, OmpEndAssumeDirective)
NODE(parser, OpenMPAtomicConstruct)
NODE(parser, OpenMPBlockConstruct)
NODE(parser, OpenMPCancelConstruct)
Expand Down
86 changes: 81 additions & 5 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,16 @@ using OmpContextSelector = traits::OmpContextSelectorSpecification;

// --- Clauses

using OmpDirectiveList = std::list<llvm::omp::Directive>;

// Ref: [5.2:214]
//
// absent-clause ->
// ABSENT(directive-name[, directive-name])
struct OmpAbsentClause {
WRAPPER_CLASS_BOILERPLATE(OmpAbsentClause, OmpDirectiveList);
};

// Ref: [5.0:135-140], [5.1:161-166], [5.2:264-265]
//
// affinity-clause ->
Expand Down Expand Up @@ -3968,6 +3978,14 @@ struct OmpBindClause {
WRAPPER_CLASS_BOILERPLATE(OmpBindClause, Binding);
};

// Ref: [5.2:214]
//
// contains-clause ->
// CONTAINS(directive-name[, directive-name])
struct OmpContainsClause {
WRAPPER_CLASS_BOILERPLATE(OmpContainsClause, OmpDirectiveList);
};

// Ref: [4.5:46-50], [5.0:74-78], [5.1:92-96], [5.2:109]
//
// When used as a data-sharing clause:
Expand Down Expand Up @@ -4138,6 +4156,14 @@ struct OmpGrainsizeClause {
std::tuple<MODIFIERS(), ScalarIntExpr> t;
};

// Ref: [5.2: 214]
//
// holds-clause ->
// HOLDS(expr)
struct OmpHoldsClause {
WRAPPER_CLASS_BOILERPLATE(OmpHoldsClause, common::Indirection<Expr>);
};

// Ref: [5.2:72-73], in 4.5-5.1 it's scattered over individual directives
// that allow the IF clause.
//
Expand Down Expand Up @@ -4219,6 +4245,21 @@ struct OmpMessageClause {
WRAPPER_CLASS_BOILERPLATE(OmpMessageClause, Expr);
};

// Ref: [5.2: 214]
//
// no_openmp_clause -> NO_OPENMP
EMPTY_CLASS(OmpNoOpenMPClause);

// Ref: [5.2: 214]
//
// no_openmp_routines_clause -> NO_OPENMP_ROUTINES
EMPTY_CLASS(OmpNoOpenMPRoutinesClause);

// Ref: [5.2: 214]
//
// no_parallelism_clause -> NO_PARALELISM
EMPTY_CLASS(OmpNoParallelismClause);

// Ref: [4.5:87-91], [5.0:140-146], [5.1:166-171], [5.2:270]
//
// num-tasks-clause ->
Expand Down Expand Up @@ -4403,6 +4444,41 @@ struct OpenMPUtilityConstruct {
std::variant<OmpErrorDirective, OmpNothingDirective> u;
};

// Ref: [5.2: 213-216]
//
// assumes-construct ->
// ASSUMES absent-clause | contains-clause | holds-clause | no-openmp-clause |
// no-openmp-routines-clause | no-parallelism-clause
struct OpenMPDeclarativeAssumes {
TUPLE_CLASS_BOILERPLATE(OpenMPDeclarativeAssumes);
std::tuple<Verbatim, OmpClauseList> t;
CharBlock source;
};

struct OmpAssumeDirective {
TUPLE_CLASS_BOILERPLATE(OmpAssumeDirective);
std::tuple<Verbatim, OmpClauseList> t;
CharBlock source;
};

struct OmpEndAssumeDirective {
WRAPPER_CLASS_BOILERPLATE(OmpEndAssumeDirective, Verbatim);
CharBlock source;
};

// Ref: [5.2: 213-216]
//
// assume-construct ->
// ASSUME absent-clause | contains-clause | holds_clause | no-openmp-clause
// no-openmp-routines-clause | no-parallelism-clause
// block
// [END ASSUME]
struct OpenMPAssumeConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPAssumeConstruct);
std::tuple<OmpAssumeDirective, Block, std::optional<OmpEndAssumeDirective>> t;
CharBlock source;
};

// 2.7.2 SECTIONS
// 2.11.2 PARALLEL SECTIONS
struct OmpSectionsDirective {
Expand Down Expand Up @@ -4536,10 +4612,10 @@ struct OpenMPDeclarativeAllocate {
struct OpenMPDeclarativeConstruct {
UNION_CLASS_BOILERPLATE(OpenMPDeclarativeConstruct);
CharBlock source;
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
OpenMPDeclareTargetConstruct, OpenMPThreadprivate,
OpenMPRequiresConstruct, OpenMPUtilityConstruct>
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclarativeAssumes,
OpenMPDeclareMapperConstruct, OpenMPDeclareReductionConstruct,
OpenMPDeclareSimdConstruct, OpenMPDeclareTargetConstruct,
OpenMPThreadprivate, OpenMPRequiresConstruct, OpenMPUtilityConstruct>
u;
};

Expand Down Expand Up @@ -4826,7 +4902,7 @@ struct OpenMPConstruct {
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPDispatchConstruct,
OpenMPUtilityConstruct, OpenMPExecutableAllocate,
OpenMPAllocatorsConstruct, OpenMPCriticalConstruct>
OpenMPAllocatorsConstruct, OpenMPAssumeConstruct, OpenMPCriticalConstruct>
u;
};

Expand Down
18 changes: 18 additions & 0 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ extractOmpDirective(const parser::OpenMPConstruct &ompConstruct) {
[](const parser::OpenMPAllocatorsConstruct &c) {
return llvm::omp::OMPD_allocators;
},
[](const parser::OpenMPAssumeConstruct &c) {
return llvm::omp::OMPD_assume;
},
[](const parser::OpenMPAtomicConstruct &c) {
return llvm::omp::OMPD_atomic;
},
Expand Down Expand Up @@ -3076,6 +3079,13 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
TODO(converter.getCurrentLocation(), "OpenMPDeclarativeAllocate");
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPDeclarativeAssumes &assumesConstruct) {
TODO(converter.getCurrentLocation(), "OpenMP ASSUMES declaration");
}

static void genOMP(
lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
Expand Down Expand Up @@ -3374,6 +3384,14 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
queue.begin());
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPAssumeConstruct &assumeConstruct) {
mlir::Location clauseLocation = converter.genLocation(assumeConstruct.source);
TODO(clauseLocation, "OpenMP ASSUME construct");
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
Expand Down
74 changes: 54 additions & 20 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,14 @@ TYPE_PARSER(construct<OmpSeverityClause>(

TYPE_PARSER(construct<OmpMessageClause>(expr))

TYPE_PARSER(
TYPE_PARSER(construct<OmpHoldsClause>(indirect(expr)))
TYPE_PARSER(construct<OmpAbsentClause>(many(maybe(","_tok) >>
construct<llvm::omp::Directive>(OmpDirectiveNameParser{}))))
TYPE_PARSER(construct<OmpContainsClause>(many(maybe(","_tok) >>
construct<llvm::omp::Directive>(OmpDirectiveNameParser{}))))

TYPE_PARSER("ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
parenthesized(Parser<OmpAbsentClause>{}))) ||
"ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
"AFFINITY" >> construct<OmpClause>(construct<OmpClause::Affinity>(
Expand All @@ -777,6 +784,8 @@ TYPE_PARSER(
parenthesized(Parser<OmpBindClause>{}))) ||
"COLLAPSE" >> construct<OmpClause>(construct<OmpClause::Collapse>(
parenthesized(scalarIntConstantExpr))) ||
"CONTAINS" >> construct<OmpClause>(construct<OmpClause::Contains>(
parenthesized(Parser<OmpContainsClause>{}))) ||
"COPYIN" >> construct<OmpClause>(construct<OmpClause::Copyin>(
parenthesized(Parser<OmpObjectList>{}))) ||
"COPYPRIVATE" >> construct<OmpClause>(construct<OmpClause::Copyprivate>(
Expand Down Expand Up @@ -821,6 +830,8 @@ TYPE_PARSER(
parenthesized(Parser<OmpObjectList>{}))) ||
"HINT" >> construct<OmpClause>(
construct<OmpClause::Hint>(parenthesized(constantExpr))) ||
"HOLDS" >> construct<OmpClause>(construct<OmpClause::Holds>(
parenthesized(Parser<OmpHoldsClause>{}))) ||
"IF" >> construct<OmpClause>(construct<OmpClause::If>(
parenthesized(Parser<OmpIfClause>{}))) ||
"INBRANCH" >> construct<OmpClause>(construct<OmpClause::Inbranch>()) ||
Expand Down Expand Up @@ -851,6 +862,11 @@ TYPE_PARSER(
"NOVARIANTS" >> construct<OmpClause>(construct<OmpClause::Novariants>(
parenthesized(scalarLogicalExpr))) ||
"NOWAIT" >> construct<OmpClause>(construct<OmpClause::Nowait>()) ||
"NO_OPENMP"_id >> construct<OmpClause>(construct<OmpClause::NoOpenmp>()) ||
"NO_OPENMP_ROUTINES" >>
construct<OmpClause>(construct<OmpClause::NoOpenmpRoutines>()) ||
"NO_PARALLELISM" >>
construct<OmpClause>(construct<OmpClause::NoParallelism>()) ||
"NUM_TASKS" >> construct<OmpClause>(construct<OmpClause::NumTasks>(
parenthesized(Parser<OmpNumTasksClause>{}))) ||
"NUM_TEAMS" >> construct<OmpClause>(construct<OmpClause::NumTeams>(
Expand Down Expand Up @@ -1279,26 +1295,43 @@ TYPE_PARSER(
parenthesized(Parser<OmpObjectList>{}), Parser<OmpClauseList>{})) /
lookAhead(endOmpLine / !statement(allocateStmt)))

// Assumes Construct
TYPE_PARSER(sourced(construct<OpenMPDeclarativeAssumes>(
verbatim("ASSUMES"_tok), Parser<OmpClauseList>{})))

// Declarative constructs
TYPE_PARSER(startOmpLine >>
withMessage("expected OpenMP construct"_err_en_US,
sourced(construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareReductionConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareMapperConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareSimdConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareTargetConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclarativeAllocate>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPRequiresConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPThreadprivate>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPUtilityConstruct>{})) /
endOmpLine))
TYPE_PARSER(
startOmpLine >> withMessage("expected OpenMP construct"_err_en_US,
sourced(construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclarativeAssumes>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareReductionConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareMapperConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareSimdConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclareTargetConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPDeclarativeAllocate>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPRequiresConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPThreadprivate>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPUtilityConstruct>{})) /
endOmpLine))

// Assume Construct
TYPE_PARSER(sourced(construct<OmpAssumeDirective>(
verbatim("ASSUME"_tok), Parser<OmpClauseList>{})))

TYPE_PARSER(sourced(construct<OmpEndAssumeDirective>(
verbatim(startOmpLine >> "END ASSUME"_tok))))

TYPE_PARSER(sourced(
construct<OpenMPAssumeConstruct>(Parser<OmpAssumeDirective>{} / endOmpLine,
block, maybe(Parser<OmpEndAssumeDirective>{} / endOmpLine))))

// Block Construct
TYPE_PARSER(construct<OpenMPBlockConstruct>(
Expand Down Expand Up @@ -1347,6 +1380,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
construct<OpenMPConstruct>(Parser<OpenMPAssumeConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))))

// END OMP Block directives
Expand Down
Loading