[lld] r182786 - [Driver] Parallelize reading initial object files.

Rui Ueyama ruiu at google.com
Tue May 28 12:00:34 PDT 2013


On Tue, May 28, 2013 at 11:37 AM, Michael J. Spencer
<bigcheesegs at gmail.com>wrote:

> Author: mspencer
> Date: Tue May 28 13:37:39 2013
> New Revision: 182786
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182786&view=rev
> Log:
> [Driver] Parallelize reading initial object files.
>
> Modified:
>     lld/trunk/lib/Driver/Driver.cpp
>
> Modified: lld/trunk/lib/Driver/Driver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=182786&r1=182785&r2=182786&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/Driver/Driver.cpp (original)
> +++ lld/trunk/lib/Driver/Driver.cpp Tue May 28 13:37:39 2013
> @@ -8,10 +8,12 @@
>
>  //===----------------------------------------------------------------------===//
>
>  #include "lld/Driver/Driver.h"
> +
>  #include "lld/Core/LLVM.h"
>  #include "lld/Core/InputFiles.h"
> -#include "lld/Core/Resolver.h"
>  #include "lld/Core/PassManager.h"
> +#include "lld/Core/Parallel.h"
> +#include "lld/Core/Resolver.h"
>  #include "lld/ReaderWriter/Reader.h"
>  #include "lld/ReaderWriter/Writer.h"
>
> @@ -39,20 +41,33 @@ bool Driver::link(const TargetInfo &targ
>    }
>
>    // Read inputs
> -  InputFiles inputs;
> +  std::vector<std::vector<std::unique_ptr<File>>> files(
> +      targetInfo.inputFiles().size());
> +  size_t index = 0;
> +  std::atomic<bool> fail(false);
> +  TaskGroup tg;
>    for (const auto &input : targetInfo.inputFiles()) {
> -    std::vector<std::unique_ptr<File>> files;
>      if (targetInfo.logInputFiles())
>        llvm::outs() << input.getPath() << "\n";
> -
> -    error_code ec = targetInfo.readFile(input.getPath(), files);
> -    if (ec) {
> -      diagnostics   << "Failed to read file: " << input.getPath() << ": "
> -                    << ec.message() << "\n";
> -      return true;
> -    }
> -    inputs.appendFiles(files);
> +
> +    tg.spawn([&, index] {
> +      if (error_code ec = targetInfo.readFile(input.getPath(),
> files[index])) {
> +        diagnostics << "Failed to read file: " << input.getPath()
> +                    << ": " << ec.message() << "\n";
> +        fail = true;
> +        return;
> +      }
> +    });
> +    ++index;
>

It's coming back to the other thread, but if targetInfo needs to be updated
during input file parsing, parallelizing this piece of code would result in
unpredictable behavior. I'm not saying that we can't paralellize this but
just don't have a good idea to deal with that.

   }
> +  tg.sync();
> +
> +  if (fail)
> +    return true;
> +
> +  InputFiles inputs;
> +  for (auto &f : files)
> +    inputs.appendFiles(f);
>
>    // Give target a chance to add files.
>    targetInfo.addImplicitFiles(inputs);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130528/51266c50/attachment.html>


More information about the llvm-commits mailing list