Skip to content

Commit c11820a

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 32001b7 commit c11820a

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
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

flang/test/Lower/OpenMP/different_vars_lastprivate_barrier.f90

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ subroutine first_and_lastprivate
2222

2323
! CHECK: omp.private {type = private} @[[I_PRIVATIZER:.*Ei_private_i32]] : i32
2424

25-
! CHECK: func.func @{{.*}}first_and_lastprivate()
26-
! CHECK: %[[ORIG_I_DECL:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "{{.*}}Ei"}
27-
! CHECK: omp.parallel {
28-
! CHECK: omp.barrier
29-
! CHECK: omp.wsloop private(@[[I_PRIVATIZER]] %[[ORIG_I_DECL]]#0 -> %[[I_ARG:.*]], @[[VAR_PRIVATIZER]] {{.*}}) {
30-
! CHECK: omp.loop_nest {{.*}} {
31-
! CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[I_ARG]] {uniq_name = "{{.*}}Ei"}
32-
! CHECK: fir.if %{{.*}} {
33-
! CHECK: %[[PRIV_I_VAL:.*]] = fir.load %[[PRIV_I_DECL]]#0 : !fir.ref<i32>
34-
! CHECK: hlfir.assign %[[PRIV_I_VAL]] to %[[ORIG_I_DECL]]#0
25+
! CHECK: func.func @{{.*}}first_and_lastprivate()
26+
! CHECK: %[[ORIG_I_DECL:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "{{.*}}Ei"}
27+
! CHECK: omp.parallel {
28+
! CHECK-NOT: omp.barrier
29+
! CHECK: omp.wsloop private(@[[I_PRIVATIZER]] %[[ORIG_I_DECL]]#0 -> %[[I_ARG:.*]], @[[VAR_PRIVATIZER]] {{.*}}) {
30+
! CHECK: omp.loop_nest {{.*}} {
31+
! CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[I_ARG]] {uniq_name = "{{.*}}Ei"}
32+
! CHECK: fir.if %{{.*}} {
33+
! CHECK: %[[PRIV_I_VAL:.*]] = fir.load %[[PRIV_I_DECL]]#0 : !fir.ref<i32>
34+
! CHECK: hlfir.assign %[[PRIV_I_VAL]] to %[[ORIG_I_DECL]]#0
35+
! CHECK: }
36+
! CHECK: omp.yield
37+
! CHECK: }
3538
! CHECK: }
36-
! CHECK: omp.yield
39+
! CHECK: omp.terminator
3740
! CHECK: }
38-
! CHECK: }
39-
! CHECK: omp.terminator
40-
! CHECK: }

0 commit comments

Comments
 (0)