Update June 23, 2023: @fhahn is the original author of this patch. @qiongsiwu1 now continues the work.
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 LTOCodeGenerator's constructor. 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.
It doesn't really make sense to use the post import hook for regular LTO, since that is a ThinLTO-specific optimization. The new LTO API uses the PreOptModuleHook, which is a better fit here (see LTO::runRegularLTO in LTO.cpp).