ELF: Add --thread option and partially parallelize writeTo().
authorRui Ueyama <ruiu@google.com>
Fri, 11 Mar 2016 04:23:12 +0000 (04:23 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 11 Mar 2016 04:23:12 +0000 (04:23 +0000)
commite98095026f2ca2466e24df8727fb56677ecab649
treeb2993e1a0ad7adc44f0f608dca7ab86bec5757d6
parentadebb9379ae6ce4622672f971219a61a83838034
ELF: Add --thread option and partially parallelize writeTo().

This patch adds --thread option and use parallel_for_each to write
sections in regular OutputSections.

This is the first patch to use more than one threads.

Note that --thread is off by default because it is experimental.
At this moment I still want to focus on single thread performance
because multi-threading is not a magic wand to fix performance
problems after all. It is generally very hard to make a slow program
faster by threads. Therefore, I want to make the linker as efficient
as possible first and then look for opportunity to make it even faster
using more than one core.

Here are some numbers to link programs with and without --threads
and using GNU gold. Numbers are in seconds.

Clang
  w/o --threads 0.697
  w --threads   0.528
  gold          1.643

Scylla
  w/o --threads 5.032
  w --threads   4.935
  gold          6.791

GNU gold
  w/o --threads 0.550
  w --threads   0.551
  gold          0.737

I limited the number of cores these processes can use to 4 using
perf command, so although my machine has 20 physical cores, the
performance gain I observed should be reproducible with a machine
which is not as beefy as mine.

llvm-svn: 263190
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/ELF/OutputSections.cpp