@@ -35,6 +35,7 @@ static constexpr std::int64_t starCst = -1;
35
35
static unsigned routineCounter = 0 ;
36
36
static constexpr llvm::StringRef accRoutinePrefix = " acc_routine_" ;
37
37
static constexpr llvm::StringRef accPrivateInitName = " acc.private.init" ;
38
+ static constexpr llvm::StringRef accReductionInitName = " acc.reduction.init" ;
38
39
39
40
static mlir::Location
40
41
genOperandLocation (Fortran::lower::AbstractConverter &converter,
@@ -344,6 +345,16 @@ static void genDataExitOperations(fir::FirOpBuilder &builder,
344
345
}
345
346
}
346
347
348
+ fir::ShapeOp genShapeOp (mlir::OpBuilder &builder, fir::SequenceType seqTy,
349
+ mlir::Location loc) {
350
+ llvm::SmallVector<mlir::Value> extents;
351
+ mlir::Type idxTy = builder.getIndexType ();
352
+ for (auto extent : seqTy.getShape ())
353
+ extents.push_back (builder.create <mlir::arith::ConstantOp>(
354
+ loc, idxTy, builder.getIntegerAttr (idxTy, extent)));
355
+ return builder.create <fir::ShapeOp>(loc, extents);
356
+ }
357
+
347
358
template <typename RecipeOp>
348
359
static void genPrivateLikeInitRegion (mlir::OpBuilder &builder, RecipeOp recipe,
349
360
mlir::Type ty, mlir::Location loc) {
@@ -361,12 +372,7 @@ static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe,
361
372
TODO (loc, " private recipe of array with dynamic extents" );
362
373
if (fir::isa_trivial (seqTy.getEleTy ())) {
363
374
auto alloca = builder.create <fir::AllocaOp>(loc, seqTy);
364
- llvm::SmallVector<mlir::Value> extents;
365
- mlir::Type idxTy = builder.getIndexType ();
366
- for (auto extent : seqTy.getShape ())
367
- extents.push_back (builder.create <mlir::arith::ConstantOp>(
368
- loc, idxTy, builder.getIntegerAttr (idxTy, extent)));
369
- auto shapeOp = builder.create <fir::ShapeOp>(loc, extents);
375
+ auto shapeOp = genShapeOp (builder, seqTy, loc);
370
376
auto declareOp = builder.create <hlfir::DeclareOp>(
371
377
loc, alloca, accPrivateInitName, shapeOp,
372
378
llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
@@ -708,14 +714,21 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder,
708
714
mlir::Value initValue = getReductionInitValue (builder, loc, ty, op);
709
715
if (fir::isa_trivial (ty)) {
710
716
mlir::Value alloca = builder.create <fir::AllocaOp>(loc, ty);
717
+ auto declareOp = builder.create <hlfir::DeclareOp>(
718
+ loc, alloca, accReductionInitName, /* shape=*/ nullptr ,
719
+ llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
711
720
builder.create <fir::StoreOp>(loc, builder.createConvert (loc, ty, initValue),
712
- alloca );
713
- return alloca ;
721
+ declareOp. getBase () );
722
+ return declareOp. getBase () ;
714
723
} else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(ty)) {
715
724
if (seqTy.hasDynamicExtents ())
716
725
TODO (loc, " private recipe of array with dynamic extents" );
717
726
if (fir::isa_trivial (seqTy.getEleTy ())) {
718
727
mlir::Value alloca = builder.create <fir::AllocaOp>(loc, seqTy);
728
+ auto shapeOp = genShapeOp (builder, seqTy, loc);
729
+ auto declareOp = builder.create <hlfir::DeclareOp>(
730
+ loc, alloca, accReductionInitName, shapeOp,
731
+ llvm::ArrayRef<mlir::Value>{}, fir::FortranVariableFlagsAttr{});
719
732
mlir::Type idxTy = builder.getIndexType ();
720
733
mlir::Type refTy = fir::ReferenceType::get (seqTy.getEleTy ());
721
734
llvm::SmallVector<fir::DoLoopOp> loops;
@@ -730,10 +743,11 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder,
730
743
loops.push_back (loop);
731
744
ivs.push_back (loop.getInductionVar ());
732
745
}
733
- auto coord = builder.create <fir::CoordinateOp>(loc, refTy, alloca, ivs);
746
+ auto coord = builder.create <fir::CoordinateOp>(loc, refTy,
747
+ declareOp.getBase (), ivs);
734
748
builder.create <fir::StoreOp>(loc, initValue, coord);
735
749
builder.setInsertionPointAfter (loops[0 ]);
736
- return alloca ;
750
+ return declareOp. getBase () ;
737
751
}
738
752
}
739
753
llvm::report_fatal_error (" Unsupported OpenACC reduction type" );
0 commit comments