Skip to content

Commit 46b0fa2

Browse files
authored
Merge branch 'main' into issue_166342
2 parents 5f7f103 + f1b5504 commit 46b0fa2

File tree

13 files changed

+315
-203
lines changed

13 files changed

+315
-203
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ class ParseTreeDumper {
588588
NODE(parser, OmpExpectation)
589589
NODE_ENUM(OmpExpectation, Value)
590590
NODE(parser, OmpFailClause)
591+
NODE(parser, OmpFallbackModifier)
592+
NODE_ENUM(OmpFallbackModifier, Value)
591593
NODE(parser, OmpFromClause)
592594
NODE(OmpFromClause, Modifier)
593595
NODE(parser, OmpGrainsizeClause)

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,6 +4000,17 @@ struct OmpExpectation {
40004000
WRAPPER_CLASS_BOILERPLATE(OmpExpectation, Value);
40014001
};
40024002

4003+
// Ref: [6.1:tbd]
4004+
//
4005+
// fallback-modifier ->
4006+
// FALLBACK(fallback-mode) // since 6.1
4007+
// fallback-mode ->
4008+
// ABORT | DEFAULT_MEM | NULL // since 6.1
4009+
struct OmpFallbackModifier {
4010+
ENUM_CLASS(Value, Abort, Default_Mem, Null);
4011+
WRAPPER_CLASS_BOILERPLATE(OmpFallbackModifier, Value);
4012+
};
4013+
40034014
// REF: [5.1:217-220], [5.2:293-294]
40044015
//
40054016
// OmpInteropRuntimeIdentifier -> // since 5.2
@@ -4129,9 +4140,8 @@ struct OmpOrderModifier {
41294140
//
41304141
// prescriptiveness ->
41314142
// STRICT // since 5.1
4132-
// FALLBACK // since 6.1
41334143
struct OmpPrescriptiveness {
4134-
ENUM_CLASS(Value, Strict, Fallback)
4144+
ENUM_CLASS(Value, Strict)
41354145
WRAPPER_CLASS_BOILERPLATE(OmpPrescriptiveness, Value);
41364146
};
41374147

@@ -4512,7 +4522,7 @@ struct OmpDynamicAllocatorsClause {
45124522

45134523
struct OmpDynGroupprivateClause {
45144524
TUPLE_CLASS_BOILERPLATE(OmpDynGroupprivateClause);
4515-
MODIFIER_BOILERPLATE(OmpAccessGroup, OmpPrescriptiveness);
4525+
MODIFIER_BOILERPLATE(OmpAccessGroup, OmpFallbackModifier);
45164526
std::tuple<MODIFIERS(), ScalarIntExpr> t;
45174527
};
45184528

flang/include/flang/Semantics/openmp-modifiers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ template <typename SpecificTy> const OmpModifierDescriptor &OmpGetDescriptor();
6767
#define DECLARE_DESCRIPTOR(name) \
6868
template <> const OmpModifierDescriptor &OmpGetDescriptor<name>()
6969

70+
DECLARE_DESCRIPTOR(parser::OmpAccessGroup);
7071
DECLARE_DESCRIPTOR(parser::OmpAlignment);
7172
DECLARE_DESCRIPTOR(parser::OmpAlignModifier);
7273
DECLARE_DESCRIPTOR(parser::OmpAllocatorComplexModifier);
@@ -82,6 +83,7 @@ DECLARE_DESCRIPTOR(parser::OmpDependenceType);
8283
DECLARE_DESCRIPTOR(parser::OmpDeviceModifier);
8384
DECLARE_DESCRIPTOR(parser::OmpDirectiveNameModifier);
8485
DECLARE_DESCRIPTOR(parser::OmpExpectation);
86+
DECLARE_DESCRIPTOR(parser::OmpFallbackModifier);
8587
DECLARE_DESCRIPTOR(parser::OmpInteropPreference);
8688
DECLARE_DESCRIPTOR(parser::OmpInteropType);
8789
DECLARE_DESCRIPTOR(parser::OmpIterator);

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ 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;
401399
}
402400
llvm_unreachable("Unexpected prescriptiveness");
403401
}
@@ -799,21 +797,31 @@ DynGroupprivate make(const parser::OmpClause::DynGroupprivate &inp,
799797
semantics::SemanticsContext &semaCtx) {
800798
// imp.v -> OmpDyngroupprivateClause
801799
CLAUSET_ENUM_CONVERT( //
802-
convert, parser::OmpAccessGroup::Value, DynGroupprivate::AccessGroup,
800+
makeAccessGroup, parser::OmpAccessGroup::Value,
801+
DynGroupprivate::AccessGroup,
803802
// clang-format off
804803
MS(Cgroup, Cgroup)
805804
// clang-format on
806805
);
807806

807+
CLAUSET_ENUM_CONVERT( //
808+
makeFallback, parser::OmpFallbackModifier::Value,
809+
DynGroupprivate::Fallback,
810+
// clang-format off
811+
MS(Abort, Abort)
812+
MS(Default_Mem, Default_Mem)
813+
MS(Null, Null)
814+
// clang-format on
815+
);
816+
808817
auto &mods = semantics::OmpGetModifiers(inp.v);
809818
auto *m0 = semantics::OmpGetUniqueModifier<parser::OmpAccessGroup>(mods);
810-
auto *m1 = semantics::OmpGetUniqueModifier<parser::OmpPrescriptiveness>(mods);
819+
auto *m1 = semantics::OmpGetUniqueModifier<parser::OmpFallbackModifier>(mods);
811820
auto &size = std::get<parser::ScalarIntExpr>(inp.v.t);
812821

813-
return DynGroupprivate{
814-
{/*AccessGroup=*/maybeApplyToV(convert, m0),
815-
/*Prescriptiveness=*/maybeApplyToV(makePrescriptiveness, m1),
816-
/*Size=*/makeExpr(size, semaCtx)}};
822+
return DynGroupprivate{{/*AccessGroup=*/maybeApplyToV(makeAccessGroup, m0),
823+
/*Fallback=*/maybeApplyToV(makeFallback, m1),
824+
/*Size=*/makeExpr(size, semaCtx)}};
817825
}
818826

819827
Enter make(const parser::OmpClause::Enter &inp,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,12 @@ TYPE_PARSER(construct<OmpDirectiveNameModifier>(OmpDirectiveNameParser{}))
791791
TYPE_PARSER(construct<OmpExpectation>( //
792792
"PRESENT" >> pure(OmpExpectation::Value::Present)))
793793

794+
TYPE_PARSER(construct<OmpFallbackModifier>("FALLBACK"_tok >>
795+
parenthesized( //
796+
"ABORT" >> pure(OmpFallbackModifier::Value::Abort) ||
797+
"DEFAULT_MEM" >> pure(OmpFallbackModifier::Value::Default_Mem) ||
798+
"NULL" >> pure(OmpFallbackModifier::Value::Null))))
799+
794800
TYPE_PARSER(construct<OmpInteropRuntimeIdentifier>(
795801
construct<OmpInteropRuntimeIdentifier>(charLiteralConstant) ||
796802
construct<OmpInteropRuntimeIdentifier>(scalarIntConstantExpr)))
@@ -857,8 +863,7 @@ TYPE_PARSER(construct<OmpOrderingModifier>(
857863
"SIMD" >> pure(OmpOrderingModifier::Value::Simd)))
858864

859865
TYPE_PARSER(construct<OmpPrescriptiveness>(
860-
"STRICT" >> pure(OmpPrescriptiveness::Value::Strict) ||
861-
"FALLBACK" >> pure(OmpPrescriptiveness::Value::Fallback)))
866+
"STRICT" >> pure(OmpPrescriptiveness::Value::Strict)))
862867

