Skip to content

Commit b8baaa8

Browse files
authored
[flang][OpenMP] Share DataSharingProcessing instance for simd loops
For `!$omp target ...` constructs, we need to share the DSP instance to prevent privatization for the same variable from happening more than once. This was partially the case already. However, we forgot to do so for `simd` variants of the construct. This commit fixes the issue. This partially fixes: https://ontrack-internal.amd.com/browse/SWDEV-446525.
2 parents 2a2be38 + b66e21f commit b8baaa8

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -2032,12 +2032,14 @@ static void createWsloop(Fortran::lower::AbstractConverter &converter,
20322032
}
20332033
}
20342034

2035-
static void createSimdWsloop(
2036-
Fortran::lower::AbstractConverter &converter,
2037-
Fortran::semantics::SemanticsContext &semaCtx,
2038-
Fortran::lower::pft::Evaluation &eval, llvm::omp::Directive ompDirective,
2039-
const Fortran::parser::OmpClauseList &beginClauseList,
2040-
const Fortran::parser::OmpClauseList *endClauseList, mlir::Location loc) {
2035+
static void
2036+
createSimdWsloop(Fortran::lower::AbstractConverter &converter,
2037+
Fortran::semantics::SemanticsContext &semaCtx,
2038+
Fortran::lower::pft::Evaluation &eval,
2039+
llvm::omp::Directive ompDirective,
2040+
const Fortran::parser::OmpClauseList &beginClauseList,
2041+
const Fortran::parser::OmpClauseList *endClauseList,
2042+
mlir::Location loc, DataSharingProcessor &dsp) {
20412043
ClauseProcessor cp(converter, semaCtx, beginClauseList);
20422044
cp.processTODO<clause::Aligned, clause::Allocate, clause::Linear,
20432045
clause::Safelen, clause::Simdlen, clause::Order>(loc,
@@ -2050,7 +2052,6 @@ static void createSimdWsloop(
20502052
// When support for vectorization is enabled, then we need to add handling of
20512053
// if clause. Currently if clause can be skipped because we always assume
20522054
// SIMD length = 1.
2053-
DataSharingProcessor dsp(converter, semaCtx, beginClauseList, eval);
20542055
createWsloop(converter, semaCtx, eval, ompDirective, beginClauseList,
20552056
endClauseList, loc, dsp);
20562057
}
@@ -2501,7 +2502,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
25012502
if (llvm::omp::allDoSimdSet.test(ompDirective)) {
25022503
// 2.9.3.2 Workshare SIMD construct
25032504
createSimdWsloop(converter, semaCtx, eval, ompDirective, loopOpClauseList,
2504-
endClauseList, currentLocation);
2505+
endClauseList, currentLocation, dsp);
25052506

25062507
} else if (llvm::omp::allSimdSet.test(ompDirective)) {
25072508
// 2.9.3.1 SIMD construct

flang/test/Lower/OpenMP/target_private.f90

+33
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,36 @@ subroutine omp_target_private
2828
!CHECK-NEXT: }
2929

3030
end subroutine omp_target_private
31+
32+
!CHECK-LABEL: func.func @_QPomp_target_target_do_simd()
33+
subroutine omp_target_target_do_simd()
34+
implicit none
35+
36+
real(8) :: var
37+
integer(8) :: iv
38+
39+
!$omp target teams distribute parallel do simd private(iv,var)
40+
do iv=0,10
41+
var = 3.14
42+
end do
43+
!$omp end target teams distribute parallel do simd
44+
45+
!CHECK: omp.target trip_count
46+
!CHECK: fir.alloca f64 {bindc_name = "var", pinned
47+
!CHECK: omp.teams {
48+
!CHECK-NEXT: omp.distribute {
49+
!CHECK-NEXT: omp.parallel {
50+
!CHECK: fir.alloca i64
51+
!CHECK: omp.wsloop
52+
!CHECK: omp.yield
53+
!CHECK-NEXT: }
54+
!CHECK-NEXT: omp.terminator
55+
!CHECK-NEXT: }
56+
!CHECK-NEXT: omp.terminator
57+
!CHECK-NEXT: }
58+
!CHECK-NEXT: omp.terminator
59+
!CHECK-NEXT: }
60+
!CHECK-NEXT: omp.terminator
61+
!CHECK-NEXT: }
62+
63+
end subroutine omp_target_target_do_simd

0 commit comments

Comments
 (0)