diff options
author | Rui Ueyama <ruiu@google.com> | 2015-01-16 15:54:13 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2015-01-16 15:54:13 +0000 |
commit | d4730ea555f1ac7a84a12199a2e9627dc9e4e31c (patch) | |
tree | 5a39727b21f5f77c72da370a861fbe9d16473484 /lld/lib/Driver/Driver.cpp | |
parent | 694cb5d9b7724a0c6dba3adbf7c855e847a6f0de (diff) | |
download | bcm5719-llvm-d4730ea555f1ac7a84a12199a2e9627dc9e4e31c.tar.gz bcm5719-llvm-d4730ea555f1ac7a84a12199a2e9627dc9e4e31c.zip |
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
Diffstat (limited to 'lld/lib/Driver/Driver.cpp')
-rw-r--r-- | lld/lib/Driver/Driver.cpp | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp index 85c2bd9d402..dc4b49132d0 100644 --- a/lld/lib/Driver/Driver.cpp +++ b/lld/lib/Driver/Driver.cpp @@ -77,42 +77,9 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { if (context.getNodes().empty()) return false; - bool fail = false; - - // Read inputs - ScopedTask readTask(getDefaultDomain(), "Read Args"); - TaskGroup tg; - std::mutex diagnosticsMutex; - for (std::unique_ptr<Node> &ie : context.getNodes()) { - tg.spawn([&] { - // Writes to the same output stream is not guaranteed to be thread-safe. - // We buffer the diagnostics output to a separate string-backed output - // stream, acquire the lock, and then print it out. - std::string buf; - llvm::raw_string_ostream stream(buf); - - if (FileNode *node = dyn_cast<FileNode>(ie.get())) { - if (File *file = node->getFile()) { - if (std::error_code ec = file->parse()) { - stream << "Cannot open " + file->path() - << ": " << ec.message() << "\n"; - fail = true; - } - } - } - - stream.flush(); - if (!buf.empty()) { - std::lock_guard<std::mutex> lock(diagnosticsMutex); - diagnostics << buf; - } - }); - } - tg.sync(); - readTask.end(); - - if (fail) - return false; + for (std::unique_ptr<Node> &ie : context.getNodes()) + if (FileNode *node = dyn_cast<FileNode>(ie.get())) + context.getTaskGroup().spawn([node] { node->getFile()->parse(); }); std::vector<std::unique_ptr<File>> internalFiles; context.createInternalFiles(internalFiles); |