Skip to content

Commit 8429f7f

Browse files
authored
[flang][OpenMP] Parsing support for DYN_GROUPPRIVATE (llvm#153615)
This does not perform semantic checks or lowering.
1 parent 0fb1057 commit 8429f7f

File tree

11 files changed

+196
-8
lines changed

11 files changed

+196
-8
lines changed

flang/include/flang/Lower/OpenMP/Clauses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ using DistSchedule = tomp::clause::DistScheduleT<TypeTy, IdTy, ExprTy>;
219219
using Doacross = tomp::clause::DoacrossT<TypeTy, IdTy, ExprTy>;
220220
using DynamicAllocators =
221221
tomp::clause::DynamicAllocatorsT<TypeTy, IdTy, ExprTy>;
222+
using DynGroupprivate = tomp::clause::DynGroupprivateT<TypeTy, IdTy, ExprTy>;
222223
using Enter = tomp::clause::EnterT<TypeTy, IdTy, ExprTy>;
223224
using Exclusive = tomp::clause::ExclusiveT<TypeTy, IdTy, ExprTy>;
224225
using Fail = tomp::clause::FailT<TypeTy, IdTy, ExprTy>;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ class ParseTreeDumper {
525525
NODE(parser, OmpAbsentClause)
526526
NODE(parser, OmpAffinityClause)
527527
NODE(OmpAffinityClause, Modifier)
528+
NODE(parser, OmpAccessGroup)
529+
NODE_ENUM(OmpAccessGroup, Value)
528530
NODE(parser, OmpAlignment)
529531
NODE(parser, OmpAlignClause)
530532
NODE(parser, OmpAlignedClause)
@@ -569,6 +571,8 @@ class ParseTreeDumper {
569571
NODE_ENUM(OmpDependenceType, Value)
570572
NODE(parser, OmpTaskDependenceType)
571573
NODE_ENUM(OmpTaskDependenceType, Value)
574+
NODE(parser, OmpDynGroupprivateClause)
575+
NODE(OmpDynGroupprivateClause, Modifier)
572576
NODE(parser, OmpIndirectClause)
573577
NODE(parser, OmpIterationOffset)
574578
NODE(parser, OmpIteration)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,11 @@ inline namespace modifier {
37363736
// ENUM_CLASS(Value, Keyword1, Keyword2);
37373737
// };
37383738

3739+
struct OmpAccessGroup {
3740+
ENUM_CLASS(Value, Cgroup);
3741+
WRAPPER_CLASS_BOILERPLATE(OmpAccessGroup, Value);
3742+
};
3743+
37393744
// Ref: [4.5:72-81], [5.0:110-119], [5.1:134-143], [5.2:169-170]
37403745
//
37413746
// alignment ->
@@ -4019,8 +4024,9 @@ struct OmpOrderModifier {
40194024
//
40204025
// prescriptiveness ->
40214026
// STRICT // since 5.1
4027+
// FALLBACK // since 6.1
40224028
struct OmpPrescriptiveness {
4023-
ENUM_CLASS(Value, Strict)
4029+
ENUM_CLASS(Value, Strict, Fallback)
40244030
WRAPPER_CLASS_BOILERPLATE(OmpPrescriptiveness, Value);
40254031
};
40264032

@@ -4375,6 +4381,12 @@ struct OmpDeviceTypeClause {
43754381
WRAPPER_CLASS_BOILERPLATE(OmpDeviceTypeClause, DeviceTypeDescription);
43764382
};
43774383

4384+
struct OmpDynGroupprivateClause {
4385+
TUPLE_CLASS_BOILERPLATE(OmpDynGroupprivateClause);
4386+
MODIFIER_BOILERPLATE(OmpAccessGroup, OmpPrescriptiveness);
4387+
std::tuple<MODIFIERS(), ScalarIntExpr> t;
4388+
};
4389+
43784390
// Ref: [5.2:158-159], [6.0:289-290]
43794391
//
43804392
// enter-clause ->

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ makePrescriptiveness(parser::OmpPrescriptiveness::Value v) {
396396
switch (v) {
397397
case parser::OmpPrescriptiveness::Value::Strict:
398398
return clause::Prescriptiveness::Strict;
399+
case parser::OmpPrescriptiveness::Value::Fallback:
400+
return clause::Prescriptiveness::Fallback;
399401
}
400402
llvm_unreachable("Unexpected prescriptiveness");
401403
}
@@ -770,6 +772,27 @@ Doacross make(const parser::OmpClause::Doacross &inp,
770772

771773
// DynamicAllocators: empty
772774

775+
DynGroupprivate make(const parser::OmpClause::DynGroupprivate &inp,
776+
semantics::SemanticsContext &semaCtx) {
777+
// imp.v -> OmpDyngroupprivateClause
778+
CLAUSET_ENUM_CONVERT( //
779+
convert, parser::OmpAccessGroup::Value, DynGroupprivate::AccessGroup,
780+
// clang-format off
781+
MS(Cgroup, Cgroup)
782+
// clang-format on
783+
);
784+
785+
auto &mods = semantics::OmpGetModifiers(inp.v);
786+
auto *m0 = semantics::OmpGetUniqueModifier<parser::OmpAccessGroup>(mods);
787+
auto *m1 = semantics::OmpGetUniqueModifier<parser::OmpPrescriptiveness>(mods);
788+
auto &size = std::get<parser::ScalarIntExpr>(inp.v.t);
789+
790+
return DynGroupprivate{
791+
{/*AccessGroup=*/maybeApplyToV(convert, m0),
792+
/*Prescriptiveness=*/maybeApplyToV(makePrescriptiveness, m1),
793+
/*Size=*/makeExpr(size, semaCtx)}};
794+
}
795+
773796
Enter make(const parser::OmpClause::Enter &inp,
774797
semantics::SemanticsContext &semaCtx) {
775798
// inp.v -> parser::OmpEnterClause

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ TYPE_PARSER(sourced(construct<OmpContextSelectorSpecification>(
469469

470470
// --- Parsers for clause modifiers -----------------------------------
471471

472+
TYPE_PARSER(construct<OmpAccessGroup>( //
473+
"CGROUP" >> pure(OmpAccessGroup::Value::Cgroup)))
474+
472475
TYPE_PARSER(construct<OmpAlignment>(scalarIntExpr))
473476

474477
TYPE_PARSER(construct<OmpAlignModifier>( //
@@ -573,7 +576,8 @@ TYPE_PARSER(construct<OmpOrderingModifier>(
573576
"SIMD" >> pure(OmpOrderingModifier::Value::Simd)))
574577

575578
TYPE_PARSER(construct<OmpPrescriptiveness>(
576-
"STRICT" >> pure(OmpPrescriptiveness::Value::Strict)))
579+
"STRICT" >> pure(OmpPrescriptiveness::Value::Strict) ||
580+
"FALLBACK" >> pure(OmpPrescriptiveness::Value::Fallback)))
577581

578582
TYPE_PARSER(construct<OmpPresentModifier>( //
579583
"PRESENT" >> pure(OmpPresentModifier::Value::Present)))
@@ -636,6 +640,12 @@ TYPE_PARSER(sourced(construct<OmpDependClause::TaskDep::Modifier>(sourced(
636640
construct<OmpDependClause::TaskDep::Modifier>(
637641
Parser<OmpTaskDependenceType>{})))))
638642

643+
TYPE_PARSER( //
644+
sourced(construct<OmpDynGroupprivateClause::Modifier>(
645+
Parser<OmpAccessGroup>{})) ||
646+
sourced(construct<OmpDynGroupprivateClause::Modifier>(
647+
Parser<OmpPrescriptiveness>{})))
648+
639649
TYPE_PARSER(
640650
sourced(construct<OmpDeviceClause::Modifier>(Parser<OmpDeviceModifier>{})))
641651

@@ -777,6 +787,10 @@ TYPE_PARSER(construct<OmpDefaultClause>(
777787
Parser<OmpDefaultClause::DataSharingAttribute>{}) ||
778788
construct<OmpDefaultClause>(indirect(Parser<OmpDirectiveSpecification>{}))))
779789

790+
TYPE_PARSER(construct<OmpDynGroupprivateClause>(
791+
maybe(nonemptyList(Parser<OmpDynGroupprivateClause::Modifier>{}) / ":"),
792+
scalarIntExpr))
793+
780794
TYPE_PARSER(construct<OmpEnterClause>(
781795
maybe(nonemptyList(Parser<OmpEnterClause::Modifier>{}) / ":"),
782796
Parser<OmpObjectList>{}))
@@ -1068,6 +1082,9 @@ TYPE_PARSER( //
10681082
construct<OmpClause>(parenthesized(Parser<OmpDoacrossClause>{})) ||
10691083
"DYNAMIC_ALLOCATORS" >>
10701084
construct<OmpClause>(construct<OmpClause::DynamicAllocators>()) ||
1085+
"DYN_GROUPPRIVATE" >>
1086+
construct<OmpClause>(construct<OmpClause::DynGroupprivate>(
1087+
parenthesized(Parser<OmpDynGroupprivateClause>{}))) ||
10711088
"ENTER" >> construct<OmpClause>(construct<OmpClause::Enter>(
10721089
parenthesized(Parser<OmpEnterClause>{}))) ||
10731090
"EXCLUSIVE" >> construct<OmpClause>(construct<OmpClause::Exclusive>(

flang/lib/Parser/unparse.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,11 @@ class UnparseVisitor {
22502250
Walk(std::get<OmpObjectList>(x.t));
22512251
Walk(": ", std::get<std::optional<std::list<Modifier>>>(x.t));
22522252
}
2253+
void Unparse(const OmpDynGroupprivateClause &x) {
2254+
using Modifier = OmpDynGroupprivateClause::Modifier;
2255+
Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
2256+
Walk(std::get<ScalarIntExpr>(x.t));
2257+
}
22532258
void Unparse(const OmpEnterClause &x) {
22542259
using Modifier = OmpEnterClause::Modifier;
22552260
Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
@@ -2941,6 +2946,7 @@ class UnparseVisitor {
29412946
WALK_NESTED_ENUM(OmpTaskDependenceType, Value) // OMP task-dependence-type
29422947
WALK_NESTED_ENUM(OmpScheduleClause, Kind) // OMP schedule-kind
29432948
WALK_NESTED_ENUM(OmpSeverityClause, Severity) // OMP severity
2949+
WALK_NESTED_ENUM(OmpAccessGroup, Value)
29442950
WALK_NESTED_ENUM(OmpDeviceModifier, Value) // OMP device modifier
29452951
WALK_NESTED_ENUM(
29462952
OmpDeviceTypeClause, DeviceTypeDescription) // OMP device_type

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,7 @@ CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
25812581
CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
25822582
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
25832583
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
2584+
CHECK_SIMPLE_CLAUSE(DynGroupprivate, OMPC_dyn_groupprivate)
25842585
CHECK_SIMPLE_CLAUSE(Exclusive, OMPC_exclusive)
25852586
CHECK_SIMPLE_CLAUSE(Final, OMPC_final)
25862587
CHECK_SIMPLE_CLAUSE(Flush, OMPC_flush)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=61 -o - %s 2>&1 | FileCheck %s
2+
3+
!CHECK: not yet implemented: DYN_GROUPPRIVATE clause is not implemented yet
4+
subroutine f00(n)
5+
implicit none
6+
integer :: n
7+
!$omp target dyn_groupprivate(n)
8+
!$omp end target
9+
end
10+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=61 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=61 %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
4+
subroutine f00(n)
5+
implicit none
6+
integer :: n
7+
!$omp target dyn_groupprivate(n)
8+
!$omp end target
9+
end
10+
11+
!UNPARSE: SUBROUTINE f00 (n)
12+
!UNPARSE: IMPLICIT NONE
13+
!UNPARSE: INTEGER n
14+
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(n)
15+
!UNPARSE: !$OMP END TARGET
16+
!UNPARSE: END SUBROUTINE
17+
18+
!PARSE-TREE: OmpBeginDirective
19+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target
20+
!PARSE-TREE: | OmpClauseList -> OmpClause -> DynGroupprivate -> OmpDynGroupprivateClause
21+
!PARSE-TREE: | | Scalar -> Integer -> Expr = 'n'
22+
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'n'
23+
!PARSE-TREE: | Flags = None
24+
25+
26+
subroutine f01(n)
27+
implicit none
28+
integer :: n
29+
!$omp target dyn_groupprivate(strict: n)
30+
!$omp end target
31+
end
32+
33+
!UNPARSE: SUBROUTINE f01 (n)
34+
!UNPARSE: IMPLICIT NONE
35+
!UNPARSE: INTEGER n
36+
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(STRICT: n)
37+
!UNPARSE: !$OMP END TARGET
38+
!UNPARSE: END SUBROUTINE
39+
40+
!PARSE-TREE: OmpBeginDirective
41+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target
42+
!PARSE-TREE: | OmpClauseList -> OmpClause -> DynGroupprivate -> OmpDynGroupprivateClause
43+
!PARSE-TREE: | | Modifier -> OmpPrescriptiveness -> Value = Strict
44+
!PARSE-TREE: | | Scalar -> Integer -> Expr = 'n'
45+
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'n'
46+
!PARSE-TREE: | Flags = None
47+
48+
49+
subroutine f02(n)
50+
implicit none
51+
integer :: n
52+
!$omp target dyn_groupprivate(fallback, cgroup: n)
53+
!$omp end target
54+
end
55+
56+
!UNPARSE: SUBROUTINE f02 (n)
57+
!UNPARSE: IMPLICIT NONE
58+
!UNPARSE: INTEGER n
59+
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(FALLBACK, CGROUP: n)
60+
!UNPARSE: !$OMP END TARGET
61+
!UNPARSE: END SUBROUTINE
62+
63+
!PARSE-TREE: OmpBeginDirective
64+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target
65+
!PARSE-TREE: | OmpClauseList -> OmpClause -> DynGroupprivate -> OmpDynGroupprivateClause
66+
!PARSE-TREE: | | Modifier -> OmpPrescriptiveness -> Value = Fallback
67+
!PARSE-TREE: | | Modifier -> OmpAccessGroup -> Value = Cgroup
68+
!PARSE-TREE: | | Scalar -> Integer -> Expr = 'n'
69+
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'n'
70+
!PARSE-TREE: | Flags = None

llvm/include/llvm/Frontend/OpenMP/ClauseT.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ ENUM(MotionExpectation, Present);
242242
// V5.2: [15.9.1] `task-dependence-type` modifier
243243
ENUM(DependenceType, Depobj, In, Inout, Inoutset, Mutexinoutset, Out, Sink,
244244
Source);
245-
ENUM(Prescriptiveness, Strict);
245+
ENUM(Prescriptiveness, Strict, Fallback);
246246

247247
template <typename I, typename E> //
248248
struct LoopIterationT {
@@ -574,6 +574,15 @@ struct DynamicAllocatorsT {
574574
using EmptyTrait = std::true_type;
575575
};
576576

577+
template <typename T, typename I, typename E> //
578+
struct DynGroupprivateT {
579+
ENUM(AccessGroup, Cgroup);
580+
using Prescriptiveness = type::Prescriptiveness;
581+
using Size = E;
582+
using TupleTrait = std::true_type;
583+
std::tuple<OPT(AccessGroup), OPT(Prescriptiveness), Size> t;
584+
};
585+
577586
// V5.2: [5.8.4] `enter` clause
578587
template <typename T, typename I, typename E> //
579588
struct EnterT {
@@ -1263,11 +1272,12 @@ template <typename T, typename I, typename E>
12631272
using TupleClausesT =
12641273
std::variant<AffinityT<T, I, E>, AlignedT<T, I, E>, AllocateT<T, I, E>,
12651274
DefaultmapT<T, I, E>, DeviceT<T, I, E>, DistScheduleT<T, I, E>,
1266-
DoacrossT<T, I, E>, FromT<T, I, E>, GrainsizeT<T, I, E>,
1267-
IfT<T, I, E>, InitT<T, I, E>, InReductionT<T, I, E>,
1268-
LastprivateT<T, I, E>, LinearT<T, I, E>, MapT<T, I, E>,
1269-
NumTasksT<T, I, E>, OrderT<T, I, E>, ReductionT<T, I, E>,
1270-
ScheduleT<T, I, E>, TaskReductionT<T, I, E>, ToT<T, I, E>>;
1275+
DoacrossT<T, I, E>, DynGroupprivateT<T, I, E>, FromT<T, I, E>,
1276+
GrainsizeT<T, I, E>, IfT<T, I, E>, InitT<T, I, E>,
1277+
InReductionT<T, I, E>, LastprivateT<T, I, E>, LinearT<T, I, E>,
1278+
MapT<T, I, E>, NumTasksT<T, I, E>, OrderT<T, I, E>,
1279+
ReductionT<T, I, E>, ScheduleT<T, I, E>,
1280+
TaskReductionT<T, I, E>, ToT<T, I, E>>;
12711281

12721282
template <typename T, typename I, typename E>
12731283
using UnionClausesT = std::variant<DependT<T, I, E>>;

0 commit comments

Comments
 (0)