Skip to content

Commit 2a32d73

Browse files
authored
[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
1 parent 2668167 commit 2a32d73

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void DataSharingProcessor::processStep1(
6767

6868
void DataSharingProcessor::processStep2(mlir::Operation *op, bool isLoop) {
6969
// 'sections' lastprivate is handled by genOMP()
70+
if (mlir::isa<mlir::omp::SectionOp>(op))
71+
return;
7072
if (!mlir::isa<mlir::omp::SectionsOp>(op)) {
7173
mlir::OpBuilder::InsertionGuard guard(firOpBuilder);
7274
copyLastPrivatize(op);

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
21542154
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, nestedEval,
21552155
llvm::omp::Directive::OMPD_section)
21562156
.setClauses(&sectionQueue.begin()->clauses)
2157+
.setDataSharingProcessor(&dsp)
21572158
.setEntryBlockArgs(&args),
21582159
sectionQueue, sectionQueue.begin());
21592160
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
! RUN: %flang_fc1 -fopenmp -emit-hlfir -o - %s | FileCheck %s
2+
3+
!$omp parallel sections
4+
!$omp section
5+
do i = 1, 2
6+
end do
7+
!$omp section
8+
do i = 1, 2
9+
end do
10+
!$omp end parallel sections
11+
end
12+
! CHECK-LABEL: func.func @_QQmain() {
13+
! CHECK: omp.parallel {
14+
! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "i", pinned}
15+
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
16+
! CHECK: omp.sections {
17+
! CHECK: omp.section {
18+
! CHECK: %[[VAL_11:.*]]:2 = fir.do_loop %[[VAL_12:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}} -> (index, i32) {
19+
! CHECK: }
20+
! CHECK: fir.store %[[VAL_11]]#1 to %[[VAL_4]]#0 : !fir.ref<i32>
21+
! CHECK: omp.terminator
22+
! CHECK: }
23+
! CHECK: omp.section {
24+
! CHECK: %[[VAL_25:.*]]:2 = fir.do_loop %[[VAL_26:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}}) -> (index, i32) {
25+
! CHECK: }
26+
! CHECK: fir.store %[[VAL_25]]#1 to %[[VAL_4]]#0 : !fir.ref<i32>
27+
! CHECK: omp.terminator
28+
! CHECK: }
29+
! CHECK: omp.terminator
30+
! CHECK: }
31+
! CHECK: omp.terminator
32+
! CHECK: }
33+
! CHECK: return
34+
! CHECK: }

0 commit comments

Comments
 (0)