Skip to content

Commit eb9c49c

Browse files
[LTO] Make getImportType a proper function (NFC) (#106450)
I'm planning to reduce the memory footprint of ThinLTO indexing by changing ImportMapTy. A look-up of the import type will involve data private to ImportMapTy, so it must be done by a member function of ImportMapTy. This patch turns getImportType into a member function so that a subsequent "real" change will just have to update the implementation of the function in place.
1 parent 53d95f3 commit eb9c49c

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class FunctionImporter {
143143
// order.
144144
SmallVector<StringRef, 0> getSourceModules() const;
145145

146+
std::optional<GlobalValueSummary::ImportKind>
147+
getImportType(const FunctionsToImportTy &GUIDToImportType,
148+
GlobalValue::GUID GUID) const;
149+
146150
const ImportMapTyImpl &getImportMap() const { return ImportMap; }
147151

148152
private:

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,15 @@ FunctionImporter::ImportMapTy::getSourceModules() const {
359359
return Modules;
360360
}
361361

362+
std::optional<GlobalValueSummary::ImportKind>
363+
FunctionImporter::ImportMapTy::getImportType(
364+
const FunctionsToImportTy &GUIDToImportType, GlobalValue::GUID GUID) const {
365+
auto Iter = GUIDToImportType.find(GUID);
366+
if (Iter == GUIDToImportType.end())
367+
return std::nullopt;
368+
return Iter->second;
369+
}
370+
362371
/// Import globals referenced by a function or other globals that are being
363372
/// imported, if importing such global is possible.
364373
class GlobalsImporter final {
@@ -1800,15 +1809,6 @@ Expected<bool> FunctionImporter::importFunctions(
18001809

18011810
IRMover Mover(DestModule);
18021811

1803-
auto getImportType = [&](const FunctionsToImportTy &GUIDToImportType,
1804-
GlobalValue::GUID GUID)
1805-
-> std::optional<GlobalValueSummary::ImportKind> {
1806-
auto Iter = GUIDToImportType.find(GUID);
1807-
if (Iter == GUIDToImportType.end())
1808-
return std::nullopt;
1809-
return Iter->second;
1810-
};
1811-
18121812
// Do the actual import of functions now, one Module at a time
18131813
for (const auto &Name : ImportList.getSourceModules()) {
18141814
// Get the module for the import
@@ -1835,7 +1835,7 @@ Expected<bool> FunctionImporter::importFunctions(
18351835
if (!F.hasName())
18361836
continue;
18371837
auto GUID = F.getGUID();
1838-
auto MaybeImportType = getImportType(ImportGUIDs, GUID);
1838+
auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
18391839
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;
18401840

18411841
LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
@@ -1871,7 +1871,7 @@ Expected<bool> FunctionImporter::importFunctions(
18711871
if (!GV.hasName())
18721872
continue;
18731873
auto GUID = GV.getGUID();
1874-
auto MaybeImportType = getImportType(ImportGUIDs, GUID);
1874+
auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
18751875
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;
18761876

18771877
LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
@@ -1891,7 +1891,7 @@ Expected<bool> FunctionImporter::importFunctions(
18911891
if (!GA.hasName() || isa<GlobalIFunc>(GA.getAliaseeObject()))
18921892
continue;
18931893
auto GUID = GA.getGUID();
1894-
auto MaybeImportType = getImportType(ImportGUIDs, GUID);
1894+
auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
18951895
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;
18961896

18971897
LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")

0 commit comments

Comments
 (0)