Run the resolver in parallel with the reader.
This patch makes File::parse() multi-thread safe. If one thread is running
File::parse(), other threads will block if they try to call the same method.
File::parse() is idempotent, so you can safely call multiple times.
With this change, we don't have to wait for all worker threads to finish
in Driver::link(). Previously, Driver::link() calls TaskGroup::sync() to
wait for all threads running File::parse(). This was not ideal because
we couldn't start the resolver until we parse all files.
This patch increase parallelism by making Driver::link() to not wait for
worker threads. The resolver calls parse() to make sure that the file
being read has been parsed, and then uses the file. In this approach,
the resolver can run with the parser threads in parallel.
http://reviews.llvm.org/D6994
llvm-svn: 226281
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp
index ae2c71f..da7fd53 100644
--- a/lld/lib/Core/Resolver.cpp
+++ b/lld/lib/Core/Resolver.cpp
@@ -236,7 +236,7 @@
for (int i = begin; i < end; ++i)
if (FileNode *node = dyn_cast<FileNode>(inputs[i].get()))
if (_newUndefinesAdded[node->getFile()])
- return true;
+ return true;
return false;
}
@@ -263,7 +263,7 @@
// Keep adding atoms until _context.getNextFile() returns an error. This
// function is where undefined atoms are resolved.
-void Resolver::resolveUndefines() {
+bool Resolver::resolveUndefines() {
ScopedTask task(getDefaultDomain(), "resolveUndefines");
int index = 0;
int groupLevel = 0;
@@ -271,7 +271,12 @@
bool undefAdded = false;
File *file = getFile(index, groupLevel);
if (!file)
- return;
+ return true;
+ if (std::error_code ec = file->parse()) {
+ llvm::errs() << "Cannot open " + file->path()
+ << ": " << ec.message() << "\n";
+ return false;
+ }
switch (file->kind()) {
case File::kindObject:
if (groupLevel > 0)
@@ -441,7 +446,8 @@
}
bool Resolver::resolve() {
- resolveUndefines();
+ if (!resolveUndefines())
+ return false;
updateReferences();
deadStripOptimize();
if (checkUndefines())