From 6fdfb5e9cdce7615b36c5df45d660c01886b2fe7 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Mon, 25 Sep 2023 13:54:46 -0700 Subject: [PATCH 1/2] [flang][openacc][hlfir] Add declare op in private recipe --- flang/include/flang/Lower/OpenACC.h | 10 ++-- flang/lib/Lower/OpenACC.cpp | 57 +++++++++++++------ .../test/Lower/OpenACC/acc-parallel-loop.f90 | 10 +++- flang/test/Lower/OpenACC/acc-parallel.f90 | 10 +++- flang/test/Lower/OpenACC/acc-private.f90 | 34 +++++++---- flang/test/Lower/OpenACC/acc-serial-loop.f90 | 10 +++- flang/test/Lower/OpenACC/acc-serial.f90 | 10 +++- 7 files changed, 100 insertions(+), 41 deletions(-) diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h index b342e4a4704da..65d73580c6ffa 100644 --- a/flang/include/flang/Lower/OpenACC.h +++ b/flang/include/flang/Lower/OpenACC.h @@ -77,7 +77,8 @@ void finalizeOpenACCRoutineAttachment(mlir::ModuleOp &, /// Get a acc.private.recipe op for the given type or create it if it does not /// exist yet. -mlir::acc::PrivateRecipeOp createOrGetPrivateRecipe(mlir::OpBuilder &, +mlir::acc::PrivateRecipeOp createOrGetPrivateRecipe(AbstractConverter &, + mlir::OpBuilder &, llvm::StringRef, mlir::Location, mlir::Type); @@ -90,10 +91,9 @@ createOrGetReductionRecipe(fir::FirOpBuilder &, llvm::StringRef, mlir::Location, /// Get a acc.firstprivate.recipe op for the given type or create it if it does /// not exist yet. -mlir::acc::FirstprivateRecipeOp createOrGetFirstprivateRecipe(mlir::OpBuilder &, - llvm::StringRef, - mlir::Location, - mlir::Type); +mlir::acc::FirstprivateRecipeOp +createOrGetFirstprivateRecipe(AbstractConverter &, mlir::OpBuilder &, + llvm::StringRef, mlir::Location, mlir::Type); void attachDeclarePostAllocAction(AbstractConverter &, fir::FirOpBuilder &, const Fortran::semantics::Symbol &); diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 6d4443ef09ed0..460032746a88f 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -34,6 +34,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 mlir::Location genOperandLocation(Fortran::lower::AbstractConverter &converter, @@ -344,27 +345,47 @@ static void genDataExitOperations(fir::FirOpBuilder &builder, } template -static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe, - mlir::Type ty, mlir::Location loc) { +static void +genPrivateLikeInitRegion(Fortran::lower::AbstractConverter &converter, + mlir::OpBuilder &builder, RecipeOp recipe, + mlir::Type ty, mlir::Location loc) { mlir::Value retVal = recipe.getInitRegion().front().getArgument(0); if (auto refTy = mlir::dyn_cast_or_null(ty)) { - if (fir::isa_trivial(refTy.getEleTy())) + if (fir::isa_trivial(refTy.getEleTy())) { retVal = builder.create(loc, refTy.getEleTy()); - else if (auto seqTy = - mlir::dyn_cast_or_null(refTy.getEleTy())) { + if (converter.getLoweringOptions().getLowerToHighLevelFIR()) { + auto declareOp = builder.create( + loc, retVal, accPrivateInitName, /*shape=*/nullptr, + llvm::ArrayRef{}, fir::FortranVariableFlagsAttr{}); + retVal = declareOp.getBase(); + } + } else if (auto seqTy = mlir::dyn_cast_or_null( + refTy.getEleTy())) { if (seqTy.hasDynamicExtents()) TODO(loc, "private recipe of array with dynamic extents"); if (fir::isa_trivial(seqTy.getEleTy())) retVal = builder.create(loc, seqTy); + + if (converter.getLoweringOptions().getLowerToHighLevelFIR()) { + llvm::SmallVector extents; + mlir::Type idxTy = builder.getIndexType(); + for (auto extent : seqTy.getShape()) + extents.push_back(builder.create( + loc, idxTy, builder.getIntegerAttr(idxTy, extent))); + auto shapeOp = builder.create(loc, extents); + auto declareOp = builder.create( + loc, retVal, accPrivateInitName, shapeOp, + llvm::ArrayRef{}, fir::FortranVariableFlagsAttr{}); + retVal = declareOp.getBase(); + } } } builder.create(loc, retVal); } -mlir::acc::PrivateRecipeOp -Fortran::lower::createOrGetPrivateRecipe(mlir::OpBuilder &builder, - llvm::StringRef recipeName, - mlir::Location loc, mlir::Type ty) { +mlir::acc::PrivateRecipeOp Fortran::lower::createOrGetPrivateRecipe( + Fortran::lower::AbstractConverter &converter, mlir::OpBuilder &builder, + llvm::StringRef recipeName, mlir::Location loc, mlir::Type ty) { mlir::ModuleOp mod = builder.getBlock()->getParent()->getParentOfType(); if (auto recipe = mod.lookupSymbol(recipeName)) @@ -377,15 +398,15 @@ Fortran::lower::createOrGetPrivateRecipe(mlir::OpBuilder &builder, builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(), {ty}, {loc}); builder.setInsertionPointToEnd(&recipe.getInitRegion().back()); - genPrivateLikeInitRegion(builder, recipe, ty, - loc); + genPrivateLikeInitRegion(converter, builder, + recipe, ty, loc); builder.restoreInsertionPoint(crtPos); return recipe; } mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( - mlir::OpBuilder &builder, llvm::StringRef recipeName, mlir::Location loc, - mlir::Type ty) { + Fortran::lower::AbstractConverter &converter, mlir::OpBuilder &builder, + llvm::StringRef recipeName, mlir::Location loc, mlir::Type ty) { mlir::ModuleOp mod = builder.getBlock()->getParent()->getParentOfType(); if (auto recipe = @@ -399,8 +420,8 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(), {ty}, {loc}); builder.setInsertionPointToEnd(&recipe.getInitRegion().back()); - genPrivateLikeInitRegion(builder, recipe, ty, - loc); + genPrivateLikeInitRegion(converter, builder, + recipe, ty, loc); // Add empty copy region for firstprivate. TODO add copy sequence. builder.createBlock(&recipe.getCopyRegion(), recipe.getCopyRegion().end(), @@ -506,8 +527,8 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList, if constexpr (std::is_same_v) { std::string recipeName = fir::getTypeAsString(retTy, converter.getKindMap(), "privatization"); - recipe = Fortran::lower::createOrGetPrivateRecipe(builder, recipeName, - operandLocation, retTy); + recipe = Fortran::lower::createOrGetPrivateRecipe( + converter, builder, recipeName, operandLocation, retTy); auto op = createDataEntryOp( builder, operandLocation, baseAddr, asFortran, bounds, true, /*implicit=*/false, mlir::acc::DataClause::acc_private, retTy); @@ -516,7 +537,7 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList, std::string recipeName = fir::getTypeAsString( retTy, converter.getKindMap(), "firstprivatization"); recipe = Fortran::lower::createOrGetFirstprivateRecipe( - builder, recipeName, operandLocation, retTy); + converter, builder, recipeName, operandLocation, retTy); auto op = createDataEntryOp( builder, operandLocation, baseAddr, asFortran, bounds, true, /*implicit=*/false, mlir::acc::DataClause::acc_firstprivate, retTy); diff --git a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 index b9113437f86aa..540467a4f9eb4 100644 --- a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 @@ -6,7 +6,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } copy { ! CHECK: ^bb0(%[[SRC:.*]]: !fir.ref>, %[[DST:.*]]: !fir.ref>): ! CHECK: %[[LB0:.*]] = arith.constant 0 : index @@ -23,7 +26,10 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! CHECK: acc.yield %{{.*}} : !fir.ref> +! FIR: acc.yield %{{.*}} : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } ! CHECK-LABEL: func.func @_QPacc_parallel_loop() diff --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90 index 8b59719dc6b93..5884872044348 100644 --- a/flang/test/Lower/OpenACC/acc-parallel.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel.f90 @@ -6,7 +6,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10x10xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } copy { ! CHECK: ^bb0(%arg0: !fir.ref>, %arg1: !fir.ref>): ! CHECK: acc.terminator @@ -14,7 +17,10 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! CHECK: acc.yield %{{.*}} : !fir.ref> +! FIR: acc.yield %{{.*}} : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } ! CHECK-LABEL: func.func @_QPacc_parallel() diff --git a/flang/test/Lower/OpenACC/acc-private.f90 b/flang/test/Lower/OpenACC/acc-private.f90 index 0ec15710aaa80..859ad82c81f54 100644 --- a/flang/test/Lower/OpenACC/acc-private.f90 +++ b/flang/test/Lower/OpenACC/acc-private.f90 @@ -6,9 +6,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_50xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32> -! FIXME: we need hlfir.declare here to satisfy the assumptions about -! the HLFIR lowering, i.e. that every varible has fir/hlfir.declare. -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } copy { ! CHECK: ^bb0(%[[SRC:.*]]: !fir.ref>, %[[DST:.*]]: !fir.ref>): ! CHECK: %[[LB0:.*]] = arith.constant 0 : index @@ -26,7 +27,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_100xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } copy { ! CHECK: ^bb0(%[[SRC:.*]]: !fir.ref>, %[[DST:.*]]: !fir.ref>): ! CHECK: %[[LB0:.*]] = arith.constant 0 : index @@ -43,8 +47,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_i32 : !fir.ref init { ! CHECK: ^bb0(%{{.*}}: !fir.ref): -! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref +! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 +! FIR: acc.yield %[[ALLOCA]] : !fir.ref +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.private.init"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref ! CHECK: } copy { ! CHECK: ^bb0(%[[SRC:.*]]: !fir.ref, %[[DST:.*]]: !fir.ref): ! CHECK: %[[VALUE:.*]] = fir.load %[[SRC]] : !fir.ref @@ -54,20 +60,28 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_50xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } ! CHECK-LABEL: acc.private.recipe @privatization_ref_100xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } ! CHECK-LABEL: acc.private.recipe @privatization_ref_i32 : !fir.ref init { ! CHECK: ^bb0(%{{.*}}: !fir.ref): ! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref +! FIR: acc.yield %[[ALLOCA]] : !fir.ref +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.private.init"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref ! CHECK: } program acc_private diff --git a/flang/test/Lower/OpenACC/acc-serial-loop.f90 b/flang/test/Lower/OpenACC/acc-serial-loop.f90 index 662a34d42d7c3..b4945e7321265 100644 --- a/flang/test/Lower/OpenACC/acc-serial-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-serial-loop.f90 @@ -6,7 +6,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } copy { ! CHECK: ^bb0(%arg0: !fir.ref>, %arg1: !fir.ref>): ! CHECK: acc.terminator @@ -14,7 +17,10 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! CHECK: acc.yield %{{.*}} : !fir.ref> +! FIR: acc.yield %{{.*}} : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } ! CHECK-LABEL: func.func @_QPacc_serial_loop() diff --git a/flang/test/Lower/OpenACC/acc-serial.f90 b/flang/test/Lower/OpenACC/acc-serial.f90 index 0c0a4012f5fab..539beb62c25ee 100644 --- a/flang/test/Lower/OpenACC/acc-serial.f90 +++ b/flang/test/Lower/OpenACC/acc-serial.f90 @@ -6,7 +6,10 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10x10xf32> -! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! FIR: acc.yield %[[ALLOCA]] : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } copy { ! CHECK: ^bb0(%arg0: !fir.ref>, %arg1: !fir.ref>): ! CHECK: acc.terminator @@ -14,7 +17,10 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! CHECK: acc.yield %{{.*}} : !fir.ref> +! FIR: acc.yield %{{.*}} : !fir.ref> +! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> +! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) +! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> ! CHECK: } ! CHECK-LABEL: func.func @_QPacc_serial() From 6b63a2752c6cf2402e4ccd0f26f03a29f94369e3 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 26 Sep 2023 10:05:36 -0700 Subject: [PATCH 2/2] Remove AbstractConverter from the API --- flang/include/flang/Lower/OpenACC.h | 10 ++-- flang/lib/Lower/OpenACC.cpp | 51 +++++++++---------- .../test/Lower/OpenACC/acc-parallel-loop.f90 | 2 - flang/test/Lower/OpenACC/acc-parallel.f90 | 2 - flang/test/Lower/OpenACC/acc-private.f90 | 6 --- flang/test/Lower/OpenACC/acc-serial-loop.f90 | 2 - flang/test/Lower/OpenACC/acc-serial.f90 | 2 - 7 files changed, 28 insertions(+), 47 deletions(-) diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h index 65d73580c6ffa..b342e4a4704da 100644 --- a/flang/include/flang/Lower/OpenACC.h +++ b/flang/include/flang/Lower/OpenACC.h @@ -77,8 +77,7 @@ void finalizeOpenACCRoutineAttachment(mlir::ModuleOp &, /// Get a acc.private.recipe op for the given type or create it if it does not /// exist yet. -mlir::acc::PrivateRecipeOp createOrGetPrivateRecipe(AbstractConverter &, - mlir::OpBuilder &, +mlir::acc::PrivateRecipeOp createOrGetPrivateRecipe(mlir::OpBuilder &, llvm::StringRef, mlir::Location, mlir::Type); @@ -91,9 +90,10 @@ createOrGetReductionRecipe(fir::FirOpBuilder &, llvm::StringRef, mlir::Location, /// Get a acc.firstprivate.recipe op for the given type or create it if it does /// not exist yet. -mlir::acc::FirstprivateRecipeOp -createOrGetFirstprivateRecipe(AbstractConverter &, mlir::OpBuilder &, - llvm::StringRef, mlir::Location, mlir::Type); +mlir::acc::FirstprivateRecipeOp createOrGetFirstprivateRecipe(mlir::OpBuilder &, + llvm::StringRef, + mlir::Location, + mlir::Type); void attachDeclarePostAllocAction(AbstractConverter &, fir::FirOpBuilder &, const Fortran::semantics::Symbol &); diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 460032746a88f..44c46ddbf8869 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -345,28 +345,22 @@ static void genDataExitOperations(fir::FirOpBuilder &builder, } template -static void -genPrivateLikeInitRegion(Fortran::lower::AbstractConverter &converter, - mlir::OpBuilder &builder, RecipeOp recipe, - mlir::Type ty, mlir::Location loc) { +static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe, + mlir::Type ty, mlir::Location loc) { mlir::Value retVal = recipe.getInitRegion().front().getArgument(0); if (auto refTy = mlir::dyn_cast_or_null(ty)) { if (fir::isa_trivial(refTy.getEleTy())) { - retVal = builder.create(loc, refTy.getEleTy()); - if (converter.getLoweringOptions().getLowerToHighLevelFIR()) { - auto declareOp = builder.create( - loc, retVal, accPrivateInitName, /*shape=*/nullptr, - llvm::ArrayRef{}, fir::FortranVariableFlagsAttr{}); - retVal = declareOp.getBase(); - } + auto alloca = builder.create(loc, refTy.getEleTy()); + auto declareOp = builder.create( + loc, alloca, accPrivateInitName, /*shape=*/nullptr, + llvm::ArrayRef{}, fir::FortranVariableFlagsAttr{}); + retVal = declareOp.getBase(); } else if (auto seqTy = mlir::dyn_cast_or_null( refTy.getEleTy())) { if (seqTy.hasDynamicExtents()) TODO(loc, "private recipe of array with dynamic extents"); - if (fir::isa_trivial(seqTy.getEleTy())) - retVal = builder.create(loc, seqTy); - - if (converter.getLoweringOptions().getLowerToHighLevelFIR()) { + if (fir::isa_trivial(seqTy.getEleTy())) { + auto alloca = builder.create(loc, seqTy); llvm::SmallVector extents; mlir::Type idxTy = builder.getIndexType(); for (auto extent : seqTy.getShape()) @@ -374,7 +368,7 @@ genPrivateLikeInitRegion(Fortran::lower::AbstractConverter &converter, loc, idxTy, builder.getIntegerAttr(idxTy, extent))); auto shapeOp = builder.create(loc, extents); auto declareOp = builder.create( - loc, retVal, accPrivateInitName, shapeOp, + loc, alloca, accPrivateInitName, shapeOp, llvm::ArrayRef{}, fir::FortranVariableFlagsAttr{}); retVal = declareOp.getBase(); } @@ -383,9 +377,10 @@ genPrivateLikeInitRegion(Fortran::lower::AbstractConverter &converter, builder.create(loc, retVal); } -mlir::acc::PrivateRecipeOp Fortran::lower::createOrGetPrivateRecipe( - Fortran::lower::AbstractConverter &converter, mlir::OpBuilder &builder, - llvm::StringRef recipeName, mlir::Location loc, mlir::Type ty) { +mlir::acc::PrivateRecipeOp +Fortran::lower::createOrGetPrivateRecipe(mlir::OpBuilder &builder, + llvm::StringRef recipeName, + mlir::Location loc, mlir::Type ty) { mlir::ModuleOp mod = builder.getBlock()->getParent()->getParentOfType(); if (auto recipe = mod.lookupSymbol(recipeName)) @@ -398,15 +393,15 @@ mlir::acc::PrivateRecipeOp Fortran::lower::createOrGetPrivateRecipe( builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(), {ty}, {loc}); builder.setInsertionPointToEnd(&recipe.getInitRegion().back()); - genPrivateLikeInitRegion(converter, builder, - recipe, ty, loc); + genPrivateLikeInitRegion(builder, recipe, ty, + loc); builder.restoreInsertionPoint(crtPos); return recipe; } mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( - Fortran::lower::AbstractConverter &converter, mlir::OpBuilder &builder, - llvm::StringRef recipeName, mlir::Location loc, mlir::Type ty) { + mlir::OpBuilder &builder, llvm::StringRef recipeName, mlir::Location loc, + mlir::Type ty) { mlir::ModuleOp mod = builder.getBlock()->getParent()->getParentOfType(); if (auto recipe = @@ -420,8 +415,8 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(), {ty}, {loc}); builder.setInsertionPointToEnd(&recipe.getInitRegion().back()); - genPrivateLikeInitRegion(converter, builder, - recipe, ty, loc); + genPrivateLikeInitRegion(builder, recipe, ty, + loc); // Add empty copy region for firstprivate. TODO add copy sequence. builder.createBlock(&recipe.getCopyRegion(), recipe.getCopyRegion().end(), @@ -527,8 +522,8 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList, if constexpr (std::is_same_v) { std::string recipeName = fir::getTypeAsString(retTy, converter.getKindMap(), "privatization"); - recipe = Fortran::lower::createOrGetPrivateRecipe( - converter, builder, recipeName, operandLocation, retTy); + recipe = Fortran::lower::createOrGetPrivateRecipe(builder, recipeName, + operandLocation, retTy); auto op = createDataEntryOp( builder, operandLocation, baseAddr, asFortran, bounds, true, /*implicit=*/false, mlir::acc::DataClause::acc_private, retTy); @@ -537,7 +532,7 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList, std::string recipeName = fir::getTypeAsString( retTy, converter.getKindMap(), "firstprivatization"); recipe = Fortran::lower::createOrGetFirstprivateRecipe( - converter, builder, recipeName, operandLocation, retTy); + builder, recipeName, operandLocation, retTy); auto op = createDataEntryOp( builder, operandLocation, baseAddr, asFortran, bounds, true, /*implicit=*/false, mlir::acc::DataClause::acc_firstprivate, retTy); diff --git a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 index 540467a4f9eb4..22726b0f49094 100644 --- a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 @@ -6,7 +6,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -26,7 +25,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! FIR: acc.yield %{{.*}} : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> diff --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90 index 5884872044348..cdde9128d70c9 100644 --- a/flang/test/Lower/OpenACC/acc-parallel.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel.f90 @@ -6,7 +6,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10x10xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -17,7 +16,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! FIR: acc.yield %{{.*}} : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> diff --git a/flang/test/Lower/OpenACC/acc-private.f90 b/flang/test/Lower/OpenACC/acc-private.f90 index 859ad82c81f54..20713ee6972d6 100644 --- a/flang/test/Lower/OpenACC/acc-private.f90 +++ b/flang/test/Lower/OpenACC/acc-private.f90 @@ -6,7 +6,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_50xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -27,7 +26,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_100xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -48,7 +46,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_i32 : !fir.ref init { ! CHECK: ^bb0(%{{.*}}: !fir.ref): ! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 -! FIR: acc.yield %[[ALLOCA]] : !fir.ref ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.private.init"} : (!fir.ref) -> (!fir.ref, !fir.ref) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref ! CHECK: } copy { @@ -61,7 +58,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_50xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -70,7 +66,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_100xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -79,7 +74,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_i32 : !fir.ref init { ! CHECK: ^bb0(%{{.*}}: !fir.ref): ! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 -! FIR: acc.yield %[[ALLOCA]] : !fir.ref ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {uniq_name = "acc.private.init"} : (!fir.ref) -> (!fir.ref, !fir.ref) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref ! CHECK: } diff --git a/flang/test/Lower/OpenACC/acc-serial-loop.f90 b/flang/test/Lower/OpenACC/acc-serial-loop.f90 index b4945e7321265..c9d556b91cb6c 100644 --- a/flang/test/Lower/OpenACC/acc-serial-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-serial-loop.f90 @@ -6,7 +6,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -17,7 +16,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! FIR: acc.yield %{{.*}} : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> diff --git a/flang/test/Lower/OpenACC/acc-serial.f90 b/flang/test/Lower/OpenACC/acc-serial.f90 index 539beb62c25ee..e538cee1407a2 100644 --- a/flang/test/Lower/OpenACC/acc-serial.f90 +++ b/flang/test/Lower/OpenACC/acc-serial.f90 @@ -6,7 +6,6 @@ ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<10x10xf32> -! FIR: acc.yield %[[ALLOCA]] : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref> @@ -17,7 +16,6 @@ ! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): -! FIR: acc.yield %{{.*}} : !fir.ref> ! HLFIR: %[[SHAPE:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2> ! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]](%[[SHAPE]]) {uniq_name = "acc.private.init"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) ! HLFIR: acc.yield %[[DECLARE]]#0 : !fir.ref>