diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h --- a/flang/include/flang/Lower/OpenACC.h +++ b/flang/include/flang/Lower/OpenACC.h @@ -68,7 +68,8 @@ mlir::acc::ReductionRecipeOp createOrGetReductionRecipe(fir::FirOpBuilder &, llvm::StringRef, mlir::Location, mlir::Type, mlir::acc::ReductionOperator, - llvm::SmallVector &); + llvm::SmallVector &, + const llvm::StringRef); /// Get a acc.firstprivate.recipe op for the given type or create it if it does /// not exist yet. diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -755,11 +755,13 @@ static mlir::Value genReductionInitRegion(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type ty, - mlir::acc::ReductionOperator op) { + mlir::acc::ReductionOperator op, + const llvm::StringRef allocaName) { ty = fir::unwrapRefType(ty); mlir::Value initValue = getReductionInitValue(builder, loc, ty, op); if (fir::isa_trivial(ty)) { - mlir::Value alloca = builder.create(loc, ty); + mlir::Value alloca = builder.create( + loc, ty, /*unique_name=*/llvm::StringRef{}, allocaName); builder.create(loc, builder.createConvert(loc, ty, initValue), alloca); return alloca; @@ -767,7 +769,8 @@ if (seqTy.hasDynamicExtents()) TODO(loc, "private recipe of array with dynamic extents"); if (fir::isa_trivial(seqTy.getEleTy())) { - mlir::Value alloca = builder.create(loc, seqTy); + mlir::Value alloca = builder.create( + loc, seqTy, /*unique_name=*/llvm::StringRef{}, allocaName); mlir::Type idxTy = builder.getIndexType(); mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy()); llvm::SmallVector loops; @@ -922,7 +925,7 @@ mlir::acc::ReductionRecipeOp Fortran::lower::createOrGetReductionRecipe( fir::FirOpBuilder &builder, llvm::StringRef recipeName, mlir::Location loc, mlir::Type ty, mlir::acc::ReductionOperator op, - llvm::SmallVector &bounds) { + llvm::SmallVector &bounds, const llvm::StringRef allocaName) { mlir::ModuleOp mod = builder.getBlock()->getParent()->getParentOfType(); if (auto recipe = mod.lookupSymbol(recipeName)) @@ -935,7 +938,8 @@ builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(), {ty}, {loc}); builder.setInsertionPointToEnd(&recipe.getInitRegion().back()); - mlir::Value initValue = genReductionInitRegion(builder, loc, ty, op); + mlir::Value initValue = + genReductionInitRegion(builder, loc, ty, op, allocaName); builder.create(loc, initValue); builder.createBlock(&recipe.getCombinerRegion(), @@ -992,7 +996,8 @@ ("reduction_" + stringifyReductionOperator(mlirOp)).str()); mlir::acc::ReductionRecipeOp recipe = Fortran::lower::createOrGetReductionRecipe( - builder, recipeName, operandLocation, ty, mlirOp, bounds); + builder, recipeName, operandLocation, ty, mlirOp, bounds, + ".reduction_private"); reductionRecipes.push_back(mlir::SymbolRefAttr::get( builder.getContext(), recipe.getSymName().str())); reductionOperands.push_back(op.getAccPtr()); diff --git a/flang/test/Lower/OpenACC/acc-reduction.f90 b/flang/test/Lower/OpenACC/acc-reduction.f90 --- a/flang/test/Lower/OpenACC/acc-reduction.f90 +++ b/flang/test/Lower/OpenACC/acc-reduction.f90 @@ -498,7 +498,7 @@ ! CHECK-LABEL: acc.reduction.recipe @reduction_add_ref_i32 : !fir.ref reduction_operator init { ! CHECK: ^bb0(%{{.*}}: !fir.ref): ! CHECK: %[[INIT:.*]] = arith.constant 0 : i32 -! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 +! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 {bindc_name = ".reduction_private"} ! CHECK: fir.store %[[INIT]] to %[[ALLOCA]] : !fir.ref ! CHECK: acc.yield %[[ALLOCA]] : !fir.ref ! CHECK: } combiner {