863868
TYPE_PARSER(construct<OmpPresentModifier>( //
864869
"PRESENT" >> pure(OmpPresentModifier::Value::Present)))
@@ -925,7 +930,7 @@ TYPE_PARSER( //
925930
sourced(construct<OmpDynGroupprivateClause::Modifier>(
926931
Parser<OmpAccessGroup>{})) ||
927932
sourced(construct<OmpDynGroupprivateClause::Modifier>(
928-
Parser<OmpPrescriptiveness>{})))
933+
Parser<OmpFallbackModifier>{})))
929934

930935
TYPE_PARSER(
931936
sourced(construct<OmpDeviceClause::Modifier>(Parser<OmpDeviceModifier>{})))

flang/lib/Parser/unparse.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,11 @@ class UnparseVisitor {
22862286
Walk(std::get<OmpObjectList>(x.t));
22872287
Walk(": ", std::get<std::optional<std::list<Modifier>>>(x.t));
22882288
}
2289+
void Unparse(const OmpFallbackModifier &x) {
2290+
Word("FALLBACK(");
2291+
Walk(x.v);
2292+
Put(")");
2293+
}
22892294
void Unparse(const OmpDynGroupprivateClause &x) {
22902295
using Modifier = OmpDynGroupprivateClause::Modifier;
22912296
Walk(std::get<std::optional<std::list<Modifier>>>(x.t), ": ");
@@ -2795,6 +2800,7 @@ class UnparseVisitor {
27952800
OmpDeviceTypeClause, DeviceTypeDescription) // OMP device_type
27962801
WALK_NESTED_ENUM(OmpReductionModifier, Value) // OMP reduction-modifier
27972802
WALK_NESTED_ENUM(OmpExpectation, Value) // OMP motion-expectation
2803+
WALK_NESTED_ENUM(OmpFallbackModifier, Value) // OMP fallback-modifier
27982804
WALK_NESTED_ENUM(OmpInteropType, Value) // OMP InteropType
27992805
WALK_NESTED_ENUM(OmpOrderClause, Ordering) // OMP ordering
28002806
WALK_NESTED_ENUM(OmpOrderModifier, Value) // OMP order-modifier

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,13 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Hint &x) {
682682
}
683683
}
684684

