Skip to content

Commit 2331062

Browse files
committed
[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
1 parent b62c7e0 commit 2331062

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

llvm/tools/llvm-link/llvm-link.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static std::unique_ptr<Module> loadArFile(const char *Argv0,
153153
Error Err = Error::success();
154154
object::Archive Archive(*Buffer, Err);
155155
ExitOnErr(std::move(Err));
156+
Linker L(*Result);
156157
for (const object::Archive::Child &C : Archive.children(Err)) {
157158
Expected<StringRef> Ename = C.getName();
158159
if (Error E = Ename.takeError()) {
@@ -186,7 +187,12 @@ static std::unique_ptr<Module> loadArFile(const char *Argv0,
186187
return nullptr;
187188
}
188189

189-
std::unique_ptr<Module> M = parseIR(MemBuf.get(), ParseErr, Context);
190+
std::unique_ptr<Module> M;
191+
if (DisableLazyLoad)
192+
M = parseIR(MemBuf.get(), ParseErr, Context);
193+
else
194+
M = getLazyIRModule(MemoryBuffer::getMemBuffer(MemBuf.get(), false),
195+
ParseErr, Context);
190196

191197
if (!M.get()) {
192198
errs() << Argv0 << ": ";
@@ -197,7 +203,7 @@ static std::unique_ptr<Module> loadArFile(const char *Argv0,
197203
}
198204
if (Verbose)
199205
errs() << "Linking member '" << ChildName << "' of archive library.\n";
200-
if (Linker::linkModules(*Result, std::move(M)))
206+
if (L.linkInModule(std::move(M)))
201207
return nullptr;
202208
} // end for each child
203209
ExitOnErr(std::move(Err));

0 commit comments

Comments
 (0)