[flang-commits] [flang] 2a32d73 - [flang][OpenMP] fix predetermined privatization inside section (#138159)
via flang-commits
flang-commits at lists.llvm.org
Thu May 8 02:08:52 PDT 2025
Author: Tom Eccles
Date: 2025-05-08T10:08:49+01:00
New Revision: 2a32d738bb213a8a1e814b65beb61e39b7c66834
URL: https://github.com/llvm/llvm-project/commit/2a32d738bb213a8a1e814b65beb61e39b7c66834
DIFF: https://github.com/llvm/llvm-project/commit/2a32d738bb213a8a1e814b65beb61e39b7c66834.diff
LOG: [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
Added:
flang/test/Lower/OpenMP/sections-predetermined-private.f90
Modified:
flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
flang/lib/Lower/OpenMP/OpenMP.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index b88454c45da85..7eec598645eac 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
@@ -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);
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index cc793c683f898..099d5c604060f 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -2154,6 +2154,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, nestedEval,
llvm::omp::Directive::OMPD_section)
.setClauses(§ionQueue.begin()->clauses)
+ .setDataSharingProcessor(&dsp)
.setEntryBlockArgs(&args),
sectionQueue, sectionQueue.begin());
}
diff --git a/flang/test/Lower/OpenMP/sections-predetermined-private.f90 b/flang/test/Lower/OpenMP/sections-predetermined-private.f90
new file mode 100644
index 0000000000000..9c2e2e127aa78
--- /dev/null
+++ b/flang/test/Lower/OpenMP/sections-predetermined-private.f90
@@ -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: }
More information about the flang-commits
mailing list