[Mlir-commits] [mlir] [mlir] Translating task_reduction clause for pass-by-value vars to LLVMIR (PR #125218)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 2 05:11:33 PST 2026
================
@@ -2469,6 +2473,228 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
return success();
}
+template <typename OP>
+static llvm::Value *createTaskReductionFunction(
+ llvm::IRBuilderBase &builder, const std::string &name, llvm::Type *redTy,
+ LLVM::ModuleTranslation &moduleTranslation,
+ SmallVectorImpl<omp::DeclareReductionOp> &reductionDecls, Region ®ion,
+ OP &op, unsigned cnt,
+ SmallVectorImpl<llvm::Value *> &privateReductionVariables,
+ DenseMap<Value, llvm::Value *> &reductionVariableMap) {
+
+ llvm::LLVMContext &Context = builder.getContext();
+ // TODO: by-ref reduction variables are yet to be handled.
+ llvm::Type *OpaquePtrTy = llvm::PointerType::get(Context, 0);
+ if (region.empty() && name == "red_fini")
+ // Finalization is optional for reductions.
+ return llvm::Constant::getNullValue(OpaquePtrTy);
+
+ // Prepare a general structure of the function to be emitted
+ llvm::FunctionType *funcType =
+ llvm::FunctionType::get(OpaquePtrTy, {OpaquePtrTy, OpaquePtrTy}, false);
+ llvm::Function *function =
+ llvm::Function::Create(funcType, llvm::Function::ExternalLinkage, name,
+ builder.GetInsertBlock()->getModule());
+ function->setDoesNotRecurse();
+ llvm::BasicBlock *entry =
+ llvm::BasicBlock::Create(Context, "entry", function);
+ llvm::IRBuilder<> bbBuilder(entry);
+
+ // Prepare the function arguments
+ llvm::Value *arg0 = function->getArg(0);
+ llvm::Value *arg1 = function->getArg(1);
+
+ if (name == "red_init") {
+ // For the initialization, map the reduction variables
+ // to the arguments of the function
+ function->addParamAttr(0, llvm::Attribute::NoAlias);
+ function->addParamAttr(1, llvm::Attribute::NoAlias);
+ mlir::omp::DeclareReductionOp &reduction = reductionDecls[cnt];
+ Region &initializerRegion = reduction.getInitializerRegion();
+ Block &entry = initializerRegion.front();
+
+ mlir::Value mlirSource = op.getTaskReductionVars()[cnt];
+ llvm::Value *llvmSource = moduleTranslation.lookupValue(mlirSource);
+ llvm::Value *origVal = llvmSource;
+
+ moduleTranslation.mapValue(reduction.getInitializerMoldArg(), origVal);
+
+ if (entry.getNumArguments() > 1) {
+ llvm::Value *allocation =
+ reductionVariableMap.lookup(op.getReductionVars()[cnt]);
----------------
NimishMishra wrote:
Thanks, yes it should be getTaskReductionVars; I have modified the same.
https://github.com/llvm/llvm-project/pull/125218
More information about the Mlir-commits
mailing list