Skip to content

Commit 62cc6b0

Browse files
clementvaljeanPerierschweitzpgi
committed
[flang][fir] Add support to mangle/deconstruct namelist group name
Add support to create unique name for namelist group and be able to deconstruct them. This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D110331 Co-authored-by: Jean Perier <[email protected]> Co-authored-by: Eric Schweitz <[email protected]>
1 parent a5d47b3 commit 62cc6b0

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

flang/include/flang/Optimizer/Support/InternalNames.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ struct NameUniquer {
4141
INTRINSIC_TYPE_DESC,
4242
PROCEDURE,
4343
TYPE_DESC,
44-
VARIABLE
44+
VARIABLE,
45+
NAMELIST_GROUP
4546
};
4647

4748
/// Components of an unparsed unique name
@@ -112,6 +113,11 @@ struct NameUniquer {
112113
llvm::Optional<llvm::StringRef> host,
113114
llvm::StringRef name);
114115

116+
/// Unique a namelist group name
117+
static std::string doNamelistGroup(llvm::ArrayRef<llvm::StringRef> modules,
118+
llvm::Optional<llvm::StringRef> host,
119+
llvm::StringRef name);
120+
115121
/// Entry point for the PROGRAM (called by the runtime)
116122
/// Can be overridden with the `--main-entry-name=<name>` option.
117123
static llvm::StringRef doProgramEntry();

flang/lib/Lower/Mangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol,
114114
symbolName);
115115
return fir::NameUniquer::doVariable(modNames, optHost, symbolName);
116116
},
117+
[&](const Fortran::semantics::NamelistDetails &) {
118+
auto modNames = moduleNames(ultimateSymbol);
119+
auto optHost = hostName(ultimateSymbol);
120+
return fir::NameUniquer::doNamelistGroup(modNames, optHost,
121+
symbolName);
122+
},
117123
[&](const Fortran::semantics::CommonBlockDetails &) {
118124
return fir::NameUniquer::doCommonBlock(symbolName);
119125
},

flang/lib/Optimizer/Support/InternalNames.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ fir::NameUniquer::doVariable(llvm::ArrayRef<llvm::StringRef> modules,
205205
return result.append(toLower(name));
206206
}
207207

208+
std::string
209+
fir::NameUniquer::doNamelistGroup(llvm::ArrayRef<llvm::StringRef> modules,
210+
llvm::Optional<llvm::StringRef> host,
211+
llvm::StringRef name) {
212+
std::string result = prefix();
213+
result.append(doModulesHost(modules, host)).append("G");
214+
return result.append(toLower(name));
215+
}
216+
208217
llvm::StringRef fir::NameUniquer::doProgramEntry() {
209218
if (mainEntryName.size())
210219
return mainEntryName;
@@ -279,6 +288,10 @@ fir::NameUniquer::deconstruct(llvm::StringRef uniq) {
279288
else
280289
kinds.push_back(readInt(uniq, i, i + 1, end));
281290
break;
291+
case 'G':
292+
nk = NameKind::NAMELIST_GROUP;
293+
name = readName(uniq, i, i + 1, end);
294+
break;
282295

283296
default:
284297
assert(false && "unknown uniquing code");

flang/unittests/Optimizer/InternalNamesTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ TEST(InternalNamesTest, doProgramEntry) {
162162
ASSERT_EQ(actual.str(), expectedMangledName);
163163
}
164164

165+
TEST(InternalNamesTest, doNamelistGroup) {
166+
std::string actual = NameUniquer::doNamelistGroup({"mod1"}, {}, "nlg");
167+
std::string expectedMangledName = "_QMmod1Gnlg";
168+
ASSERT_EQ(actual, expectedMangledName);
169+
}
170+
165171
TEST(InternalNamesTest, deconstructTest) {
166172
std::pair actual = NameUniquer::deconstruct("_QBhello");
167173
auto expectedNameKind = NameUniquer::NameKind::COMMON;
@@ -208,6 +214,11 @@ TEST(InternalNamesTest, complexdeconstructTest) {
208214
expectedNameKind = NameKind::DISPATCH_TABLE;
209215
expectedComponents = {{}, {}, "t", {}};
210216
validateDeconstructedName(actual, expectedNameKind, expectedComponents);
217+
218+
actual = NameUniquer::deconstruct("_QFmstartGmpitop");
219+
expectedNameKind = NameKind::NAMELIST_GROUP;
220+
expectedComponents = {{}, {"mstart"}, "mpitop", {}};
221+
validateDeconstructedName(actual, expectedNameKind, expectedComponents);
211222
}
212223

213224
// main() from gtest_main

0 commit comments

Comments
 (0)