[Mlir-commits] [mlir] [mlir][OpenMP] Translate task_reduction on omp.taskgroup (PR #199565)
Sairudra More
llvmlistbot at llvm.org
Thu Jun 11 00:06:45 PDT 2026
================
@@ -3643,6 +3646,183 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
return success();
}
+/// Build an outlined init helper for a task_reduction declare_reduction op.
+/// Signature: void(ptr %priv, ptr %orig). For non-byref reductions, the init
+/// region's mold argument is mapped to the value loaded from %orig, and the
+/// yielded scalar is stored into %priv.
+static llvm::Function *
+emitTaskReductionInitFn(omp::DeclareReductionOp decl, StringRef baseName,
+ LLVM::ModuleTranslation &moduleTranslation) {
+ llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
+ llvm::LLVMContext &ctx = llvmModule->getContext();
+ llvm::Type *voidTy = llvm::Type::getVoidTy(ctx);
+ llvm::Type *ptrTy = llvm::PointerType::getUnqual(ctx);
+ llvm::FunctionType *fty =
+ llvm::FunctionType::get(voidTy, {ptrTy, ptrTy}, false);
+ llvm::Function *fn =
+ llvm::Function::Create(fty, llvm::GlobalValue::InternalLinkage,
+ baseName + ".red.init", llvmModule);
+ fn->setDoesNotRecurse();
+ fn->getArg(0)->setName("priv");
+ fn->getArg(1)->setName("orig");
+
+ llvm::BasicBlock *entry = llvm::BasicBlock::Create(ctx, "entry", fn);
+ llvm::IRBuilder<> b(entry);
+
+ llvm::Type *elemTy = moduleTranslation.convertType(decl.getType());
+ llvm::Value *origVal = b.CreateLoad(elemTy, fn->getArg(1), "omp.orig");
----------------
Saieiei wrote:
@MattPD, I updated the init helper to mirror the regular reduction path: it now loads from `%orig` only when the mold argument is non-pointer. For pointer-typed reductions, it forwards `%orig` directly, so the init helper lowers to `store ptr %orig, ptr %priv` without the spurious load.
I left the combiner unchanged after checking the regular reduction lowering, since the by-value combiner path also loads the pointer operands there. Added pointer-typed taskgroup reduction test coverage for this case.
https://github.com/llvm/llvm-project/pull/199565
More information about the Mlir-commits
mailing list