aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <kyrtzidis@apple.com>2023-05-22 15:16:20 -0700
committerArgyrios Kyrtzidis <kyrtzidis@apple.com>2023-05-22 21:41:01 -0700
commitbacb45eb9a776c032f69d55a561fa450ba545c57 (patch)
tree2a5eb68d640d86871a0f547b5bbcbb1cad49a783 /llvm/lib/LTO/LTO.cpp
parent61bc3ada1f9088a852126d5556f837f24683160b (diff)
downloadllvm-bacb45eb9a776c032f69d55a561fa450ba545c57.zip
llvm-bacb45eb9a776c032f69d55a561fa450ba545c57.tar.gz
llvm-bacb45eb9a776c032f69d55a561fa450ba545c57.tar.bz2
[ThinLTO] Make the cache key independent of the module identifier paths
Otherwise there are cache misses just from changing the name of a path, even though the input modules did not change. rdar://109672225 Differential Revision: https://reviews.llvm.org/D151165
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index de9b8f1..2f52a20 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -174,22 +174,38 @@ void llvm::computeLTOCacheKey(
// imported symbols for each module may affect code generation and is
// sensitive to link order, so include that as well.
using ImportMapIteratorTy = FunctionImporter::ImportMapTy::const_iterator;
- std::vector<ImportMapIteratorTy> ImportModulesVector;
+ struct ImportModule {
+ ImportMapIteratorTy ModIt;
+ const ModuleSummaryIndex::ModuleInfo *ModInfo;
+
+ StringRef getIdentifier() const { return ModIt->getKey(); }
+ const FunctionImporter::FunctionsToImportTy &getFunctions() const {
+ return ModIt->second;
+ }
+
+ const ModuleHash &getHash() const { return ModInfo->second.second; }
+ uint64_t getId() const { return ModInfo->second.first; }
+ };
+
+ std::vector<ImportModule> ImportModulesVector;
ImportModulesVector.reserve(ImportList.size());
for (ImportMapIteratorTy It = ImportList.begin(); It != ImportList.end();
++It) {
- ImportModulesVector.push_back(It);
+ ImportModulesVector.push_back({It, Index.getModule(It->getKey())});
}
+ // Order using moduleId integer which is based on the order the module was
+ // added.
llvm::sort(ImportModulesVector,
- [](const ImportMapIteratorTy &Lhs, const ImportMapIteratorTy &Rhs)
- -> bool { return Lhs->getKey() < Rhs->getKey(); });
- for (const ImportMapIteratorTy &EntryIt : ImportModulesVector) {
- auto ModHash = Index.getModuleHash(EntryIt->first());
+ [](const ImportModule &Lhs, const ImportModule &Rhs) -> bool {
+ return Lhs.getId() < Rhs.getId();
+ });
+ for (const ImportModule &Entry : ImportModulesVector) {
+ auto ModHash = Entry.getHash();
Hasher.update(ArrayRef<uint8_t>((uint8_t *)&ModHash[0], sizeof(ModHash)));
- AddUint64(EntryIt->second.size());
- for (auto &Fn : EntryIt->second)
+ AddUint64(Entry.getFunctions().size());
+ for (auto &Fn : Entry.getFunctions())
AddUint64(Fn);
}
@@ -259,9 +275,10 @@ void llvm::computeLTOCacheKey(
// Imported functions may introduce new uses of type identifier resolutions,
// so we need to collect their used resolutions as well.
- for (auto &ImpM : ImportList)
- for (auto &ImpF : ImpM.second) {
- GlobalValueSummary *S = Index.findSummaryInModule(ImpF, ImpM.first());
+ for (const ImportModule &ImpM : ImportModulesVector)
+ for (auto &ImpF : ImpM.getFunctions()) {
+ GlobalValueSummary *S =
+ Index.findSummaryInModule(ImpF, ImpM.getIdentifier());
AddUsedThings(S);
// If this is an alias, we also care about any types/etc. that the aliasee
// may reference.