[flang-commits] [flang] 5cb48f7 - [flang][openacc] Add lowering support for device_resident clause on OpenACC declare
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Mon Aug 7 10:16:38 PDT 2023
Author: Valentin Clement
Date: 2023-08-07T10:16:32-07:00
New Revision: 5cb48f7543af55544a1b60e22c6b55fc39156042
URL: https://github.com/llvm/llvm-project/commit/5cb48f7543af55544a1b60e22c6b55fc39156042
DIFF: https://github.com/llvm/llvm-project/commit/5cb48f7543af55544a1b60e22c6b55fc39156042.diff
LOG: [flang][openacc] Add lowering support for device_resident clause on OpenACC declare
Depends on D156828
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D156829
Added:
Modified:
flang/lib/Lower/OpenACC.cpp
flang/test/Lower/OpenACC/acc-declare.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 9bc8fe79df035b..ce534e7630b87b 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2404,7 +2404,7 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
mlir::Location loc,
const Fortran::parser::AccClauseList &accClauseList) {
llvm::SmallVector<mlir::Value> dataClauseOperands, copyEntryOperands,
- createEntryOperands, copyoutEntryOperands;
+ createEntryOperands, copyoutEntryOperands, deviceResidentEntryOperands;
Fortran::lower::StatementContext stmtCtx;
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
for (const Fortran::parser::AccClause &clause : accClauseList.v) {
@@ -2471,6 +2471,17 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
linkClause->v, converter, semanticsContext, stmtCtx,
dataClauseOperands, mlir::acc::DataClause::acc_declare_link,
/*structured=*/true);
+ } else if (const auto *deviceResidentClause =
+ std::get_if<Fortran::parser::AccClause::DeviceResident>(
+ &clause.u)) {
+ auto crtDataStart = dataClauseOperands.size();
+ genDataOperandOperations<mlir::acc::DeclareDeviceResidentOp>(
+ deviceResidentClause->v, converter, semanticsContext, stmtCtx,
+ dataClauseOperands,
+ mlir::acc::DataClause::acc_declare_device_resident,
+ /*structured=*/true);
+ deviceResidentEntryOperands.append(
+ dataClauseOperands.begin() + crtDataStart, dataClauseOperands.end());
} else {
mlir::Location clauseLocation = converter.genLocation(clause.source);
TODO(clauseLocation, "clause on declare directive");
@@ -2479,15 +2490,19 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);
if (!createEntryOperands.empty() || !copyEntryOperands.empty() ||
- !copyoutEntryOperands.empty()) {
+ !copyoutEntryOperands.empty() || !deviceResidentEntryOperands.empty()) {
// Attach declare exit operation generation to function context.
fctCtx.attachCleanup([&builder, loc, dataClauseOperands,
createEntryOperands, copyEntryOperands,
- copyoutEntryOperands]() {
+ copyoutEntryOperands, deviceResidentEntryOperands]() {
builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
builder, createEntryOperands, /*structured=*/true,
/*implicit=*/false);
+ genDataExitOperations<mlir::acc::DeclareDeviceResidentOp,
+ mlir::acc::DeleteOp>(
+ builder, deviceResidentEntryOperands, /*structured=*/true,
+ /*implicit=*/false);
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index cb0043d5e8e335..2851fd83ac0784 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -205,4 +205,21 @@ subroutine acc_declare_link(a)
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
! CHECK-NOT: acc.declare_exit
+ subroutine acc_declare_device_resident(a)
+ integer :: a(100), i
+ !$acc declare device_resident(a)
+
+ do i = 1, 100
+ a(i) = i
+ end do
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_device_resident(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<100xi32>> {fir.bindc_name = "a"})
+! CHECK: %[[DEVICERES:.*]] = acc.declare_device_resident varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
+! CHECK: acc.declare_enter dataOperands(%[[DEVICERES]] : !fir.ref<!fir.array<100xi32>>)
+! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
+! CHECK: acc.declare_exit dataOperands(%[[DEVICERES]] : !fir.ref<!fir.array<100xi32>>)
+! CHECK: acc.delete accPtr(%[[DEVICERES]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) {dataClause = #acc<data_clause acc_declare_device_resident>, name = "a"}
+
end module
More information about the flang-commits
mailing list