@@ -516,6 +516,7 @@ class ModuleImportsManager {
516
516
const ModuleSummaryIndex &Index,
517
517
DenseMap<StringRef, FunctionImporter::ExportSetTy> *ExportLists = nullptr )
518
518
: IsPrevailing(IsPrevailing), Index(Index), ExportLists(ExportLists) {}
519
+ virtual bool canImport (ValueInfo VI) { return true ; }
519
520
520
521
public:
521
522
virtual ~ModuleImportsManager () = default ;
@@ -544,6 +545,11 @@ class WorkloadImportsManager : public ModuleImportsManager {
544
545
// determine if a module's import list should be done by the base
545
546
// ModuleImportsManager or by us.
546
547
StringMap<DenseSet<ValueInfo>> Workloads;
548
+ // Track the roots to avoid importing them due to other callers. We want there
549
+ // to be only one variant), for which we optimize according to the contextual
550
+ // profile. "Variants" refers to copies due to importing - we want there to be
551
+ // just one instance of this function.
552
+ DenseSet<ValueInfo> Roots;
547
553
548
554
void
549
555
computeImportForModule (const GVSummaryMapTy &DefinedGVSummaries,
@@ -783,12 +789,15 @@ class WorkloadImportsManager : public ModuleImportsManager {
783
789
}
784
790
auto &Set = Workloads[RootDefiningModule];
785
791
Root.getContainedGuids (ContainedGUIDs);
792
+ Roots.insert (RootVI);
786
793
for (auto Guid : ContainedGUIDs)
787
794
if (auto VI = Index.getValueInfo (Guid))
788
795
Set.insert (VI);
789
796
}
790
797
}
791
798
799
+ bool canImport (ValueInfo VI) override { return !Roots.contains (VI); }
800
+
792
801
public:
793
802
WorkloadImportsManager (
794
803
function_ref<bool (GlobalValue::GUID, const GlobalValueSummary *)>
@@ -886,6 +895,15 @@ void ModuleImportsManager::computeImportForFunction(
886
895
continue ;
887
896
}
888
897
898
+ if (!canImport (VI)) {
899
+ LLVM_DEBUG (
900
+ dbgs () << " Skipping over " << VI.getGUID ()
901
+ << " because its import is handled in a different module." );
902
+ assert (VI.getSummaryList ().size () == 1 &&
903
+ " The root was expected to be an external symbol" );
904
+ continue ;
905
+ }
906
+
889
907
auto GetBonusMultiplier = [](CalleeInfo::HotnessType Hotness) -> float {
890
908
if (Hotness == CalleeInfo::HotnessType::Hot)
891
909
return ImportHotMultiplier;
0 commit comments