@@ -1428,7 +1428,7 @@ static LogicalResult
1428
1428
initFirstPrivateVars (llvm::IRBuilderBase &builder,
1429
1429
LLVM::ModuleTranslation &moduleTranslation,
1430
1430
SmallVectorImpl<mlir::Value> &mlirPrivateVars,
1431
- SmallVectorImpl <llvm::Value *> & llvmPrivateVars,
1431
+ ArrayRef <llvm::Value *> llvmPrivateVars,
1432
1432
SmallVectorImpl<omp::PrivateClauseOp> &privateDecls,
1433
1433
llvm::BasicBlock *afterAllocas) {
1434
1434
llvm::IRBuilderBase::InsertPointGuard guard (builder);
@@ -1751,11 +1751,15 @@ class TaskContextStructManager {
1751
1751
// / variable, adding them to llvmPrivateVars. Null values are added where
1752
1752
// / private decls were skipped so that the ordering continues to match the
1753
1753
// / private decls.
1754
- void createGEPsToPrivateVars (SmallVectorImpl<llvm::Value *> &llvmPrivateVars );
1754
+ void createGEPsToPrivateVars ();
1755
1755
1756
1756
// / De-allocate the task context structure.
1757
1757
void freeStructPtr ();
1758
1758
1759
+ MutableArrayRef<llvm::Value *> getLLVMPrivateVars () {
1760
+ return llvmPrivateVars;
1761
+ }
1762
+
1759
1763
llvm::Value *getStructPtr () { return structPtr; }
1760
1764
1761
1765
private:
@@ -1766,6 +1770,10 @@ class TaskContextStructManager {
1766
1770
// / The type of each member of the structure, in order.
1767
1771
SmallVector<llvm::Type *> privateVarTypes;
1768
1772
1773
+ // / LLVM values for each private variable, or null if that private variable is
1774
+ // / not included in the task context structure
1775
+ SmallVector<llvm::Value *> llvmPrivateVars;
1776
+
1769
1777
// / A pointer to the structure containing context for this task.
1770
1778
llvm::Value *structPtr = nullptr ;
1771
1779
// / The type of the structure
@@ -1801,14 +1809,14 @@ void TaskContextStructManager::generateTaskContextStruct() {
1801
1809
" omp.task.context_ptr" );
1802
1810
}
1803
1811
1804
- void TaskContextStructManager::createGEPsToPrivateVars (
1805
- SmallVectorImpl<llvm::Value *> &llvmPrivateVars) {
1812
+ void TaskContextStructManager::createGEPsToPrivateVars () {
1806
1813
if (!structPtr) {
1807
1814
assert (privateVarTypes.empty ());
1808
1815
return ;
1809
1816
}
1810
1817
1811
1818
// Create GEPs for each struct member and initialize llvmPrivateVars to point
1819
+ llvmPrivateVars.clear ();
1812
1820
llvmPrivateVars.reserve (privateVarTypes.size ());
1813
1821
llvm::Value *zero = builder.getInt32 (0 );
1814
1822
unsigned i = 0 ;
@@ -1904,19 +1912,18 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
1904
1912
builder.SetInsertPoint (initBlock->getTerminator ());
1905
1913
1906
1914
// Create task variable structure
1907
- llvm::SmallVector<llvm::Value *> privateVarAllocations;
1908
1915
taskStructMgr.generateTaskContextStruct ();
1909
1916
// GEPs so that we can initialize the variables. Don't use these GEPs inside
1910
1917
// of the body otherwise it will be the GEP not the struct which is fowarded
1911
1918
// to the outlined function. GEPs forwarded in this way are passed in a
1912
1919
// stack-allocated (by OpenMPIRBuilder) structure which is not safe for tasks
1913
1920
// which may not be executed until after the current stack frame goes out of
1914
1921
// scope.
1915
- taskStructMgr.createGEPsToPrivateVars (privateVarAllocations );
1922
+ taskStructMgr.createGEPsToPrivateVars ();
1916
1923
1917
1924
for (auto [privDecl, mlirPrivVar, blockArg, llvmPrivateVarAlloc] :
1918
1925
llvm::zip_equal (privateDecls, mlirPrivateVars, privateBlockArgs,
1919
- privateVarAllocations )) {
1926
+ taskStructMgr. getLLVMPrivateVars () )) {
1920
1927
if (!privDecl.readsFromMold ())
1921
1928
// to be handled inside the task
1922
1929
continue ;
@@ -1950,8 +1957,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
1950
1957
1951
1958
// firstprivate copy region
1952
1959
if (failed (initFirstPrivateVars (builder, moduleTranslation, mlirPrivateVars,
1953
- privateVarAllocations, privateDecls ,
1954
- copyBlock)))
1960
+ taskStructMgr. getLLVMPrivateVars () ,
1961
+ privateDecls, copyBlock)))
1955
1962
return llvm::failure ();
1956
1963
1957
1964
// Set up for call to createTask()
@@ -1992,7 +1999,9 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
1992
1999
1993
2000
// Find and map the addresses of each variable within the task context
1994
2001
// structure
1995
- taskStructMgr.createGEPsToPrivateVars (llvmPrivateVars);
2002
+ taskStructMgr.createGEPsToPrivateVars ();
2003
+ llvm::copy (taskStructMgr.getLLVMPrivateVars (),
2004
+ std::back_inserter (llvmPrivateVars));
1996
2005
for (auto [blockArg, llvmPrivateVar] :
1997
2006
llvm::zip_equal (privateBlockArgs, llvmPrivateVars)) {
1998
2007
if (!llvmPrivateVar)
0 commit comments