@@ -400,8 +400,7 @@ class GlobalsImporter final {
400
400
// later, in ComputeCrossModuleImport, after import decisions are
401
401
// complete, which is more efficient than adding them here.
402
402
if (ExportLists)
403
- (*ExportLists)[RefSummary->modulePath ()][VI] =
404
- GlobalValueSummary::Definition;
403
+ (*ExportLists)[RefSummary->modulePath ()].insert (VI);
405
404
406
405
// If variable is not writeonly we attempt to recursively analyze
407
406
// its references in order to import referenced constants.
@@ -582,7 +581,7 @@ class WorkloadImportsManager : public ModuleImportsManager {
582
581
GlobalValueSummary::Definition;
583
582
GVI.onImportingSummary (*GVS);
584
583
if (ExportLists)
585
- (*ExportLists)[ExportingModule][VI] = GlobalValueSummary::Definition ;
584
+ (*ExportLists)[ExportingModule]. insert (VI) ;
586
585
}
587
586
LLVM_DEBUG (dbgs () << " [Workload] Done\n " );
588
587
}
@@ -818,10 +817,8 @@ static void computeImportForFunction(
818
817
// Since definition takes precedence over declaration for the same VI,
819
818
// try emplace <VI, declaration> pair without checking insert result.
820
819
// If insert doesn't happen, there must be an existing entry keyed by
821
- // VI.
822
- if (ExportLists)
823
- (*ExportLists)[DeclSourceModule].try_emplace (
824
- VI, GlobalValueSummary::Declaration);
820
+ // VI. Note `ExportLists` only keeps track of definitions so VI won't
821
+ // be inserted.
825
822
ImportList[DeclSourceModule].try_emplace (
826
823
VI.getGUID (), GlobalValueSummary::Declaration);
827
824
}
@@ -892,7 +889,7 @@ static void computeImportForFunction(
892
889
// later, in ComputeCrossModuleImport, after import decisions are
893
890
// complete, which is more efficient than adding them here.
894
891
if (ExportLists)
895
- (*ExportLists)[ExportModulePath][VI] = GlobalValueSummary::Definition ;
892
+ (*ExportLists)[ExportModulePath]. insert (VI) ;
896
893
}
897
894
898
895
auto GetAdjustedThreshold = [](unsigned Threshold, bool IsHotCallsite) {
@@ -998,14 +995,29 @@ static bool isGlobalVarSummary(const ModuleSummaryIndex &Index,
998
995
return false ;
999
996
}
1000
997
1001
- template < class T >
1002
- static unsigned numGlobalVarSummaries ( const ModuleSummaryIndex &Index, T &Cont ,
998
+ static unsigned numGlobalVarSummaries ( const ModuleSummaryIndex &Index,
999
+ FunctionImporter::ExportSetTy &ExportSet ,
1003
1000
unsigned &DefinedGVS,
1004
1001
unsigned &DefinedFS) {
1002
+ DefinedGVS = 0 ;
1003
+ DefinedFS = 0 ;
1004
+ for (auto &VI : ExportSet) {
1005
+ if (isGlobalVarSummary (Index, VI.getGUID ())) {
1006
+ ++DefinedGVS;
1007
+ } else
1008
+ ++DefinedFS;
1009
+ }
1010
+ return DefinedGVS;
1011
+ }
1012
+
1013
+ static unsigned
1014
+ numGlobalVarSummaries (const ModuleSummaryIndex &Index,
1015
+ FunctionImporter::FunctionsToImportTy &ImportMap,
1016
+ unsigned &DefinedGVS, unsigned &DefinedFS) {
1005
1017
unsigned NumGVS = 0 ;
1006
1018
DefinedGVS = 0 ;
1007
1019
DefinedFS = 0 ;
1008
- for (auto &[GUID, Type] : Cont ) {
1020
+ for (auto &[GUID, Type] : ImportMap ) {
1009
1021
if (isGlobalVarSummary (Index, GUID)) {
1010
1022
if (Type == GlobalValueSummary::Definition)
1011
1023
++DefinedGVS;
@@ -1046,7 +1058,7 @@ static bool checkVariableImport(
1046
1058
};
1047
1059
1048
1060
for (auto &ExportPerModule : ExportLists)
1049
- for (auto &[VI, Unused] : ExportPerModule.second )
1061
+ for (auto &VI : ExportPerModule.second )
1050
1062
if (!FlattenedImports.count (VI.getGUID ()) &&
1051
1063
IsReadOrWriteOnlyVarNeedingImporting (ExportPerModule.first , VI))
1052
1064
return false ;
@@ -1079,14 +1091,12 @@ void llvm::ComputeCrossModuleImport(
1079
1091
// since we may import the same values multiple times into different modules
1080
1092
// during the import computation.
1081
1093
for (auto &ELI : ExportLists) {
1094
+ // `NewExports` tracks the VI that gets exported because the full definition
1095
+ // of its user/referencer gets exported.
1082
1096
FunctionImporter::ExportSetTy NewExports;
1083
1097
const auto &DefinedGVSummaries =
1084
1098
ModuleToDefinedGVSummaries.lookup (ELI.first );
1085
- for (auto &[EI, Type] : ELI.second ) {
1086
- // If a variable is exported as a declaration, its 'refs' and 'calls' are
1087
- // not further exported.
1088
- if (Type == GlobalValueSummary::Declaration)
1089
- continue ;
1099
+ for (auto &EI : ELI.second ) {
1090
1100
// Find the copy defined in the exporting module so that we can mark the
1091
1101
// values it references in that specific definition as exported.
1092
1102
// Below we will add all references and called values, without regard to
@@ -1108,19 +1118,19 @@ void llvm::ComputeCrossModuleImport(
1108
1118
for (const auto &VI : GVS->refs ()) {
1109
1119
// Try to emplace the declaration entry. If a definition entry
1110
1120
// already exists for key `VI`, this is a no-op.
1111
- NewExports.try_emplace (VI, GlobalValueSummary::Declaration );
1121
+ NewExports.insert (VI);
1112
1122
}
1113
1123
} else {
1114
1124
auto *FS = cast<FunctionSummary>(S);
1115
1125
for (const auto &Edge : FS->calls ()) {
1116
1126
// Try to emplace the declaration entry. If a definition entry
1117
1127
// already exists for key `VI`, this is a no-op.
1118
- NewExports.try_emplace (Edge.first , GlobalValueSummary::Declaration );
1128
+ NewExports.insert (Edge.first );
1119
1129
}
1120
1130
for (const auto &Ref : FS->refs ()) {
1121
1131
// Try to emplace the declaration entry. If a definition entry
1122
1132
// already exists for key `VI`, this is a no-op.
1123
- NewExports.try_emplace (Ref, GlobalValueSummary::Declaration );
1133
+ NewExports.insert (Ref);
1124
1134
}
1125
1135
}
1126
1136
}
@@ -1129,7 +1139,7 @@ void llvm::ComputeCrossModuleImport(
1129
1139
// the same ref/call target multiple times in above loop, and it is more
1130
1140
// efficient to avoid a set lookup each time.
1131
1141
for (auto EI = NewExports.begin (); EI != NewExports.end ();) {
1132
- if (!DefinedGVSummaries.count (EI->first . getGUID ()))
1142
+ if (!DefinedGVSummaries.count (EI->getGUID ()))
1133
1143
NewExports.erase (EI++);
1134
1144
else
1135
1145
++EI;
0 commit comments