[flang-commits] [flang] 5ee88e0 - [flang[OpenACC] Lower data directive
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Mar 24 07:30:39 PDT 2022
Author: Valentin Clement
Date: 2022-03-24T15:30:31+01:00
New Revision: 5ee88e0ba50474a963f6ccf6c6133c0cf632e5b9
URL: https://github.com/llvm/llvm-project/commit/5ee88e0ba50474a963f6ccf6c6133c0cf632e5b9
DIFF: https://github.com/llvm/llvm-project/commit/5ee88e0ba50474a963f6ccf6c6133c0cf632e5b9.diff
LOG: [flang[OpenACC] Lower data directive
This patch adds lowering for the `!$acc data`
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/D122398
Added:
flang/test/Lower/OpenACC/acc-data.f90
Modified:
flang/lib/Lower/OpenACC.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 922c53ef43123..abac3ff585768 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -514,24 +514,21 @@ genACCParallelOp(Fortran::lower::AbstractConverter &converter,
static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
const Fortran::parser::AccClauseList &accClauseList) {
mlir::Value ifCond;
- SmallVector<Value, 2> copyOperands, copyinOperands, copyinReadonlyOperands,
+ SmallVector<mlir::Value> copyOperands, copyinOperands, copyinReadonlyOperands,
copyoutOperands, copyoutZeroOperands, createOperands, createZeroOperands,
noCreateOperands, presentOperands, deviceptrOperands, attachOperands;
- 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 *copyClause =
std::get_if<Fortran::parser::AccClause::Copy>(&clause.u)) {
genObjectList(copyClause->v, converter, copyOperands);
@@ -573,8 +570,8 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
}
// Prepare the operand segement size attribute and the operands value range.
- SmallVector<Value, 8> operands;
- SmallVector<int32_t, 8> operandSegments;
+ SmallVector<mlir::Value> operands;
+ SmallVector<int32_t> operandSegments;
addOperand(operands, operandSegments, ifCond);
addOperands(operands, operandSegments, copyOperands);
addOperands(operands, operandSegments, copyinOperands);
diff --git a/flang/test/Lower/OpenACC/acc-data.f90 b/flang/test/Lower/OpenACC/acc-data.f90
new file mode 100644
index 0000000000000..1716ac99629e4
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-data.f90
@@ -0,0 +1,97 @@
+! This test checks lowering of OpenACC data directive.
+
+! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+
+subroutine acc_data
+ real, dimension(10, 10) :: a, b, c
+ real, pointer :: d, e
+ 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"}
+!CHECK: [[E:%.*]] = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "e", uniq_name = "{{.*}}Ee"}
+
+ !$acc data if(.TRUE.) copy(a)
+ !$acc end data
+
+!CHECK: [[IF1:%.*]] = arith.constant true
+!CHECK: acc.data if([[IF1]]) copy([[A]] : !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data copy(a) if(ifCondition)
+ !$acc end data
+
+!CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref<!fir.logical<4>>
+!CHECK: [[IF2:%.*]] = fir.convert [[IFCOND]] : (!fir.logical<4>) -> i1
+!CHECK: acc.data if([[IF2]]) copy([[A]] : !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data copy(a, b, c)
+ !$acc end data
+
+!CHECK: acc.data copy([[A]], [[B]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data copy(a) copy(b) copy(c)
+ !$acc end data
+
+!CHECK: acc.data copy([[A]], [[B]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data copyin(a) copyin(readonly: b, c)
+ !$acc end data
+
+!CHECK: acc.data copyin([[A]] : !fir.ref<!fir.array<10x10xf32>>) copyin_readonly([[B]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data copyout(a) copyout(zero: b) copyout(c)
+ !$acc end data
+
+!CHECK: acc.data copyout([[A]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) copyout_zero([[B]] : !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data create(a, b) create(zero: c)
+ !$acc end data
+
+!CHECK: acc.data create([[A]], [[B]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) create_zero([[C]] : !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data no_create(a, b) create(zero: c)
+ !$acc end data
+
+!CHECK: acc.data create_zero([[C]] : !fir.ref<!fir.array<10x10xf32>>) no_create([[A]], [[B]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data present(a, b, c)
+ !$acc end data
+
+!CHECK: acc.data present([[A]], [[B]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data deviceptr(b, c)
+ !$acc end data
+
+!CHECK: acc.data deviceptr([[B]], [[C]] : !fir.ref<!fir.array<10x10xf32>>, !fir.ref<!fir.array<10x10xf32>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+ !$acc data attach(d, e)
+ !$acc end data
+
+!CHECK: acc.data attach([[D]], [[E]] : !fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>) {
+!CHECK: acc.terminator
+!CHECK-NEXT: }{{$}}
+
+end subroutine acc_data
+
More information about the flang-commits
mailing list