diff options
author | Peter Klausler <pklausler@nvidia.com> | 2025-06-11 13:12:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-11 13:12:59 -0700 |
commit | b42aef5e6f32a3ac6c259cb4cacf58239400b5aa (patch) | |
tree | ec07070e59c768ee633dae437effb2b8b8439582 /flang/lib/Semantics/mod-file.cpp | |
parent | a2d2941830d9c141d7f43da1ff58e7b7235a9f7d (diff) | |
download | llvm-b42aef5e6f32a3ac6c259cb4cacf58239400b5aa.zip llvm-b42aef5e6f32a3ac6c259cb4cacf58239400b5aa.tar.gz llvm-b42aef5e6f32a3ac6c259cb4cacf58239400b5aa.tar.bz2 |
[flang] Don't duplicate hermetic module file dependencies (#143605)
When emitting the modules on which a module depends under the
-fhermetic-module-files options, eliminate duplicates by name rather
than by symbol addresses. This way, when a dependent module is in the
symbol table more than once due to the use of a nested hermetic module,
it doesn't get emitted multiple times to the new module file.
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r-- | flang/lib/Semantics/mod-file.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp index a726418..9f9e9f5 100644 --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -143,18 +143,22 @@ void ModFileWriter::Write(const Symbol &symbol) { std::string path{context_.moduleDirectory() + '/' + ModFileName(symbol.name(), ancestorName, context_.moduleFileSuffix())}; - UnorderedSymbolSet hermeticModules; - hermeticModules.insert(symbol); + std::set<std::string> hermeticModuleNames; + hermeticModuleNames.insert(symbol.name().ToString()); UnorderedSymbolSet additionalModules; PutSymbols(DEREF(symbol.scope()), hermeticModuleFileOutput_ ? &additionalModules : nullptr); auto asStr{GetAsString(symbol)}; while (!additionalModules.empty()) { - for (auto ref : UnorderedSymbolSet{std::move(additionalModules)}) { - if (hermeticModules.insert(*ref).second && - !ref->owner().IsIntrinsicModules()) { - PutSymbols(DEREF(ref->scope()), &additionalModules); - asStr += GetAsString(*ref); + UnorderedSymbolSet nextPass{std::move(additionalModules)}; + additionalModules.clear(); + for (const Symbol &modSym : nextPass) { + if (!modSym.owner().IsIntrinsicModules() && + hermeticModuleNames.find(modSym.name().ToString()) == + hermeticModuleNames.end()) { + hermeticModuleNames.insert(modSym.name().ToString()); + PutSymbols(DEREF(modSym.scope()), &additionalModules); + asStr += GetAsString(modSym); } } } |