Skip to content

Commit 4b644ff

Browse files
committed
R10: Re-implementing a few checks by removing stack
1 parent 8464253 commit 4b644ff

File tree

7 files changed

+27
-131
lines changed

7 files changed

+27
-131
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ class Symbol {
755755
OmpDeclarativeAllocateDirective, OmpExecutableAllocateDirective,
756756
OmpDeclareSimd, OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction,
757757
OmpFlushed, OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined,
758-
OmpImplicit, OmpDependObject, OmpInclusiveScan, OmpExclusiveScan);
758+
OmpImplicit, OmpDependObject, OmpInclusiveScan, OmpExclusiveScan,
759+
OmpInScanReduction);
759760
using Flags = common::EnumSet<Flag, Flag_enumSize>;
760761

761762
const Scope &owner() const { return *owner_; }

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

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,9 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
990990
const auto &objectList{
991991
std::get<parser::OmpObjectList>(reductionClause->v.t)};
992992
auto checkReductionSymbolInScan = [&](const parser::Name *name) {
993-
if (name->symbol) {
994-
if (!scanReductionInfoStack.top().findSymbolInScanConstruct(
995-
name->symbol)) {
993+
if (auto &symbol = name->symbol) {
994+
if (!symbol->test(Symbol::Flag::OmpInclusiveScan) &&
995+
!symbol->test(Symbol::Flag::OmpExclusiveScan)) {
996996
context_.Say(name->source,
997997
"List item %s must appear in EXCLUSIVE or "
998998
"INCLUSIVE clause of an "
@@ -1014,7 +1014,6 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
10141014
},
10151015
ompObj.u);
10161016
}
1017-
scanReductionInfoStack.pop();
10181017
}
10191018
}
10201019
}
@@ -2740,12 +2739,14 @@ CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
27402739
CHECK_SIMPLE_CLAUSE(Detach, OMPC_detach)
27412740
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
27422741
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
2742+
CHECK_SIMPLE_CLAUSE(Exclusive, OMPC_exclusive)
27432743
CHECK_SIMPLE_CLAUSE(Final, OMPC_final)
27442744
CHECK_SIMPLE_CLAUSE(Flush, OMPC_flush)
27452745
CHECK_SIMPLE_CLAUSE(Full, OMPC_full)
27462746
CHECK_SIMPLE_CLAUSE(Grainsize, OMPC_grainsize)
27472747
CHECK_SIMPLE_CLAUSE(Hint, OMPC_hint)
27482748
CHECK_SIMPLE_CLAUSE(Holds, OMPC_holds)
2749+
CHECK_SIMPLE_CLAUSE(Inclusive, OMPC_inclusive)
27492750
CHECK_SIMPLE_CLAUSE(InReduction, OMPC_in_reduction)
27502751
CHECK_SIMPLE_CLAUSE(Match, OMPC_match)
27512752
CHECK_SIMPLE_CLAUSE(Nontemporal, OMPC_nontemporal)
@@ -2842,26 +2843,10 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
28422843
if (const auto &maybeModifier{
28432844
std::get<std::optional<ReductionModifier>>(x.v.t)}) {
28442845
const ReductionModifier modifier{*maybeModifier};
2845-
if (modifier == ReductionModifier::Inscan) {
2846-
scanReductionInfoStack.emplace();
2847-
const auto &ompObjectList{std::get<parser::OmpObjectList>(x.v.t)};
2848-
scanReductionInfoStack.top().mapSymbolsToReductionModifiers(
2849-
ompObjectList, modifier);
2850-
}
28512846
CheckReductionModifier(modifier);
28522847
}
28532848
}
28542849

