[lld-macho] Cache library paths from findLibrary

On top of https://reviews.llvm.org/D113063 this took another 10 seconds
off our overall link time.

Reviewed By: #lld-macho, int3

Differential Revision: https://reviews.llvm.org/D113073
This commit is contained in:
Keith Smiley 2021-11-03 09:49:13 -07:00
parent 9904bcf2a4
commit f79e65e61f
1 changed files with 23 additions and 8 deletions

View File

@ -80,16 +80,30 @@ static HeaderFileType getOutputType(const InputArgList &args) {
} }
} }
static DenseMap<CachedHashStringRef, StringRef> resolvedLibraries;
static Optional<StringRef> findLibrary(StringRef name) { static Optional<StringRef> findLibrary(StringRef name) {
if (config->searchDylibsFirst) { CachedHashStringRef key(name);
if (Optional<StringRef> path = findPathCombination( auto entry = resolvedLibraries.find(key);
"lib" + name, config->librarySearchPaths, {".tbd", ".dylib"})) if (entry != resolvedLibraries.end())
return path; return entry->second;
auto doFind = [&] {
if (config->searchDylibsFirst) {
if (Optional<StringRef> path = findPathCombination(
"lib" + name, config->librarySearchPaths, {".tbd", ".dylib"}))
return path;
return findPathCombination("lib" + name, config->librarySearchPaths,
{".a"});
}
return findPathCombination("lib" + name, config->librarySearchPaths, return findPathCombination("lib" + name, config->librarySearchPaths,
{".a"}); {".tbd", ".dylib", ".a"});
} };
return findPathCombination("lib" + name, config->librarySearchPaths,
{".tbd", ".dylib", ".a"}); Optional<StringRef> path = doFind();
if (path)
resolvedLibraries[key] = *path;
return path;
} }
static Optional<StringRef> findFramework(StringRef name) { static Optional<StringRef> findFramework(StringRef name) {
@ -1076,6 +1090,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
errorHandler().cleanupCallback = []() { errorHandler().cleanupCallback = []() {
freeArena(); freeArena();
resolvedLibraries.clear();
concatOutputSections.clear(); concatOutputSections.clear();
inputFiles.clear(); inputFiles.clear();
inputSections.clear(); inputSections.clear();