@@ -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
}
@@ -819,9 +818,6 @@ static void computeImportForFunction(
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
820
// VI.
822
- if (ExportLists)
823
- (*ExportLists)[DeclSourceModule].try_emplace (
824
- VI, GlobalValueSummary::Declaration);
825
821
ImportList[DeclSourceModule].try_emplace (
826
822
VI.getGUID (), GlobalValueSummary::Declaration);
827
823
}
@@ -892,7 +888,7 @@ static void computeImportForFunction(
892
888
// later, in ComputeCrossModuleImport, after import decisions are
893
889
// complete, which is more efficient than adding them here.
894
890
if (ExportLists)
895
- (*ExportLists)[ExportModulePath][VI] = GlobalValueSummary::Definition ;
891
+ (*ExportLists)[ExportModulePath]. insert (VI) ;
896
892
}
897
893
898
894
auto GetAdjustedThreshold = [](unsigned Threshold, bool IsHotCallsite) {
@@ -998,10 +994,27 @@ static bool isGlobalVarSummary(const ModuleSummaryIndex &Index,
998
994
return false ;
999
995
}
1000
996
1001
- template <class T >
1002
- static unsigned numGlobalVarSummaries (const ModuleSummaryIndex &Index, T &Cont,
1003
- unsigned &DefinedGVS,
1004
- unsigned &DefinedFS) {
997
+ static unsigned
998
+ numGlobalVarSummariesInSet (const ModuleSummaryIndex &Index,
999
+ FunctionImporter::ExportSetTy &ExportSet,
1000
+ unsigned &DefinedGVS, unsigned &DefinedFS) {
1001
+ unsigned NumGVS = 0 ;
1002
+ DefinedGVS = 0 ;
1003
+ DefinedFS = 0 ;
1004
+ for (auto &VI : ExportSet) {
1005
+ if (isGlobalVarSummary (Index, VI.getGUID ())) {
1006
+ ++DefinedGVS;
1007
+ ++NumGVS;
1008
+ } else
1009
+ ++DefinedFS;
1010
+ }
1011
+ return NumGVS;
1012
+ }
1013
+
1014
+ static unsigned
1015
+ numGlobalVarSummaries (const ModuleSummaryIndex &Index,
1016
+ FunctionImporter::FunctionsToImportTy &Cont,
1017
+ unsigned &DefinedGVS, unsigned &DefinedFS) {
1005
1018
unsigned NumGVS = 0 ;
1006
1019
DefinedGVS = 0 ;
1007
1020
DefinedFS = 0 ;
@@ -1046,7 +1059,7 @@ static bool checkVariableImport(
1046
1059
};
1047
1060
1048
1061
for (auto &ExportPerModule : ExportLists)
1049
- for (auto &[VI, Unused] : ExportPerModule.second )
1062
+ for (auto &VI : ExportPerModule.second )
1050
1063
if (!FlattenedImports.count (VI.getGUID ()) &&
1051
1064
IsReadOrWriteOnlyVarNeedingImporting (ExportPerModule.first , VI))
1052
1065
return false ;
@@ -1082,11 +1095,7 @@ void llvm::ComputeCrossModuleImport(
1082
1095
FunctionImporter::ExportSetTy NewExports;
1083
1096
const auto &DefinedGVSummaries =
1084
1097
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 ;
1098
+ for (auto &EI : ELI.second ) {
1090
1099
// Find the copy defined in the exporting module so that we can mark the
1091
1100
// values it references in that specific definition as exported.
1092
1101
// Below we will add all references and called values, without regard to
@@ -1108,19 +1117,19 @@ void llvm::ComputeCrossModuleImport(
1108
1117
for (const auto &VI : GVS->refs ()) {
1109
1118
// Try to emplace the declaration entry. If a definition entry
1110
1119
// already exists for key `VI`, this is a no-op.
1111
- NewExports.try_emplace (VI, GlobalValueSummary::Declaration );
1120
+ NewExports.insert (VI);
1112
1121
}
1113
1122
} else {
1114
1123
auto *FS = cast<FunctionSummary>(S);
1115
1124
for (const auto &Edge : FS->calls ()) {
1116
1125
// Try to emplace the declaration entry. If a definition entry
1117
1126
// already exists for key `VI`, this is a no-op.
1118
- NewExports.try_emplace (Edge.first , GlobalValueSummary::Declaration );
1127
+ NewExports.insert (Edge.first );
1119
1128
}
1120
1129
for (const auto &Ref : FS->refs ()) {
1121
1130
// Try to emplace the declaration entry. If a definition entry
1122
1131
// already exists for key `VI`, this is a no-op.
1123
- NewExports.try_emplace (Ref, GlobalValueSummary::Declaration );
1132
+ NewExports.insert (Ref);
1124
1133
}
1125
1134
}
1126
1135
}
@@ -1129,7 +1138,7 @@ void llvm::ComputeCrossModuleImport(
1129
1138
// the same ref/call target multiple times in above loop, and it is more
1130
1139
// efficient to avoid a set lookup each time.
1131
1140
for (auto EI = NewExports.begin (); EI != NewExports.end ();) {
1132
- if (!DefinedGVSummaries.count (EI->first . getGUID ()))
1141
+ if (!DefinedGVSummaries.count (EI->getGUID ()))
1133
1142
NewExports.erase (EI++);
1134
1143
else
1135
1144
++EI;
@@ -1146,7 +1155,7 @@ void llvm::ComputeCrossModuleImport(
1146
1155
auto &Exports = ExportLists[ModName];
1147
1156
unsigned DefinedGVS = 0 , DefinedFS = 0 ;
1148
1157
unsigned NumGVS =
1149
- numGlobalVarSummaries (Index, Exports, DefinedGVS, DefinedFS);
1158
+ numGlobalVarSummariesInSet (Index, Exports, DefinedGVS, DefinedFS);
1150
1159
LLVM_DEBUG (dbgs () << " * Module " << ModName << " exports " << DefinedFS
1151
1160
<< " function as definitions, "
1152
1161
<< Exports.size () - NumGVS - DefinedFS
0 commit comments