685+
void OmpStructureChecker::Enter(const parser::OmpClause::DynGroupprivate &x) {
686+
CheckAllowedClause(llvm::omp::Clause::OMPC_dyn_groupprivate);
687+
parser::CharBlock source{GetContext().clauseSource};
688+
689+
OmpVerifyModifiers(x.v, llvm::omp::OMPC_dyn_groupprivate, source, context_);
690+
}
691+
685692
void OmpStructureChecker::Enter(const parser::OmpDirectiveSpecification &x) {
686693
// OmpDirectiveSpecification exists on its own only in METADIRECTIVE.
687694
// In other cases it's a part of other constructs that handle directive
@@ -3316,6 +3323,32 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
33163323
}
33173324
}
33183325

3326+
// Default access-group for DYN_GROUPPRIVATE is "cgroup". On a given
3327+
// construct there can be at most one DYN_GROUPPRIVATE with a given
3328+
// access-group.
3329+
const parser::OmpClause
3330+
*accGrpClause[parser::OmpAccessGroup::Value_enumSize] = {nullptr};
3331+
for (auto [_, clause] :
3332+
FindClauses(llvm::omp::Clause::OMPC_dyn_groupprivate)) {
3333+
auto &wrapper{std::get<parser::OmpClause::DynGroupprivate>(clause->u)};
3334+
auto &modifiers{OmpGetModifiers(wrapper.v)};
3335+
auto accGrp{parser::OmpAccessGroup::Value::Cgroup};
3336+
if (auto *ag{OmpGetUniqueModifier<parser::OmpAccessGroup>(modifiers)}) {
3337+
accGrp = ag->v;
3338+
}
3339+
auto &firstClause{accGrpClause[llvm::to_underlying(accGrp)]};
3340+
if (firstClause) {
3341+
context_
3342+
.Say(clause->source,
3343+
"The access-group modifier can only occur on a single clause in a construct"_err_en_US)
3344+
.Attach(firstClause->source,
3345+
"Previous clause with access-group modifier"_en_US);
3346+
break;
3347+
} else {
3348+
firstClause = clause;
3349+
}
3350+
}
3351+
33193352
CheckRequireAtLeastOneOf();
33203353
}
33213354

@@ -5475,7 +5508,6 @@ CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
54755508
CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
54765509
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
54775510
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
5478-
CHECK_SIMPLE_CLAUSE(DynGroupprivate, OMPC_dyn_groupprivate)
54795511
CHECK_SIMPLE_CLAUSE(Exclusive, OMPC_exclusive)
54805512
CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
54815513
CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)

