@@ -174,22 +174,38 @@ void llvm::computeLTOCacheKey(
174
174
// imported symbols for each module may affect code generation and is
175
175
// sensitive to link order, so include that as well.
176
176
using ImportMapIteratorTy = FunctionImporter::ImportMapTy::const_iterator;
177
- std::vector<ImportMapIteratorTy> ImportModulesVector;
177
+ struct ImportModule {
178
+ ImportMapIteratorTy ModIt;
179
+ const ModuleSummaryIndex::ModuleInfo *ModInfo;
180
+
181
+ StringRef getIdentifier () const { return ModIt->getKey (); }
182
+ const FunctionImporter::FunctionsToImportTy &getFunctions () const {
183
+ return ModIt->second ;
184
+ }
185
+
186
+ const ModuleHash &getHash () const { return ModInfo->second .second ; }
187
+ uint64_t getId () const { return ModInfo->second .first ; }
188
+ };
189
+
190
+ std::vector<ImportModule> ImportModulesVector;
178
191
ImportModulesVector.reserve (ImportList.size ());
179
192
180
193
for (ImportMapIteratorTy It = ImportList.begin (); It != ImportList.end ();
181
194
++It) {
182
- ImportModulesVector.push_back (It );
195
+ ImportModulesVector.push_back ({It, Index. getModule (It-> getKey ())} );
183
196
}
197
+ // Order using moduleId integer which is based on the order the module was
198
+ // added.
184
199
llvm::sort (ImportModulesVector,
185
- [](const ImportMapIteratorTy &Lhs, const ImportMapIteratorTy &Rhs)
186
- -> bool { return Lhs->getKey () < Rhs->getKey (); });
187
- for (const ImportMapIteratorTy &EntryIt : ImportModulesVector) {
188
- auto ModHash = Index.getModuleHash (EntryIt->first ());
200
+ [](const ImportModule &Lhs, const ImportModule &Rhs) -> bool {
201
+ return Lhs.getId () < Rhs.getId ();
202
+ });
203
+ for (const ImportModule &Entry : ImportModulesVector) {
204
+ auto ModHash = Entry.getHash ();
189
205
Hasher.update (ArrayRef<uint8_t >((uint8_t *)&ModHash[0 ], sizeof (ModHash)));
190
206
191
- AddUint64 (EntryIt-> second .size ());
192
- for (auto &Fn : EntryIt-> second )
207
+ AddUint64 (Entry. getFunctions () .size ());
208
+ for (auto &Fn : Entry. getFunctions () )
193
209
AddUint64 (Fn);
194
210
}
195
211
@@ -259,9 +275,10 @@ void llvm::computeLTOCacheKey(
259
275
260
276
// Imported functions may introduce new uses of type identifier resolutions,
261
277
// so we need to collect their used resolutions as well.
262
- for (auto &ImpM : ImportList)
263
- for (auto &ImpF : ImpM.second ) {
264
- GlobalValueSummary *S = Index.findSummaryInModule (ImpF, ImpM.first ());
278
+ for (const ImportModule &ImpM : ImportModulesVector)
279
+ for (auto &ImpF : ImpM.getFunctions ()) {
280
+ GlobalValueSummary *S =
281
+ Index.findSummaryInModule (ImpF, ImpM.getIdentifier ());
265
282
AddUsedThings (S);
266
283
// If this is an alias, we also care about any types/etc. that the aliasee
267
284
// may reference.
0 commit comments