[flang][OpenMP] fix predetermined privatization inside section (#138159)

This now produces code equivalent to if there was an explicit private
clause on the SECTIONS construct.

The problem was that each SECTION construct got its own DSP, which tried
to privatize the same symbol for that SECTION. Privatization for
SECTION(S) happens on the outer SECTION construct and so the outer
construct's DSP should be shared.

Fixes #135108
This commit is contained in:
Tom Eccles
2025-05-08 10:08:49 +01:00
committed by GitHub
parent 2668167e2c
commit 2a32d738bb
3 changed files with 37 additions and 0 deletions

View File

@@ -67,6 +67,8 @@ void DataSharingProcessor::processStep1(
void DataSharingProcessor::processStep2(mlir::Operation *op, bool isLoop) {
// 'sections' lastprivate is handled by genOMP()
if (mlir::isa<mlir::omp::SectionOp>(op))
return;
if (!mlir::isa<mlir::omp::SectionsOp>(op)) {
mlir::OpBuilder::InsertionGuard guard(firOpBuilder);
copyLastPrivatize(op);

View File

@@ -2154,6 +2154,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, nestedEval,
llvm::omp::Directive::OMPD_section)
.setClauses(&sectionQueue.begin()->clauses)
.setDataSharingProcessor(&dsp)
.setEntryBlockArgs(&args),
sectionQueue, sectionQueue.begin());
}

View File

@@ -0,0 +1,34 @@
! RUN: %flang_fc1 -fopenmp -emit-hlfir -o - %s | FileCheck %s
!$omp parallel sections
!$omp section
do i = 1, 2
end do
!$omp section
do i = 1, 2
end do
!$omp end parallel sections
end
! CHECK-LABEL: func.func @_QQmain() {
! CHECK: omp.parallel {
! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "i", pinned}
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
! CHECK: omp.sections {
! CHECK: omp.section {
! CHECK: %[[VAL_11:.*]]:2 = fir.do_loop %[[VAL_12:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}} -> (index, i32) {
! CHECK: }
! CHECK: fir.store %[[VAL_11]]#1 to %[[VAL_4]]#0 : !fir.ref<i32>
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.section {
! CHECK: %[[VAL_25:.*]]:2 = fir.do_loop %[[VAL_26:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}}) -> (index, i32) {
! CHECK: }
! CHECK: fir.store %[[VAL_25]]#1 to %[[VAL_4]]#0 : !fir.ref<i32>
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: return
! CHECK: }