[PATCH] D115417: [LTO] Fix incomplete optimization remarks when PreOptModuleHook or PostInternalizeModuleHook is defined

Xu Mingjie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 8 18:51:18 PST 2021


Enna1 created this revision.
Enna1 added reviewers: xazax.hun, davide, tejohnson.
Herald added subscribers: ormris, steven_wu, rnkovacs, hiraditya, inglorion.
Enna1 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In https://reviews.llvm.org/rG20a895c4be01769a37dfffb3c6b513a7bc9b8d17, 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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115417

Files:
  llvm/lib/LTO/LTO.cpp


Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -1106,7 +1106,7 @@
 
   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 @@
 
     if (Conf.PostInternalizeModuleHook &&
         !Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))
-      return Error::success();
+      return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
   }
 
   if (!RegularLTO.EmptyCombinedModule || Conf.AlwaysEmitRegularLTOObj) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115417.393008.patch
Type: text/x-patch
Size: 774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211209/ddb28de6/attachment.bin>


More information about the llvm-commits mailing list