[llvm-branch-commits] [flang] [mlir] [mlir][OpenMP] Pack task private variables into a heap-allocated context struct (PR #125307)
Tom Eccles via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Feb 24 05:23:37 PST 2025
================
@@ -1794,37 +1909,118 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
moduleTranslation, allocaIP);
// Allocate and initialize private variables
- // TODO: package private variables up in a structure
builder.SetInsertPoint(initBlock->getTerminator());
- for (auto [privDecl, mlirPrivVar, blockArg] :
- llvm::zip_equal(privateDecls, mlirPrivateVars, privateBlockArgs)) {
- llvm::Type *llvmAllocType =
- moduleTranslation.convertType(privDecl.getType());
- // Allocations:
- builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
- llvm::Value *llvmPrivateVar = builder.CreateAlloca(
- llvmAllocType, /*ArraySize=*/nullptr, "omp.private.alloc");
+ // Create task variable structure
+ taskStructMgr.generateTaskContextStruct();
+ // GEPs so that we can initialize the variables. Don't use these GEPs inside
+ // of the body otherwise it will be the GEP not the struct which is fowarded
+ // to the outlined function. GEPs forwarded in this way are passed in a
+ // stack-allocated (by OpenMPIRBuilder) structure which is not safe for tasks
+ // which may not be executed until after the current stack frame goes out of
+ // scope.
+ taskStructMgr.createGEPsToPrivateVars();
+
+ for (auto [privDecl, mlirPrivVar, blockArg, llvmPrivateVarAlloc] :
+ llvm::zip_equal(privateDecls, mlirPrivateVars, privateBlockArgs,
+ taskStructMgr.getLLVMPrivateVarGEPs())) {
+ if (!privDecl.readsFromMold())
+ // to be handled inside the task
+ continue;
+ assert(llvmPrivateVarAlloc &&
+ "reads from mold so shouldn't have been skipped");
- auto err =
+ llvm::Expected<llvm::Value *> privateVarOrErr =
initPrivateVar(builder, moduleTranslation, privDecl, mlirPrivVar,
- blockArg, llvmPrivateVar, llvmPrivateVars, initBlock);
- if (err)
+ blockArg, llvmPrivateVarAlloc, initBlock);
+ if (auto err = privateVarOrErr.takeError())
----------------
tblah wrote:
Thanks. Fixed in [459d2d5](https://github.com/llvm/llvm-project/pull/125307/commits/459d2d5ea7f803cc6553b7d9007283281263f1fe)
This is a bit hard to find on the diff after the rebase unfortunately.
https://github.com/llvm/llvm-project/pull/125307
More information about the llvm-branch-commits
mailing list