flang/lib/Semantics/openmp-modifiers.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ unsigned OmpModifierDescriptor::since(llvm::omp::Clause id) const {
7474
// Note: The intent for these functions is to have them be automatically-
7575
// generated in the future.
7676

77+
template <>
78+
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAccessGroup>() {
79+
static const OmpModifierDescriptor desc{
80+
/*name=*/"access-group",
81+
/*props=*/
82+
{
83+
{61, {OmpProperty::Unique}},
84+
},
85+
/*clauses=*/
86+
{
87+
{61, {Clause::OMPC_dyn_groupprivate}},
88+
},
89+
};
90+
return desc;
91+
}
92+
7793
template <>
7894
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAlignment>() {
7995
static const OmpModifierDescriptor desc{
@@ -321,6 +337,22 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpExpectation>() {
321337
return desc;
322338
}
323339

340+
template <>
341+
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpFallbackModifier>() {
342+
static const OmpModifierDescriptor desc{
343+
/*name=*/"fallback-modifier",
344+
/*props=*/
345+
{
346+
{61, {OmpProperty::Unique}},
347+
},
348+
/*clauses=*/
349+
{
350+
{61, {Clause::OMPC_dyn_groupprivate}},
351+
},
352+
};
353+
return desc;
354+
}
355+
324356
template <>
325357
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpInteropPreference>() {
326358
static const OmpModifierDescriptor desc{

flang/test/Parser/OpenMP/dyn-groupprivate-clause.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ subroutine f00(n)
2626
subroutine f01(n)
2727
implicit none
2828
integer :: n
29-
!$omp target dyn_groupprivate(strict: n)
29+
!$omp target dyn_groupprivate(fallback(abort): n)
3030
!$omp end target
3131
end
3232

3333
!UNPARSE: SUBROUTINE f01 (n)
3434
!UNPARSE: IMPLICIT NONE
3535
!UNPARSE: INTEGER n
36-
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(STRICT: n)
36+
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(FALLBACK(ABORT): n)
3737
!UNPARSE: !$OMP END TARGET
3838
!UNPARSE: END SUBROUTINE
3939

4040
!PARSE-TREE: OmpBeginDirective
4141
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target
4242
!PARSE-TREE: | OmpClauseList -> OmpClause -> DynGroupprivate -> OmpDynGroupprivateClause
43-
!PARSE-TREE: | | Modifier -> OmpPrescriptiveness -> Value = Strict
43+
!PARSE-TREE: | | Modifier -> OmpFallbackModifier -> Value = Abort
4444
!PARSE-TREE: | | Scalar -> Integer -> Expr = 'n'
4545
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'n'
4646
!PARSE-TREE: | Flags = None
@@ -49,21 +49,21 @@ subroutine f01(n)
4949
subroutine f02(n)
5050
implicit none
5151
integer :: n
52-
!$omp target dyn_groupprivate(fallback, cgroup: n)
52+
!$omp target dyn_groupprivate(fallback(default_mem), cgroup: n)
5353
!$omp end target
5454
end
5555

5656
!UNPARSE: SUBROUTINE f02 (n)
5757
!UNPARSE: IMPLICIT NONE
5858
!UNPARSE: INTEGER n
59-
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(FALLBACK, CGROUP: n)
59+
!UNPARSE: !$OMP TARGET DYN_GROUPPRIVATE(FALLBACK(DEFAULT_MEM), CGROUP: n)
6060
!UNPARSE: !$OMP END TARGET
6161
!UNPARSE: END SUBROUTINE
6262

6363
!PARSE-TREE: OmpBeginDirective
6464
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = target
6565
!PARSE-TREE: | OmpClauseList -> OmpClause -> DynGroupprivate -> OmpDynGroupprivateClause
66-
!PARSE-TREE: | | Modifier -> OmpPrescriptiveness -> Value = Fallback
66+
!PARSE-TREE: | | Modifier -> OmpFallbackModifier -> Value = Default_Mem
6767
!PARSE-TREE: | | Modifier -> OmpAccessGroup -> Value = Cgroup
6868
!PARSE-TREE: | | Scalar -> Integer -> Expr = 'n'
6969
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'n'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=61
2+
3+
subroutine f00(x)
4+
integer :: x
5+
!ERROR: The access-group modifier can only occur on a single clause in a construct
6+
!$omp target dyn_groupprivate(cgroup: x), dyn_groupprivate(10)
7+
!$omp end target
8+
end

0 commit comments

Comments
 (0)