[flang-commits] [flang] 67defe5 - [flang][OpenACC] Lower exit data directive
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Mar 24 07:16:02 PDT 2022
Author: Valentin Clement
Date: 2022-03-24T15:15:56+01:00
New Revision: 67defe50679078c2ffa5543348e378e1cd996fd9
URL: https://github.com/llvm/llvm-project/commit/67defe50679078c2ffa5543348e378e1cd996fd9
DIFF: https://github.com/llvm/llvm-project/commit/67defe50679078c2ffa5543348e378e1cd996fd9.diff
LOG: [flang][OpenACC] Lower exit data directive
This patch adds lowering for the `!$acc exit data` directive
from the PFT to OpenACC dialect.
This patch is part of the upstreaming effort from fir-dev branch.
Depends on D122384
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D122386
Added:
flang/test/Lower/OpenACC/acc-exit-data.f90
Modified:
flang/lib/Lower/OpenACC.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index b2fab2f1f448f..fca8bbdea1acd 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -664,7 +664,7 @@ static void
genACCExitDataOp(Fortran::lower::AbstractConverter &converter,
const Fortran::parser::AccClauseList &accClauseList) {
mlir::Value ifCond, async, waitDevnum;
- SmallVector<Value, 2> copyoutOperands, deleteOperands, detachOperands,
+ SmallVector<mlir::Value> copyoutOperands, deleteOperands, detachOperands,
waitOperands;
// Async and wait clause have optional values but can be present with
@@ -674,50 +674,24 @@ genACCExitDataOp(Fortran::lower::AbstractConverter &converter,
bool addWaitAttr = false;
bool addFinalizeAttr = false;
- auto &firOpBuilder = converter.getFirOpBuilder();
- auto currentLocation = converter.getCurrentLocation();
+ fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+ mlir::Location currentLocation = converter.getCurrentLocation();
Fortran::lower::StatementContext stmtCtx;
// Lower clauses values mapped to operands.
// Keep track of each group of operands separatly as clauses can appear
// more than once.
- for (const auto &clause : accClauseList.v) {
+ for (const Fortran::parser::AccClause &clause : accClauseList.v) {
if (const auto *ifClause =
std::get_if<Fortran::parser::AccClause::If>(&clause.u)) {
- Value cond = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(ifClause->v), stmtCtx));
- ifCond = firOpBuilder.createConvert(currentLocation,
- firOpBuilder.getI1Type(), cond);
+ genIfClause(converter, ifClause, ifCond, stmtCtx);
} else if (const auto *asyncClause =
std::get_if<Fortran::parser::AccClause::Async>(&clause.u)) {
- const auto &asyncClauseValue = asyncClause->v;
- if (asyncClauseValue) { // async has a value.
- async = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(*asyncClauseValue), stmtCtx));
- } else {
- addAsyncAttr = true;
- }
+ genAsyncClause(converter, asyncClause, async, addAsyncAttr, stmtCtx);
} else if (const auto *waitClause =
std::get_if<Fortran::parser::AccClause::Wait>(&clause.u)) {
- const auto &waitClauseValue = waitClause->v;
- if (waitClauseValue) { // wait has a value.
- const Fortran::parser::AccWaitArgument &waitArg = *waitClauseValue;
- const std::list<Fortran::parser::ScalarIntExpr> &waitList =
- std::get<std::list<Fortran::parser::ScalarIntExpr>>(waitArg.t);
- for (const Fortran::parser::ScalarIntExpr &value : waitList) {
- Value v = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(value), stmtCtx));
- waitOperands.push_back(v);
- }
-
- const std::optional<Fortran::parser::ScalarIntExpr> &waitDevnumValue =
- std::get<std::optional<Fortran::parser::ScalarIntExpr>>(waitArg.t);
- if (waitDevnumValue)
- waitDevnum = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(*waitDevnumValue), stmtCtx));
- } else {
- addWaitAttr = true;
- }
+ genWaitClause(converter, waitClause, waitOperands, waitDevnum,
+ addWaitAttr, stmtCtx);
} else if (const auto *copyoutClause =
std::get_if<Fortran::parser::AccClause::Copyout>(
&clause.u)) {
@@ -748,7 +722,7 @@ genACCExitDataOp(Fortran::lower::AbstractConverter &converter,
addOperands(operands, operandSegments, deleteOperands);
addOperands(operands, operandSegments, detachOperands);
- auto exitDataOp = createSimpleOp<mlir::acc::ExitDataOp>(
+ mlir::acc::ExitDataOp exitDataOp = createSimpleOp<mlir::acc::ExitDataOp>(
firOpBuilder, currentLocation, operands, operandSegments);
if (addAsyncAttr)
diff --git a/flang/test/Lower/OpenACC/acc-exit-data.f90 b/flang/test/Lower/OpenACC/acc-exit-data.f90
new file mode 100644
index 0000000000000..5bae065bf1ea6
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-exit-data.f90
@@ -0,0 +1,66 @@
+! This test checks lowering of OpenACC exit data directive.
+
+! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+
+subroutine acc_exit_data
+ integer :: async = 1
+ real, dimension(10, 10) :: a, b, c
+ real, pointer :: d
+ logical :: ifCondition = .TRUE.
+
+!CHECK: [[A:%.*]] = fir.alloca !fir.array<10x10xf32> {{{.*}}uniq_name = "{{.*}}Ea"}
+!CHECK: [[B:%.*]] = fir.alloca !fir.array<10x10xf32> {{{.*}}uniq_name = "{{.*}}Eb"}
+!CHECK: [[C:%.*]] = fir.alloca !fir.array<10x10xf32> {{{.*}}uniq_name = "{{.*}}Ec"}
+!CHECK: [[D:%.*]] = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "d", uniq_name = "{{.*}}Ed"}
+
+ !$acc exit data delete(a)
+!CHECK: acc.exit_data delete([[A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
+
+ !$acc exit data delete(a) if(.true.)
+!CHECK: [[IF1:%.*]] = arith.constant true
+!CHECK: acc.exit_data if([[IF1]]) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
+
+ !$acc exit data delete(a) if(ifCondition)
+!CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref<!fir.logical<4>>
+!CHECK: [[IF2:%.*]] = fir.convert [[IFCOND]] : (!fir.logical<4>) -> i1
+!CHECK: acc.exit_data if([[IF2]]) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
+
+ !$acc exit data delete(a) delete(b) delete(c)
+!CHECK: acc.exit_data delete([[A]], [[B]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>){{$}}
+
+ !$acc exit data copyout(a) delete(b) detach(d)
+!CHECK: acc.exit_data copyout([[A]] : !fir.ref<!fir.array<10x10xf32>>) delete([[B]] : !fir.ref<!fir.array<10x10xf32>>) detach([[D]] : !fir.ref<!fir.box<!fir.ptr<f32>>>){{$}}
+
+ !$acc exit data delete(a) async
+!CHECK: acc.exit_data delete([[A]] : !fir.ref<!fir.array<10x10xf32>>) attributes {async}
+
+ !$acc exit data delete(a) wait
+!CHECK: acc.exit_data delete([[A]] : !fir.ref<!fir.array<10x10xf32>>) attributes {wait}
+
+ !$acc exit data delete(a) async wait
+!CHECK: acc.exit_data delete([[A]] : !fir.ref<!fir.array<10x10xf32>>) attributes {async, wait}
+
+ !$acc exit data delete(a) async(1)
+!CHECK: [[ASYNC1:%.*]] = arith.constant 1 : i32
+!CHECK: acc.exit_data async([[ASYNC1]] : i32) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>)
+
+ !$acc exit data delete(a) async(async)
+!CHECK: [[ASYNC2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
+!CHECK: acc.exit_data async([[ASYNC2]] : i32) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>)
+
+ !$acc exit data delete(a) wait(1)
+!CHECK: [[WAIT1:%.*]] = arith.constant 1 : i32
+!CHECK: acc.exit_data wait([[WAIT1]] : i32) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>)
+
+ !$acc exit data delete(a) wait(queues: 1, 2)
+!CHECK: [[WAIT2:%.*]] = arith.constant 1 : i32
+!CHECK: [[WAIT3:%.*]] = arith.constant 2 : i32
+!CHECK: acc.exit_data wait([[WAIT2]], [[WAIT3]] : i32, i32) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>)
+
+ !$acc exit data delete(a) wait(devnum: 1: queues: 1, 2)
+!CHECK: [[WAIT4:%.*]] = arith.constant 1 : i32
+!CHECK: [[WAIT5:%.*]] = arith.constant 2 : i32
+!CHECK: [[WAIT6:%.*]] = arith.constant 1 : i32
+!CHECK: acc.exit_data wait_devnum([[WAIT6]] : i32) wait([[WAIT4]], [[WAIT5]] : i32, i32) delete([[A]] : !fir.ref<!fir.array<10x10xf32>>)
+
+end subroutine acc_exit_data
More information about the flang-commits
mailing list