[llvm] 2331062 - [llvm-link] Improve link time for bitcode archives [NFC]
Sergey Dmitriev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 19 17:42:21 PST 2021
Author: Sergey Dmitriev
Date: 2021-01-19T16:41:28-08:00
New Revision: 233106269db6af64f9eff7db0bdf119593f822b1
URL: https://github.com/llvm/llvm-project/commit/233106269db6af64f9eff7db0bdf119593f822b1
DIFF: https://github.com/llvm/llvm-project/commit/233106269db6af64f9eff7db0bdf119593f822b1.diff
LOG: [llvm-link] Improve link time for bitcode archives [NFC]
Linking large bitcode archives currently takes a lot of time with llvm-link,
this patch adds couple improvements which reduce link time for archives
- Use one Linker instance for archive instead of recreating it for each member
- Lazy load archive members
Reviewed By: tra, jdoerfert
Differential Revision: https://reviews.llvm.org/D94643
Added:
Modified:
llvm/tools/llvm-link/llvm-link.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 158b168107f1..eed49c438335 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -153,6 +153,7 @@ static std::unique_ptr<Module> loadArFile(const char *Argv0,
Error Err = Error::success();
object::Archive Archive(*Buffer, Err);
ExitOnErr(std::move(Err));
+ Linker L(*Result);
for (const object::Archive::Child &C : Archive.children(Err)) {
Expected<StringRef> Ename = C.getName();
if (Error E = Ename.takeError()) {
@@ -186,7 +187,12 @@ static std::unique_ptr<Module> loadArFile(const char *Argv0,
return nullptr;
}
- std::unique_ptr<Module> M = parseIR(MemBuf.get(), ParseErr, Context);
+ std::unique_ptr<Module> M;
+ if (DisableLazyLoad)
+ M = parseIR(MemBuf.get(), ParseErr, Context);
+ else
+ M = getLazyIRModule(MemoryBuffer::getMemBuffer(MemBuf.get(), false),
+ ParseErr, Context);
if (!M.get()) {
errs() << Argv0 << ": ";
@@ -197,7 +203,7 @@ static std::unique_ptr<Module> loadArFile(const char *Argv0,
}
if (Verbose)
errs() << "Linking member '" << ChildName << "' of archive library.\n";
- if (Linker::linkModules(*Result, std::move(M)))
+ if (L.linkInModule(std::move(M)))
return nullptr;
} // end for each child
ExitOnErr(std::move(Err));
More information about the llvm-commits
mailing list