[flang-commits] [flang] [flang][OpenMP][NFC] Share SetSymbolDSA between semantics and lowering (PR #207826)
via flang-commits
flang-commits at lists.llvm.org
Tue Jul 7 10:53:12 PDT 2026
https://github.com/chichunchen updated https://github.com/llvm/llvm-project/pull/207826
>From 65510ba80540c197b029baa9bdf68387c63a133f Mon Sep 17 00:00:00 2001
From: "Chi Chun, Chen" <chichun.chen at hpe.com>
Date: Thu, 2 Jul 2026 16:26:35 -0500
Subject: [PATCH] [flang][OpenMP][NFC] Share SetSymbolDSA between semantics and
lowering
Move the DSA helper from the private OmpAttributeVisitor::SetSymbolDSA into the
public openmp-dsa header next to GetSymbolDSA, and share the DSA flag set
through a single GetDataSharingAttributeFlags().
This lets an upcoming metadirective lowering change reuse the helper to set the
predetermined DSA of the loop induction variables of a selected variant. A
loop-associated variant is resolved during lowering, so the usual semantic DSA
resolution never runs on its loop nest and lowering must set those flags itself.
Assisted with Copilot.
---
flang/include/flang/Semantics/openmp-dsa.h | 4 ++++
flang/lib/Semantics/openmp-dsa.cpp | 22 +++++++++++++++++-----
flang/lib/Semantics/resolve-directives.cpp | 15 +--------------
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/flang/include/flang/Semantics/openmp-dsa.h b/flang/include/flang/Semantics/openmp-dsa.h
index 4b94a679f29ef..a6e15ff965b29 100644
--- a/flang/include/flang/Semantics/openmp-dsa.h
+++ b/flang/include/flang/Semantics/openmp-dsa.h
@@ -13,8 +13,12 @@
namespace Fortran::semantics {
+Symbol::Flags GetDataSharingAttributeFlags();
+
Symbol::Flags GetSymbolDSA(const Symbol &symbol);
+void SetSymbolDSA(Symbol &symbol, Symbol::Flags flags);
+
} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_OPENMP_DSA_H_
diff --git a/flang/lib/Semantics/openmp-dsa.cpp b/flang/lib/Semantics/openmp-dsa.cpp
index 48aa36febe5c5..7aa5bf9c200b4 100644
--- a/flang/lib/Semantics/openmp-dsa.cpp
+++ b/flang/lib/Semantics/openmp-dsa.cpp
@@ -10,12 +10,14 @@
namespace Fortran::semantics {
-Symbol::Flags GetSymbolDSA(const Symbol &symbol) {
- Symbol::Flags dsaFlags{Symbol::Flag::OmpPrivate,
+Symbol::Flags GetDataSharingAttributeFlags() {
+ return Symbol::Flags{Symbol::Flag::OmpShared, Symbol::Flag::OmpPrivate,
Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
- Symbol::Flag::OmpShared, Symbol::Flag::OmpLinear,
- Symbol::Flag::OmpReduction};
- Symbol::Flags dsa{symbol.flags() & dsaFlags};
+ Symbol::Flag::OmpReduction, Symbol::Flag::OmpLinear};
+}
+
+Symbol::Flags GetSymbolDSA(const Symbol &symbol) {
+ Symbol::Flags dsa{symbol.flags() & GetDataSharingAttributeFlags()};
if (dsa.any()) {
return dsa;
}
@@ -26,4 +28,14 @@ Symbol::Flags GetSymbolDSA(const Symbol &symbol) {
return {};
}
+// Clear any previous data-sharing attribute flags and set the new ones.
+// Needed when setting PreDetermined DSAs, that take precedence over Implicit
+// ones.
+void SetSymbolDSA(Symbol &symbol, Symbol::Flags flags) {
+ symbol.flags() &= ~(GetDataSharingAttributeFlags() |
+ Symbol::Flags{Symbol::Flag::OmpExplicit, Symbol::Flag::OmpImplicit,
+ Symbol::Flag::OmpPreDetermined});
+ symbol.flags() |= flags;
+}
+
} // namespace Fortran::semantics
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index cd4b986858d7e..51ad81bcbc2ef 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -982,10 +982,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
}
private:
- Symbol::Flags dataSharingAttributeFlags{Symbol::Flag::OmpShared,
- Symbol::Flag::OmpPrivate, Symbol::Flag::OmpFirstPrivate,
- Symbol::Flag::OmpLastPrivate, Symbol::Flag::OmpReduction,
- Symbol::Flag::OmpLinear};
+ Symbol::Flags dataSharingAttributeFlags{GetDataSharingAttributeFlags()};
Symbol::Flags dataMappingAttributeFlags{Symbol::Flag::OmpMapTo,
Symbol::Flag::OmpMapFrom, Symbol::Flag::OmpMapToFrom,
@@ -1055,16 +1052,6 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
symbol.set(Symbol::Flag::OmpExplicit);
}
}
-
- // Clear any previous data-sharing attribute flags and set the new ones.
- // Needed when setting PreDetermined DSAs, that take precedence over
- // Implicit ones.
- void SetSymbolDSA(Symbol &symbol, Symbol::Flags flags) {
- symbol.flags() &= ~(dataSharingAttributeFlags |
- Symbol::Flags{Symbol::Flag::OmpExplicit, Symbol::Flag::OmpImplicit,
- Symbol::Flag::OmpPreDetermined});
- symbol.flags() |= flags;
- }
};
void ResolveAccParts(SemanticsContext &context, const parser::ProgramUnit &node,
More information about the flang-commits
mailing list