[COFF] Add a fastpath for /INCLUDE: in .drective sections
authorReid Kleckner <rnk@google.com>
Sat, 25 Apr 2020 00:26:17 +0000 (17:26 -0700)
committerReid Kleckner <rnk@google.com>
Tue, 28 Apr 2020 17:35:57 +0000 (10:35 -0700)
commit01b5f521408d943dcb05455c5168ae19bcfaa98a
treeb6d53419f515bdd736a3a3544bbdec89459ff1b3
parent14f07bcab0d60669777fd70d9183c1dc803f12f5
[COFF] Add a fastpath for /INCLUDE: in .drective sections

This speeds up linking chrome.dll with PGO instrumentation by 13%
(154271ms -> 134033ms).

LLVM's Option library is very slow. In particular, it allocates at least
one large-ish heap object (Arg) for every argument. When PGO
instrumentation is enabled, all the __profd_* symbols are added to the
@llvm.used list, which compiles down to these /INCLUDE: directives. This
means we have O(#symbols) directives to parse in the section, so we end
up allocating an Arg for every function symbol in the object file. This
is unnecessary.

To address the issue and speed up the link, extend the fast path that we
already have for /EXPORT:, which has similar scaling issues.

I promise that I took a hard look at optimizing the Option library, but
its data structures are very general and would need a lot of cleanup. We
have accumulated lots of optional features (option groups, aliases,
multiple values) over the years, and these are now properties of every
parsed argument, when the vast majority of arguments do not use these
features.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D78845
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/DriverUtils.cpp