Skip to content

Commit 4e30cf7

Browse files
[LTO] Introduce getSourceModules (NFC) (#105955)
This patch introduces getSourceModules to compute the list of source modules in the ascending alphabetical order. The new function is intended to hide implementation details of ImportMapTy while simplifying FunctionImporter::importFunctions a little bit.
1 parent 7cc789b commit 4e30cf7

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

llvm/include/llvm/Transforms/IPO/FunctionImport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ class FunctionImporter {
139139
maybeAddDeclaration(FromModule, GUID);
140140
}
141141

142+
// Return the list of source modules sorted in the ascending alphabetical
143+
// order.
144+
SmallVector<StringRef, 0> getSourceModules() const;
145+
142146
const ImportMapTyImpl &getImportMap() const { return ImportMap; }
143147

144148
private:

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ void FunctionImporter::ImportMapTy::maybeAddDeclaration(
352352
ImportMap[FromModule].try_emplace(GUID, GlobalValueSummary::Declaration);
353353
}
354354

355+
SmallVector<StringRef, 0>
356+
FunctionImporter::ImportMapTy::getSourceModules() const {
357+
SmallVector<StringRef, 0> Modules(make_first_range(ImportMap));
358+
llvm::sort(Modules);
359+
return Modules;
360+
}
361+
355362
/// Import globals referenced by a function or other globals that are being
356363
/// imported, if importing such global is possible.
357364
class GlobalsImporter final {
@@ -1770,11 +1777,6 @@ Expected<bool> FunctionImporter::importFunctions(
17701777
unsigned ImportedCount = 0, ImportedGVCount = 0;
17711778

17721779
IRMover Mover(DestModule);
1773-
// Do the actual import of functions now, one Module at a time
1774-
std::set<StringRef> ModuleNameOrderedList;
1775-
for (const auto &FunctionsToImportPerModule : ImportList.getImportMap()) {
1776-
ModuleNameOrderedList.insert(FunctionsToImportPerModule.first);
1777-
}
17781780

17791781
auto getImportType = [&](const FunctionsToImportTy &GUIDToImportType,
17801782
GlobalValue::GUID GUID)
@@ -1785,7 +1787,8 @@ Expected<bool> FunctionImporter::importFunctions(
17851787
return Iter->second;
17861788
};
17871789

1788-
for (const auto &Name : ModuleNameOrderedList) {
1790+
// Do the actual import of functions now, one Module at a time
1791+
for (const auto &Name : ImportList.getSourceModules()) {
17891792
// Get the module for the import
17901793
const auto &FunctionsToImportPerModule =
17911794
ImportList.getImportMap().find(Name);

0 commit comments

Comments
 (0)