Skip to content

Commit 7b24612

Browse files
committed
[flang][openacc] Always generate acc.declare_exit
Always generate the acc.declare_exit operation so it matches the acc.declare_enter operation. This is to ensure the lifetime of data in the implicit region. Reviewed By: razvanlupusoru Differential Revision: https://reviews.llvm.org/D157524
1 parent 0b837e2 commit 7b24612

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,27 +2556,24 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
25562556
}
25572557
builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);
25582558

2559-
if (!createEntryOperands.empty() || !copyEntryOperands.empty() ||
2560-
!copyoutEntryOperands.empty() || !deviceResidentEntryOperands.empty()) {
2561-
// Attach declare exit operation generation to function context.
2562-
fctCtx.attachCleanup([&builder, loc, dataClauseOperands,
2563-
createEntryOperands, copyEntryOperands,
2564-
copyoutEntryOperands, deviceResidentEntryOperands]() {
2565-
builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
2566-
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
2567-
builder, createEntryOperands, /*structured=*/true,
2568-
/*implicit=*/false);
2569-
genDataExitOperations<mlir::acc::DeclareDeviceResidentOp,
2570-
mlir::acc::DeleteOp>(
2571-
builder, deviceResidentEntryOperands, /*structured=*/true,
2572-
/*implicit=*/false);
2573-
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
2574-
builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
2575-
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
2576-
builder, copyoutEntryOperands, /*structured=*/true,
2577-
/*implicit=*/false);
2578-
});
2579-
}
2559+
// Attach declare exit operation generation to function context.
2560+
fctCtx.attachCleanup([&builder, loc, dataClauseOperands, createEntryOperands,
2561+
copyEntryOperands, copyoutEntryOperands,
2562+
deviceResidentEntryOperands]() {
2563+
builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
2564+
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
2565+
builder, createEntryOperands, /*structured=*/true,
2566+
/*implicit=*/false);
2567+
genDataExitOperations<mlir::acc::DeclareDeviceResidentOp,
2568+
mlir::acc::DeleteOp>(
2569+
builder, deviceResidentEntryOperands, /*structured=*/true,
2570+
/*implicit=*/false);
2571+
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
2572+
builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
2573+
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
2574+
builder, copyoutEntryOperands, /*structured=*/true,
2575+
/*implicit=*/false);
2576+
});
25802577
}
25812578

25822579
static void

flang/test/Lower/OpenACC/acc-declare.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ subroutine acc_declare_present(a)
133133
! CHECK: %[[PRESENT:.*]] = acc.present varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
134134
! CHECK: acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
135135
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
136-
! CHECK-NOT: acc.declare_exit
136+
! CHECK: acc.declare_exit dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
137137

138138
subroutine acc_declare_copyin()
139139
integer :: a(100), b(10), i
@@ -153,7 +153,7 @@ subroutine acc_declare_copyin()
153153
! CHECK: %[[COPYIN_B:.*]] = acc.copyin varPtr(%[[B]] : !fir.ref<!fir.array<10xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xi32>> {dataClause = #acc<data_clause acc_copyin_readonly>, name = "b"}
154154
! CHECK: acc.declare_enter dataOperands(%[[COPYIN_A]], %[[COPYIN_B]] : !fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<10xi32>>)
155155
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
156-
! CHECK-NOT: acc.declare_exit
156+
! CHECK: acc.declare_exit dataOperands(%[[COPYIN_A]], %[[COPYIN_B]] : !fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<10xi32>>)
157157

158158
subroutine acc_declare_copyout()
159159
integer :: a(100), i
@@ -187,7 +187,7 @@ subroutine acc_declare_deviceptr(a)
187187
! CHECK: %[[DEVICEPTR:.*]] = acc.deviceptr varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
188188
! CHECK: acc.declare_enter dataOperands(%[[DEVICEPTR]] : !fir.ref<!fir.array<100xi32>>)
189189
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
190-
! CHECK-NOT: acc.declare_exit
190+
! CHECK: acc.declare_exit dataOperands(%[[DEVICEPTR]] : !fir.ref<!fir.array<100xi32>>)
191191

192192
subroutine acc_declare_link(a)
193193
integer :: a(100), i
@@ -203,7 +203,7 @@ subroutine acc_declare_link(a)
203203
! CHECK: %[[LINK:.*]] = acc.declare_link varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
204204
! CHECK: acc.declare_enter dataOperands(%[[LINK]] : !fir.ref<!fir.array<100xi32>>)
205205
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
206-
! CHECK-NOT: acc.declare_exit
206+
! CHECK: acc.declare_exit dataOperands(%[[LINK]] : !fir.ref<!fir.array<100xi32>>)
207207

208208
subroutine acc_declare_device_resident(a)
209209
integer :: a(100), i

0 commit comments

Comments
 (0)