This patch rebases https://reviews.llvm.org/D98183 and consolidates -save-temps across libLTO, llvm-lto and llvm-lto2.
Original summary of https://reviews.llvm.org/D98183:
This patch updates LTOCodeGenerator to use addSaveTemps to support the
-save-temps option when using libLTO. At the moment, the save-temps
hooks are set up in parseCodeGenDebugOptions, because that's the
earliest the options have been parsed. I am not sure if there's a better
place, given the way libLTO's API is structured. At the moment, the
temporary files are created in the current working directory, because I
do not think there's a way to get the path for the final binary
up-front.
It also adds support for running the PostImportModuleHook just before
IR optimiztions are run. At the moment, the following temporary files
are created:
ld-temp.0.3.import.bc (before IR optimizations) ld-temp.0.4.opt.bc (after IR optimizations) ld-temp.0.5.precodegen.bc (before codegen)
Other hooks can be supported in the future, but the 3 IR files above
should be the most valuable ones when investigating mis-compiles or
crashes when doing full LTO using libLTO.
llvm-lto2.cpp tests the new LTO API, so it is a bit odd for it to use a flag from the legacy LTO API.
I'm not sure it makes sense to common the flag between these 2 different interfaces and their corresponding tools.