Skip to content

Commit e267605

Browse files
authored
[flang][OpenMP] Move check for threadprivate iteration variable (llvm#191208)
This moves the test of whether the iteration variable of an affected DO loop is marked as threadprivate. This makes the `ordCollapseLevel` member unnecessary. Issue: llvm#191249
1 parent 9791929 commit e267605

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
610610
void Post(const parser::OpenMPSimpleStandaloneConstruct &) { PopContext(); }
611611

612612
bool Pre(const parser::OpenMPLoopConstruct &);
613-
void Post(const parser::OpenMPLoopConstruct &) {
614-
ordCollapseLevel++;
615-
PopContext();
616-
}
613+
void Post(const parser::OpenMPLoopConstruct &) { PopContext(); }
617614
void Post(const parser::OmpBeginLoopDirective &) {
618615
GetContext().withinConstruct = true;
619616
}
@@ -1173,8 +1170,6 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
11731170
targetLabels_.clear();
11741171
};
11751172

1176-
std::int64_t ordCollapseLevel{0};
1177-
11781173
void AddOmpRequiresToScope(Scope &,
11791174
const WithOmpDeclarative::RequiresClauses *,
11801175
const common::OmpMemoryOrderType *);
@@ -2097,7 +2092,6 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
20972092
}
20982093

20992094
PrivatizeAssociatedLoopIndexAndCheckLoopLevel(x);
2100-
ordCollapseLevel = GetNumAffectedLoopsFromLoopConstruct(x) + 1;
21012095
return true;
21022096
}
21032097

@@ -2172,23 +2166,12 @@ bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
21722166
if (iv && iv->symbol)
21732167
ivs.push_back(iv);
21742168
}
2175-
ordCollapseLevel--;
21762169
for (auto iv : ivs) {
21772170
if (!iv->symbol->test(Symbol::Flag::OmpPreDetermined)) {
21782171
ResolveSeqLoopIndexInParallelOrTaskConstruct(*iv);
21792172
} else {
21802173
// TODO: conflict checks with explicitly determined DSA
21812174
}
2182-
if (ordCollapseLevel) {
2183-
if (const auto *details{iv->symbol->detailsIf<HostAssocDetails>()}) {
2184-
const Symbol *tpSymbol = &details->symbol();
2185-
if (tpSymbol->test(Symbol::Flag::OmpThreadprivate)) {
2186-
context_.Say(iv->source,
2187-
"Loop iteration variable %s is not allowed in THREADPRIVATE."_err_en_US,
2188-
iv->ToString());
2189-
}
2190-
}
2191-
}
21922175
}
21932176
}
21942177
return true;
@@ -2316,7 +2299,7 @@ void OmpAttributeVisitor::CollectNumAffectedLoopsFromClauses(
23162299
// construct with multiple associated do-loops are lastprivate.
23172300
void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
23182301
const parser::OpenMPLoopConstruct &x) {
2319-
std::int64_t level{GetContext().associatedLoopLevel};
2302+
int64_t level{GetContext().associatedLoopLevel};
23202303
if (level <= 0) {
23212304
return;
23222305
}
@@ -2341,6 +2324,15 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
23412324
if (const parser::Name *iv{GetLoopIndex(*loop)}) {
23422325
if (!iv->symbol || !IsLocalInsideScope(*iv->symbol, currScope())) {
23432326
if (auto *symbol{ResolveOmp(*iv, ivDSA, currScope())}) {
2327+
if (const auto *details{
2328+
iv->symbol->detailsIf<HostAssocDetails>()}) {
2329+
const Symbol *tpSymbol = &details->symbol();
2330+
if (tpSymbol->test(Symbol::Flag::OmpThreadprivate)) {
2331+
context_.Say(iv->source,
2332+
"Loop iteration variable %s is not allowed in THREADPRIVATE."_err_en_US,
2333+
iv->ToString());
2334+
}
2335+
}
23442336
SetSymbolDSA(*symbol, {Symbol::Flag::OmpPreDetermined, ivDSA});
23452337
iv->symbol = symbol; // adjust the symbol within region
23462338
AddToContextObjectWithDSA(*symbol, ivDSA);

0 commit comments

Comments
 (0)