Skip to content

Commit dd07fa7

Browse files
committed
Move llvm private vars into task context struct manager
1 parent 9baebf1 commit dd07fa7

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ static LogicalResult
14281428
initFirstPrivateVars(llvm::IRBuilderBase &builder,
14291429
LLVM::ModuleTranslation &moduleTranslation,
14301430
SmallVectorImpl<mlir::Value> &mlirPrivateVars,
1431-
SmallVectorImpl<llvm::Value *> &llvmPrivateVars,
1431+
ArrayRef<llvm::Value *> llvmPrivateVars,
14321432
SmallVectorImpl<omp::PrivateClauseOp> &privateDecls,
14331433
llvm::BasicBlock *afterAllocas) {
14341434
llvm::IRBuilderBase::InsertPointGuard guard(builder);
@@ -1751,11 +1751,15 @@ class TaskContextStructManager {
17511751
/// variable, adding them to llvmPrivateVars. Null values are added where
17521752
/// private decls were skipped so that the ordering continues to match the
17531753
/// private decls.
1754-
void createGEPsToPrivateVars(SmallVectorImpl<llvm::Value *> &llvmPrivateVars);
1754+
void createGEPsToPrivateVars();
17551755

17561756
/// De-allocate the task context structure.
17571757
void freeStructPtr();
17581758

1759+
MutableArrayRef<llvm::Value *> getLLVMPrivateVars() {
1760+
return llvmPrivateVars;
1761+
}
1762+
17591763
llvm::Value *getStructPtr() { return structPtr; }
17601764

17611765
private:
@@ -1766,6 +1770,10 @@ class TaskContextStructManager {
17661770
/// The type of each member of the structure, in order.
17671771
SmallVector<llvm::Type *> privateVarTypes;
17681772

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+
17691777
/// A pointer to the structure containing context for this task.
17701778
llvm::Value *structPtr = nullptr;
17711779
/// The type of the structure
@@ -1801,14 +1809,14 @@ void TaskContextStructManager::generateTaskContextStruct() {
18011809
"omp.task.context_ptr");
18021810
}
18031811

1804-
void TaskContextStructManager::createGEPsToPrivateVars(
1805-
SmallVectorImpl<llvm::Value *> &llvmPrivateVars) {
1812+
void TaskContextStructManager::createGEPsToPrivateVars() {
18061813
if (!structPtr) {
18071814
assert(privateVarTypes.empty());
18081815
return;
18091816
}
18101817

18111818
// Create GEPs for each struct member and initialize llvmPrivateVars to point
1819+
llvmPrivateVars.clear();
18121820
llvmPrivateVars.reserve(privateVarTypes.size());
18131821
llvm::Value *zero = builder.getInt32(0);
18141822
unsigned i = 0;
@@ -1904,19 +1912,18 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19041912
builder.SetInsertPoint(initBlock->getTerminator());
19051913

19061914
// Create task variable structure
1907-
llvm::SmallVector<llvm::Value *> privateVarAllocations;
19081915
taskStructMgr.generateTaskContextStruct();
19091916
// GEPs so that we can initialize the variables. Don't use these GEPs inside
19101917
// of the body otherwise it will be the GEP not the struct which is fowarded
19111918
// to the outlined function. GEPs forwarded in this way are passed in a
19121919
// stack-allocated (by OpenMPIRBuilder) structure which is not safe for tasks
19131920
// which may not be executed until after the current stack frame goes out of
19141921
// scope.
1915-
taskStructMgr.createGEPsToPrivateVars(privateVarAllocations);
1922+
taskStructMgr.createGEPsToPrivateVars();
19161923

19171924
for (auto [privDecl, mlirPrivVar, blockArg, llvmPrivateVarAlloc] :
19181925
llvm::zip_equal(privateDecls, mlirPrivateVars, privateBlockArgs,
1919-
privateVarAllocations)) {
1926+
taskStructMgr.getLLVMPrivateVars())) {
19201927
if (!privDecl.readsFromMold())
19211928
// to be handled inside the task
19221929
continue;
@@ -1950,8 +1957,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19501957

19511958
// firstprivate copy region
19521959
if (failed(initFirstPrivateVars(builder, moduleTranslation, mlirPrivateVars,
1953-
privateVarAllocations, privateDecls,
1954-
copyBlock)))
1960+
taskStructMgr.getLLVMPrivateVars(),
1961+
privateDecls, copyBlock)))
19551962
return llvm::failure();
19561963

19571964
// Set up for call to createTask()
@@ -1992,7 +1999,9 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19921999

19932000
// Find and map the addresses of each variable within the task context
19942001
// structure
1995-
taskStructMgr.createGEPsToPrivateVars(llvmPrivateVars);
2002+
taskStructMgr.createGEPsToPrivateVars();
2003+
llvm::copy(taskStructMgr.getLLVMPrivateVars(),
2004+
std::back_inserter(llvmPrivateVars));
19962005
for (auto [blockArg, llvmPrivateVar] :
19972006
llvm::zip_equal(privateBlockArgs, llvmPrivateVars)) {
19982007
if (!llvmPrivateVar)

0 commit comments

Comments
 (0)