@@ -165,22 +165,38 @@ void llvm::computeLTOCacheKey(
165
165
// imported symbols for each module may affect code generation and is
166
166
// sensitive to link order, so include that as well.
167
167
using ImportMapIteratorTy = FunctionImporter::ImportMapTy::const_iterator;
168
- std::vector<ImportMapIteratorTy> ImportModulesVector;
168
+ struct ImportModule {
169
+ ImportMapIteratorTy ModIt;
170
+ const ModuleSummaryIndex::ModuleInfo *ModInfo;
171
+
172
+ StringRef getIdentifier () const { return ModIt->getKey (); }
173
+ const FunctionImporter::FunctionsToImportTy &getFunctions () const {
174
+ return ModIt->second ;
175
+ }
176
+
177
+ const ModuleHash &getHash () const { return ModInfo->second .second ; }
178
+ uint64_t getId () const { return ModInfo->second .first ; }
179
+ };
180
+
181
+ std::vector<ImportModule> ImportModulesVector;
169
182
ImportModulesVector.reserve (ImportList.size ());
170
183
171
184
for (ImportMapIteratorTy It = ImportList.begin (); It != ImportList.end ();
172
185
++It) {
173
- ImportModulesVector.push_back (It );
186
+ ImportModulesVector.push_back ({It, Index. getModule (It-> getKey ())} );
174
187
}
188
+ // Order using moduleId integer which is based on the order the module was
189
+ // added.
175
190
llvm::sort (ImportModulesVector,
176
- [](const ImportMapIteratorTy &Lhs, const ImportMapIteratorTy &Rhs)
177
- -> bool { return Lhs->getKey () < Rhs->getKey (); });
178
- for (const ImportMapIteratorTy &EntryIt : ImportModulesVector) {
179
- auto ModHash = Index.getModuleHash (EntryIt->first ());
191
+ [](const ImportModule &Lhs, const ImportModule &Rhs) -> bool {
192
+ return Lhs.getId () < Rhs.getId ();
193
+ });
194
+ for (const ImportModule &Entry : ImportModulesVector) {
195
+ auto ModHash = Entry.getHash ();
180
196
Hasher.update (ArrayRef<uint8_t >((uint8_t *)&ModHash[0 ], sizeof (ModHash)));
181
197
182
- AddUint64 (EntryIt-> second .size ());
183
- for (auto &Fn : EntryIt-> second )
198
+ AddUint64 (Entry. getFunctions () .size ());
199
+ for (auto &Fn : Entry. getFunctions () )
184
200
AddUint64 (Fn);
185
201
}
186
202
@@ -250,9 +266,10 @@ void llvm::computeLTOCacheKey(
250
266
251
267
// Imported functions may introduce new uses of type identifier resolutions,
252
268
// so we need to collect their used resolutions as well.
253
- for (auto &ImpM : ImportList)
254
- for (auto &ImpF : ImpM.second ) {
255
- GlobalValueSummary *S = Index.findSummaryInModule (ImpF, ImpM.first ());
269
+ for (const ImportModule &ImpM : ImportModulesVector)
270
+ for (auto &ImpF : ImpM.getFunctions ()) {
271
+ GlobalValueSummary *S =
272
+ Index.findSummaryInModule (ImpF, ImpM.getIdentifier ());
256
273
AddUsedThings (S);
257
274
// If this is an alias, we also care about any types/etc. that the aliasee
258
275
// may reference.
0 commit comments