Skip to content

Commit 01ba4d3

Browse files
author
Razvan Lupusoru
committed
Add support for exit action for present used in acc declare
1 parent fed14e2 commit 01ba4d3

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,7 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
38353835
const Fortran::parser::AccClauseList &accClauseList) {
38363836
llvm::SmallVector<mlir::Value> dataClauseOperands, copyEntryOperands,
38373837
copyinEntryOperands, createEntryOperands, copyoutEntryOperands,
3838-
deviceResidentEntryOperands;
3838+
presentEntryOperands, deviceResidentEntryOperands;
38393839
Fortran::lower::StatementContext stmtCtx;
38403840
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
38413841

@@ -3866,11 +3866,14 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
38663866
} else if (const auto *presentClause =
38673867
std::get_if<Fortran::parser::AccClause::Present>(
38683868
&clause.u)) {
3869+
auto crtDataStart = dataClauseOperands.size();
38693870
genDeclareDataOperandOperations<mlir::acc::PresentOp,
3870-
mlir::acc::PresentOp>(
3871+
mlir::acc::DeleteOp>(
38713872
presentClause->v, converter, semanticsContext, stmtCtx,
38723873
dataClauseOperands, mlir::acc::DataClause::acc_present,
38733874
/*structured=*/true, /*implicit=*/false);
3875+
presentEntryOperands.append(dataClauseOperands.begin() + crtDataStart,
3876+
dataClauseOperands.end());
38743877
} else if (const auto *copyinClause =
38753878
std::get_if<Fortran::parser::AccClause::Copyin>(&clause.u)) {
38763879
auto crtDataStart = dataClauseOperands.size();
@@ -3949,14 +3952,15 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
39493952

39503953
openAccCtx.attachCleanup([&builder, loc, createEntryOperands,
39513954
copyEntryOperands, copyinEntryOperands,
3952-
copyoutEntryOperands, deviceResidentEntryOperands,
3953-
declareToken]() {
3955+
copyoutEntryOperands, presentEntryOperands,
3956+
deviceResidentEntryOperands, declareToken]() {
39543957
llvm::SmallVector<mlir::Value> operands;
39553958
operands.append(createEntryOperands);
39563959
operands.append(deviceResidentEntryOperands);
39573960
operands.append(copyEntryOperands);
39583961
operands.append(copyinEntryOperands);
39593962
operands.append(copyoutEntryOperands);
3963+
operands.append(presentEntryOperands);
39603964

39613965
mlir::func::FuncOp funcOp = builder.getFunction();
39623966
auto ops = funcOp.getOps<mlir::acc::DeclareExitOp>();
@@ -3978,6 +3982,8 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
39783982
builder, copyinEntryOperands, /*structured=*/true);
39793983
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
39803984
builder, copyoutEntryOperands, /*structured=*/true);
3985+
genDataExitOperations<mlir::acc::PresentOp, mlir::acc::DeleteOp>(
3986+
builder, presentEntryOperands, /*structured=*/true);
39813987
});
39823988
}
39833989

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ subroutine acc_declare_present(a)
6565
! CHECK-DAG: %[[DECL:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) dummy_scope %{{[0-9]+}} {acc.declare = #acc.declare<dataClause = acc_present>, uniq_name = "_QMacc_declareFacc_declare_presentEa"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
6666
! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%{{.*}} : index) startIdx(%[[C1]] : index)
6767
! CHECK: %[[PRESENT:.*]] = acc.present varPtr(%[[DECL]]#0 : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
68-
! CHECK: acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
68+
! CHECK: %[[TOKEN:.*]] = acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
6969
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
70+
! CHECK: acc.declare_exit token(%[[TOKEN]]) dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
71+
! CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) {dataClause = #acc<data_clause acc_present>, name = "a"}
7072

7173
subroutine acc_declare_copyin()
7274
integer :: a(100), b(10), i

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ subroutine acc_declare_present(a)
5959
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<100xi32>> {fir.bindc_name = "a"})
6060
! CHECK: %[[DECL:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) dummy_scope %{{[0-9]+}} {acc.declare = #acc.declare<dataClause = acc_present>, uniq_name = "_QMacc_declareFacc_declare_presentEa"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
6161
! CHECK: %[[PRESENT:.*]] = acc.present varPtr(%[[DECL]]#0 : !fir.ref<!fir.array<100xi32>>) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
62-
! CHECK: acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
62+
! CHECK: %[[TOKEN:.*]] = acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
6363
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
64+
! CHECK: acc.declare_exit token(%[[TOKEN]]) dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
65+
! CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>) {dataClause = #acc<data_clause acc_present>, name = "a"}
6466

6567
subroutine acc_declare_copyin()
6668
integer :: a(100), b(10), i

0 commit comments

Comments
 (0)