Skip to content

Commit d747f70

Browse files
authored
[OpenACC] Add reduction recipe helper to ACC Dialect (llvm#154566)
Similar to how we did for private/firstprivate, these helper functions should make generating the recipes for the Clang FE easier.
1 parent 9dbc133 commit d747f70

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,11 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
15401540
/// recipe.
15411541
void addFirstPrivatization(MLIRContext *, mlir::acc::FirstprivateOp op,
15421542
mlir::acc::FirstprivateRecipeOp recipe);
1543+
1544+
/// Adds a reduction clause variable to this operation, including its
1545+
/// recipe.
1546+
void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
1547+
mlir::acc::ReductionRecipeOp recipe);
15431548
}];
15441549

15451550
let assemblyFormat = [{
@@ -1689,6 +1694,10 @@ def OpenACC_SerialOp : OpenACC_Op<"serial",
16891694
/// recipe.
16901695
void addFirstPrivatization(MLIRContext *, mlir::acc::FirstprivateOp op,
16911696
mlir::acc::FirstprivateRecipeOp recipe);
1697+
/// Adds a reduction clause variable to this operation, including its
1698+
/// recipe.
1699+
void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
1700+
mlir::acc::ReductionRecipeOp recipe);
16921701
}];
16931702

16941703
let assemblyFormat = [{
@@ -2415,6 +2424,10 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
24152424
/// Adds a private clause variable to this operation, including its recipe.
24162425
void addPrivatization(MLIRContext *, mlir::acc::PrivateOp op,
24172426
mlir::acc::PrivateRecipeOp recipe);
2427+
/// Adds a reduction clause variable to this operation, including its
2428+
/// recipe.
2429+
void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
2430+
mlir::acc::ReductionRecipeOp recipe);
24182431
}];
24192432

24202433
let hasCustomAssemblyFormat = 1;

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,22 @@ void acc::ParallelOp::addFirstPrivatization(
14041404
mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
14051405
setFirstprivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
14061406
}
1407+
1408+
void acc::ParallelOp::addReduction(MLIRContext *context,
1409+
mlir::acc::ReductionOp op,
1410+
mlir::acc::ReductionRecipeOp recipe) {
1411+
getReductionOperandsMutable().append(op.getResult());
1412+
1413+
llvm::SmallVector<mlir::Attribute> recipes;
1414+
1415+
if (getReductionRecipesAttr())
1416+
llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
1417+
1418+
recipes.push_back(
1419+
mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
1420+
setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
1421+
}
1422+
14071423
static ParseResult parseNumGangs(
14081424
mlir::OpAsmParser &parser,
14091425
llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &operands,
@@ -2070,6 +2086,21 @@ void acc::SerialOp::addFirstPrivatization(
20702086
setFirstprivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
20712087
}
20722088

2089+
void acc::SerialOp::addReduction(MLIRContext *context,
2090+
mlir::acc::ReductionOp op,
2091+
mlir::acc::ReductionRecipeOp recipe) {
2092+
getReductionOperandsMutable().append(op.getResult());
2093+
2094+
llvm::SmallVector<mlir::Attribute> recipes;
2095+
2096+
if (getReductionRecipesAttr())
2097+
llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
2098+
2099+
recipes.push_back(
2100+
mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
2101+
setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
2102+
}
2103+
20732104
//===----------------------------------------------------------------------===//
20742105
// KernelsOp
20752106
//===----------------------------------------------------------------------===//
@@ -3088,6 +3119,20 @@ void acc::LoopOp::addPrivatization(MLIRContext *context,
30883119
setPrivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
30893120
}
30903121

3122+
void acc::LoopOp::addReduction(MLIRContext *context, mlir::acc::ReductionOp op,
3123+
mlir::acc::ReductionRecipeOp recipe) {
3124+
getReductionOperandsMutable().append(op.getResult());
3125+
3126+
llvm::SmallVector<mlir::Attribute> recipes;
3127+
3128+
if (getReductionRecipesAttr())
3129+
llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
3130+
3131+
recipes.push_back(
3132+
mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
3133+
setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
3134+
}
3135+
30913136
//===----------------------------------------------------------------------===//
30923137
// DataOp
30933138
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)