@@ -370,6 +370,29 @@ class GlobalsImporter final {
370
370
}
371
371
};
372
372
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
+
373
396
static const char *
374
397
getFailureName (FunctionImporter::ImportFailureReason Reason) {
375
398
switch (Reason) {
@@ -567,20 +590,13 @@ static void computeImportForFunction(
567
590
}
568
591
}
569
592
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) {
580
596
// Worklist contains the list of function imported in this module, for which
581
597
// we will analyse the callees and may import further down the callgraph.
582
598
SmallVector<EdgeInfo, 128 > Worklist;
583
- GlobalsImporter GVI (Index, DefinedGVSummaries, isPrevailing , ImportList,
599
+ GlobalsImporter GVI (Index, DefinedGVSummaries, IsPrevailing , ImportList,
584
600
ExportLists);
585
601
FunctionImporter::ImportThresholdsTy ImportThresholds;
586
602
@@ -603,7 +619,7 @@ static void ComputeImportForModule(
603
619
continue ;
604
620
LLVM_DEBUG (dbgs () << " Initialize import for " << VI << " \n " );
605
621
computeImportForFunction (*FuncSummary, Index, ImportInstrLimit,
606
- DefinedGVSummaries, isPrevailing , Worklist, GVI,
622
+ DefinedGVSummaries, IsPrevailing , Worklist, GVI,
607
623
ImportList, ExportLists, ImportThresholds);
608
624
}
609
625
@@ -615,7 +631,7 @@ static void ComputeImportForModule(
615
631
616
632
if (auto *FS = dyn_cast<FunctionSummary>(Summary))
617
633
computeImportForFunction (*FS, Index, Threshold, DefinedGVSummaries,
618
- isPrevailing , Worklist, GVI, ImportList,
634
+ IsPrevailing , Worklist, GVI, ImportList,
619
635
ExportLists, ImportThresholds);
620
636
}
621
637
@@ -717,13 +733,14 @@ void llvm::ComputeCrossModuleImport(
717
733
isPrevailing,
718
734
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
719
735
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists) {
736
+ ModuleImportsManager MIS (isPrevailing, Index, &ExportLists);
720
737
// For each module that has function defined, compute the import/export lists.
721
738
for (const auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
722
739
auto &ImportList = ImportLists[DefinedGVSummaries.first ];
723
740
LLVM_DEBUG (dbgs () << " Computing import for Module '"
724
741
<< DefinedGVSummaries.first << " '\n " );
725
- ComputeImportForModule (DefinedGVSummaries.second , isPrevailing, Index ,
726
- DefinedGVSummaries.first , ImportList, &ExportLists );
742
+ MIS. computeImportForModule (DefinedGVSummaries.second ,
743
+ DefinedGVSummaries.first , ImportList);
727
744
}
728
745
729
746
// When computing imports we only added the variables and functions being
@@ -839,8 +856,8 @@ static void ComputeCrossModuleImportForModuleForTest(
839
856
840
857
// Compute the import list for this module.
841
858
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);
844
861
845
862
#ifndef NDEBUG
846
863
dumpImportListForModule (Index, ModulePath, ImportList);
0 commit comments