-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Propagate volatile on reduction variables #142435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang] Propagate volatile on reduction variables #142435
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Asher Mancinelli (ashermancinelli) ChangesReference type was being constructed without propagating volatility. Fix and add a test. Sorry for another small patch, I missed this in my last one. Full diff: https://github.com/llvm/llvm-project/pull/142435.diff 2 Files Affected:
diff --git a/flang/lib/Lower/OpenMP/PrivateReductionUtils.cpp b/flang/lib/Lower/OpenMP/PrivateReductionUtils.cpp
index 268c7828ab56f..c2237187922e6 100644
--- a/flang/lib/Lower/OpenMP/PrivateReductionUtils.cpp
+++ b/flang/lib/Lower/OpenMP/PrivateReductionUtils.cpp
@@ -57,6 +57,7 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
};
mlir::Type valTy = fir::unwrapRefType(argType);
+ const bool argIsVolatile = fir::isa_volatile_type(argType);
if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(valTy)) {
// TODO: what about undoing init of unboxed derived types?
if (auto recTy = mlir::dyn_cast<fir::RecordType>(
@@ -64,7 +65,7 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
mlir::Type eleTy = boxTy.getEleTy();
if (mlir::isa<fir::PointerType, fir::HeapType>(eleTy)) {
mlir::Type mutableBoxTy =
- fir::ReferenceType::get(fir::BoxType::get(eleTy));
+ fir::ReferenceType::get(fir::BoxType::get(eleTy), argIsVolatile);
mlir::Value converted =
builder.createConvert(loc, mutableBoxTy, block->getArgument(0));
if (recTy.getNumLenParams() > 0)
diff --git a/flang/test/Lower/volatile-openmp2.f03 b/flang/test/Lower/volatile-openmp2.f03
new file mode 100644
index 0000000000000..4df14ea52ff90
--- /dev/null
+++ b/flang/test/Lower/volatile-openmp2.f03
@@ -0,0 +1,34 @@
+! RUN: bbc -fopenmp --strict-fir-volatile-verifier %s -o - | FileCheck %s
+type x
+ integer::x1=1
+end type x
+class(x),allocatable,volatile,asynchronous::v(:)
+!$omp parallel private(v)
+!$omp end parallel
+end
+
+! CHECK-LABEL: func.func @_QQmain() {
+! CHECK: %[[VAL_0:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_1:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_2:.*]] = arith.constant 2 : index
+! CHECK: %[[VAL_3:.*]] = fir.dummy_scope : !fir.dscope
+! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QFE.n.x1) : !fir.ref<!fir.char<1,2>>
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] typeparams %[[VAL_2]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.n.x1"} : (!fir.ref<!fir.char<1,2>>, index) -> (!fir.ref<!fir.char<1,2>>, !fir.ref<!fir.char<1,2>>)
+! CHECK: %[[VAL_6:.*]] = fir.address_of(@_QFE.di.x.x1) : !fir.ref<i32>
+! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.di.x.x1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: %[[VAL_8:.*]] = fir.address_of(@_QFE.n.x) : !fir.ref<!fir.char<1>>
+! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] typeparams %[[VAL_1]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.n.x"} : (!fir.ref<!fir.char<1>>, index) -> (!fir.ref<!fir.char<1>>, !fir.ref<!fir.char<1>>)
+! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QFEv) : !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>>>
+! CHECK: %[[VAL_11:.*]] = fir.volatile_cast %[[VAL_10]] : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>>>) -> !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>
+! CHECK: %[[VAL_12:.*]]:2 = hlfir.declare %[[VAL_11]] {fortran_attrs = #fir.var_attrs<allocatable, asynchronous, volatile>, uniq_name = "_QFEv"} : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>) -> (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>, !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>)
+! CHECK: %[[VAL_13:.*]] = fir.address_of(@_QFE.c.x) : !fir.ref<!fir.array<1x!fir.type<{{.*}}>>>
+! CHECK: %[[VAL_14:.*]] = fir.shape_shift %[[VAL_0]], %[[VAL_1]] : (index, index) -> !fir.shapeshift<1>
+! CHECK: %[[VAL_15:.*]]:2 = hlfir.declare %[[VAL_13]](%[[VAL_14]]) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.c.x"} : (!fir.ref<!fir.array<1x!fir.type<{{.*}}>>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<1x!fir.type<{{.*}}>>>, !fir.ref<!fir.array<1x!fir.type<{{.*}}>>>)
+! CHECK: %[[VAL_16:.*]] = fir.address_of(@_QFE.dt.x) : !fir.ref<!fir.type<{{.*}}>>
+! CHECK: %[[VAL_17:.*]]:2 = hlfir.declare %[[VAL_16]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.dt.x"} : (!fir.ref<!fir.type<{{.*}}>>) -> (!fir.ref<!fir.type<{{.*}}>>, !fir.ref<!fir.type<{{.*}}>>)
+! CHECK: omp.parallel private(@_QFEv_private_class_heap_Uxrec__QFTx %[[VAL_12]]#0 -> %[[VAL_18:.*]] : !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>) {
+! CHECK: %[[VAL_19:.*]]:2 = hlfir.declare %[[VAL_18]] {fortran_attrs = #fir.var_attrs<allocatable, asynchronous, volatile>, uniq_name = "_QFEv"} : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>) -> (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>, !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<{{.*}}>>>, volatile>, volatile>)
+! CHECK: omp.terminator
+! CHECK: }
+! CHECK: return
+! CHECK: }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Reference type was being constructed without propagating volatility. Fix and add a test. Sorry for another small patch, I missed this in my last one.
55937e1
to
4be1b11
Compare
Reference types were being constructed from openmp private clauses without propagating volatility. Fix this by checking the volatility of the original variable and add a test.
Reference types were being constructed from openmp private clauses without propagating volatility. Fix this by checking the volatility of the original variable and add a test.
Reference type was being constructed without propagating volatility. Fix and add a test.
Sorry for another small patch, I missed this in my last one.