@@ -1458,7 +1458,7 @@ static LogicalResult
14581458copyFirstPrivateVars (llvm::IRBuilderBase &builder,
14591459 LLVM::ModuleTranslation &moduleTranslation,
14601460 SmallVectorImpl<mlir::Value> &mlirPrivateVars,
1461- SmallVectorImpl <llvm::Value *> & llvmPrivateVars,
1461+ ArrayRef <llvm::Value *> llvmPrivateVars,
14621462 SmallVectorImpl<omp::PrivateClauseOp> &privateDecls) {
14631463 // Apply copy region for firstprivate.
14641464 bool needsFirstprivate =
@@ -1776,11 +1776,15 @@ class TaskContextStructManager {
17761776 // / variable, adding them to llvmPrivateVars. Null values are added where
17771777 // / private decls were skipped so that the ordering continues to match the
17781778 // / private decls.
1779- void createGEPsToPrivateVars (SmallVectorImpl<llvm::Value *> &llvmPrivateVars );
1779+ void createGEPsToPrivateVars ();
17801780
17811781 // / De-allocate the task context structure.
17821782 void freeStructPtr ();
17831783
1784+ MutableArrayRef<llvm::Value *> getLLVMPrivateVars () {
1785+ return llvmPrivateVars;
1786+ }
1787+
17841788 llvm::Value *getStructPtr () { return structPtr; }
17851789
17861790private:
@@ -1791,6 +1795,10 @@ class TaskContextStructManager {
17911795 // / The type of each member of the structure, in order.
17921796 SmallVector<llvm::Type *> privateVarTypes;
17931797
1798+ // / LLVM values for each private variable, or null if that private variable is
1799+ // / not included in the task context structure
1800+ SmallVector<llvm::Value *> llvmPrivateVars;
1801+
17941802 // / A pointer to the structure containing context for this task.
17951803 llvm::Value *structPtr = nullptr ;
17961804 // / The type of the structure
@@ -1826,14 +1834,14 @@ void TaskContextStructManager::generateTaskContextStruct() {
18261834 " omp.task.context_ptr" );
18271835}
18281836
1829- void TaskContextStructManager::createGEPsToPrivateVars (
1830- SmallVectorImpl<llvm::Value *> &llvmPrivateVars) {
1837+ void TaskContextStructManager::createGEPsToPrivateVars () {
18311838 if (!structPtr) {
18321839 assert (privateVarTypes.empty ());
18331840 return ;
18341841 }
18351842
18361843 // Create GEPs for each struct member and initialize llvmPrivateVars to point
1844+ llvmPrivateVars.clear ();
18371845 llvmPrivateVars.reserve (privateVarTypes.size ());
18381846 llvm::Value *zero = builder.getInt32 (0 );
18391847 unsigned i = 0 ;
@@ -1929,19 +1937,18 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19291937 builder.SetInsertPoint (initBlock->getTerminator ());
19301938
19311939 // Create task variable structure
1932- llvm::SmallVector<llvm::Value *> privateVarAllocations;
19331940 taskStructMgr.generateTaskContextStruct ();
19341941 // GEPs so that we can initialize the variables. Don't use these GEPs inside
19351942 // of the body otherwise it will be the GEP not the struct which is fowarded
19361943 // to the outlined function. GEPs forwarded in this way are passed in a
19371944 // stack-allocated (by OpenMPIRBuilder) structure which is not safe for tasks
19381945 // which may not be executed until after the current stack frame goes out of
19391946 // scope.
1940- taskStructMgr.createGEPsToPrivateVars (privateVarAllocations );
1947+ taskStructMgr.createGEPsToPrivateVars ();
19411948
19421949 for (auto [privDecl, mlirPrivVar, blockArg, llvmPrivateVarAlloc] :
19431950 llvm::zip_equal (privateDecls, mlirPrivateVars, privateBlockArgs,
1944- privateVarAllocations )) {
1951+ taskStructMgr. getLLVMPrivateVars () )) {
19451952 if (!privDecl.readsFromMold ())
19461953 // to be handled inside the task
19471954 continue ;
@@ -1976,7 +1983,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19761983 // firstprivate copy region
19771984 setInsertPointForPossiblyEmptyBlock (builder, copyBlock);
19781985 if (failed (copyFirstPrivateVars (builder, moduleTranslation, mlirPrivateVars,
1979- privateVarAllocations, privateDecls)))
1986+ taskStructMgr.getLLVMPrivateVars (),
1987+ privateDecls)))
19801988 return llvm::failure ();
19811989
19821990 // Set up for call to createTask()
@@ -2017,7 +2025,9 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
20172025
20182026 // Find and map the addresses of each variable within the task context
20192027 // structure
2020- taskStructMgr.createGEPsToPrivateVars (llvmPrivateVars);
2028+ taskStructMgr.createGEPsToPrivateVars ();
2029+ llvm::copy (taskStructMgr.getLLVMPrivateVars (),
2030+ std::back_inserter (llvmPrivateVars));
20212031 for (auto [blockArg, llvmPrivateVar] :
20222032 llvm::zip_equal (privateBlockArgs, llvmPrivateVars)) {
20232033 if (!llvmPrivateVar)
0 commit comments