Skip to content

Commit 87fb7b0

Browse files
authored
[flang] Adding NOTIFY specifier in image selector and add notify type checks (#148810)
This PR adds support for the NOTIFY specifier in the image selector as described in the 2023 standard, and add checks for the NOTIFY_TYPE type.
1 parent 338fb02 commit 87fb7b0

File tree

16 files changed

+118
-6
lines changed

16 files changed

+118
-6
lines changed

flang/examples/FeatureList/FeatureList.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ struct NodeVisitor {
348348
READ_FEATURE(TeamValue)
349349
READ_FEATURE(ImageSelector)
350350
READ_FEATURE(ImageSelectorSpec)
351+
READ_FEATURE(ImageSelectorSpec::Notify)
351352
READ_FEATURE(ImageSelectorSpec::Stat)
352353
READ_FEATURE(ImageSelectorSpec::Team_Number)
353354
READ_FEATURE(ImplicitPart)

flang/include/flang/Evaluate/traverse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Traverse {
146146
return Combine(x.base(), x.subscript());
147147
}
148148
Result operator()(const CoarrayRef &x) const {
149-
return Combine(x.base(), x.cosubscript(), x.stat(), x.team());
149+
return Combine(x.base(), x.cosubscript(), x.notify(), x.stat(), x.team());
150150
}
151151
Result operator()(const DataRef &x) const { return visitor_(x.u); }
152152
Result operator()(const Substring &x) const {

flang/include/flang/Evaluate/variable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class CoarrayRef {
260260
// it's TEAM=.
261261
std::optional<Expr<SomeType>> team() const;
262262
CoarrayRef &set_team(Expr<SomeType> &&);
263+
// When notify() is Expr<Some>, it's NOTIFY=.
264+
std::optional<Expr<SomeType>> notify() const;
265+
CoarrayRef &set_notify(Expr<SomeType> &&);
263266

264267
int Rank() const;
265268
int Corank() const { return 0; }
@@ -272,6 +275,7 @@ class CoarrayRef {
272275
private:
273276
common::CopyableIndirection<DataRef> base_;
274277
std::vector<Expr<SubscriptInteger>> cosubscript_;
278+
std::optional<common::CopyableIndirection<Expr<SomeType>>> notify_;
275279
std::optional<common::CopyableIndirection<Expr<SomeInteger>>> stat_;
276280
std::optional<common::CopyableIndirection<Expr<SomeType>>> team_;
277281
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ class ParseTreeDumper {
387387
NODE(parser, TeamValue)
388388
NODE(parser, ImageSelector)
389389
NODE(parser, ImageSelectorSpec)
390+
NODE(ImageSelectorSpec, Notify)
390391
NODE(ImageSelectorSpec, Stat)
391392
NODE(ImageSelectorSpec, Team_Number)
392393
NODE(parser, ImplicitPart)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,13 +1684,15 @@ using Cosubscript = ScalarIntExpr;
16841684
WRAPPER_CLASS(TeamValue, Scalar<common::Indirection<Expr>>);
16851685

16861686
// R926 image-selector-spec ->
1687+
// NOTIFY = notify-variable |
16871688
// STAT = stat-variable | TEAM = team-value |
16881689
// TEAM_NUMBER = scalar-int-expr
16891690
struct ImageSelectorSpec {
16901691
WRAPPER_CLASS(Stat, Scalar<Integer<common::Indirection<Variable>>>);
16911692
WRAPPER_CLASS(Team_Number, ScalarIntExpr);
1693+
WRAPPER_CLASS(Notify, Scalar<common::Indirection<Variable>>);
16921694
UNION_CLASS_BOILERPLATE(ImageSelectorSpec);
1693-
std::variant<Stat, TeamValue, Team_Number> u;
1695+
std::variant<Notify, Stat, TeamValue, Team_Number> u;
16941696
};
16951697

16961698
// R924 image-selector ->

flang/include/flang/Semantics/tools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ bool IsBindCProcedure(const Scope &);
107107
// Returns a pointer to the function's symbol when true, else null
108108
const Symbol *IsFunctionResultWithSameNameAsFunction(const Symbol &);
109109
bool IsOrContainsEventOrLockComponent(const Symbol &);
110+
bool IsOrContainsNotifyComponent(const Symbol &);
110111
bool CanBeTypeBoundProc(const Symbol &);
111112
// Does a non-PARAMETER symbol have explicit initialization with =value or
112113
// =>target in its declaration (but not in a DATA statement)? (Being
@@ -652,6 +653,8 @@ using PotentialAndPointerComponentIterator =
652653
// dereferenced.
653654
PotentialComponentIterator::const_iterator FindEventOrLockPotentialComponent(
654655
const DerivedTypeSpec &, bool ignoreCoarrays = false);
656+
PotentialComponentIterator::const_iterator FindNotifyPotentialComponent(
657+
const DerivedTypeSpec &, bool ignoreCoarrays = false);
655658
PotentialComponentIterator::const_iterator FindCoarrayPotentialComponent(
656659
const DerivedTypeSpec &);
657660
PotentialAndPointerComponentIterator::const_iterator

flang/lib/Evaluate/variable.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ std::optional<Expr<SomeType>> CoarrayRef::team() const {
8989
}
9090
}
9191

92+
std::optional<Expr<SomeType>> CoarrayRef::notify() const {
93+
if (notify_) {
94+
return notify_.value().value();
95+
} else {
96+
return std::nullopt;
97+
}
98+
}
99+
92100
CoarrayRef &CoarrayRef::set_stat(Expr<SomeInteger> &&v) {
93101
CHECK(IsVariable(v));
94102
stat_.emplace(std::move(v));
@@ -100,6 +108,11 @@ CoarrayRef &CoarrayRef::set_team(Expr<SomeType> &&v) {
100108
return *this;
101109
}
102110

111+
CoarrayRef &CoarrayRef::set_notify(Expr<SomeType> &&v) {
112+
notify_.emplace(std::move(v));
113+
return *this;
114+
}
115+
103116
const Symbol &CoarrayRef::GetFirstSymbol() const {
104117
return base().GetFirstSymbol();
105118
}

flang/lib/Lower/Support/Utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class HashEvaluateExpr {
8282
x.cosubscript())
8383
cosubs -= getHashValue(v);
8484
return getHashValue(x.base()) * 97u - cosubs + getHashValue(x.stat()) +
85-
257u + getHashValue(x.team());
85+
257u + getHashValue(x.team()) + getHashValue(x.notify());
8686
}
8787
static unsigned getHashValue(const Fortran::evaluate::NamedEntity &x) {
8888
if (x.IsSymbol())
@@ -341,7 +341,8 @@ class IsEqualEvaluateExpr {
341341
const Fortran::evaluate::CoarrayRef &y) {
342342
return isEqual(x.base(), y.base()) &&
343343
isEqual(x.cosubscript(), y.cosubscript()) &&
344-
isEqual(x.stat(), y.stat()) && isEqual(x.team(), y.team());
344+
isEqual(x.stat(), y.stat()) && isEqual(x.team(), y.team()) &&
345+
isEqual(x.notify(), y.notify());
345346
}
346347
static bool isEqual(const Fortran::evaluate::NamedEntity &x,
347348
const Fortran::evaluate::NamedEntity &y) {

flang/lib/Parser/Fortran-parsers.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,12 +1212,15 @@ TYPE_CONTEXT_PARSER("image selector"_en_US,
12121212
12131213
// R926 image-selector-spec ->
12141214
// STAT = stat-variable | TEAM = team-value |
1215-
// TEAM_NUMBER = scalar-int-expr
1215+
// TEAM_NUMBER = scalar-int-expr |
1216+
// NOTIFY = notify-variable
12161217
TYPE_PARSER(construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Stat>(
12171218
"STAT =" >> scalar(integer(indirect(variable))))) ||
12181219
construct<ImageSelectorSpec>(construct<TeamValue>("TEAM =" >> teamValue)) ||
12191220
construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Team_Number>(
1220-
"TEAM_NUMBER =" >> scalarIntExpr)))
1221+
"TEAM_NUMBER =" >> scalarIntExpr)) ||
1222+
construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Notify>(
1223+
"NOTIFY =" >> scalar(indirect(variable)))))
12211224
12221225
// R927 allocate-stmt ->
12231226
// ALLOCATE ( [type-spec ::] allocation-list [, alloc-opt-list] )

flang/lib/Parser/unparse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ class UnparseVisitor {
819819
Word("TEAM=");
820820
}
821821
}
822+
void Before(const ImageSelectorSpec::Notify &) { Word("NOTIFY="); }
822823
void Unparse(const AllocateStmt &x) { // R927
823824
Word("ALLOCATE(");
824825
Walk(std::get<std::optional<TypeSpec>>(x.t), "::");

0 commit comments

Comments
 (0)