[flang-commits] [flang] [flang] NameUniquer helper for detecting module-scope data (PR #192733)
via flang-commits
flang-commits at lists.llvm.org
Fri Apr 17 14:01:15 PDT 2026
https://github.com/nvptm updated https://github.com/llvm/llvm-project/pull/192733
>From 1402b96a00441288ecdc6a7705ee7277cb835d0c Mon Sep 17 00:00:00 2001
From: nvpm <pmathew at nvidia.com>
Date: Fri, 17 Apr 2026 13:43:47 -0700
Subject: [PATCH 1/2] Utility for moduledata
---
.../flang/Optimizer/Support/InternalNames.h | 5 ++++
flang/lib/Optimizer/Support/InternalNames.cpp | 23 +++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/flang/include/flang/Optimizer/Support/InternalNames.h b/flang/include/flang/Optimizer/Support/InternalNames.h
index 62375ab8f9de3..238d491ac99c1 100644
--- a/flang/include/flang/Optimizer/Support/InternalNames.h
+++ b/flang/include/flang/Optimizer/Support/InternalNames.h
@@ -156,6 +156,11 @@ struct NameUniquer {
static bool belongsToModule(llvm::StringRef uniquedName,
llvm::StringRef moduleName);
+ /// True if \p uniquedName denotes module-scope data (variable, named
+ /// constant, or common block), as opposed to procedures, types, or other
+ /// symbols that may still carry a module prefix in the mangling.
+ static bool isModuleScopeDataUniquedName(llvm::StringRef uniquedName);
+
/// Given a mangled derived type name, get the name of the related derived
/// type descriptor object. Returns an empty string if \p mangledTypeName is
/// not a valid mangled derived type name.
diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp
index 011021c9f0350..a5f35f90e3fc3 100644
--- a/flang/lib/Optimizer/Support/InternalNames.cpp
+++ b/flang/lib/Optimizer/Support/InternalNames.cpp
@@ -347,6 +347,29 @@ bool fir::NameUniquer::belongsToModule(llvm::StringRef uniquedName,
result.second.modules[0] == moduleName;
}
+/// Flang records the lexical module/submodule nesting of a symbol in the
+/// uniqued root produced by \c fir::NameUniquer; \c deconstruct exposes that
+/// as \c parts.modules. A non-empty module path means the symbol was declared
+/// under a module or submodule, not only at program or internal unit scope.
+/// We then require \c VARIABLE, \c CONSTANT, or \c COMMON so we match
+/// module-level data (including common), not procedures or other name kinds
+/// that can also carry a module prefix.
+bool fir::NameUniquer::isModuleScopeDataUniquedName(
+ llvm::StringRef uniquedName) {
+ auto [kind, parts] = fir::NameUniquer::deconstruct(uniquedName);
+ if (parts.modules.empty())
+ return false;
+
+ switch (kind) {
+ case fir::NameUniquer::NameKind::VARIABLE:
+ case fir::NameUniquer::NameKind::CONSTANT:
+ case fir::NameUniquer::NameKind::COMMON:
+ return true;
+ default:
+ return false;
+ }
+}
+
static std::string
mangleTypeDescriptorKinds(llvm::ArrayRef<std::int64_t> kinds) {
if (kinds.empty())
>From 296364f02fff07e23f3b8d1e24759311e8a5b38e Mon Sep 17 00:00:00 2001
From: nvpm <pmathew at nvidia.com>
Date: Fri, 17 Apr 2026 14:00:58 -0700
Subject: [PATCH 2/2] Format
---
flang/lib/Optimizer/Support/InternalNames.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp
index a5f35f90e3fc3..b02ee054387f4 100644
--- a/flang/lib/Optimizer/Support/InternalNames.cpp
+++ b/flang/lib/Optimizer/Support/InternalNames.cpp
@@ -359,7 +359,7 @@ bool fir::NameUniquer::isModuleScopeDataUniquedName(
auto [kind, parts] = fir::NameUniquer::deconstruct(uniquedName);
if (parts.modules.empty())
return false;
-
+
switch (kind) {
case fir::NameUniquer::NameKind::VARIABLE:
case fir::NameUniquer::NameKind::CONSTANT:
More information about the flang-commits
mailing list