Skip to content

Commit fdda5c9

Browse files
kparzyszmahesh-attarde
authored andcommitted
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_TARGET (llvm#160573)
1 parent 836c4c9 commit fdda5c9

18 files changed

+319
-281
lines changed

flang/examples/FeatureList/FeatureList.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,6 @@ struct NodeVisitor {
451451
READ_FEATURE(OmpBlockConstruct)
452452
READ_FEATURE(OmpClause)
453453
READ_FEATURE(OmpClauseList)
454-
READ_FEATURE(OmpDeclareTargetSpecifier)
455-
READ_FEATURE(OmpDeclareTargetWithClause)
456-
READ_FEATURE(OmpDeclareTargetWithList)
457454
READ_FEATURE(OmpDefaultClause)
458455
READ_FEATURE(OmpDefaultClause::DataSharingAttribute)
459456
READ_FEATURE(OmpDefaultmapClause)

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,6 @@ class ParseTreeDumper {
538538
NODE_ENUM(OmpCloseModifier, Value)
539539
NODE(parser, OmpContainsClause)
540540
NODE(parser, OmpContextSelectorSpecification)
541-
NODE(parser, OmpDeclareTargetSpecifier)
542-
NODE(parser, OmpDeclareTargetWithClause)
543-
NODE(parser, OmpDeclareTargetWithList)
544541
NODE(parser, OmpDeclareVariantDirective)
545542
NODE(parser, OmpDefaultClause)
546543
NODE_ENUM(OmpDefaultClause, DataSharingAttribute)

flang/include/flang/Parser/openmp-utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct ConstructId {
4141
MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate);
4242
MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes);
4343
MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction);
44-
MAKE_CONSTR_ID(OpenMPDeclareTargetConstruct, D::OMPD_declare_target);
4544
MAKE_CONSTR_ID(OpenMPExecutableAllocate, D::OMPD_allocate);
4645
MAKE_CONSTR_ID(OpenMPRequiresConstruct, D::OMPD_requires);
4746

@@ -97,7 +96,6 @@ struct DirectiveNameScope {
9796
} else if constexpr (std::is_same_v<T, OpenMPDeclarativeAllocate> ||
9897
std::is_same_v<T, OpenMPDeclarativeAssumes> ||
9998
std::is_same_v<T, OpenMPDeclareReductionConstruct> ||
100-
std::is_same_v<T, OpenMPDeclareTargetConstruct> ||
10199
std::is_same_v<T, OpenMPExecutableAllocate> ||
102100
std::is_same_v<T, OpenMPRequiresConstruct>) {
103101
return MakeName(std::get<Verbatim>(x.t).source, ConstructId<T>::id);

flang/include/flang/Parser/parse-tree.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,28 +4943,16 @@ struct OmpDeclareVariantDirective {
49434943
CharBlock source;
49444944
};
49454945

4946-
// 2.10.6 declare-target -> DECLARE TARGET (extended-list) |
4947-
// DECLARE TARGET [declare-target-clause[ [,]
4948-
// declare-target-clause]...]
4949-
struct OmpDeclareTargetWithList {
4950-
WRAPPER_CLASS_BOILERPLATE(OmpDeclareTargetWithList, OmpObjectList);
4951-
CharBlock source;
4952-
};
4953-
4954-
struct OmpDeclareTargetWithClause {
4955-
WRAPPER_CLASS_BOILERPLATE(OmpDeclareTargetWithClause, OmpClauseList);
4956-
CharBlock source;
4957-
};
4958-
4959-
struct OmpDeclareTargetSpecifier {
4960-
UNION_CLASS_BOILERPLATE(OmpDeclareTargetSpecifier);
4961-
std::variant<OmpDeclareTargetWithList, OmpDeclareTargetWithClause> u;
4962-
};
4963-
4946+
// Ref: [4.5:110-113], [5.0:180-185], [5.1:210-216], [5.2:206-207],
4947+
// [6.0:346-348]
4948+
//
4949+
// declare-target-directive -> // since 4.5
4950+
// DECLARE_TARGET[(extended-list)] |
4951+
// DECLARE_TARGET clause-list
49644952
struct OpenMPDeclareTargetConstruct {
4965-
TUPLE_CLASS_BOILERPLATE(OpenMPDeclareTargetConstruct);
4953+
WRAPPER_CLASS_BOILERPLATE(
4954+
OpenMPDeclareTargetConstruct, OmpDirectiveSpecification);
49664955
CharBlock source;
4967-
std::tuple<Verbatim, OmpDeclareTargetSpecifier> t;
49684956
};
49694957

49704958
// OMP v5.2: 5.8.8

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -761,19 +761,17 @@ static void promoteNonCPtrUseDevicePtrArgsToUseDeviceAddr(
761761
static void getDeclareTargetInfo(
762762
lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx,
763763
lower::pft::Evaluation &eval,
764-
const parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
764+
const parser::OpenMPDeclareTargetConstruct &construct,
765765
mlir::omp::DeclareTargetOperands &clauseOps,
766766
llvm::SmallVectorImpl<DeclareTargetCaptureInfo> &symbolAndClause) {
767-
const auto &spec =
768-
std::get<parser::OmpDeclareTargetSpecifier>(declareTargetConstruct.t);
769-
if (const auto *objectList{parser::Unwrap<parser::OmpObjectList>(spec.u)}) {
770-
ObjectList objects{makeObjects(*objectList, semaCtx)};
767+
768+
if (!construct.v.Arguments().v.empty()) {
769+
ObjectList objects{makeObjects(construct.v.Arguments(), semaCtx)};
771770
// Case: declare target(func, var1, var2)
772771
gatherFuncAndVarSyms(objects, mlir::omp::DeclareTargetCaptureClause::to,
773772
symbolAndClause, /*automap=*/false);
774-
} else if (const auto *clauseList{
775-
parser::Unwrap<parser::OmpClauseList>(spec.u)}) {
776-
List<Clause> clauses = makeClauses(*clauseList, semaCtx);
773+
} else {
774+
List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
777775
if (clauses.empty()) {
778776
Fortran::lower::pft::FunctionLikeUnit *owningProc =
779777
eval.getOwningProcedure();

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,23 +1773,11 @@ TYPE_PARSER(sourced(construct<OpenMPDeclareReductionConstruct>(
17731773
IsDirective(llvm::omp::Directive::OMPD_declare_reduction)) >=
17741774
Parser<OmpDirectiveSpecification>{})))
17751775

1776-
// declare-target with list
1777-
TYPE_PARSER(sourced(construct<OmpDeclareTargetWithList>(
1778-
parenthesized(Parser<OmpObjectList>{}))))
1779-
1780-
// declare-target with clause
1781-
TYPE_PARSER(
1782-
sourced(construct<OmpDeclareTargetWithClause>(Parser<OmpClauseList>{})))
1783-
1784-
// declare-target-specifier
1785-
TYPE_PARSER(
1786-
construct<OmpDeclareTargetSpecifier>(Parser<OmpDeclareTargetWithList>{}) ||
1787-
construct<OmpDeclareTargetSpecifier>(Parser<OmpDeclareTargetWithClause>{}))
1788-
17891776
// 2.10.6 Declare Target Construct
17901777
TYPE_PARSER(sourced(construct<OpenMPDeclareTargetConstruct>(
1791-
verbatim("DECLARE TARGET"_tok) || verbatim("DECLARE_TARGET"_tok),
1792-
Parser<OmpDeclareTargetSpecifier>{})))
1778+
predicated(Parser<OmpDirectiveName>{},
1779+
IsDirective(llvm::omp::Directive::OMPD_declare_target)) >=
1780+
Parser<OmpDirectiveSpecification>{})))
17931781

17941782
static OmpMapperSpecifier ConstructOmpMapperSpecifier(
17951783
std::optional<Name> &&mapperName, TypeSpec &&typeSpec, Name &&varName) {

flang/lib/Parser/unparse.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,9 +2492,6 @@ class UnparseVisitor {
24922492
void Unparse(const OpenMPCriticalConstruct &x) {
24932493
Unparse(static_cast<const OmpBlockConstruct &>(x));
24942494
}
2495-
void Unparse(const OmpDeclareTargetWithList &x) {
2496-
Put("("), Walk(x.v), Put(")");
2497-
}
24982495
void Unparse(const OmpInitializerProc &x) {
24992496
Walk(std::get<ProcedureDesignator>(x.t));
25002497
Put("(");
@@ -2582,8 +2579,8 @@ class UnparseVisitor {
25822579
}
25832580
void Unparse(const OpenMPDeclareTargetConstruct &x) {
25842581
BeginOpenMP();
2585-
Word("!$OMP DECLARE TARGET ");
2586-
Walk(std::get<parser::OmpDeclareTargetSpecifier>(x.t));
2582+
Word("!$OMP ");
2583+
Walk(x.v);
25872584
Put("\n");
25882585
EndOpenMP();
25892586
}

0 commit comments

Comments
 (0)