Skip to content

Commit 24a0859

Browse files
authored
[nfc][thinlto] Factor common state for computeImportForModule (#65427)
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.
1 parent d4fa088 commit 24a0859

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,29 @@ class GlobalsImporter final {
370370
}
371371
};
372372

373+
/// Determine the list of imports and exports for each module.
374+
class ModuleImportsManager final {
375+
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
376+
IsPrevailing;
377+
const ModuleSummaryIndex &Index;
378+
DenseMap<StringRef, FunctionImporter::ExportSetTy> *const ExportLists;
379+
380+
public:
381+
ModuleImportsManager(
382+
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
383+
IsPrevailing,
384+
const ModuleSummaryIndex &Index,
385+
DenseMap<StringRef, FunctionImporter::ExportSetTy> *ExportLists = nullptr)
386+
: IsPrevailing(IsPrevailing), Index(Index), ExportLists(ExportLists) {}
387+
388+
/// Given the list of globals defined in a module, compute the list of imports
389+
/// as well as the list of "exports", i.e. the list of symbols referenced from
390+
/// another module (that may require promotion).
391+
void computeImportForModule(const GVSummaryMapTy &DefinedGVSummaries,
392+
StringRef ModName,
393+
FunctionImporter::ImportMapTy &ImportList);
394+
};
395+
373396
static const char *
374397
getFailureName(FunctionImporter::ImportFailureReason Reason) {
375398
switch (Reason) {
@@ -567,20 +590,13 @@ static void computeImportForFunction(
567590
}
568591
}
569592

570-
/// Given the list of globals defined in a module, compute the list of imports
571-
/// as well as the list of "exports", i.e. the list of symbols referenced from
572-
/// another module (that may require promotion).
573-
static void ComputeImportForModule(
574-
const GVSummaryMapTy &DefinedGVSummaries,
575-
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
576-
isPrevailing,
577-
const ModuleSummaryIndex &Index, StringRef ModName,
578-
FunctionImporter::ImportMapTy &ImportList,
579-
DenseMap<StringRef, FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
593+
void ModuleImportsManager::computeImportForModule(
594+
const GVSummaryMapTy &DefinedGVSummaries, StringRef ModName,
595+
FunctionImporter::ImportMapTy &ImportList) {
580596
// Worklist contains the list of function imported in this module, for which
581597
// we will analyse the callees and may import further down the callgraph.
582598
SmallVector<EdgeInfo, 128> Worklist;
583-
GlobalsImporter GVI(Index, DefinedGVSummaries, isPrevailing, ImportList,
599+
GlobalsImporter GVI(Index, DefinedGVSummaries, IsPrevailing, ImportList,
584600
ExportLists);
585601
FunctionImporter::ImportThresholdsTy ImportThresholds;
586602

@@ -603,7 +619,7 @@ static void ComputeImportForModule(
603619
continue;
604620
LLVM_DEBUG(dbgs() << "Initialize import for " << VI << "\n");
605621
computeImportForFunction(*FuncSummary, Index, ImportInstrLimit,
606-
DefinedGVSummaries, isPrevailing, Worklist, GVI,
622+
DefinedGVSummaries, IsPrevailing, Worklist, GVI,
607623
ImportList, ExportLists, ImportThresholds);
608624
}
609625

@@ -615,7 +631,7 @@ static void ComputeImportForModule(
615631

616632
if (auto *FS = dyn_cast<FunctionSummary>(Summary))
617633
computeImportForFunction(*FS, Index, Threshold, DefinedGVSummaries,
618-
isPrevailing, Worklist, GVI, ImportList,
634+
IsPrevailing, Worklist, GVI, ImportList,
619635
ExportLists, ImportThresholds);
620636
}
621637

@@ -717,13 +733,14 @@ void llvm::ComputeCrossModuleImport(
717733
isPrevailing,
718734
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
719735
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists) {
736+
ModuleImportsManager MIS(isPrevailing, Index, &ExportLists);
720737
// For each module that has function defined, compute the import/export lists.
721738
for (const auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
722739
auto &ImportList = ImportLists[DefinedGVSummaries.first];
723740
LLVM_DEBUG(dbgs() << "Computing import for Module '"
724741
<< DefinedGVSummaries.first << "'\n");
725-
ComputeImportForModule(DefinedGVSummaries.second, isPrevailing, Index,
726-
DefinedGVSummaries.first, ImportList, &ExportLists);
742+
MIS.computeImportForModule(DefinedGVSummaries.second,
743+
DefinedGVSummaries.first, ImportList);
727744
}
728745

729746
// When computing imports we only added the variables and functions being
@@ -839,8 +856,8 @@ static void ComputeCrossModuleImportForModuleForTest(
839856

840857
// Compute the import list for this module.
841858
LLVM_DEBUG(dbgs() << "Computing import for Module '" << ModulePath << "'\n");
842-
ComputeImportForModule(FunctionSummaryMap, isPrevailing, Index, ModulePath,
843-
ImportList);
859+
ModuleImportsManager MIS(isPrevailing, Index);
860+
MIS.computeImportForModule(FunctionSummaryMap, ModulePath, ImportList);
844861

845862
#ifndef NDEBUG
846863
dumpImportListForModule(Index, ModulePath, ImportList);

0 commit comments

Comments
 (0)