[llvm] eb9c49c - [LTO] Make getImportType a proper function (NFC) (#106450)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 13:53:10 PDT 2024
Author: Kazu Hirata
Date: 2024-08-28T13:53:07-07:00
New Revision: eb9c49c900f43aa79811f80847c97c6596197430
URL: https://github.com/llvm/llvm-project/commit/eb9c49c900f43aa79811f80847c97c6596197430
DIFF: https://github.com/llvm/llvm-project/commit/eb9c49c900f43aa79811f80847c97c6596197430.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/FunctionImport.h
llvm/lib/Transforms/IPO/FunctionImport.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
index 78932c12e76ff8..b7280c56be9cc8 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -143,6 +143,10 @@ class FunctionImporter {
// order.
SmallVector<StringRef, 0> getSourceModules() const;
+ std::optional<GlobalValueSummary::ImportKind>
+ getImportType(const FunctionsToImportTy &GUIDToImportType,
+ GlobalValue::GUID GUID) const;
+
const ImportMapTyImpl &getImportMap() const { return ImportMap; }
private:
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 6227b085f13a60..7a60ae51f02cb4 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -359,6 +359,15 @@ FunctionImporter::ImportMapTy::getSourceModules() const {
return Modules;
}
+std::optional<GlobalValueSummary::ImportKind>
+FunctionImporter::ImportMapTy::getImportType(
+ const FunctionsToImportTy &GUIDToImportType, GlobalValue::GUID GUID) const {
+ auto Iter = GUIDToImportType.find(GUID);
+ if (Iter == GUIDToImportType.end())
+ return std::nullopt;
+ return Iter->second;
+}
+
/// Import globals referenced by a function or other globals that are being
/// imported, if importing such global is possible.
class GlobalsImporter final {
@@ -1800,15 +1809,6 @@ Expected<bool> FunctionImporter::importFunctions(
IRMover Mover(DestModule);
- auto getImportType = [&](const FunctionsToImportTy &GUIDToImportType,
- GlobalValue::GUID GUID)
- -> std::optional<GlobalValueSummary::ImportKind> {
- auto Iter = GUIDToImportType.find(GUID);
- if (Iter == GUIDToImportType.end())
- return std::nullopt;
- return Iter->second;
- };
-
// Do the actual import of functions now, one Module at a time
for (const auto &Name : ImportList.getSourceModules()) {
// Get the module for the import
@@ -1835,7 +1835,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (!F.hasName())
continue;
auto GUID = F.getGUID();
- auto MaybeImportType = getImportType(ImportGUIDs, GUID);
+ auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;
LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
@@ -1871,7 +1871,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (!GV.hasName())
continue;
auto GUID = GV.getGUID();
- auto MaybeImportType = getImportType(ImportGUIDs, GUID);
+ auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;
LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
@@ -1891,7 +1891,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (!GA.hasName() || isa<GlobalIFunc>(GA.getAliaseeObject()))
continue;
auto GUID = GA.getGUID();
- auto MaybeImportType = getImportType(ImportGUIDs, GUID);
+ auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;
LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
More information about the llvm-commits
mailing list