Skip to content

Commit 3487dfc

Browse files
committed
Add methods to operation to test if the mold arg is read
1 parent d6d50cd commit 3487dfc

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
@@ -587,7 +587,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
587587
sym);
588588
// TODO: currently there are false positives from dead uses of the mold
589589
// arg
590-
if (!result.getInitMoldArg().getUses().empty())
590+
if (result.initReadsFromMold())
591591
mightHaveReadHostSym = true;
592592
}
593593

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
@@ -1730,20 +1730,6 @@ buildDependData(std::optional<ArrayAttr> dependKinds, OperandRange dependVars,
17301730
}
17311731
}
17321732

1733-
static bool privatizerReadsSourceVariable(omp::PrivateClauseOp &priv) {
1734-
if (priv.getDataSharingType() == omp::DataSharingClauseType::FirstPrivate)
1735-
return true;
1736-
1737-
Region &initRegion = priv.getInitRegion();
1738-
if (initRegion.empty())
1739-
return false;
1740-
1741-
BlockArgument sourceVariable = priv.getInitMoldArg();
1742-
if (!sourceVariable)
1743-
return false;
1744-
return !sourceVariable.use_empty();
1745-
}
1746-
17471733
namespace {
17481734
/// TaskContextStructManager takes care of creating and freeing a structure
17491735
/// containing information needed by the task body to execute.
@@ -1796,7 +1782,7 @@ void TaskContextStructManager::generateTaskContextStruct() {
17961782
for (omp::PrivateClauseOp &privOp : privateDecls) {
17971783
// Skip private variables which can safely be allocated and initialised
17981784
// inside of the task
1799-
if (!privatizerReadsSourceVariable(privOp))
1785+
if (!privOp.readsFromMold())
18001786
continue;
18011787
Type mlirType = privOp.getType();
18021788
privateVarTypes.push_back(moduleTranslation.convertType(mlirType));
@@ -1828,7 +1814,7 @@ void TaskContextStructManager::createGEPsToPrivateVars(
18281814
llvm::Value *zero = builder.getInt32(0);
18291815
unsigned i = 0;
18301816
for (auto privDecl : privateDecls) {
1831-
if (!privatizerReadsSourceVariable(privDecl)) {
1817+
if (!privDecl.readsFromMold()) {
18321818
// Handle this inside of the task so we don't pass unnessecary vars in
18331819
llvmPrivateVars.push_back(nullptr);
18341820
continue;
@@ -1984,7 +1970,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
19841970
llvm::BasicBlock *privInitBlock = nullptr;
19851971
for (auto [blockArg, privDecl, mlirPrivVar] :
19861972
llvm::zip_equal(privateBlockArgs, privateDecls, mlirPrivateVars)) {
1987-
if (privatizerReadsSourceVariable(privDecl))
1973+
if (privDecl.readsFromMold())
19881974
// This is handled before the task executes
19891975
continue;
19901976

0 commit comments

Comments
 (0)