Skip to content

Commit db48d49

Browse files
authored
[mlir][OpenMP] Pack task private variables into a heap-allocated context struct (#125307)
See RFC: https://discourse.llvm.org/t/rfc-openmp-supporting-delayed-task-execution-with-firstprivate-variables/83084 The aim here is to ensure that tasks which are not executed for a while after they are created do not try to reference any data which are now out of scope. This is done by packing the data referred to by the task into a heap allocated structure (freed at the end of the task). I decided to create the task context structure in OpenMPToLLVMIRTranslation instead of adapting how it is done CodeExtractor (via OpenMPIRBuilder] because CodeExtractor is (at least in theory) generic code which could have other unrelated uses.
1 parent fcc8802 commit db48d49

File tree

5 files changed

+353
-49
lines changed

5 files changed

+353
-49
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
594594
sym, cannotHaveNonDefaultLowerBounds);
595595
// TODO: currently there are false positives from dead uses of the mold
596596
// arg
597-
if (!result.getInitMoldArg().getUses().empty())
597+
if (result.initReadsFromMold())
598598
mightHaveReadHostSym.insert(sym);
599599
}
600600

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,24 @@ def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove, RecipeInterface]>
146146
return region.empty() ? nullptr : region.getArgument(0);
147147
}
148148

149+
/// Returns true if the init region might read from the mold argument
150+
bool initReadsFromMold() {
151+
BlockArgument moldArg = getInitMoldArg();
152+
return moldArg && !moldArg.use_empty();
153+
}
154+
155+
/// Returns true if any region of this privatizer might read from the mold
156+
/// argument
157+
bool readsFromMold() {
158+
return initReadsFromMold() || !getCopyRegion().empty();
159+
}
160+
149161
/// needsMap returns true if the value being privatized should additionally
150162
/// be mapped to the target region using a MapInfoOp. This is most common
151163
/// when an allocatable is privatized. In such cases, the descriptor is used
152164
/// in privatization and needs to be mapped on to the device.
153165
bool needsMap() {
154-
BlockArgument moldArg = getInitMoldArg();
155-
return moldArg ? !moldArg.use_empty() : false;
166+
return initReadsFromMold();
156167
}
157168

158169
/// Get the type for arguments to nested regions. This should

0 commit comments

Comments
 (0)