[flang-commits] [flang] c88f3e2 - [flang][openacc] Update num_gangs parser
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Jun 27 11:10:46 PDT 2023
Author: Valentin Clement
Date: 2023-06-27T11:10:38-07:00
New Revision: c88f3e209cc4ccaa50754507880c553699e988b3
URL: https://github.com/llvm/llvm-project/commit/c88f3e209cc4ccaa50754507880c553699e988b3
DIFF: https://github.com/llvm/llvm-project/commit/c88f3e209cc4ccaa50754507880c553699e988b3.diff
LOG: [flang][openacc] Update num_gangs parser
Update num_gangs definition in ACC.td and its lowering
to support up to 3 arguments.
Depends on D153796
Depends on D153801
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D153806
Added:
Modified:
flang/lib/Lower/OpenACC.cpp
flang/lib/Semantics/check-acc-structure.cpp
flang/test/Lower/OpenACC/acc-parallel.f90
flang/test/Semantics/OpenACC/acc-parallel.f90
llvm/include/llvm/Frontend/OpenACC/ACC.td
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 0c3d2b6a4339b..29f6d8507b73b 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1108,7 +1108,6 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
// Parallel operation operands
mlir::Value async;
- mlir::Value numGangs;
mlir::Value numWorkers;
mlir::Value vectorLength;
mlir::Value ifCond;
@@ -1116,7 +1115,7 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
mlir::Value waitDevnum;
llvm::SmallVector<mlir::Value> waitOperands, attachEntryOperands,
copyEntryOperands, copyoutEntryOperands, createEntryOperands,
- dataClauseOperands;
+ dataClauseOperands, numGangs;
llvm::SmallVector<mlir::Value> reductionOperands, privateOperands,
firstprivateOperands;
@@ -1147,8 +1146,9 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
} else if (const auto *numGangsClause =
std::get_if<Fortran::parser::AccClause::NumGangs>(
&clause.u)) {
- numGangs = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(numGangsClause->v), stmtCtx));
+ for (const Fortran::parser::ScalarIntExpr &expr : numGangsClause->v)
+ numGangs.push_back(fir::getBase(converter.genExprValue(
+ *Fortran::semantics::GetExpr(expr), stmtCtx)));
} else if (const auto *numWorkersClause =
std::get_if<Fortran::parser::AccClause::NumWorkers>(
&clause.u)) {
@@ -1291,7 +1291,7 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
addOperand(operands, operandSegments, async);
addOperands(operands, operandSegments, waitOperands);
if constexpr (!std::is_same_v<Op, mlir::acc::SerialOp>) {
- addOperand(operands, operandSegments, numGangs);
+ addOperands(operands, operandSegments, numGangs);
addOperand(operands, operandSegments, numWorkers);
addOperand(operands, operandSegments, vectorLength);
}
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 4c5e81d6015ea..f5c226b0c32f2 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -331,7 +331,6 @@ CHECK_SIMPLE_CLAUSE(Independent, ACCC_independent)
CHECK_SIMPLE_CLAUSE(Link, ACCC_link)
CHECK_SIMPLE_CLAUSE(NoCreate, ACCC_no_create)
CHECK_SIMPLE_CLAUSE(Nohost, ACCC_nohost)
-CHECK_SIMPLE_CLAUSE(NumGangs, ACCC_num_gangs)
CHECK_SIMPLE_CLAUSE(NumWorkers, ACCC_num_workers)
CHECK_SIMPLE_CLAUSE(Present, ACCC_present)
CHECK_SIMPLE_CLAUSE(Private, ACCC_private)
@@ -424,6 +423,14 @@ void AccStructureChecker::Enter(const parser::AccClause::Gang &g) {
}
}
+void AccStructureChecker::Enter(const parser::AccClause::NumGangs &n) {
+ CheckAllowed(llvm::acc::Clause::ACCC_num_gangs);
+
+ if (n.v.size() > 3)
+ context_.Say(GetContext().clauseSource,
+ "NUM_GANGS clause accepts a maximum of 3 arguments"_err_en_US);
+}
+
void AccStructureChecker::Enter(const parser::AccClause::Self &x) {
CheckAllowed(llvm::acc::Clause::ACCC_self);
const std::optional<parser::AccSelfClause> &accSelfClause = x.v;
diff --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90
index 54b928cdeec1f..23afbe6a165fb 100644
--- a/flang/test/Lower/OpenACC/acc-parallel.f90
+++ b/flang/test/Lower/OpenACC/acc-parallel.f90
@@ -116,6 +116,13 @@ subroutine acc_parallel
!CHECK: [[NUMGANGS2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
!CHECK: acc.parallel num_gangs([[NUMGANGS2]] : i32) {
!CHECK: acc.yield
+!CHECK-NEXT: }{{$}}
+
+ !$acc parallel num_gangs(1, 1, 1)
+ !$acc end parallel
+
+!CHECK: acc.parallel num_gangs(%{{.*}}, %{{.*}}, %{{.*}} : i32, i32, i32) {
+!CHECK: acc.yield
!CHECK-NEXT: }{{$}}
!$acc parallel num_workers(10)
diff --git a/flang/test/Semantics/OpenACC/acc-parallel.f90 b/flang/test/Semantics/OpenACC/acc-parallel.f90
index 758e1a53c0d57..e85922e37c63e 100644
--- a/flang/test/Semantics/OpenACC/acc-parallel.f90
+++ b/flang/test/Semantics/OpenACC/acc-parallel.f90
@@ -55,6 +55,10 @@ program openacc_parallel_validity
!$acc parallel num_gangs(8)
!$acc end parallel
+ !ERROR: NUM_GANGS clause accepts a maximum of 3 arguments
+ !$acc parallel num_gangs(1, 1, 1, 1)
+ !$acc end parallel
+
!$acc parallel num_workers(8)
!$acc end parallel
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index 00ec2e5b9bf5a..1b18607585141 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -183,6 +183,7 @@ def ACCC_NoHost : Clause<"nohost"> {}
// 2.5.9
def ACCC_NumGangs : Clause<"num_gangs"> {
let flangClass = "ScalarIntExpr";
+ let isValueList = 1;
}
// 2.5.10
More information about the flang-commits
mailing list