[flang-commits] [flang] [flang][openacc][hlfir] Add declare op in reduction recipe (PR #67484)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Tue Sep 26 13:14:47 PDT 2023
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/67484
Same change than #67368 but for the reduction recipe.
>From a822d2606994ae72d063c1839ee94f75d7799a9b Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 25 Sep 2023 15:07:48 -0700
Subject: [PATCH] [flang][openacc][hlfir] Add declare op in reduction recipe
Same change than #67368 but for the reduction recipe.
---
flang/lib/Lower/OpenACC.cpp | 34 ++++--
flang/test/Lower/OpenACC/acc-reduction.f90 | 125 +++++++++++++--------
2 files changed, 104 insertions(+), 55 deletions(-)
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 44c46ddbf886937..93b06e77e458ebe 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -35,6 +35,7 @@ static constexpr std::int64_t starCst = -1;
static unsigned routineCounter = 0;
static constexpr llvm::StringRef accRoutinePrefix = "acc_routine_";
static constexpr llvm::StringRef accPrivateInitName = "acc.private.init";
+static constexpr llvm::StringRef accReductionInitName = "acc.reduction.init";
static mlir::Location
genOperandLocation(Fortran::lower::AbstractConverter &converter,
@@ -344,6 +345,16 @@ static void genDataExitOperations(fir::FirOpBuilder &builder,
}
}
+fir::ShapeOp genShapeOp(mlir::OpBuilder &builder, fir::SequenceType seqTy,
+ mlir::Location loc) {
+ llvm::SmallVector<mlir::Value> extents;
+ mlir::Type idxTy = builder.getIndexType();
+ for (auto extent : seqTy.getShape())
+ extents.push_back(builder.create<mlir::arith::ConstantOp>(
+ loc, idxTy, builder.getIntegerAttr(idxTy, extent)));
+ return builder.create<fir::ShapeOp>(loc, extents);
+}
+
template <typename RecipeOp>
static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe,
mlir::Type ty, mlir::Location loc) {
@@ -361,12 +372,7 @@ static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe,
TODO(loc, "private recipe of array with dynamic extents");
if (fir::isa_trivial(seqTy.getEleTy())) {
auto alloca = builder.create<fir::AllocaOp>(loc, seqTy);
- llvm::SmallVector<mlir::Value> extents;
- mlir::Type idxTy = builder.getIndexType();
- for (auto extent : seqTy.getShape())
- extents.push_back(builder.create<mlir::arith::ConstantOp>(
- loc, idxTy, builder.getIntegerAttr(idxTy, extent)));
- auto shapeOp = builder.create<fir::ShapeOp>(loc, extents);
+ auto shapeOp = genShapeOp(builder, seqTy, loc);
auto declareOp = builder.create<hlfir::DeclareOp>(
loc, alloca, accPrivateInitName, shapeOp,
llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
@@ -708,14 +714,21 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder,
mlir::Value initValue = getReductionInitValue(builder, loc, ty, op);
if (fir::isa_trivial(ty)) {
mlir::Value alloca = builder.create<fir::AllocaOp>(loc, ty);
+ auto declareOp = builder.create<hlfir::DeclareOp>(
+ loc, alloca, accReductionInitName, /*shape=*/nullptr,
+ llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
builder.create<fir::StoreOp>(loc, builder.createConvert(loc, ty, initValue),
- alloca);
- return alloca;
+ declareOp.getBase());
+ return declareOp.getBase();
} else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(ty)) {
if (seqTy.hasDynamicExtents())
TODO(loc, "private recipe of array with dynamic extents");
if (fir::isa_trivial(seqTy.getEleTy())) {
mlir::Value alloca = builder.create<fir::AllocaOp>(loc, seqTy);
+ auto shapeOp = genShapeOp(builder, seqTy, loc);
+ auto declareOp = builder.create<hlfir::DeclareOp>(
+ loc, alloca, accReductionInitName, shapeOp,
+ llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
mlir::Type idxTy = builder.getIndexType();
mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy());
llvm::SmallVector<fir::DoLoopOp> loops;
@@ -730,10 +743,11 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder,
loops.push_back(loop);
ivs.push_back(loop.getInductionVar());
}
- auto coord = builder.create<fir::CoordinateOp>(loc, refTy, alloca, ivs);
+ auto coord = builder.create<fir::CoordinateOp>(loc, refTy,
+ declareOp.getBase(), ivs);
builder.create<fir::StoreOp>(loc, initValue, coord);
builder.setInsertionPointAfter(loops[0]);
- return alloca;
+ return declareOp.getBase();
}
}
llvm::report_fatal_error("Unsupported OpenACC reduction type");
diff --git a/flang/test/Lower/OpenACC/acc-reduction.f90 b/flang/test/Lower/OpenACC/acc-reduction.f90
index d33199f9e406873..86e99a48c2e6135 100644
--- a/flang/test/Lower/OpenACC/acc-reduction.f90
+++ b/flang/test/Lower/OpenACC/acc-reduction.f90
@@ -11,8 +11,9 @@
! CHECK: %[[UNDEF1:.*]] = fir.insert_value %[[UNDEF]], %[[REAL]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
! CHECK: %[[UNDEF2:.*]] = fir.insert_value %[[UNDEF1]], %[[IMAG]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.complex<4>
-! CHECK: fir.store %[[UNDEF2]] to %[[ALLOCA]] : !fir.ref<!fir.complex<4>>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.complex<4>>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
+! HLFIR: fir.store %[[UNDEF2]] to %[[DECLARE]]#0 : !fir.ref<!fir.complex<4>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.complex<4>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.complex<4>>, %[[ARG1:.*]]: !fir.ref<!fir.complex<4>>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.complex<4>>
@@ -30,8 +31,9 @@
! CHECK: %[[UNDEF1:.*]] = fir.insert_value %[[UNDEF]], %[[REAL]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
! CHECK: %[[UNDEF2:.*]] = fir.insert_value %[[UNDEF1]], %[[IMAG]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.complex<4>
-! CHECK: fir.store %[[UNDEF2]] to %[[ALLOCA]] : !fir.ref<!fir.complex<4>>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.complex<4>>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
+! HLFIR: fir.store %[[UNDEF2]] to %[[DECLARE]]#0 : !fir.ref<!fir.complex<4>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.complex<4>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.complex<4>>, %[[ARG1:.*]]: !fir.ref<!fir.complex<4>>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.complex<4>>
@@ -45,9 +47,10 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.logical<4>>):
! CHECK: %[[CST:.*]] = arith.constant false
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.logical<4>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
! CHECK: %[[CONVERT:.*]] = fir.convert %[[CST]] : (i1) -> !fir.logical<4>
-! CHECK: fir.store %[[CONVERT]] to %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
+! HLFIR: fir.store %[[CONVERT]] to %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.logical<4>>, %[[ARG1:.*]]: !fir.ref<!fir.logical<4>>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.logical<4>>
@@ -64,9 +67,10 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.logical<4>>):
! CHECK: %[[CST:.*]] = arith.constant true
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.logical<4>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
! CHECK: %[[CONVERT:.*]] = fir.convert %[[CST]] : (i1) -> !fir.logical<4>
-! CHECK: fir.store %[[CONVERT]] to %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
+! HLFIR: fir.store %[[CONVERT]] to %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.logical<4>>, %[[ARG1:.*]]: !fir.ref<!fir.logical<4>>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.logical<4>>
@@ -83,9 +87,10 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.logical<4>>):
! CHECK: %[[CST:.*]] = arith.constant false
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.logical<4>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
! CHECK: %[[CONVERT:.*]] = fir.convert %[[CST]] : (i1) -> !fir.logical<4>
-! CHECK: fir.store %[[CONVERT]] to %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
+! HLFIR: fir.store %[[CONVERT]] to %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.logical<4>>, %[[ARG1:.*]]: !fir.ref<!fir.logical<4>>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.logical<4>>
@@ -102,9 +107,10 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.logical<4>>):
! CHECK: %[[CST:.*]] = arith.constant true
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.logical<4>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
! CHECK: %[[CONVERT:.*]] = fir.convert %[[CST]] : (i1) -> !fir.logical<4>
-! CHECK: fir.store %[[CONVERT]] to %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.logical<4>>
+! HLFIR: fir.store %[[CONVERT]] to %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.logical<4>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.logical<4>>, %[[ARG1:.*]]: !fir.ref<!fir.logical<4>>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.logical<4>>
@@ -121,8 +127,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
! CHECK: %[[CST:.*]] = arith.constant 0 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[CST]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[CST]] to %[[DECLARE]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
@@ -136,8 +143,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
! CHECK: %[[CST:.*]] = arith.constant 0 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[CST]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[CST]] to %[[DECLARE:.*]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE:.*]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
@@ -151,8 +159,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
! CHECK: %[[CST:.*]] = arith.constant -1 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[CST]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[CST]] to %[[DECLARE]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
@@ -166,14 +175,16 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
! CHECK: %[[INIT:.*]] = arith.constant -1.401300e-45 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>)
! CHECK: %[[LB:.*]] = arith.constant 0 : index
! CHECK: %[[UB:.*]] = arith.constant 99 : index
! CHECK: %[[STEP:.*]] = arith.constant 1 : index
! CHECK: fir.do_loop %[[IV:.*]] = %[[LB]] to %[[UB]] step %[[STEP]] {
-! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[ALLOCA]], %[[IV]] : (!fir.ref<!fir.array<100xf32>>, index) -> !fir.ref<f32>
-! CHECK: fir.store %[[INIT]] to %[[COORD]] : !fir.ref<f32>
+! HLFIR: %[[COORD:.*]] = fir.coordinate_of %[[DECLARE]]#0, %[[IV]] : (!fir.ref<!fir.array<100xf32>>, index) -> !fir.ref<f32>
+! HLFIR: fir.store %[[INIT]] to %[[COORD]] : !fir.ref<f32>
! CHECK: }
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100xf32>>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xf32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100xf32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100xf32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
@@ -195,8 +206,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<f32>):
! CHECK: %[[INIT:.*]] = arith.constant -1.401300e-45 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca f32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<f32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<f32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %0 {uniq_name = "acc.reduction.init"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<f32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<f32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
@@ -211,7 +223,9 @@
! CHECK: ^bb0(%arg0: !fir.ref<!fir.array<100x10xi32>>):
! CHECK: %[[INIT:.*]] = arith.constant -2147483648 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xi32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100x10xi32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<100x10xi32>>, !fir.ref<!fir.array<100x10xi32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100x10xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100x10xi32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
@@ -238,8 +252,9 @@
! CHECK: ^bb0(%arg0: !fir.ref<i32>):
! CHECK: %[[INIT:.*]] = arith.constant -2147483648 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
@@ -254,7 +269,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100x10xf32>>):
! CHECK: %[[INIT:.*]] = arith.constant 3.40282347E+38 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xf32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100x10xf32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<100x10xf32>>, !fir.ref<!fir.array<100x10xf32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10xf32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100x10xf32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100x10xf32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
@@ -281,8 +298,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<f32>):
! CHECK: %[[INIT:.*]] = arith.constant 3.40282347E+38 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca f32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<f32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<f32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<f32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<f32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
@@ -297,7 +315,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xi32>>):
! CHECK: %[[INIT:.*]] = arith.constant 2147483647 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100xi32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100xi32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
@@ -319,8 +339,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
! CHECK: %[[INIT:.*]] = arith.constant 2147483647 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
@@ -335,8 +356,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<f32>):
! CHECK: %[[INIT:.*]] = arith.constant 1.000000e+00 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca f32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<f32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<f32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<f32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<f32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
@@ -350,7 +372,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xi32>>):
! CHECK: %[[INIT:.*]] = arith.constant 1 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100xi32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100xi32>>):
! CHECK: %[[LB:.*]] = arith.constant 0 : index
@@ -371,8 +395,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
! CHECK: %[[INIT:.*]] = arith.constant 1 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
@@ -386,7 +411,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
! CHECK: %[[INIT:.*]] = arith.constant 0.000000e+00 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100xf32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xf32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100xf32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100xf32>>):
! CHECK: %[[LB:.*]] = arith.constant 0 : index
@@ -407,8 +434,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<f32>):
! CHECK: %[[INIT:.*]] = arith.constant 0.000000e+00 : f32
! CHECK: %[[ALLOCA:.*]] = fir.alloca f32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<f32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<f32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<f32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<f32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
@@ -422,7 +450,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100x10x2xi32>>):
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10x2xi32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100x10x2xi32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}}, %{{.*}} : (index, index, index) -> !fir.shape<3>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10x2xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<100x10x2xi32>>, !fir.ref<!fir.array<100x10x2xi32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10x2xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100x10x2xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100x10x2xi32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
@@ -453,7 +483,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100x10xi32>>):
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100x10xi32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100x10xi32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100x10xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<100x10xi32>>, !fir.ref<!fir.array<100x10xi32>>)
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100x10xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100x10xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100x10xi32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
@@ -479,7 +511,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xi32>>):
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100xi32>>
+! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.reduction.init"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
+! HFLIR: acc.yield %[[DECLARE]]#0 : !fir.ref<!fir.array<100xi32>>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<!fir.array<100xi32>>, %[[ARG1:.*]]: !fir.ref<!fir.array<100xi32>>):
! CHECK: %[[LB:.*]] = arith.constant 0 : index
@@ -500,8 +534,9 @@
! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
! CHECK: %[[INIT:.*]] = arith.constant 0 : i32
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
-! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref<i32>
-! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.reduction.init"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! HLFIR: fir.store %[[INIT]] to %[[DECLARE]]#0 : !fir.ref<i32>
+! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref<i32>
! CHECK: } combiner {
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
! CHECK: %[[LOAD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
More information about the flang-commits
mailing list