@@ -1470,7 +1470,7 @@ static LogicalResult
14701470copyFirstPrivateVars (llvm::IRBuilderBase &builder,
14711471 LLVM::ModuleTranslation &moduleTranslation,
14721472 SmallVectorImpl<mlir::Value> &mlirPrivateVars,
1473- SmallVectorImpl <llvm::Value *> & llvmPrivateVars,
1473+ ArrayRef <llvm::Value *> llvmPrivateVars,
14741474 SmallVectorImpl<omp::PrivateClauseOp> &privateDecls) {
14751475 // Apply copy region for firstprivate.
14761476 bool needsFirstprivate =
@@ -1788,11 +1788,15 @@ class TaskContextStructManager {
17881788 // / variable, adding them to llvmPrivateVars. Null values are added where
17891789 // / private decls were skipped so that the ordering continues to match the
17901790 // / private decls.
1791- void createGEPsToPrivateVars (SmallVectorImpl<llvm::Value *> &llvmPrivateVars );
1791+ void createGEPsToPrivateVars ();
17921792
17931793 // / De-allocate the task context structure.
17941794 void freeStructPtr ();
17951795
1796+ MutableArrayRef<llvm::Value *> getLLVMPrivateVars () {
1797+ return llvmPrivateVars;
1798+ }
1799+
17961800 llvm::Value *getStructPtr () { return structPtr; }
17971801
17981802private:
@@ -1803,6 +1807,10 @@ class TaskContextStructManager {
18031807 // / The type of each member of the structure, in order.
18041808 SmallVector<llvm::Type *> privateVarTypes;
18051809
1810+ // / LLVM values for each private variable, or null if that private variable is
1811+ // / not included in the task context structure
1812+ SmallVector<llvm::Value *> llvmPrivateVars;
1813+
18061814 // / A pointer to the structure containing context for this task.
18071815 llvm::Value *structPtr = nullptr ;
18081816 // / The type of the structure
@@ -1838,14 +1846,14 @@ void TaskContextStructManager::generateTaskContextStruct() {
18381846 " omp.task.context_ptr" );
18391847}
18401848
1841- void TaskContextStructManager::createGEPsToPrivateVars (
1842- SmallVectorImpl<llvm::Value *> &llvmPrivateVars) {
1849+ void TaskContextStructManager::createGEPsToPrivateVars () {
18431850 if (!structPtr) {
18441851 assert (privateVarTypes.empty ());
18451852 return ;
18461853 }
18471854
18481855 // Create GEPs for each struct member and initialize llvmPrivateVars to point
1856+ llvmPrivateVars.clear ();
18491857 llvmPrivateVars.reserve (privateVarTypes.size ());
18501858 llvm::Value *zero = builder.getInt32 (0 );
18511859 unsigned i = 0 ;
@@ -1941,19 +1949,18 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19411949 builder.SetInsertPoint (initBlock->getTerminator ());
19421950
19431951 // Create task variable structure
1944- llvm::SmallVector<llvm::Value *> privateVarAllocations;
19451952 taskStructMgr.generateTaskContextStruct ();
19461953 // GEPs so that we can initialize the variables. Don't use these GEPs inside
19471954 // of the body otherwise it will be the GEP not the struct which is fowarded
19481955 // to the outlined function. GEPs forwarded in this way are passed in a
19491956 // stack-allocated (by OpenMPIRBuilder) structure which is not safe for tasks
19501957 // which may not be executed until after the current stack frame goes out of
19511958 // scope.
1952- taskStructMgr.createGEPsToPrivateVars (privateVarAllocations );
1959+ taskStructMgr.createGEPsToPrivateVars ();
19531960
19541961 for (auto [privDecl, mlirPrivVar, blockArg, llvmPrivateVarAlloc] :
19551962 llvm::zip_equal (privateDecls, mlirPrivateVars, privateBlockArgs,
1956- privateVarAllocations )) {
1963+ taskStructMgr. getLLVMPrivateVars () )) {
19571964 if (!privDecl.readsFromMold ())
19581965 // to be handled inside the task
19591966 continue ;
@@ -1988,7 +1995,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19881995 // firstprivate copy region
19891996 setInsertPointForPossiblyEmptyBlock (builder, copyBlock);
19901997 if (failed (copyFirstPrivateVars (builder, moduleTranslation, mlirPrivateVars,
1991- privateVarAllocations, privateDecls)))
1998+ taskStructMgr.getLLVMPrivateVars (),
1999+ privateDecls)))
19922000 return llvm::failure ();
19932001
19942002 // Set up for call to createTask()
@@ -2029,7 +2037,9 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
20292037
20302038 // Find and map the addresses of each variable within the task context
20312039 // structure
2032- taskStructMgr.createGEPsToPrivateVars (llvmPrivateVars);
2040+ taskStructMgr.createGEPsToPrivateVars ();
2041+ llvm::copy (taskStructMgr.getLLVMPrivateVars (),
2042+ std::back_inserter (llvmPrivateVars));
20332043 for (auto [blockArg, llvmPrivateVar] :
20342044 llvm::zip_equal (privateBlockArgs, llvmPrivateVars)) {
20352045 if (!llvmPrivateVar)
0 commit comments