Skip to content

Commit 91aa3bb

Browse files
committed
[flang][OpenMP] fix predetermined privatization inside section
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 9693bf4 commit 91aa3bb

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,11 @@ struct OpWithBodyGenInfo {
10571057
return *this;
10581058
}
10591059

1060+
OpWithBodyGenInfo &setSkipDspStep2(bool value) {
1061+
skipDspStep2 = value;
1062+
return *this;
1063+
}
1064+
10601065
OpWithBodyGenInfo &setEntryBlockArgs(const EntryBlockArgs *value) {
10611066
blockArgs = value;
10621067
return *this;
@@ -1088,6 +1093,8 @@ struct OpWithBodyGenInfo {
10881093
const List<Clause> *clauses = nullptr;
10891094
/// [in] if provided, processes the construct's data-sharing attributes.
10901095
DataSharingProcessor *dsp = nullptr;
1096+
/// [in] if true, skip DataSharingProcessor::processStep2
1097+
bool skipDspStep2 = false;
10911098
/// [in] if provided, it is used to create the op's region entry block. It is
10921099
/// overriden when a \see genRegionEntryCB is provided. This is only valid for
10931100
/// operations implementing the \see mlir::omp::BlockArgOpenMPOpInterface.
@@ -1240,7 +1247,7 @@ static void createBodyOfOp(mlir::Operation &op, const OpWithBodyGenInfo &info,
12401247
// loop (this may not make sense in production code, but a user could
12411248
// write that and we should handle it).
12421249
firOpBuilder.setInsertionPoint(term);
1243-
if (privatize) {
1250+
if (privatize && !info.skipDspStep2) {
12441251
// DataSharingProcessor::processStep2() may create operations before/after
12451252
// the one passed as argument. We need to treat loop wrappers and their
12461253
// nested loop as a unit, so we need to pass the bottom level wrapper (if
@@ -2162,7 +2169,10 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
21622169
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, nestedEval,
21632170
llvm::omp::Directive::OMPD_section)
21642171
.setClauses(&sectionQueue.begin()->clauses)
2165-
.setEntryBlockArgs(&args),
2172+
.setEntryBlockArgs(&args)
2173+
.setDataSharingProcessor(&dsp)
2174+
// lastprivate is handled differently for SECTIONS, see below
2175+
.setSkipDspStep2(true),
21662176
sectionQueue, sectionQueue.begin());
21672177
}
21682178

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)