2855-
void OmpStructureChecker::Enter(const parser::OmpClause::Inclusive &x) {
2856-
CheckAllowed(llvm::omp::Clause::OMPC_inclusive);
2857-
CheckAndMarkSymbolsUsedInScan(x.v);
2858-
}
2859-
2860-
void OmpStructureChecker::Enter(const parser::OmpClause::Exclusive &x) {
2861-
CheckAllowed(llvm::omp::Clause::OMPC_exclusive);
2862-
CheckAndMarkSymbolsUsedInScan(x.v);
2863-
}
2864-
28652850
bool OmpStructureChecker::CheckReductionOperators(
28662851
const parser::OmpClause::Reduction &x) {
28672852

@@ -2903,41 +2888,6 @@ bool OmpStructureChecker::CheckReductionOperators(
29032888
return ok;
29042889
}
29052890

2906-
void OmpStructureChecker::CheckAndMarkSymbolsUsedInScan(
2907-
const parser::OmpObjectList &x) {
2908-
for (const auto &ompObj : x.v) {
2909-
auto checkAndMark = [&](const parser::Name *name) {
2910-
if (name->symbol) {
2911-
if (CurrentDirectiveIsNested()) {
2912-
ScanReductionInfo &scanReductionInfo = scanReductionInfoStack.top();
2913-
std::optional<ReductionModifier> reductionMod =
2914-
scanReductionInfo.findReductionModifier(name->symbol);
2915-
if (!reductionMod.has_value() ||
2916-
reductionMod.value() != ReductionModifier::Inscan) {
2917-
context_.Say(name->source,
2918-
"List item %s must appear in REDUCTION clause "
2919-
"with the INSCAN modifier of the parent "
2920-
"directive"_err_en_US,
2921-
name->ToString());
2922-
}
2923-
scanReductionInfo.markSymbolAsUsedInScanConstruct(name->symbol);
2924-
}
2925-
}
2926-
};
2927-
common::visit(
2928-
common::visitors{
2929-
[&](const parser::Designator &designator) {
2930-
if (const auto *name{
2931-
semantics::getDesignatorNameIfDataRef(designator)}) {
2932-
checkAndMark(name);
2933-
}
2934-
},
2935-
[&](const auto &name) { checkAndMark(&name); },
2936-
},
2937-
ompObj.u);
2938-
}
2939-
}
2940-
29412891
bool OmpStructureChecker::CheckIntrinsicOperator(
29422892
const parser::DefinedOperator::IntrinsicOperator &op) {
29432893

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "flang/Semantics/openmp-directive-sets.h"
2121
#include "flang/Semantics/semantics.h"
2222
#include "llvm/Frontend/OpenMP/OMPConstants.h"
23-
#include <optional>
24-
#include <stack>
2523

2624
using OmpClauseSet =
2725
Fortran::common::EnumSet<llvm::omp::Clause, llvm::omp::Clause_enumSize>;
@@ -73,42 +71,6 @@ class OmpStructureChecker
7371
}
7472
using llvmOmpClause = const llvm::omp::Clause;
7573
using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
76-
using Symbol = Fortran::semantics::Symbol;
77-
class ScanReductionInfo {
78-
std::set<Symbol *> usedInScan;
79-
std::map<Symbol *, ReductionModifier> reductionMod;
80-
81-
public:
82-
void mapSymbolsToReductionModifiers(
83-
const parser::OmpObjectList &x, const ReductionModifier &modifier) {
84-
for (const auto &ompObject : x.v) {
85-
if (const auto *name{parser::Unwrap<parser::Name>(ompObject)}) {
86-
if (const auto &symbol{name->symbol}) {
87-
reductionMod[symbol] = modifier;
88-
}
89-
}
90-
}
91-
}
92-
93-
void markSymbolAsUsedInScanConstruct(Symbol *sym) {
94-
usedInScan.insert(sym);
95-
}
96-
97-
bool findSymbolInScanConstruct(Symbol *sym) {
98-
if (usedInScan.find(sym) != usedInScan.end()) {
99-
return true;
100-
}
101-
return false;
102-
}
103-
104-
std::optional<ReductionModifier> findReductionModifier(Symbol *sym) {
105-
if (reductionMod.find(sym) != reductionMod.end()) {
106-
return reductionMod[sym];
107-
}
108-
return std::nullopt;
109-
}
110-
};
111-
std::stack<class ScanReductionInfo> scanReductionInfoStack;
11274

11375
void Enter(const parser::OpenMPConstruct &);
11476
void Leave(const parser::OpenMPConstruct &);
@@ -287,7 +249,6 @@ class OmpStructureChecker
287249
const parser::OmpObjectList &ompObjectList);
288250
void CheckPredefinedAllocatorRestriction(
289251
const parser::CharBlock &source, const parser::Name &name);
290-
void CheckAndMarkSymbolsUsedInScan(const parser::OmpObjectList &x);
291252
bool isPredefinedAllocator{false};
292253

