[llvm] [LTO] Make getImportType a proper function (NFC) (PR #106450)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 13:31:19 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From efa7006ec62b9b4c86b0121dc18ccf794993baea Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 28 Aug 2024 12:29:23 -0700
Subject: [PATCH] [LTO] Make getImportType a proper function (NFC)
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.
---
.../llvm/Transforms/IPO/FunctionImport.h | 4 ++++
llvm/lib/Transforms/IPO/FunctionImport.cpp | 24 +++++++++----------
2 files changed, 16 insertions(+), 12 deletions(-)
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