Skip to content

Commit 24b7759

Browse files
Leporacanthicuskiranchandramohankparzysz
authored
[FLANG][OpenMP]Add frontend support for ASSUME and ASSUMES (#120770)
Enough suport to parse correctly formed directives of !$OMP ASSUME and !$OMP ASSUMES with teh related clauses that go with them: ABSENT, CONTAINS, NO_OPENPP, NO_OPENMP_ROUTINES, NO_PARALLELISM and HOLDS. Tests added for unparsing and dump parse-tree. Semantics support is very minimal and no specific tests added. The lowering will hit a TODO, and there are tests in Lower/OpenMP/Todo to make it clear that this is currently expected behaviour. --------- Co-authored-by: Kiran Chandramohan <[email protected]> Co-authored-by: Krzysztof Parzyszek <[email protected]>
1 parent f08824b commit 24b7759

File tree

12 files changed

+307
-28
lines changed

12 files changed

+307
-28
lines changed

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
143143
const CharBlock &source{std::get<0>(c.t).source};
144144
return normalize_construct_name(source.ToString());
145145
},
146+
[&](const OpenMPAssumeConstruct &c) -> std::string {
147+
const CharBlock &source{std::get<0>(c.t).source};
148+
return normalize_construct_name(source.ToString());
149+
},
146150
[&](const OpenMPAllocatorsConstruct &c) -> std::string {
147151
const CharBlock &source{std::get<0>(c.t).source};
148152
return normalize_construct_name(source.ToString());

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ class ParseTreeDumper {
510510
NODE_ENUM(OmpMapTypeModifier, Value)
511511
NODE(parser, OmpIteratorSpecifier)
512512
NODE(parser, OmpIterator)
513+
NODE(parser, OmpAbsentClause)
513514
NODE(parser, OmpAffinityClause)
514515
NODE(OmpAffinityClause, Modifier)
515516
NODE(parser, OmpAlignment)
@@ -543,6 +544,7 @@ class ParseTreeDumper {
543544
#define GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
544545
#include "llvm/Frontend/OpenMP/OMP.inc"
545546
NODE(parser, OmpClauseList)
547+
NODE(parser, OmpContainsClause)
546548
NODE(parser, OmpCriticalDirective)
547549
NODE(parser, OmpErrorDirective)
548550
NODE(parser, OmpNothingDirective)
@@ -585,6 +587,7 @@ class ParseTreeDumper {
585587
NODE(parser, OmpExpectation)
586588
NODE_ENUM(OmpExpectation, Value)
587589
NODE(parser, OmpDirectiveNameModifier)
590+
NODE(parser, OmpHoldsClause)
588591
NODE(parser, OmpIfClause)
589592
NODE(OmpIfClause, Modifier)
590593
NODE(parser, OmpLastprivateClause)
@@ -608,6 +611,9 @@ class ParseTreeDumper {
608611
}
609612
NODE(parser, OmpObject)
610613
NODE(parser, OmpObjectList)
614+
NODE(parser, OmpNoOpenMPClause)
615+
NODE(parser, OmpNoOpenMPRoutinesClause)
616+
NODE(parser, OmpNoParallelismClause)
611617
NODE(parser, OmpOrderClause)
612618
NODE(OmpOrderClause, Modifier)
613619
NODE_ENUM(OmpOrderClause, Ordering)
@@ -672,6 +678,10 @@ class ParseTreeDumper {
672678
NODE(parser, OpenACCStandaloneDeclarativeConstruct)
673679
NODE(parser, OpenACCStandaloneConstruct)
674680
NODE(parser, OpenACCWaitConstruct)
681+
NODE(parser, OpenMPAssumeConstruct)
682+
NODE(parser, OpenMPDeclarativeAssumes)
683+
NODE(parser, OmpAssumeDirective)
684+
NODE(parser, OmpEndAssumeDirective)
675685
NODE(parser, OpenMPAtomicConstruct)
676686
NODE(parser, OpenMPBlockConstruct)
677687
NODE(parser, OpenMPCancelConstruct)

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

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,6 +3953,16 @@ using OmpContextSelector = traits::OmpContextSelectorSpecification;
39533953

39543954
// --- Clauses
39553955

3956+
using OmpDirectiveList = std::list<llvm::omp::Directive>;
3957+
3958+
// Ref: [5.2:214]
3959+
//
3960+
// absent-clause ->
3961+
// ABSENT(directive-name[, directive-name])
3962+
struct OmpAbsentClause {
3963+
WRAPPER_CLASS_BOILERPLATE(OmpAbsentClause, OmpDirectiveList);
3964+
};
3965+
39563966
// Ref: [5.0:135-140], [5.1:161-166], [5.2:264-265]
39573967
//
39583968
// affinity-clause ->
@@ -4026,6 +4036,14 @@ struct OmpBindClause {
40264036
WRAPPER_CLASS_BOILERPLATE(OmpBindClause, Binding);
40274037
};
40284038

4039+
// Ref: [5.2:214]
4040+
//
4041+
// contains-clause ->
4042+
// CONTAINS(directive-name[, directive-name])
4043+
struct OmpContainsClause {
4044+
WRAPPER_CLASS_BOILERPLATE(OmpContainsClause, OmpDirectiveList);
4045+
};
4046+
40294047
// Ref: [4.5:46-50], [5.0:74-78], [5.1:92-96], [5.2:109]
40304048
//
40314049
// When used as a data-sharing clause:
@@ -4198,6 +4216,14 @@ struct OmpGrainsizeClause {
41984216
std::tuple<MODIFIERS(), ScalarIntExpr> t;
41994217
};
42004218

4219+
// Ref: [5.2: 214]
4220+
//
4221+
// holds-clause ->
4222+
// HOLDS(expr)
4223+
struct OmpHoldsClause {
4224+
WRAPPER_CLASS_BOILERPLATE(OmpHoldsClause, common::Indirection<Expr>);
4225+
};
4226+
42014227
// Ref: [5.2:72-73], in 4.5-5.1 it's scattered over individual directives
42024228
// that allow the IF clause.
42034229
//
@@ -4279,6 +4305,21 @@ struct OmpMessageClause {
42794305
WRAPPER_CLASS_BOILERPLATE(OmpMessageClause, Expr);
42804306
};
42814307

4308+
// Ref: [5.2: 214]
4309+
//
4310+
// no_openmp_clause -> NO_OPENMP
4311+
EMPTY_CLASS(OmpNoOpenMPClause);
4312+
4313+
// Ref: [5.2: 214]
4314+
//
4315+
// no_openmp_routines_clause -> NO_OPENMP_ROUTINES
4316+
EMPTY_CLASS(OmpNoOpenMPRoutinesClause);
4317+
4318+
// Ref: [5.2: 214]
4319+
//
4320+
// no_parallelism_clause -> NO_PARALELISM
4321+
EMPTY_CLASS(OmpNoParallelismClause);
4322+
42824323
// Ref: [4.5:87-91], [5.0:140-146], [5.1:166-171], [5.2:270]
42834324
//
42844325
// num-tasks-clause ->
@@ -4473,6 +4514,41 @@ struct OpenMPUtilityConstruct {
44734514
std::variant<OmpErrorDirective, OmpNothingDirective> u;
44744515
};
44754516

4517+
// Ref: [5.2: 213-216]
4518+
//
4519+
// assumes-construct ->
4520+
// ASSUMES absent-clause | contains-clause | holds-clause | no-openmp-clause |
4521+
// no-openmp-routines-clause | no-parallelism-clause
4522+
struct OpenMPDeclarativeAssumes {
4523+
TUPLE_CLASS_BOILERPLATE(OpenMPDeclarativeAssumes);
4524+
std::tuple<Verbatim, OmpClauseList> t;
4525+
CharBlock source;
4526+
};
4527+
4528+
struct OmpAssumeDirective {
4529+
TUPLE_CLASS_BOILERPLATE(OmpAssumeDirective);
4530+
std::tuple<Verbatim, OmpClauseList> t;
4531+
CharBlock source;
4532+
};
4533+
4534+
struct OmpEndAssumeDirective {
4535+
WRAPPER_CLASS_BOILERPLATE(OmpEndAssumeDirective, Verbatim);
4536+
CharBlock source;
4537+
};
4538+
4539+
// Ref: [5.2: 213-216]
4540+
//
4541+
// assume-construct ->
4542+
// ASSUME absent-clause | contains-clause | holds_clause | no-openmp-clause
4543+
// no-openmp-routines-clause | no-parallelism-clause
4544+
// block
4545+
// [END ASSUME]
4546+
struct OpenMPAssumeConstruct {
4547+
TUPLE_CLASS_BOILERPLATE(OpenMPAssumeConstruct);
4548+
std::tuple<OmpAssumeDirective, Block, std::optional<OmpEndAssumeDirective>> t;
4549+
CharBlock source;
4550+
};
4551+
44764552
// 2.7.2 SECTIONS
44774553
// 2.11.2 PARALLEL SECTIONS
44784554
struct OmpSectionsDirective {
@@ -4595,10 +4671,11 @@ struct OpenMPDeclarativeAllocate {
45954671
struct OpenMPDeclarativeConstruct {
45964672
UNION_CLASS_BOILERPLATE(OpenMPDeclarativeConstruct);
45974673
CharBlock source;
4598-
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
4599-
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
4674+
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclarativeAssumes,
4675+
OpenMPDeclareMapperConstruct, OpenMPDeclareReductionConstruct,
4676+
OpenMPDeclareSimdConstruct, OpenMPDeclareTargetConstruct,
46004677
OpenMPThreadprivate, OpenMPRequiresConstruct, OpenMPUtilityConstruct,
4601-
OpenMPDeclareTargetConstruct, OmpMetadirectiveDirective>
4678+
OmpMetadirectiveDirective>
46024679
u;
46034680
};
46044681

@@ -4885,7 +4962,7 @@ struct OpenMPConstruct {
48854962
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
48864963
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPDispatchConstruct,
48874964
OpenMPUtilityConstruct, OpenMPExecutableAllocate,
4888-
OpenMPAllocatorsConstruct, OpenMPCriticalConstruct>
4965+
OpenMPAllocatorsConstruct, OpenMPAssumeConstruct, OpenMPCriticalConstruct>
48894966
u;
48904967
};
48914968

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ extractOmpDirective(const parser::OpenMPConstruct &ompConstruct) {
367367
[](const parser::OpenMPAllocatorsConstruct &c) {
368368
return llvm::omp::OMPD_allocators;
369369
},
370+
[](const parser::OpenMPAssumeConstruct &c) {
371+
return llvm::omp::OMPD_assume;
372+
},
370373
[](const parser::OpenMPAtomicConstruct &c) {
371374
return llvm::omp::OMPD_atomic;
372375
},
@@ -3103,6 +3106,13 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
31033106
TODO(converter.getCurrentLocation(), "OpenMPDeclarativeAllocate");
31043107
}
31053108

3109+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3110+
semantics::SemanticsContext &semaCtx,
3111+
lower::pft::Evaluation &eval,
3112+
const parser::OpenMPDeclarativeAssumes &assumesConstruct) {
3113+
TODO(converter.getCurrentLocation(), "OpenMP ASSUMES declaration");
3114+
}
3115+
31063116
static void genOMP(
31073117
lower::AbstractConverter &converter, lower::SymMap &symTable,
31083118
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
@@ -3447,6 +3457,14 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
34473457
queue.begin());
34483458
}
34493459

3460+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3461+
semantics::SemanticsContext &semaCtx,
3462+
lower::pft::Evaluation &eval,
3463+
const parser::OpenMPAssumeConstruct &assumeConstruct) {
3464+
mlir::Location clauseLocation = converter.genLocation(assumeConstruct.source);
3465+
TODO(clauseLocation, "OpenMP ASSUME construct");
3466+
}
3467+
34503468
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
34513469
semantics::SemanticsContext &semaCtx,
34523470
lower::pft::Evaluation &eval,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,14 @@ TYPE_PARSER(construct<OmpSeverityClause>(
773773

774774
TYPE_PARSER(construct<OmpMessageClause>(expr))
775775

776-
TYPE_PARSER(
776+
TYPE_PARSER(construct<OmpHoldsClause>(indirect(expr)))
777+
TYPE_PARSER(construct<OmpAbsentClause>(many(maybe(","_tok) >>
778+
construct<llvm::omp::Directive>(OmpDirectiveNameParser{}))))
779+
TYPE_PARSER(construct<OmpContainsClause>(many(maybe(","_tok) >>
780+
construct<llvm::omp::Directive>(OmpDirectiveNameParser{}))))
781+
782+
TYPE_PARSER("ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
783+
parenthesized(Parser<OmpAbsentClause>{}))) ||
777784
"ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
778785
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
779786
"AFFINITY" >> construct<OmpClause>(construct<OmpClause::Affinity>(
@@ -795,6 +802,8 @@ TYPE_PARSER(
795802
parenthesized(Parser<OmpBindClause>{}))) ||
796803
"COLLAPSE" >> construct<OmpClause>(construct<OmpClause::Collapse>(
797804
parenthesized(scalarIntConstantExpr))) ||
805+
"CONTAINS" >> construct<OmpClause>(construct<OmpClause::Contains>(
806+
parenthesized(Parser<OmpContainsClause>{}))) ||
798807
"COPYIN" >> construct<OmpClause>(construct<OmpClause::Copyin>(
799808
parenthesized(Parser<OmpObjectList>{}))) ||
800809
"COPYPRIVATE" >> construct<OmpClause>(construct<OmpClause::Copyprivate>(
@@ -839,6 +848,8 @@ TYPE_PARSER(
839848
parenthesized(Parser<OmpObjectList>{}))) ||
840849
"HINT" >> construct<OmpClause>(
841850
construct<OmpClause::Hint>(parenthesized(constantExpr))) ||
851+
"HOLDS" >> construct<OmpClause>(construct<OmpClause::Holds>(
852+
parenthesized(Parser<OmpHoldsClause>{}))) ||
842853
"IF" >> construct<OmpClause>(construct<OmpClause::If>(
843854
parenthesized(Parser<OmpIfClause>{}))) ||
844855
"INBRANCH" >> construct<OmpClause>(construct<OmpClause::Inbranch>()) ||
@@ -869,6 +880,11 @@ TYPE_PARSER(
869880
"NOVARIANTS" >> construct<OmpClause>(construct<OmpClause::Novariants>(
870881
parenthesized(scalarLogicalExpr))) ||
871882
"NOWAIT" >> construct<OmpClause>(construct<OmpClause::Nowait>()) ||
883+
"NO_OPENMP"_id >> construct<OmpClause>(construct<OmpClause::NoOpenmp>()) ||
884+
"NO_OPENMP_ROUTINES" >>
885+
construct<OmpClause>(construct<OmpClause::NoOpenmpRoutines>()) ||
886+
"NO_PARALLELISM" >>
887+
construct<OmpClause>(construct<OmpClause::NoParallelism>()) ||
872888
"NUM_TASKS" >> construct<OmpClause>(construct<OmpClause::NumTasks>(
873889
parenthesized(Parser<OmpNumTasksClause>{}))) ||
874890
"NUM_TEAMS" >> construct<OmpClause>(construct<OmpClause::NumTeams>(
@@ -1299,28 +1315,45 @@ TYPE_PARSER(
12991315
parenthesized(Parser<OmpObjectList>{}), Parser<OmpClauseList>{})) /
13001316
lookAhead(endOmpLine / !statement(allocateStmt)))
13011317

1318+
// Assumes Construct
1319+
TYPE_PARSER(sourced(construct<OpenMPDeclarativeAssumes>(
1320+
verbatim("ASSUMES"_tok), Parser<OmpClauseList>{})))
1321+
13021322
// Declarative constructs
1303-
TYPE_PARSER(startOmpLine >>
1304-
withMessage("expected OpenMP construct"_err_en_US,
1305-
sourced(construct<OpenMPDeclarativeConstruct>(
1306-
Parser<OpenMPDeclareReductionConstruct>{}) ||
1307-
construct<OpenMPDeclarativeConstruct>(
1308-
Parser<OpenMPDeclareMapperConstruct>{}) ||
1309-
construct<OpenMPDeclarativeConstruct>(
1310-
Parser<OpenMPDeclareSimdConstruct>{}) ||
1311-
construct<OpenMPDeclarativeConstruct>(
1312-
Parser<OpenMPDeclareTargetConstruct>{}) ||
1313-
construct<OpenMPDeclarativeConstruct>(
1314-
Parser<OpenMPDeclarativeAllocate>{}) ||
1315-
construct<OpenMPDeclarativeConstruct>(
1316-
Parser<OpenMPRequiresConstruct>{}) ||
1317-
construct<OpenMPDeclarativeConstruct>(
1318-
Parser<OpenMPThreadprivate>{}) ||
1319-
construct<OpenMPDeclarativeConstruct>(
1320-
Parser<OpenMPUtilityConstruct>{}) ||
1321-
construct<OpenMPDeclarativeConstruct>(
1322-
Parser<OmpMetadirectiveDirective>{})) /
1323-
endOmpLine))
1323+
TYPE_PARSER(
1324+
startOmpLine >> withMessage("expected OpenMP construct"_err_en_US,
1325+
sourced(construct<OpenMPDeclarativeConstruct>(
1326+
Parser<OpenMPDeclarativeAssumes>{}) ||
1327+
construct<OpenMPDeclarativeConstruct>(
1328+
Parser<OpenMPDeclareReductionConstruct>{}) ||
1329+
construct<OpenMPDeclarativeConstruct>(
1330+
Parser<OpenMPDeclareMapperConstruct>{}) ||
1331+
construct<OpenMPDeclarativeConstruct>(
1332+
Parser<OpenMPDeclareSimdConstruct>{}) ||
1333+
construct<OpenMPDeclarativeConstruct>(
1334+
Parser<OpenMPDeclareTargetConstruct>{}) ||
1335+
construct<OpenMPDeclarativeConstruct>(
1336+
Parser<OpenMPDeclarativeAllocate>{}) ||
1337+
construct<OpenMPDeclarativeConstruct>(
1338+
Parser<OpenMPRequiresConstruct>{}) ||
1339+
construct<OpenMPDeclarativeConstruct>(
1340+
Parser<OpenMPThreadprivate>{}) ||
1341+
construct<OpenMPDeclarativeConstruct>(
1342+
Parser<OpenMPUtilityConstruct>{}) ||
1343+
construct<OpenMPDeclarativeConstruct>(
1344+
Parser<OmpMetadirectiveDirective>{})) /
1345+
endOmpLine))
1346+
1347+
// Assume Construct
1348+
TYPE_PARSER(sourced(construct<OmpAssumeDirective>(
1349+
verbatim("ASSUME"_tok), Parser<OmpClauseList>{})))
1350+
1351+
TYPE_PARSER(sourced(construct<OmpEndAssumeDirective>(
1352+
verbatim(startOmpLine >> "END ASSUME"_tok))))
1353+
1354+
TYPE_PARSER(sourced(
1355+
construct<OpenMPAssumeConstruct>(Parser<OmpAssumeDirective>{} / endOmpLine,
1356+
block, maybe(Parser<OmpEndAssumeDirective>{} / endOmpLine))))
13241357

13251358
// Block Construct
13261359
TYPE_PARSER(construct<OpenMPBlockConstruct>(
@@ -1369,6 +1402,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
13691402
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
13701403
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
13711404
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
1405+
construct<OpenMPConstruct>(Parser<OpenMPAssumeConstruct>{}),
13721406
construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))))
13731407

13741408
// END OMP Block directives

0 commit comments

Comments
 (0)