[flang-commits] [flang] 9d7c7f6 - [flang][openacc] Lower acc set directive
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Wed Aug 23 14:08:48 PDT 2023
Author: Valentin Clement
Date: 2023-08-23T14:08:39-07:00
New Revision: 9d7c7f698386ab5d289567636598afc153ef36b6
URL: https://github.com/llvm/llvm-project/commit/9d7c7f698386ab5d289567636598afc153ef36b6
DIFF: https://github.com/llvm/llvm-project/commit/9d7c7f698386ab5d289567636598afc153ef36b6.diff
LOG: [flang][openacc] Lower acc set directive
Lower the acc set directive to the acc.set op.
Depends on D158554
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D158555
Added:
flang/test/Lower/OpenACC/acc-set.f90
Modified:
flang/lib/Lower/OpenACC.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 1aa97efe3aadc9..a0d20c46c3804d 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2305,6 +2305,53 @@ genACCInitShutdownOp(Fortran::lower::AbstractConverter &converter,
createSimpleOp<Op>(firOpBuilder, currentLocation, operands, operandSegments);
}
+void genACCSetOp(Fortran::lower::AbstractConverter &converter,
+ mlir::Location currentLocation,
+ const Fortran::parser::AccClauseList &accClauseList) {
+ mlir::Value ifCond, deviceNum, defaultAsync;
+ llvm::SmallVector<mlir::Value> deviceTypeOperands;
+
+ fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+ Fortran::lower::StatementContext stmtCtx;
+
+ // Lower clauses values mapped to operands.
+ // Keep track of each group of operands separately as clauses can appear
+ // more than once.
+ for (const Fortran::parser::AccClause &clause : accClauseList.v) {
+ mlir::Location clauseLocation = converter.genLocation(clause.source);
+ if (const auto *ifClause =
+ std::get_if<Fortran::parser::AccClause::If>(&clause.u)) {
+ genIfClause(converter, clauseLocation, ifClause, ifCond, stmtCtx);
+ } else if (const auto *defaultAsyncClause =
+ std::get_if<Fortran::parser::AccClause::DefaultAsync>(
+ &clause.u)) {
+ defaultAsync = fir::getBase(converter.genExprValue(
+ *Fortran::semantics::GetExpr(defaultAsyncClause->v), stmtCtx));
+ } else if (const auto *deviceNumClause =
+ std::get_if<Fortran::parser::AccClause::DeviceNum>(
+ &clause.u)) {
+ deviceNum = fir::getBase(converter.genExprValue(
+ *Fortran::semantics::GetExpr(deviceNumClause->v), stmtCtx));
+ } else if (const auto *deviceTypeClause =
+ std::get_if<Fortran::parser::AccClause::DeviceType>(
+ &clause.u)) {
+ genDeviceTypeClause(converter, clauseLocation, deviceTypeClause,
+ deviceTypeOperands, stmtCtx);
+ }
+ }
+
+ // Prepare the operand segment size attribute and the operands value range.
+ llvm::SmallVector<mlir::Value> operands;
+ llvm::SmallVector<int32_t, 4> operandSegments;
+ addOperands(operands, operandSegments, deviceTypeOperands);
+ addOperand(operands, operandSegments, defaultAsync);
+ addOperand(operands, operandSegments, deviceNum);
+ addOperand(operands, operandSegments, ifCond);
+
+ createSimpleOp<mlir::acc::SetOp>(firOpBuilder, currentLocation, operands,
+ operandSegments);
+}
+
static void
genACCUpdateOp(Fortran::lower::AbstractConverter &converter,
mlir::Location currentLocation,
@@ -2425,7 +2472,7 @@ genACC(Fortran::lower::AbstractConverter &converter,
genACCInitShutdownOp<mlir::acc::ShutdownOp>(converter, currentLocation,
accClauseList);
} else if (standaloneDirective.v == llvm::acc::Directive::ACCD_set) {
- TODO(currentLocation, "OpenACC set directive not lowered yet!");
+ genACCSetOp(converter, currentLocation, accClauseList);
} else if (standaloneDirective.v == llvm::acc::Directive::ACCD_update) {
genACCUpdateOp(converter, currentLocation, semanticsContext, stmtCtx,
accClauseList);
diff --git a/flang/test/Lower/OpenACC/acc-set.f90 b/flang/test/Lower/OpenACC/acc-set.f90
new file mode 100644
index 00000000000000..90889a21ff4235
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-set.f90
@@ -0,0 +1,40 @@
+! This test checks lowering of OpenACC set directive.
+
+! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+
+program test_acc_set
+ logical :: l
+
+!$acc set default_async(1)
+
+!$acc set default_async(1) if(l)
+
+!$acc set device_num(0)
+
+!$acc set device_type(*)
+
+!$acc set device_type(0)
+
+end
+
+! CHECK-LABEL: func.func @_QQmain()
+! CHECK: %[[L:.*]] = fir.alloca !fir.logical<4> {bindc_name = "l", uniq_name = "_QFEl"}
+
+! CHECK: %[[C1:.*]] = arith.constant 1 : i32
+! CHECK: acc.set default_async(%[[C1]] : i32)
+
+! CHECK: %[[C1:.*]] = arith.constant 1 : i32
+! CHECK: %[[LOAD_L:.*]] = fir.load %[[L]] : !fir.ref<!fir.logical<4>>
+! CHECK: %[[CONV_L:.*]] = fir.convert %[[LOAD_L]] : (!fir.logical<4>) -> i1
+! CHECK: acc.set default_async(%[[C1]] : i32) if(%[[CONV_L]])
+
+! CHECK: %[[C0:.*]] = arith.constant 0 : i32
+! CHECK: acc.set device_num(%[[C0]] : i32)
+
+! CHECK: %[[C_1:.*]] = arith.constant -1 : index
+! CHECK: acc.set device_type(%[[C_1]] : index)
+
+! CHECK: %[[C0:.*]] = arith.constant 0 : i32
+! CHECK: acc.set device_type(%[[C0]] : i32)
+
+
More information about the flang-commits
mailing list