diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -490,24 +490,21 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter, const Fortran::parser::AccClauseList &accClauseList) { mlir::Value ifCond; - SmallVector copyOperands, copyinOperands, copyinReadonlyOperands, + SmallVector 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(&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(&clause.u)) { genObjectList(copyClause->v, converter, copyOperands); @@ -549,8 +546,8 @@ } // Prepare the operand segement size attribute and the operands value range. - SmallVector operands; - SmallVector operandSegments; + SmallVector operands; + SmallVector 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 --- /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> {bindc_name = "d", uniq_name = "{{.*}}Ed"} +!CHECK: [[E:%.*]] = fir.alloca !fir.box> {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>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + + !$acc data copy(a) if(ifCondition) + !$acc end data + +!CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref> +!CHECK: [[IF2:%.*]] = fir.convert [[IFCOND]] : (!fir.logical<4>) -> i1 +!CHECK: acc.data if([[IF2]]) copy([[A]] : !fir.ref>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + + !$acc data copy(a, b, c) + !$acc end data + +!CHECK: acc.data copy([[A]], [[B]], [[C]] : !fir.ref>, !fir.ref>, !fir.ref>) { +!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.ref>, !fir.ref>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + + !$acc data copyin(a) copyin(readonly: b, c) + !$acc end data + +!CHECK: acc.data copyin([[A]] : !fir.ref>) copyin_readonly([[B]], [[C]] : !fir.ref>, !fir.ref>) { +!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.ref>) copyout_zero([[B]] : !fir.ref>) { +!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.ref>) create_zero([[C]] : !fir.ref>) { +!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>) no_create([[A]], [[B]] : !fir.ref>, !fir.ref>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + + !$acc data present(a, b, c) + !$acc end data + +!CHECK: acc.data present([[A]], [[B]], [[C]] : !fir.ref>, !fir.ref>, !fir.ref>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + + !$acc data deviceptr(b, c) + !$acc end data + +!CHECK: acc.data deviceptr([[B]], [[C]] : !fir.ref>, !fir.ref>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + + !$acc data attach(d, e) + !$acc end data + +!CHECK: acc.data attach([[D]], [[E]] : !fir.ref>>, !fir.ref>>) { +!CHECK: acc.terminator +!CHECK-NEXT: }{{$}} + +end subroutine acc_data +