aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorXu Mingjie <xumingjie.enna1@bytedance.com>2021-12-20 18:16:09 -0800
committerFangrui Song <i@maskray.me>2021-12-20 18:16:09 -0800
commitcb63ad8d1d8c5d4d3b50a616067e1aac9ce1eda8 (patch)
tree844f1d0ea238ed89dbc7ff928004ac58f07c35d8 /llvm/lib/LTO/LTO.cpp
parent80c95bbdf359c54abaeacdbcc070b7b5d3b25b6a (diff)
downloadllvm-cb63ad8d1d8c5d4d3b50a616067e1aac9ce1eda8.zip
llvm-cb63ad8d1d8c5d4d3b50a616067e1aac9ce1eda8.tar.gz
llvm-cb63ad8d1d8c5d4d3b50a616067e1aac9ce1eda8.tar.bz2
[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
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 6ce2ed2..f26ef4b 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1106,7 +1106,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
if (Conf.PreOptModuleHook &&
!Conf.PreOptModuleHook(0, *RegularLTO.CombinedModule))
- return Error::success();
+ return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
if (!Conf.CodeGenOnly) {
for (const auto &R : GlobalResolutions) {
@@ -1132,7 +1132,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
if (Conf.PostInternalizeModuleHook &&
!Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))
- return Error::success();
+ return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
}
if (!RegularLTO.EmptyCombinedModule || Conf.AlwaysEmitRegularLTOObj) {