[flang-commits] [flang] [Flang][OpenMP] Per-sym checks to introduce barriers (PR #127074)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Thu Feb 13 07:35:35 PST 2025
https://github.com/skatrak created https://github.com/llvm/llvm-project/pull/127074
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 the same symbol both sets the flag and has `lastprivate`.
>From 3c477dfd589d68c8a7046518f20bcb4c4e69d83b Mon Sep 17 00:00:00 2001
From: Sergio Afonso <safonsof at amd.com>
Date: Thu, 13 Feb 2025 15:30:12 +0000
Subject: [PATCH] [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.
---
flang/lib/Lower/OpenMP/DataSharingProcessor.cpp | 6 +++---
flang/lib/Lower/OpenMP/DataSharingProcessor.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index 55f543ca38178..d13f101f516e7 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
@@ -166,7 +166,7 @@ void DataSharingProcessor::cloneSymbol(const semantics::Symbol *sym) {
if (needInitClone()) {
Fortran::lower::initializeCloneAtRuntime(converter, *sym, symTable);
- mightHaveReadHostSym = true;
+ mightHaveReadHostSym.insert(sym);
}
}
@@ -222,7 +222,7 @@ bool DataSharingProcessor::needBarrier() {
for (const semantics::Symbol *sym : allPrivatizedSymbols) {
if (sym->test(semantics::Symbol::Flag::OmpLastPrivate) &&
(sym->test(semantics::Symbol::Flag::OmpFirstPrivate) ||
- mightHaveReadHostSym))
+ mightHaveReadHostSym.contains(sym)))
return true;
}
return false;
@@ -594,7 +594,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
// TODO: currently there are false positives from dead uses of the mold
// arg
if (!result.getInitMoldArg().getUses().empty())
- mightHaveReadHostSym = true;
+ mightHaveReadHostSym.insert(sym);
}
// Populate the `copy` region if this is a `firstprivate`.
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.h b/flang/lib/Lower/OpenMP/DataSharingProcessor.h
index 8e15c6d260389..54a42fd199831 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.h
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.h
@@ -86,7 +86,7 @@ class DataSharingProcessor {
lower::pft::Evaluation &eval;
bool shouldCollectPreDeterminedSymbols;
bool useDelayedPrivatization;
- bool mightHaveReadHostSym = false;
+ llvm::SmallSet<const semantics::Symbol *, 16> mightHaveReadHostSym;
lower::SymMap &symTable;
OMPConstructSymbolVisitor visitor;
More information about the flang-commits
mailing list