Skip to content

Commit 3f02adf

Browse files
committed
Add methods to operation to test if the mold arg is read
1 parent 9a4fe6a commit 3f02adf

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
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() : false;
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

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,20 +1755,6 @@ buildDependData(std::optional<ArrayAttr> dependKinds, OperandRange dependVars,
17551755
}
17561756
}
17571757

1758-
static bool privatizerReadsSourceVariable(omp::PrivateClauseOp &priv) {
1759-
if (priv.getDataSharingType() == omp::DataSharingClauseType::FirstPrivate)
1760-
return true;
1761-
1762-
Region &initRegion = priv.getInitRegion();
1763-
if (initRegion.empty())
1764-
return false;
1765-
1766-
BlockArgument sourceVariable = priv.getInitMoldArg();
1767-
if (!sourceVariable)
1768-
return false;
1769-
return !sourceVariable.use_empty();
1770-
}
1771-
17721758
namespace {
17731759
/// TaskContextStructManager takes care of creating and freeing a structure
17741760
/// containing information needed by the task body to execute.
@@ -1821,7 +1807,7 @@ void TaskContextStructManager::generateTaskContextStruct() {
18211807
for (omp::PrivateClauseOp &privOp : privateDecls) {
18221808
// Skip private variables which can safely be allocated and initialised
18231809
// inside of the task
1824-
if (!privatizerReadsSourceVariable(privOp))
1810+
if (!privOp.readsFromMold())
18251811
continue;
18261812
Type mlirType = privOp.getType();
18271813
privateVarTypes.push_back(moduleTranslation.convertType(mlirType));
@@ -1853,7 +1839,7 @@ void TaskContextStructManager::createGEPsToPrivateVars(
18531839
llvm::Value *zero = builder.getInt32(0);
18541840
unsigned i = 0;
18551841
for (auto privDecl : privateDecls) {
1856-
if (!privatizerReadsSourceVariable(privDecl)) {
1842+
if (!privDecl.readsFromMold()) {
18571843
// Handle this inside of the task so we don't pass unnessecary vars in
18581844
llvmPrivateVars.push_back(nullptr);
18591845
continue;
@@ -2008,7 +1994,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
20081994
llvm::BasicBlock *privInitBlock = nullptr;
20091995
for (auto [blockArg, privDecl, mlirPrivVar] :
20101996
llvm::zip_equal(privateBlockArgs, privateDecls, mlirPrivateVars)) {
2011-
if (privatizerReadsSourceVariable(privDecl))
1997+
if (privDecl.readsFromMold())
20121998
// This is handled before the task executes
20131999
continue;
20142000

0 commit comments

Comments
 (0)