[Mlir-commits] [mlir] d747f70 - [OpenACC] Add reduction recipe helper to ACC Dialect (#154566)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Aug 22 10:38:28 PDT 2025
Author: Erich Keane
Date: 2025-08-22T10:38:25-07:00
New Revision: d747f70d37315728fe9cef784a287f67e54bf533
URL: https://github.com/llvm/llvm-project/commit/d747f70d37315728fe9cef784a287f67e54bf533
DIFF: https://github.com/llvm/llvm-project/commit/d747f70d37315728fe9cef784a287f67e54bf533.diff
LOG: [OpenACC] Add reduction recipe helper to ACC Dialect (#154566)
Similar to how we did for private/firstprivate, these helper functions
should make generating the recipes for the Clang FE easier.
Added:
Modified:
mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 47646b3b8fec9..0db11aa9af683 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -1540,6 +1540,11 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
/// recipe.
void addFirstPrivatization(MLIRContext *, mlir::acc::FirstprivateOp op,
mlir::acc::FirstprivateRecipeOp recipe);
+
+ /// Adds a reduction clause variable to this operation, including its
+ /// recipe.
+ void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe);
}];
let assemblyFormat = [{
@@ -1689,6 +1694,10 @@ def OpenACC_SerialOp : OpenACC_Op<"serial",
/// recipe.
void addFirstPrivatization(MLIRContext *, mlir::acc::FirstprivateOp op,
mlir::acc::FirstprivateRecipeOp recipe);
+ /// Adds a reduction clause variable to this operation, including its
+ /// recipe.
+ void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe);
}];
let assemblyFormat = [{
@@ -2415,6 +2424,10 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
/// Adds a private clause variable to this operation, including its recipe.
void addPrivatization(MLIRContext *, mlir::acc::PrivateOp op,
mlir::acc::PrivateRecipeOp recipe);
+ /// Adds a reduction clause variable to this operation, including its
+ /// recipe.
+ void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe);
}];
let hasCustomAssemblyFormat = 1;
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index d7c8916f43a2c..5fd426eee1dfd 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -1404,6 +1404,22 @@ void acc::ParallelOp::addFirstPrivatization(
mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
setFirstprivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
}
+
+void acc::ParallelOp::addReduction(MLIRContext *context,
+ mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe) {
+ getReductionOperandsMutable().append(op.getResult());
+
+ llvm::SmallVector<mlir::Attribute> recipes;
+
+ if (getReductionRecipesAttr())
+ llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
+
+ recipes.push_back(
+ mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
+ setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
+}
+
static ParseResult parseNumGangs(
mlir::OpAsmParser &parser,
llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &operands,
@@ -2070,6 +2086,21 @@ void acc::SerialOp::addFirstPrivatization(
setFirstprivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
}
+void acc::SerialOp::addReduction(MLIRContext *context,
+ mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe) {
+ getReductionOperandsMutable().append(op.getResult());
+
+ llvm::SmallVector<mlir::Attribute> recipes;
+
+ if (getReductionRecipesAttr())
+ llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
+
+ recipes.push_back(
+ mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
+ setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
+}
+
//===----------------------------------------------------------------------===//
// KernelsOp
//===----------------------------------------------------------------------===//
@@ -3088,6 +3119,20 @@ void acc::LoopOp::addPrivatization(MLIRContext *context,
setPrivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
}
+void acc::LoopOp::addReduction(MLIRContext *context, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe) {
+ getReductionOperandsMutable().append(op.getResult());
+
+ llvm::SmallVector<mlir::Attribute> recipes;
+
+ if (getReductionRecipesAttr())
+ llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
+
+ recipes.push_back(
+ mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
+ setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
+}
+
//===----------------------------------------------------------------------===//
// DataOp
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list