From b66e21f8164cc03e4ac6462aa35b372a9740ab10 Mon Sep 17 00:00:00 2001 From: ergawy Date: Wed, 24 Apr 2024 03:35:46 -0500 Subject: [PATCH] [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. --- flang/lib/Lower/OpenMP/OpenMP.cpp | 17 +++++------ flang/test/Lower/OpenMP/target_private.f90 | 33 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index d107c48a6422f7..0b8b6edd501b36 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -2032,12 +2032,14 @@ static void createWsloop(Fortran::lower::AbstractConverter &converter, } } -static void createSimdWsloop( - Fortran::lower::AbstractConverter &converter, - Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::pft::Evaluation &eval, llvm::omp::Directive ompDirective, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList, mlir::Location loc) { +static void +createSimdWsloop(Fortran::lower::AbstractConverter &converter, + Fortran::semantics::SemanticsContext &semaCtx, + Fortran::lower::pft::Evaluation &eval, + llvm::omp::Directive ompDirective, + const Fortran::parser::OmpClauseList &beginClauseList, + const Fortran::parser::OmpClauseList *endClauseList, + mlir::Location loc, DataSharingProcessor &dsp) { ClauseProcessor cp(converter, semaCtx, beginClauseList); cp.processTODO(loc, @@ -2050,7 +2052,6 @@ static void createSimdWsloop( // When support for vectorization is enabled, then we need to add handling of // if clause. Currently if clause can be skipped because we always assume // SIMD length = 1. - DataSharingProcessor dsp(converter, semaCtx, beginClauseList, eval); createWsloop(converter, semaCtx, eval, ompDirective, beginClauseList, endClauseList, loc, dsp); } @@ -2501,7 +2502,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, if (llvm::omp::allDoSimdSet.test(ompDirective)) { // 2.9.3.2 Workshare SIMD construct createSimdWsloop(converter, semaCtx, eval, ompDirective, loopOpClauseList, - endClauseList, currentLocation); + endClauseList, currentLocation, dsp); } else if (llvm::omp::allSimdSet.test(ompDirective)) { // 2.9.3.1 SIMD construct diff --git a/flang/test/Lower/OpenMP/target_private.f90 b/flang/test/Lower/OpenMP/target_private.f90 index 98e3b79d035dfd..5d73d810c5e2d9 100644 --- a/flang/test/Lower/OpenMP/target_private.f90 +++ b/flang/test/Lower/OpenMP/target_private.f90 @@ -28,3 +28,36 @@ subroutine omp_target_private !CHECK-NEXT: } end subroutine omp_target_private + +!CHECK-LABEL: func.func @_QPomp_target_target_do_simd() +subroutine omp_target_target_do_simd() + implicit none + + real(8) :: var + integer(8) :: iv + +!$omp target teams distribute parallel do simd private(iv,var) + do iv=0,10 + var = 3.14 + end do +!$omp end target teams distribute parallel do simd + +!CHECK: omp.target trip_count +!CHECK: fir.alloca f64 {bindc_name = "var", pinned +!CHECK: omp.teams { +!CHECK-NEXT: omp.distribute { +!CHECK-NEXT: omp.parallel { +!CHECK: fir.alloca i64 +!CHECK: omp.wsloop +!CHECK: omp.yield +!CHECK-NEXT: } +!CHECK-NEXT: omp.terminator +!CHECK-NEXT: } +!CHECK-NEXT: omp.terminator +!CHECK-NEXT: } +!CHECK-NEXT: omp.terminator +!CHECK-NEXT: } +!CHECK-NEXT: omp.terminator +!CHECK-NEXT: } + +end subroutine omp_target_target_do_simd