Skip to content

Commit

Permalink
[flang][openacc] Add lowering support for present clause on OpenACC d…
Browse files Browse the repository at this point in the history
…eclare

Lower the present clause on the OpenACC declare construct in
function/subroutine.

Depends on D156572

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156721
  • Loading branch information
clementval committed Aug 1, 2023
1 parent 29851f4 commit 392203d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
30 changes: 21 additions & 9 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ static Op createDataEntryOp(fir::FirOpBuilder &builder, mlir::Location loc,

static void addDeclareAttr(fir::FirOpBuilder &builder, mlir::Operation *op,
mlir::acc::DataClause clause) {
if (!op)
return;
op->setAttr(mlir::acc::getDeclareAttrName(),
mlir::acc::DeclareAttr::get(builder.getContext(),
mlir::acc::DataClauseAttr::get(
Expand Down Expand Up @@ -2427,22 +2429,32 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
/*structured=*/true, /*setDeclareAttr=*/true);
createEntryOperands.append(dataClauseOperands.begin() + crtDataStart,
dataClauseOperands.end());
} else if (const auto *presentClause =
std::get_if<Fortran::parser::AccClause::Present>(
&clause.u)) {
genDataOperandOperations<mlir::acc::PresentOp>(
presentClause->v, converter, semanticsContext, stmtCtx,
dataClauseOperands, mlir::acc::DataClause::acc_present,
/*structured=*/true, /*setDeclareAttr=*/true);
} else {
mlir::Location clauseLocation = converter.genLocation(clause.source);
TODO(clauseLocation, "clause on declare directive");
}
}
builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);

// Attach declare exit operation generation to function context.
fctCtx.attachCleanup([&builder, loc, dataClauseOperands, createEntryOperands,
copyEntryOperands]() {
builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
builder, createEntryOperands, /*structured=*/true, /*implicit=*/false);
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(builder,
copyEntryOperands, /*structured=*/true, /*implicit=*/false);
});
if (!createEntryOperands.empty() || !copyEntryOperands.empty()) {
// Attach declare exit operation generation to function context.
fctCtx.attachCleanup([&builder, loc, dataClauseOperands,
createEntryOperands, copyEntryOperands]() {
builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
builder, createEntryOperands, /*structured=*/true,
/*implicit=*/false);
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
});
}
}

static void
Expand Down
16 changes: 16 additions & 0 deletions flang/test/Lower/OpenACC/acc-declare.f90
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,21 @@ subroutine acc_declare_create()
! CHECK: acc.delete accPtr(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) {dataClause = #acc<data_clause acc_create>, name = "a"}
! CHECK: return

subroutine acc_declare_present(a)
integer :: a(100), i
!$acc declare present(a)

do i = 1, 100
a(i) = i
end do
end subroutine

! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_present(
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<100xi32>> {fir.bindc_name = "a"})
! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%{{.*}} : index) startIdx(%c1 : index)
! CHECK: %[[PRESENT:.*]] = acc.present varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
! CHECK: acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
! CHECK-NOT: acc.declare_exit

end module

0 comments on commit 392203d

Please sign in to comment.