Skip to content
1 change: 0 additions & 1 deletion flang/examples/FeatureList/FeatureList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ struct NodeVisitor {
READ_FEATURE(OmpOrderingModifier::Value)
READ_FEATURE(OmpSectionBlocks)
READ_FEATURE(OmpSectionsDirective)
READ_FEATURE(OmpSimpleStandaloneDirective)
READ_FEATURE(Only)
READ_FEATURE(OpenACCAtomicConstruct)
READ_FEATURE(OpenACCBlockConstruct)
Expand Down
15 changes: 10 additions & 5 deletions flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
return std::visit(
Fortran::common::visitors{
[&](const OpenMPStandaloneConstruct &c) -> std::string {
return std::visit(
[&](const auto &c) {
// Get source from the directive or verbatim fields
const CharBlock &source{std::get<0>(c.t).source};
return normalize_construct_name(source.ToString());
return common::visit(
common::visitors{
[&](const OmpMetadirectiveDirective &d) {
return normalize_construct_name(d.source.ToString());
},
[&](auto &&d) {
const CharBlock &source{
std::get<OmpDirectiveName>(d.v.t).source};
return normalize_construct_name(source.ToString());
},
},
c.u);
},
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ class ParseTreeDumper {
NODE(parser, OmpLocatorList)
NODE(parser, OmpReductionSpecifier)
NODE(parser, OmpArgument)
NODE(parser, OmpArgumentList)
NODE(parser, OmpMetadirectiveDirective)
NODE(parser, OmpMatchClause)
NODE(parser, OmpOtherwiseClause)
Expand Down Expand Up @@ -663,7 +664,6 @@ class ParseTreeDumper {
NODE_ENUM(OmpOrderingModifier, Value)
NODE(parser, OmpSectionBlocks)
NODE(parser, OmpSectionsDirective)
NODE(parser, OmpSimpleStandaloneDirective)
NODE(parser, OmpToClause)
NODE(OmpToClause, Modifier)
NODE(parser, Only)
Expand Down
32 changes: 14 additions & 18 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,11 @@ struct OmpArgument {
OmpMapperSpecifier, OmpReductionSpecifier>
u;
};

struct OmpArgumentList {
WRAPPER_CLASS_BOILERPLATE(OmpArgumentList, std::list<OmpArgument>);
CharBlock source;
};
} // namespace arguments

inline namespace traits {
Expand Down Expand Up @@ -4511,10 +4516,11 @@ struct OmpDirectiveSpecification {
llvm::omp::Directive DirId() const { //
return std::get<OmpDirectiveName>(t).v;
}
const OmpArgumentList &Arguments() const;
const OmpClauseList &Clauses() const;

CharBlock source;
std::tuple<OmpDirectiveName, std::optional<std::list<OmpArgument>>,
std::tuple<OmpDirectiveName, std::optional<OmpArgumentList>,
std::optional<OmpClauseList>, Flags>
t;
};
Expand Down Expand Up @@ -4865,16 +4871,15 @@ struct OmpLoopDirective {

// 2.14.2 cancellation-point -> CANCELLATION POINT construct-type-clause
struct OpenMPCancellationPointConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPCancellationPointConstruct);
WRAPPER_CLASS_BOILERPLATE(
OpenMPCancellationPointConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<Verbatim, OmpClauseList> t;
};

// 2.14.1 cancel -> CANCEL construct-type-clause [ [,] if-clause]
struct OpenMPCancelConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPCancelConstruct);
WRAPPER_CLASS_BOILERPLATE(OpenMPCancelConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<Verbatim, OmpClauseList> t;
};

// Ref: [5.0:254-255], [5.1:287-288], [5.2:322-323]
Expand All @@ -4884,9 +4889,8 @@ struct OpenMPCancelConstruct {
// destroy-clause |
// update-clause
struct OpenMPDepobjConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPDepobjConstruct);
WRAPPER_CLASS_BOILERPLATE(OpenMPDepobjConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<Verbatim, OmpObject, OmpClause> t;
};

// Ref: [5.2: 200-201]
Expand Down Expand Up @@ -4927,22 +4931,14 @@ struct OpenMPDispatchConstruct {
// ACQ_REL | RELEASE | ACQUIRE | // since 5.0
// SEQ_CST // since 5.1
struct OpenMPFlushConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
CharBlock source;
std::tuple<Verbatim, std::optional<OmpObjectList>,
std::optional<OmpClauseList>, /*TrailingClauses=*/bool>
t;
};

struct OmpSimpleStandaloneDirective {
WRAPPER_CLASS_BOILERPLATE(OmpSimpleStandaloneDirective, llvm::omp::Directive);
WRAPPER_CLASS_BOILERPLATE(OpenMPFlushConstruct, OmpDirectiveSpecification);
CharBlock source;
};

struct OpenMPSimpleStandaloneConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPSimpleStandaloneConstruct);
WRAPPER_CLASS_BOILERPLATE(
OpenMPSimpleStandaloneConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<OmpSimpleStandaloneDirective, OmpClauseList> t;
};

struct OpenMPStandaloneConstruct {
Expand Down
19 changes: 19 additions & 0 deletions flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ Object makeObject(const parser::OmpObject &object,
return makeObject(std::get<parser::Designator>(object.u), semaCtx);
}

ObjectList makeObjects(const parser::OmpArgumentList &objects,
semantics::SemanticsContext &semaCtx) {
return makeList(objects.v, [&](const parser::OmpArgument &arg) {
return common::visit(
common::visitors{
[&](const parser::OmpLocator &locator) -> Object {
if (auto *object = std::get_if<parser::OmpObject>(&locator.u)) {
return makeObject(*object, semaCtx);
}
llvm_unreachable("Expecting object");
},
[](auto &&s) -> Object { //
llvm_unreachable("Expecting object");
},
},
arg.u);
});
}

std::optional<Object> getBaseObject(const Object &object,
semantics::SemanticsContext &semaCtx) {
// If it's just the symbol, then there is no base.
Expand Down
3 changes: 3 additions & 0 deletions flang/lib/Lower/OpenMP/Clauses.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ inline ObjectList makeObjects(const parser::OmpObjectList &objects,
return makeList(objects.v, makeObjectFn(semaCtx));
}

ObjectList makeObjects(const parser::OmpArgumentList &objects,
semantics::SemanticsContext &semaCtx);

template <typename FuncTy, //
typename ArgTy, //
typename ResultTy = std::invoke_result_t<FuncTy, ArgTy>>
Expand Down
48 changes: 20 additions & 28 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ extractOmpDirective(const parser::OpenMPConstruct &ompConstruct) {
return common::visit(
common::visitors{
[](const parser::OpenMPSimpleStandaloneConstruct &c) {
return std::get<parser::OmpSimpleStandaloneDirective>(c.t)
.v;
return c.v.DirId();
},
[](const parser::OpenMPFlushConstruct &c) {
return llvm::omp::OMPD_flush;
Expand Down Expand Up @@ -3286,14 +3285,12 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
// OpenMPStandaloneConstruct visitors
//===----------------------------------------------------------------------===//

static void genOMP(
lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
const parser::OpenMPSimpleStandaloneConstruct &simpleStandaloneConstruct) {
const auto &directive = std::get<parser::OmpSimpleStandaloneDirective>(
simpleStandaloneConstruct.t);
List<Clause> clauses = makeClauses(
std::get<parser::OmpClauseList>(simpleStandaloneConstruct.t), semaCtx);
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPSimpleStandaloneConstruct &construct) {
const auto &directive = std::get<parser::OmpDirectiveName>(construct.v.t);
List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
mlir::Location currentLocation = converter.genLocation(directive.source);

ConstructQueue queue{
Expand All @@ -3313,22 +3310,16 @@ static void genOMP(
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPFlushConstruct &flushConstruct) {
const auto &verbatim = std::get<parser::Verbatim>(flushConstruct.t);
const auto &objectList =
std::get<std::optional<parser::OmpObjectList>>(flushConstruct.t);
const auto &clauseList =
std::get<std::optional<parser::OmpClauseList>>(flushConstruct.t);
ObjectList objects =
objectList ? makeObjects(*objectList, semaCtx) : ObjectList{};
const parser::OpenMPFlushConstruct &construct) {
const auto &argumentList = construct.v.Arguments();
const auto &clauseList = construct.v.Clauses();
ObjectList objects = makeObjects(argumentList, semaCtx);
List<Clause> clauses =
clauseList ? makeList(clauseList->v,
[&](auto &&s) { return makeClause(s, semaCtx); })
: List<Clause>{};
mlir::Location currentLocation = converter.genLocation(verbatim.source);
makeList(clauseList.v, [&](auto &&s) { return makeClause(s, semaCtx); });
mlir::Location currentLocation = converter.genLocation(construct.source);

ConstructQueue queue{buildConstructQueue(
converter.getFirOpBuilder().getModule(), semaCtx, eval, verbatim.source,
converter.getFirOpBuilder().getModule(), semaCtx, eval, construct.source,
llvm::omp::Directive::OMPD_flush, clauses)};
genFlushOp(converter, symTable, semaCtx, eval, currentLocation, objects,
queue, queue.begin());
Expand All @@ -3355,11 +3346,12 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
const parser::OpenMPDepobjConstruct &construct) {
// These values will be ignored until the construct itself is implemented,
// but run them anyway for the sake of testing (via a Todo test).
auto &ompObj = std::get<parser::OmpObject>(construct.t);
const Object &depObj = makeObject(ompObj, semaCtx);
Clause clause = makeClause(std::get<parser::OmpClause>(construct.t), semaCtx);
(void)depObj;
(void)clause;
ObjectList objects = makeObjects(construct.v.Arguments(), semaCtx);
assert(objects.size() == 1);
List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
assert(clauses.size() == 1);
(void)objects;
(void)clauses;

TODO(converter.getCurrentLocation(), "OpenMPDepobjConstruct");
}
Expand Down
Loading