Add an out-of-process ThinLTOCodeGenerator for legacy C API. Instead of
spawning threads and run codegen inside libLTO, OutOfProcess
CodeGenerator constructs clang invocations and uses "clang -fthinlto-index="
option to generate object files. The goal of this design is to enable
libLTO ThinLTOCodeGenerator to expose more information to the build
system so the build system can manage the system resource better.
The other goals/benefits for this design are:
- No linker change is needed using this model. libLTO is in charge of
constructing the job, waiting for the completion and handing back the results
to linker with the exact same API.
- Although this patch only comes with a proof-of-concept out-of-process
code generator which invokes clang locally, it can be easily extended. It
provides a ThinLTOCodegenManager abstraction, which provides customization
points to adapt to any protocol or system.
- It is currenlty using a cl::opt to switch between different ThinLTO
codegen mode which means user can easily toggle between different codegen
models.
Based on patch by Daniel Grumberg
There's a huge amount of code duplication between this and the base ThinLTOCodeGenerator::run(). Perhaps ThinLTOCodeGenerator can be refactored to use a CodegenManager, and have an in-process thread version of CodegenManager so that both can use the same base run() method but the customization points would be in the CodegenManager virtual methods. Or even better, refactor to use ThinBackendProc (see comment above)?