Skip to content

Commit fe35620

Browse files
committed
retain flag setting, check parallel
1 parent d74cb3e commit fe35620

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,17 @@ void DataSharingProcessor::insertDeallocs() {
9494
void DataSharingProcessor::cloneSymbol(const Fortran::semantics::Symbol *sym) {
9595
// Privatization for symbols which are pre-determined (like loop index
9696
// variables) happen separately, for everything else privatize here.
97-
if (sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined))
97+
auto isOMPParallelConstruct = [](Fortran::lower::pft::Evaluation &eval) {
98+
if (const auto *ompConstruct = eval.getIf<parser::OpenMPConstruct>())
99+
if (std::holds_alternative<parser::OpenMPBlockConstruct>(ompConstruct->u))
100+
return true;
101+
return false;
102+
};
103+
104+
if (sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined) &&
105+
!isOMPParallelConstruct(eval))
98106
return;
107+
99108
bool success = converter.createHostAssociateVarClone(*sym);
100109
(void)success;
101110
assert(success && "Privatization failed due to existing binding");
@@ -344,7 +353,6 @@ void DataSharingProcessor::collectSymbols(
344353
assert(curScope && "couldn't find current scope");
345354
if (isPrivatizable(*sym) && !symbolsInNestedRegions.contains(sym) &&
346355
!privatizedSymbols.contains(sym) &&
347-
!sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined) &&
348356
(collectImplicit ||
349357
!sym->test(Fortran::semantics::Symbol::Flag::OmpImplicit)) &&
350358
clauseScopes.contains(&sym->owner()))

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
16741674
// parallel or task
16751675
if (auto *symbol{ResolveOmp(iv, Symbol::Flag::OmpPrivate, targetIt->scope)}) {
16761676
targetIt++;
1677+
symbol->set(Symbol::Flag::OmpPreDetermined);
16771678
iv.symbol = symbol; // adjust the symbol within region
16781679
for (auto it{dirContext_.rbegin()}; it != targetIt; ++it) {
16791680
AddToContextObjectWithDSA(*symbol, Symbol::Flag::OmpPrivate, *it);

flang/test/Semantics/OpenMP/do05-positivecase.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ program omp_do
99
!DEF: /omp_do/n ObjectEntity INTEGER(4)
1010
integer i,n
1111
!$omp parallel
12-
!DEF: /omp_do/OtherConstruct1/i (OmpPrivate) HostAssoc INTEGER(4)
12+
!DEF: /omp_do/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
1313
do i=1,10
1414
!$omp single
1515
print *, "hello"

flang/test/Semantics/OpenMP/symbol08.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ subroutine test_do
3737
do j=6,10
3838
!REF: /test_do/a
3939
a(1,1,1) = 0.
40-
!DEF: /test_do/OtherConstruct1/k (OmpPrivate) HostAssoc INTEGER(4)
40+
!DEF: /test_do/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
4141
do k=11,15
4242
!REF: /test_do/a
4343
!REF: /test_do/OtherConstruct1/k
@@ -170,9 +170,9 @@ subroutine test_simd
170170
!$omp parallel do simd
171171
!DEF: /test_simd/OtherConstruct1/i (OmpLinear, OmpPreDetermined) HostAssoc INTEGER(4)
172172
do i=1,5
173-
!DEF: /test_simd/OtherConstruct1/j (OmpPrivate) HostAssoc INTEGER(4)
173+
!DEF: /test_simd/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
174174
do j=6,10
175-
!DEF: /test_simd/OtherConstruct1/k (OmpPrivate) HostAssoc INTEGER(4)
175+
!DEF: /test_simd/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
176176
do k=11,15
177177
!REF: /test_simd/a
178178
!REF: /test_simd/OtherConstruct1/k
@@ -228,7 +228,7 @@ subroutine test_seq_loop
228228
print *, i, j
229229
!$omp parallel
230230
!REF: /test_seq_loop/i
231-
!DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j (OmpPrivate) HostAssoc INTEGER(4)
231+
!DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
232232
print *, i, j
233233
!$omp do
234234
!DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)

0 commit comments

Comments
 (0)