[PATCH] D51759: [llvm] Improve the performance of getSymbols used by ArchiveWriter
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 11 15:03:08 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341998: [object] Improve the performance of getSymbols used by ArchiveWriter (authored by alexshap, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D51759?vs=164328&id=164984#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51759
Files:
llvm/trunk/lib/Object/ArchiveWriter.cpp
Index: llvm/trunk/lib/Object/ArchiveWriter.cpp
===================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp
@@ -372,20 +372,32 @@
static Expected<std::vector<unsigned>>
getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) {
std::vector<unsigned> Ret;
- LLVMContext Context;
- Expected<std::unique_ptr<object::SymbolicFile>> ObjOrErr =
- object::SymbolicFile::createSymbolicFile(Buf, llvm::file_magic::unknown,
- &Context);
- if (!ObjOrErr) {
- // FIXME: check only for "not an object file" errors.
- consumeError(ObjOrErr.takeError());
- return Ret;
+ // In the scenario when LLVMContext is populated SymbolicFile will contain a
+ // reference to it, thus SymbolicFile should be destroyed first.
+ LLVMContext Context;
+ std::unique_ptr<object::SymbolicFile> Obj;
+ if (identify_magic(Buf.getBuffer()) == file_magic::bitcode) {
+ auto ObjOrErr = object::SymbolicFile::createSymbolicFile(
+ Buf, file_magic::bitcode, &Context);
+ if (!ObjOrErr) {
+ // FIXME: check only for "not an object file" errors.
+ consumeError(ObjOrErr.takeError());
+ return Ret;
+ }
+ Obj = std::move(*ObjOrErr);
+ } else {
+ auto ObjOrErr = object::SymbolicFile::createSymbolicFile(Buf);
+ if (!ObjOrErr) {
+ // FIXME: check only for "not an object file" errors.
+ consumeError(ObjOrErr.takeError());
+ return Ret;
+ }
+ Obj = std::move(*ObjOrErr);
}
HasObject = true;
- object::SymbolicFile &Obj = *ObjOrErr.get();
- for (const object::BasicSymbolRef &S : Obj.symbols()) {
+ for (const object::BasicSymbolRef &S : Obj->symbols()) {
if (!isArchiveSymbol(S))
continue;
Ret.push_back(SymNames.tell());
@@ -470,7 +482,7 @@
if (WriteSymtab) {
uint64_t MaxOffset = 0;
uint64_t LastOffset = MaxOffset;
- for (const auto& M : Data) {
+ for (const auto &M : Data) {
// Record the start of the member's offset
LastOffset = MaxOffset;
// Account for the size of each part associated with the member.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51759.164984.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180911/7626f677/attachment.bin>
More information about the llvm-commits
mailing list