[llvm] [nfc][thinlto] Factor common state for `computeImportForModule` (PR #65427)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 11:53:06 PDT 2023
https://github.com/mtrofin updated https://github.com/llvm/llvm-project/pull/65427:
>From 22d602c73191499ab082462a2ee91055a85e3956 Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Tue, 5 Sep 2023 17:21:18 -0700
Subject: [PATCH 1/2] [nfc][thinlto] Factor common state for
`computeImportForModule`
Added a class to hold such common state. The goal is to both reduce the
argument list of other utilities used by `computeImportForModule` (which
will be brought as members in a subsequent patch), and to make it easy
to extend such state later.
---
llvm/lib/Transforms/IPO/FunctionImport.cpp | 51 ++++++++++++++--------
1 file changed, 34 insertions(+), 17 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 6123285622ab5f..dd6c5d38cd7f23 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -370,6 +370,29 @@ class GlobalsImporter final {
}
};
+/// Determine the list of imports and exports for each module.
+class ModuleImportsScheduler final {
+ function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
+ IsPrevailing;
+ const ModuleSummaryIndex &Index;
+ DenseMap<StringRef, FunctionImporter::ExportSetTy> *const ExportLists;
+
+public:
+ ModuleImportsScheduler(
+ function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
+ IsPrevailing,
+ const ModuleSummaryIndex &Index,
+ DenseMap<StringRef, FunctionImporter::ExportSetTy> *ExportLists = nullptr)
+ : IsPrevailing(IsPrevailing), Index(Index), ExportLists(ExportLists) {}
+
+ /// Given the list of globals defined in a module, compute the list of imports
+ /// as well as the list of "exports", i.e. the list of symbols referenced from
+ /// another module (that may require promotion).
+ void computeImportForModule(const GVSummaryMapTy &DefinedGVSummaries,
+ StringRef ModName,
+ FunctionImporter::ImportMapTy &ImportList);
+};
+
static const char *
getFailureName(FunctionImporter::ImportFailureReason Reason) {
switch (Reason) {
@@ -567,20 +590,13 @@ static void computeImportForFunction(
}
}
-/// Given the list of globals defined in a module, compute the list of imports
-/// as well as the list of "exports", i.e. the list of symbols referenced from
-/// another module (that may require promotion).
-static void ComputeImportForModule(
- const GVSummaryMapTy &DefinedGVSummaries,
- function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
- isPrevailing,
- const ModuleSummaryIndex &Index, StringRef ModName,
- FunctionImporter::ImportMapTy &ImportList,
- DenseMap<StringRef, FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
+void ModuleImportsScheduler::computeImportForModule(
+ const GVSummaryMapTy &DefinedGVSummaries, StringRef ModName,
+ FunctionImporter::ImportMapTy &ImportList) {
// Worklist contains the list of function imported in this module, for which
// we will analyse the callees and may import further down the callgraph.
SmallVector<EdgeInfo, 128> Worklist;
- GlobalsImporter GVI(Index, DefinedGVSummaries, isPrevailing, ImportList,
+ GlobalsImporter GVI(Index, DefinedGVSummaries, IsPrevailing, ImportList,
ExportLists);
FunctionImporter::ImportThresholdsTy ImportThresholds;
@@ -603,7 +619,7 @@ static void ComputeImportForModule(
continue;
LLVM_DEBUG(dbgs() << "Initialize import for " << VI << "\n");
computeImportForFunction(*FuncSummary, Index, ImportInstrLimit,
- DefinedGVSummaries, isPrevailing, Worklist, GVI,
+ DefinedGVSummaries, IsPrevailing, Worklist, GVI,
ImportList, ExportLists, ImportThresholds);
}
@@ -615,7 +631,7 @@ static void ComputeImportForModule(
if (auto *FS = dyn_cast<FunctionSummary>(Summary))
computeImportForFunction(*FS, Index, Threshold, DefinedGVSummaries,
- isPrevailing, Worklist, GVI, ImportList,
+ IsPrevailing, Worklist, GVI, ImportList,
ExportLists, ImportThresholds);
}
@@ -717,13 +733,14 @@ void llvm::ComputeCrossModuleImport(
isPrevailing,
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists) {
+ ModuleImportsScheduler MIS(isPrevailing, Index, &ExportLists);
// For each module that has function defined, compute the import/export lists.
for (const auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
auto &ImportList = ImportLists[DefinedGVSummaries.first];
LLVM_DEBUG(dbgs() << "Computing import for Module '"
<< DefinedGVSummaries.first << "'\n");
- ComputeImportForModule(DefinedGVSummaries.second, isPrevailing, Index,
- DefinedGVSummaries.first, ImportList, &ExportLists);
+ MIS.computeImportForModule(DefinedGVSummaries.second,
+ DefinedGVSummaries.first, ImportList);
}
// When computing imports we only added the variables and functions being
@@ -839,8 +856,8 @@ static void ComputeCrossModuleImportForModuleForTest(
// Compute the import list for this module.
LLVM_DEBUG(dbgs() << "Computing import for Module '" << ModulePath << "'\n");
- ComputeImportForModule(FunctionSummaryMap, isPrevailing, Index, ModulePath,
- ImportList);
+ ModuleImportsScheduler MIS(isPrevailing, Index);
+ MIS.computeImportForModule(FunctionSummaryMap, ModulePath, ImportList);
#ifndef NDEBUG
dumpImportListForModule(Index, ModulePath, ImportList);
>From 940797965f83396016659685564f68395afbdbba Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Wed, 6 Sep 2023 11:28:13 -0700
Subject: [PATCH 2/2] Renamed to `ModuleImportsManager`
---
llvm/lib/Transforms/IPO/FunctionImport.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index dd6c5d38cd7f23..80c360b8dd0f74 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -371,14 +371,14 @@ class GlobalsImporter final {
};
/// Determine the list of imports and exports for each module.
-class ModuleImportsScheduler final {
+class ModuleImportsManager final {
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
IsPrevailing;
const ModuleSummaryIndex &Index;
DenseMap<StringRef, FunctionImporter::ExportSetTy> *const ExportLists;
public:
- ModuleImportsScheduler(
+ ModuleImportsManager(
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
IsPrevailing,
const ModuleSummaryIndex &Index,
@@ -590,7 +590,7 @@ static void computeImportForFunction(
}
}
-void ModuleImportsScheduler::computeImportForModule(
+void ModuleImportsManager::computeImportForModule(
const GVSummaryMapTy &DefinedGVSummaries, StringRef ModName,
FunctionImporter::ImportMapTy &ImportList) {
// Worklist contains the list of function imported in this module, for which
@@ -733,7 +733,7 @@ void llvm::ComputeCrossModuleImport(
isPrevailing,
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists) {
- ModuleImportsScheduler MIS(isPrevailing, Index, &ExportLists);
+ ModuleImportsManager MIS(isPrevailing, Index, &ExportLists);
// For each module that has function defined, compute the import/export lists.
for (const auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
auto &ImportList = ImportLists[DefinedGVSummaries.first];
@@ -856,7 +856,7 @@ static void ComputeCrossModuleImportForModuleForTest(
// Compute the import list for this module.
LLVM_DEBUG(dbgs() << "Computing import for Module '" << ModulePath << "'\n");
- ModuleImportsScheduler MIS(isPrevailing, Index);
+ ModuleImportsManager MIS(isPrevailing, Index);
MIS.computeImportForModule(FunctionSummaryMap, ModulePath, ImportList);
#ifndef NDEBUG
More information about the llvm-commits
mailing list