Skip to content

Commit 262e994

Browse files
authored
[Flang][OpenMP] Fix default firstprivatization miscategorization of mod file symbols (llvm#157009)
In at least certain cases, notably when equivalence is used (at least for the example this showed up as a problem in) we currently miscategorize symbols as firstprivate when they may not be, as they can throw a false positive when a use symbol from a mod file is picked up. The fix to this is to chase up the appropriate symbol to access the correct details.
1 parent f1fa037 commit 262e994

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,14 +2523,15 @@ static bool IsTargetCaptureImplicitlyFirstprivatizeable(const Symbol &symbol,
25232523
return false;
25242524
};
25252525

2526-
if (checkSymbol(symbol)) {
2527-
const auto *hostAssoc{symbol.detailsIf<HostAssocDetails>()};
2528-
if (hostAssoc) {
2529-
return checkSymbol(hostAssoc->symbol());
2530-
}
2531-
return true;
2532-
}
2533-
return false;
2526+
return common::visit(
2527+
common::visitors{
2528+
[&](const UseDetails &x) -> bool { return checkSymbol(x.symbol()); },
2529+
[&](const HostAssocDetails &x) -> bool {
2530+
return checkSymbol(x.symbol());
2531+
},
2532+
[&](const auto &) -> bool { return checkSymbol(symbol); },
2533+
},
2534+
symbol.details());
25342535
}
25352536

25362537
void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
! Test that we appropriately categorize types as firstprivate even across
2+
! module boundaries.
3+
4+
!RUN: split-file %s %t
5+
6+
!RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging -fopenmp-version=50 %t/imp_scalar_map_module.f90 -o - \
7+
!RUN: | %flang_fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging -fopenmp-version=50 %t/imp_scalar_map_target.f90 -o - \
8+
!RUN: | FileCheck %t/imp_scalar_map_target.f90
9+
10+
!--- imp_scalar_map_module.f90
11+
module test_data
12+
implicit none
13+
integer :: z
14+
real :: i(10,10), j(5,5,2), k(25,2)
15+
equivalence(j(1,1,1),k(1,1))
16+
end module
17+
18+
!--- imp_scalar_map_target.f90
19+
subroutine target_imp_capture
20+
use test_data
21+
implicit none
22+
integer :: x, y
23+
24+
!$omp target map(tofrom: x)
25+
x = y + z + i(1,1) + j(1,1,1) + k(1,1)
26+
!$omp end target
27+
28+
end subroutine target_imp_capture
29+
30+
! CHECK-LABEL: func.func @_QPtarget_imp_capture()
31+
! CHECK: %[[VAL_0:.*]] = omp.map.info var_ptr({{.*}} : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32> {name = "x"}
32+
! CHECK: %[[VAL_1:.*]] = omp.map.info var_ptr({{.*}} : !fir.ref<!fir.array<10x10xf32>>, !fir.array<10x10xf32>) map_clauses(implicit, tofrom) capture(ByRef) bounds({{.*}}) -> !fir.ref<!fir.array<10x10xf32>> {name = "i"}
33+
! CHECK: %[[VAL_2:.*]] = omp.map.info var_ptr(%{{.*}} : !fir.ptr<!fir.array<5x5x2xf32>>, !fir.array<5x5x2xf32>) map_clauses(implicit, tofrom) capture(ByRef) bounds({{.*}}) -> !fir.ptr<!fir.array<5x5x2xf32>> {name = "j"}
34+
! CHECK: %[[VAL_3:.*]] = omp.map.info var_ptr(%{{.*}} : !fir.ptr<!fir.array<25x2xf32>>, !fir.array<25x2xf32>) map_clauses(implicit, tofrom) capture(ByRef) bounds({{.*}}) -> !fir.ptr<!fir.array<25x2xf32>> {name = "k"}
35+
! CHECK: %[[VAL_4:.*]] = omp.map.info var_ptr(%{{.*}} : !fir.ref<i32>, i32) map_clauses(to) capture(ByCopy) -> !fir.ref<i32>
36+
! CHECK: %[[VAL_5:.*]] = omp.map.info var_ptr(%{{.*}} : !fir.ref<i32>, i32) map_clauses(to) capture(ByCopy) -> !fir.ref<i32>
37+
! CHECK: omp.target map_entries(%[[VAL_0]] -> %[[VAL_6:.*]], %[[VAL_1]] -> %[[VAL_7:.*]], %[[VAL_2]] -> %[[VAL_8:.*]], %[[VAL_3]] -> %[[VAL_9:.*]], %[[VAL_4]] -> %[[VAL_10:.*]], %[[VAL_5]] -> %[[VAL_11:.*]] : !fir.ref<i32>, !fir.ref<!fir.array<10x10xf32>>, !fir.ptr<!fir.array<5x5x2xf32>>, !fir.ptr<!fir.array<25x2xf32>>, !fir.ref<i32>, !fir.ref<i32>) private(@_QFtarget_imp_captureEy_firstprivate_i32 %{{.*}}#0 -> %[[VAL_12:.*]] [map_idx=4], @_QMtest_dataEz_firstprivate_i32 %{{.*}}#0 -> %[[VAL_13:.*]] [map_idx=5] : !fir.ref<i32>, !fir.ref<i32>) {

0 commit comments

Comments
 (0)