[PATCH] D32881: Read public symbol names for LazyObjectFiles in parallel.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 4 15:44:50 PDT 2017
ruiu updated this revision to Diff 97889.
ruiu added a comment.
- Removed unrelated changes.
https://reviews.llvm.org/D32881
Files:
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
Index: lld/ELF/InputFiles.h
===================================================================
--- lld/ELF/InputFiles.h
+++ lld/ELF/InputFiles.h
@@ -226,15 +226,18 @@
}
template <class ELFT> void parse();
+ void readSymbols();
MemoryBufferRef getBuffer();
InputFile *fetch();
private:
std::vector<StringRef> getSymbols();
template <class ELFT> std::vector<StringRef> getElfSymbols();
std::vector<StringRef> getBitcodeSymbols();
+ llvm::Optional<std::vector<StringRef>> Symbols;
bool Seen = false;
+ llvm::BumpPtrAllocator Alloc;
};
// An ArchiveFile object represents a .a file.
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -984,8 +984,11 @@
return createObjectFile(MBRef);
}
+void LazyObjectFile::readSymbols() { Symbols = getSymbols(); }
+
template <class ELFT> void LazyObjectFile::parse() {
- for (StringRef Sym : getSymbols())
+ assert(Symbols.hasValue());
+ for (StringRef Sym : *Symbols)
Symtab<ELFT>::X->addLazyObject(Sym, *this);
}
@@ -1017,6 +1020,11 @@
std::vector<StringRef> LazyObjectFile::getBitcodeSymbols() {
std::unique_ptr<lto::InputFile> Obj =
check(lto::InputFile::create(this->MB), toString(this));
+
+ // Since this function is called inside parallel_for,
+ // we want to use a per-object allocator.
+ StringSaver Saver(Alloc);
+
std::vector<StringRef> V;
for (const lto::InputFile::Symbol &Sym : Obj->symbols())
if (!Sym.isUndefined())
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -319,6 +319,18 @@
return Default;
}
+// We need to call readSymbols() on each LazyObjectFile to let it
+// construct per-file internal data structure. Do that in parallel.
+static void readLazyObjects(ArrayRef<InputFile *> Files) {
+ std::vector<LazyObjectFile *> V;
+ for (InputFile *F : Files)
+ if (auto *Lazy = dyn_cast<LazyObjectFile>(F))
+ V.push_back(Lazy);
+
+ parallelForEach(V.begin(), V.end(),
+ [](LazyObjectFile *F) { F->readSymbols(); });
+}
+
void LinkerDriver::main(ArrayRef<const char *> ArgsArr, bool CanExitEarly) {
ELFOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -380,6 +392,7 @@
inferMachineType();
setConfigs();
checkOptions(Args);
+ readLazyObjects(Files);
if (ErrorCount)
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32881.97889.patch
Type: text/x-patch
Size: 2491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170504/aeb9ced4/attachment.bin>
More information about the llvm-commits
mailing list