[LTO] Fix incomplete optimization remarks for dead functions when PreOptModuleHook...
authorXu Mingjie <xumingjie.enna1@bytedance.com>
Tue, 21 Dec 2021 02:16:09 +0000 (18:16 -0800)
committerFangrui Song <i@maskray.me>
Tue, 21 Dec 2021 02:16:09 +0000 (18:16 -0800)
commitcb63ad8d1d8c5d4d3b50a616067e1aac9ce1eda8
tree844f1d0ea238ed89dbc7ff928004ac58f07c35d8
parent80c95bbdf359c54abaeacdbcc070b7b5d3b25b6a
[LTO] Fix incomplete optimization remarks for dead functions when PreOptModuleHook or PostInternalizeModuleHook is defined

In 20a895c4be01769a37dfffb3c6b513a7bc9b8d17, we introduce `finalizeOptimizationRemarks()` to make sure we flush the diagnostic remarks file in case the linker doesn't call the global destructors before exiting.
In https://reviews.llvm.org/D73597, we add optimization remarks for removed functions for debugging or for detecting dead code.
But there is a case, if PreOptModuleHook or PostInternalizeModuleHook is defined (e.g. `--plugin-opt=emit-llvm` is passed to linker), we do not call `finalizeOptimizationRemarks()`, therefore we will get an incomplete optimization remarks file.
This patch make sure we flush the diagnostic remarks file when PreOptModuleHook or PostInternalizeModuleHook is defined.

Reviewed By: tejohnson, MaskRay

Differential Revision: https://reviews.llvm.org/D115417
lld/test/ELF/lto/opt-remarks-incomplete.ll [new file with mode: 0644]
llvm/lib/LTO/LTO.cpp