Skip to content

Commit 3683d41

Browse files
committed
Add methods to operation to test if the mold arg is read
1 parent 92b347c commit 3683d41

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
@@ -1767,20 +1767,6 @@ buildDependData(std::optional<ArrayAttr> dependKinds, OperandRange dependVars,
17671767
}
17681768
}
17691769

1770-
static bool privatizerReadsSourceVariable(omp::PrivateClauseOp &priv) {
1771-
if (priv.getDataSharingType() == omp::DataSharingClauseType::FirstPrivate)
1772-
return true;
1773-
1774-
Region &initRegion = priv.getInitRegion();
1775-
if (initRegion.empty())
1776-
return false;
1777-
1778-
BlockArgument sourceVariable = priv.getInitMoldArg();
1779-
if (!sourceVariable)
1780-
return false;
1781-
return !sourceVariable.use_empty();
1782-
}
1783-
17841770
namespace {
17851771
/// TaskContextStructManager takes care of creating and freeing a structure
17861772
/// containing information needed by the task body to execute.
@@ -1833,7 +1819,7 @@ void TaskContextStructManager::generateTaskContextStruct() {
18331819
for (omp::PrivateClauseOp &privOp : privateDecls) {
18341820
// Skip private variables which can safely be allocated and initialised
18351821
// inside of the task
1836-
if (!privatizerReadsSourceVariable(privOp))
1822+
if (!privOp.readsFromMold())
18371823
continue;
18381824
Type mlirType = privOp.getType();
18391825
privateVarTypes.push_back(moduleTranslation.convertType(mlirType));
@@ -1865,7 +1851,7 @@ void TaskContextStructManager::createGEPsToPrivateVars(
18651851
llvm::Value *zero = builder.getInt32(0);
18661852
unsigned i = 0;
18671853
for (auto privDecl : privateDecls) {
1868-
if (!privatizerReadsSourceVariable(privDecl)) {
1854+
if (!privDecl.readsFromMold()) {
18691855
// Handle this inside of the task so we don't pass unnessecary vars in
18701856
llvmPrivateVars.push_back(nullptr);
18711857
continue;
@@ -2020,7 +2006,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
20202006
llvm::BasicBlock *privInitBlock = nullptr;
20212007
for (auto [blockArg, privDecl, mlirPrivVar] :
20222008
llvm::zip_equal(privateBlockArgs, privateDecls, mlirPrivateVars)) {
2023-
if (privatizerReadsSourceVariable(privDecl))
2009+
if (privDecl.readsFromMold())
20242010
// This is handled before the task executes
20252011
continue;
20262012

0 commit comments

Comments
 (0)