Skip to content

Commit 3c477df

Browse files
committed
[Flang][OpenMP] Per-sym checks to introduce barriers
Whenever there is a `lastprivate` variable and another unrelated variable sets the `mightHaveReadHostSym` flag during Flang lowering privatization, this will result in the insertion of a barrier. This patch modifies this behavior such that this barrier will not be inserted unless it has to be the same variable to set the flag and be `lastprivate` for this to be done.
1 parent d2240cd commit 3c477df

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void DataSharingProcessor::cloneSymbol(const semantics::Symbol *sym) {
166166

167167
if (needInitClone()) {
168168
Fortran::lower::initializeCloneAtRuntime(converter, *sym, symTable);
169-
mightHaveReadHostSym = true;
169+
mightHaveReadHostSym.insert(sym);
170170
}
171171
}
172172

@@ -222,7 +222,7 @@ bool DataSharingProcessor::needBarrier() {
222222
for (const semantics::Symbol *sym : allPrivatizedSymbols) {
223223
if (sym->test(semantics::Symbol::Flag::OmpLastPrivate) &&
224224
(sym->test(semantics::Symbol::Flag::OmpFirstPrivate) ||
225-
mightHaveReadHostSym))
225+
mightHaveReadHostSym.contains(sym)))
226226
return true;
227227
}
228228
return false;
@@ -594,7 +594,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
594594
// TODO: currently there are false positives from dead uses of the mold
595595
// arg
596596
if (!result.getInitMoldArg().getUses().empty())
597-
mightHaveReadHostSym = true;
597+
mightHaveReadHostSym.insert(sym);
598598
}
599599

600600
// Populate the `copy` region if this is a `firstprivate`.

flang/lib/Lower/OpenMP/DataSharingProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class DataSharingProcessor {
8686
lower::pft::Evaluation &eval;
8787
bool shouldCollectPreDeterminedSymbols;
8888
bool useDelayedPrivatization;
89-
bool mightHaveReadHostSym = false;
89+
llvm::SmallSet<const semantics::Symbol *, 16> mightHaveReadHostSym;
9090
lower::SymMap &symTable;
9191
OMPConstructSymbolVisitor visitor;
9292

0 commit comments

Comments
 (0)