[PATCH] [lld][Driver] Parallelize reading initial object files.

kledzik at apple.com kledzik at apple.com
Fri Apr 12 16:04:43 PDT 2013



================
Comment at: lib/Driver/Driver.cpp:53-67
@@ +52,17 @@
+
+    tg.spawn([&, index] {
+      auto buffer = input.getBuffer();
+      if (error_code ec = buffer) {
+        diagnostics << "Failed to read file: " << input.getPath()
+                    << ": " << ec.message() << "\n";
+        fail = true;
+        return;
+      }
+
+      std::unique_ptr<MemoryBuffer> buff(MemoryBuffer::getMemBuffer(
+          buffer->getBuffer(), buffer->getBufferIdentifier()));
+      if (error_code ec = targetInfo.parseFile(buff, files[index])) {
+        diagnostics << "Failed to read file: " << input.getPath()
+                    << ": " << ec.message() << "\n";
+        fail = true;
+        return;
----------------
Is there a reason why the high level readFile() in the original was split up into its two low level steps of getBuffer() and parseFile()? Using the low level steps makes this code more complicated.

Also, if multiple files have errors, you can get intermixed error message since you have lots of threads writing to diagnostics at once.  Another way would be to have a parallel array of error_codes and each thread/lambda just sets its error code in ec[index] and returns.  Then after the tg.sync(), you walk the ec array in order and if there is an error, you write it out.  That way every run results in the same error messages in the same order, and you don't need the atomic "fail" anymore (unless  you want it to terminate early).


http://llvm-reviews.chandlerc.com/D664



More information about the llvm-commits mailing list