[flang-commits] [flang] f752265 - [flang][OpenMP] Support for privatization in common block
Nimish Mishra via flang-commits
flang-commits at lists.llvm.org
Mon Jul 31 04:17:29 PDT 2023
Author: Nimish Mishra
Date: 2023-07-31T16:46:18+05:30
New Revision: f752265231c2d15590a53e45bcc850acf2450dfc
URL: https://github.com/llvm/llvm-project/commit/f752265231c2d15590a53e45bcc850acf2450dfc
DIFF: https://github.com/llvm/llvm-project/commit/f752265231c2d15590a53e45bcc850acf2450dfc.diff
LOG: [flang][OpenMP] Support for privatization in common block
This patch provides support for usage of common block
in private/firstprivate and lastprivate clauses.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D156120
Added:
flang/test/Lower/OpenMP/firstprivate-commonblock.f90
flang/test/Lower/OpenMP/lastprivate-commonblock.f90
Modified:
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/OpenMP.cpp
Removed:
flang/test/Lower/OpenMP/Todo/firstprivate-commonblock.f90
flang/test/Lower/OpenMP/Todo/lastprivate-commonblock.f90
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 95c9b1495ee2ba..4d2209a5200279 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -564,18 +564,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
bool createHostAssociateVarClone(
const Fortran::semantics::Symbol &sym) override final {
- bool success{false};
- if (const auto *commonDet =
- sym.detailsIf<Fortran::semantics::CommonBlockDetails>()) {
- for (const auto &mem : commonDet->objects())
- success = genHostAssociateVarClone(*mem);
- } else {
- success = genHostAssociateVarClone(sym);
- }
- return success;
- }
-
- bool genHostAssociateVarClone(const Fortran::semantics::Symbol &sym) {
mlir::Location loc = genLocation(sym.name());
mlir::Type symType = genType(sym);
const auto *details = sym.detailsIf<Fortran::semantics::HostAssocDetails>();
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 22ff20c6c39236..4aa433b3a970f1 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -413,15 +413,30 @@ void DataSharingProcessor::collectDefaultSymbols() {
void DataSharingProcessor::privatize() {
for (const Fortran::semantics::Symbol *sym : privatizedSymbols) {
- cloneSymbol(sym);
- copyFirstPrivateSymbol(sym);
+ if (const auto *commonDet =
+ sym->detailsIf<Fortran::semantics::CommonBlockDetails>()) {
+ for (const auto mem : commonDet->objects()) {
+ cloneSymbol(&*mem);
+ copyFirstPrivateSymbol(&*mem);
+ }
+ } else {
+ cloneSymbol(sym);
+ copyFirstPrivateSymbol(sym);
+ }
}
}
void DataSharingProcessor::copyLastPrivatize(mlir::Operation *op) {
insertLastPrivateCompare(op);
for (const Fortran::semantics::Symbol *sym : privatizedSymbols)
- copyLastPrivateSymbol(sym, &lastPrivIP);
+ if (const auto *commonDet =
+ sym->detailsIf<Fortran::semantics::CommonBlockDetails>()) {
+ for (const auto mem : commonDet->objects()) {
+ copyLastPrivateSymbol(&*mem, &lastPrivIP);
+ }
+ } else {
+ copyLastPrivateSymbol(sym, &lastPrivIP);
+ }
}
void DataSharingProcessor::defaultPrivatize() {
diff --git a/flang/test/Lower/OpenMP/Todo/firstprivate-commonblock.f90 b/flang/test/Lower/OpenMP/Todo/firstprivate-commonblock.f90
deleted file mode 100644
index 7d6cad255db4e4..00000000000000
--- a/flang/test/Lower/OpenMP/Todo/firstprivate-commonblock.f90
+++ /dev/null
@@ -1,11 +0,0 @@
-! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-! XFAIL: *
-
-! CHECK: not yet implemented: Common Block in privatization clause
-subroutine firstprivate_common
- common /c/ x, y
- real x, y
- !$omp parallel firstprivate(/c/)
- !$omp end parallel
-end subroutine
diff --git a/flang/test/Lower/OpenMP/Todo/lastprivate-commonblock.f90 b/flang/test/Lower/OpenMP/Todo/lastprivate-commonblock.f90
deleted file mode 100644
index 242953790d1321..00000000000000
--- a/flang/test/Lower/OpenMP/Todo/lastprivate-commonblock.f90
+++ /dev/null
@@ -1,13 +0,0 @@
-! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-! XFAIL: *
-
-! CHECK: not yet implemented: Common Block in privatization clause
-subroutine lastprivate_common
- common /c/ x, y
- real x, y
- !$omp do lastprivate(/c/)
- do i=1,100
- end do
- !$omp end do
-end subroutine
diff --git a/flang/test/Lower/OpenMP/firstprivate-commonblock.f90 b/flang/test/Lower/OpenMP/firstprivate-commonblock.f90
new file mode 100644
index 00000000000000..9b1759555c6bb5
--- /dev/null
+++ b/flang/test/Lower/OpenMP/firstprivate-commonblock.f90
@@ -0,0 +1,30 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+!CHECK: func.func @_QPfirstprivate_common() {
+!CHECK: %[[val_0:.*]] = fir.address_of(@_QCc) : !fir.ref<!fir.array<8xi8>>
+!CHECK: %[[val_1:.*]] = fir.convert %[[val_0]] : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
+!CHECK: %[[val_c0:.*]] = arith.constant 0 : index
+!CHECK: %[[val_2:.*]] = fir.coordinate_of %[[val_1]], %[[val_c0]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
+!CHECK: %[[val_3:.*]] = fir.convert %[[val_2]] : (!fir.ref<i8>) -> !fir.ref<f32>
+!CHECK: %[[val_4:.*]] = fir.convert %[[val_0]] : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
+!CHECK: %[[val_c4:.*]] = arith.constant 4 : index
+!CHECK: %[[val_5:.*]] = fir.coordinate_of %[[val_4]], %[[val_c4]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
+!CHECK: %[[val_6:.*]] = fir.convert %[[val_5]] : (!fir.ref<i8>) -> !fir.ref<f32>
+!CHECK: omp.parallel {
+!CHECK: %[[val_7:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFfirstprivate_commonEx"}
+!CHECK: %[[val_8:.*]] = fir.load %[[val_3]] : !fir.ref<f32>
+!CHECK: fir.store %[[val_8]] to %[[val_7]] : !fir.ref<f32>
+!CHECK: %[[val_9:.*]] = fir.alloca f32 {bindc_name = "y", pinned, uniq_name = "_QFfirstprivate_commonEy"}
+!CHECK: %[[val_10:.*]] = fir.load %[[val_6]] : !fir.ref<f32>
+!CHECK: fir.store %[[val_10]] to %[[val_9]] : !fir.ref<f32>
+!CHECK: omp.terminator
+!CHECK: }
+!CHECK: return
+!CHECK: }
+
+subroutine firstprivate_common
+ common /c/ x, y
+ real x, y
+ !$omp parallel firstprivate(/c/)
+ !$omp end parallel
+end subroutine
diff --git a/flang/test/Lower/OpenMP/lastprivate-commonblock.f90 b/flang/test/Lower/OpenMP/lastprivate-commonblock.f90
new file mode 100644
index 00000000000000..d0d9cca7ff21f1
--- /dev/null
+++ b/flang/test/Lower/OpenMP/lastprivate-commonblock.f90
@@ -0,0 +1,40 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+!CHECK: func.func @_QPlastprivate_common() {
+!CHECK: %[[val_0:.*]] = fir.alloca i32 {adapt.valuebyref}
+!CHECK: %[[val_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFlastprivate_commonEi"}
+!CHECK: %[[val_2:.*]] = fir.address_of(@_QCc) : !fir.ref<!fir.array<8xi8>>
+!CHECK: %[[val_3:.*]] = fir.convert %[[val_2]] : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
+!CHECK: %[[val_c0:.*]] = arith.constant 0 : index
+!CHECK: %[[val_4:.*]] = fir.coordinate_of %[[val_3]], %[[val_c0]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
+!CHECK: %[[val_5:.*]] = fir.convert %[[val_4]] : (!fir.ref<i8>) -> !fir.ref<f32>
+!CHECK: %[[val_6:.*]] = fir.convert %[[val_2]] : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
+!CHECK: %[[val_c4:.*]] = arith.constant 4 : index
+!CHECK: %[[val_7:.*]] = fir.coordinate_of %[[val_6]], %[[val_c4]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
+!CHECK: %[[val_8:.*]] = fir.convert %[[val_7]] : (!fir.ref<i8>) -> !fir.ref<f32>
+!CHECK: %[[val_9:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivate_commonEx"}
+!CHECK: %[[val_10:.*]] = fir.alloca f32 {bindc_name = "y", pinned, uniq_name = "_QFlastprivate_commonEy"}
+!CHECK: %[[val_c1_i32:.*]] = arith.constant 1 : i32
+!CHECK: %[[val_c100_i32:.*]] = arith.constant 100 : i32
+!CHECK: %[[val_c1_i32_0:.*]] = arith.constant 1 : i32
+!CHECK: omp.wsloop for (%[[arg:.*]]) : i32 = (%[[val_c1_i32]]) to (%[[val_c100_i32]]) inclusive step (%[[val_c1_i32_0]]) {
+!CHECK: fir.store %[[arg]] to %[[val_0]] : !fir.ref<i32>
+!CHECK: %[[val_11:.*]] = arith.cmpi eq, %[[arg]], %[[val_c100_i32]] : i32
+!CHECK: fir.if %[[val_11]] {
+!CHECK: %[[val_12:.*]] = fir.load %[[val_9]] : !fir.ref<f32>
+!CHECK: fir.store %[[val_12]] to %[[val_5]] : !fir.ref<f32>
+!CHECK: %[[val_13:.*]] = fir.load %[[val_10]] : !fir.ref<f32>
+!CHECK: fir.store %[[val_13]] to %[[val_8]] : !fir.ref<f32>
+!CHECK: }
+!CHECK: omp.yield
+!CHECK: }
+!CHECK: return
+!CHECK: }
+subroutine lastprivate_common
+ common /c/ x, y
+ real x, y
+ !$omp do lastprivate(/c/)
+ do i=1,100
+ end do
+ !$omp end do
+end subroutine
More information about the flang-commits
mailing list