[flang-commits] [mlir] [flang] [openacc] Update acc.loop to expose data operands (PR #70954)
Razvan Lupusoru via flang-commits
flang-commits at lists.llvm.org
Wed Nov 1 08:47:05 PDT 2023
https://github.com/razvanlupusoru created https://github.com/llvm/llvm-project/pull/70954
The compute and data constructs implement getNumDataOperands and getDataOperand. The acc.loop operation similarly has multiple data operands - thus it makes sense to expose them the same way.
For loop, only private and reduction operands are exposed this way. Technically, acc.loop also holds cache operands - but these are hints not a data attribute.
>From 8ff85e926f73d9ab72b0fd8ec981653c9e339d70 Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <rlupusoru at nvidia.com>
Date: Wed, 1 Nov 2023 08:45:24 -0700
Subject: [PATCH] [openacc] Update acc.loop to expose data operands
The compute and data constructs implement getNumDataOperands and
getDataOperand. The acc.loop operation similarly has multiple data
operands - thus it makes sense to expose them the same way.
For loop, only private and reduction operands are exposed this way.
Technically, acc.loop also holds cache operands - but these are hints
not a data attribute.
---
flang/lib/Lower/OpenACC.cpp | 2 +-
mlir/include/mlir/Dialect/OpenACC/OpenACC.h | 4 ++++
mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td | 11 +++++++++--
mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 16 ++++++++++++++++
4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 8218af691b79c86..738af5d60a8353f 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1592,9 +1592,9 @@ createLoopOp(Fortran::lower::AbstractConverter &converter,
addOperand(operands, operandSegments, workerNum);
addOperand(operands, operandSegments, vectorNum);
addOperands(operands, operandSegments, tileOperands);
+ addOperands(operands, operandSegments, cacheOperands);
addOperands(operands, operandSegments, privateOperands);
addOperands(operands, operandSegments, reductionOperands);
- addOperands(operands, operandSegments, cacheOperands);
auto loopOp = createRegionOp<mlir::acc::LoopOp, mlir::acc::YieldOp>(
builder, currentLocation, eval, operands, operandSegments);
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h
index bc4680656d4cf62..4dc94782c1c9b54 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h
@@ -48,12 +48,16 @@
mlir::acc::CacheOp
#define ACC_COMPUTE_CONSTRUCT_OPS \
mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
+#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
+ ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
#define ACC_DATA_CONSTRUCT_OPS \
mlir::acc::DataOp, mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, \
mlir::acc::UpdateOp, mlir::acc::HostDataOp, mlir::acc::DeclareEnterOp, \
mlir::acc::DeclareExitOp, mlir::acc::DeclareOp
#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
+#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
+ ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
namespace mlir {
namespace acc {
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 3c5173fdda7f66a..17cb9d6f1c2cb63 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -1196,11 +1196,12 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
UnitAttr:$hasWorker,
UnitAttr:$hasVector,
Variadic<IntOrIndex>:$tileOperands,
+ Variadic<OpenACC_PointerLikeTypeInterface>:$cacheOperands,
Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
OptionalAttr<SymbolRefArrayAttr>:$privatizations,
Variadic<AnyType>:$reductionOperands,
- OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes,
- Variadic<OpenACC_PointerLikeTypeInterface>:$cacheOperands);
+ OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes
+ );
let results = (outs Variadic<AnyType>:$results);
@@ -1211,6 +1212,12 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
static StringRef getGangNumKeyword() { return "num"; }
static StringRef getGangDimKeyword() { return "dim"; }
static StringRef getGangStaticKeyword() { return "static"; }
+
+ /// The number of private and reduction operands.
+ unsigned getNumDataOperands();
+
+ /// The i-th data operand passed.
+ Value getDataOperand(unsigned i);
}];
let hasCustomAssemblyFormat = 1;
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index d3747d331040918..df64d561f46cb3e 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -878,6 +878,22 @@ LogicalResult acc::LoopOp::verify() {
return success();
}
+unsigned LoopOp::getNumDataOperands() {
+ return getReductionOperands().size() + getPrivateOperands().size();
+}
+
+Value LoopOp::getDataOperand(unsigned i) {
+ unsigned numOptional = getGangNum() ? 1 : 0;
+ numOptional += getGangDim() ? 1 : 0;
+ numOptional += getGangStatic() ? 1 : 0;
+ numOptional += getVectorLength() ? 1 : 0;
+ numOptional += getWorkerNum() ? 1 : 0;
+ numOptional += getVectorLength() ? 1 : 0;
+ numOptional += getTileOperands().size();
+ numOptional += getCacheOperands().size();
+ return getOperand(numOptional + i);
+}
+
//===----------------------------------------------------------------------===//
// DataOp
//===----------------------------------------------------------------------===//
More information about the flang-commits
mailing list