293254
void CheckAllowedRequiresClause(llvmOmpClause clause);

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
546546
}
547547
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
548548
ResolveOmpObjectList(objList, Symbol::Flag::OmpReduction);
549+
using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
550+
const auto &maybeModifier{
551+
std::get<std::optional<ReductionModifier>>(x.v.t)};
552+
if (maybeModifier && *maybeModifier == ReductionModifier::Inscan) {
553+
ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
554+
}
549555
return false;
550556
}
551557

@@ -702,7 +708,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
702708

703709
Symbol::Flags ompFlagsRequireMark{Symbol::Flag::OmpThreadprivate,
704710
Symbol::Flag::OmpDeclareTarget, Symbol::Flag::OmpExclusiveScan,
705-
Symbol::Flag::OmpInclusiveScan};
711+
Symbol::Flag::OmpInclusiveScan, Symbol::Flag::OmpInScanReduction};
706712

707713
Symbol::Flags dataCopyingAttributeFlags{
708714
Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpCopyPrivate};
@@ -2439,6 +2445,16 @@ void OmpAttributeVisitor::ResolveOmpObject(
24392445
name->ToString());
24402446
}
24412447
}
2448+
if (ompFlag == Symbol::Flag::OmpInclusiveScan ||
2449+
ompFlag == Symbol::Flag::OmpExclusiveScan) {
2450+
if (!symbol->test(Symbol::Flag::OmpInScanReduction)) {
2451+
context_.Say(name->source,
2452+
"List item %s must appear in REDUCTION clause "
2453+
"with the INSCAN modifier of the parent "
2454+
"directive"_err_en_US,
2455+
name->ToString());
2456+
}
2457+
}
24422458
if (GetContext().directive ==
24432459
llvm::omp::Directive::OMPD_target_data) {
24442460
checkExclusivelists(symbol, Symbol::Flag::OmpUseDevicePtr,

flang/test/Semantics/OpenMP/scan.f90

Lines changed: 0 additions & 33 deletions
This file was deleted.

flang/test/Semantics/OpenMP/scan1.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ subroutine test_scan()
44
integer x, y, k, z
55

66
!ERROR: Orphaned SCAN directives are prohibited; perhaps you forgot to enclose the directive in to a WORKSHARING LOOP, a WORKSHARING LOOP SIMD or a SIMD directive.
7+
!ERROR: List item x must appear in REDUCTION clause with the INSCAN modifier of the parent directive
78
!$omp scan inclusive(x)
89
!$omp parallel do simd
910
do k = 1, n

flang/test/Semantics/OpenMP/scan2.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ program omp_reduction
1212

1313
! CHECK: OtherConstruct scope
1414
! CHECK: i (OmpPrivate, OmpPreDetermined): HostAssoc
15-
! CHECK: k (OmpReduction, OmpInclusiveScan): HostAssoc
15+
! CHECK: k (OmpReduction, OmpInclusiveScan, OmpInScanReduction): HostAssoc
1616
!$omp parallel do reduction(inscan, +:k)
1717
do i=1,10
1818
!$omp scan inclusive(k)
1919
end do
2020
!$omp end parallel do
21-
! CHECK: m (OmpReduction, OmpExclusiveScan): HostAssoc
21+
! CHECK: m (OmpReduction, OmpExclusiveScan, OmpInScanReduction): HostAssoc
2222
!$omp parallel do reduction(inscan, +:m)
2323
do i=1,10
2424
!$omp scan exclusive(m)

0 commit comments

Comments
 (0)