[PATCH] D109737: [LTO] Emit DebugLoc for dead function in optimization remarks

Xu Mingjie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 13 20:44:08 PDT 2021


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

Currently, the dead functions information getting from optimizations remarks does not contain debug location, but knowing where these dead functions locate could be useful for debugging or for detecting dead code.

Cause in `LTO::addRegularLTO()` we use `BitcodeModule::getLazyModule()` to read the bitcode module, when we pass Function F to `ore::NV()`, F is not materialized, so `F->getSubprogram()` returns nullptr, and there is no debug location information of dead functions in optimizations remarks.

This patch call `F->materialize()` before we pass Function F to `ore::NV()`, then debug location information will be emitted for dead functions in optimization remarks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109737

Files:
  llvm/lib/LTO/LTO.cpp


Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -857,6 +857,8 @@
   for (GlobalValue *GV : Mod.Keep) {
     if (LivenessFromIndex && !ThinLTO.CombinedIndex.isGUIDLive(GV->getGUID())) {
       if (Function *F = dyn_cast<Function>(GV)) {
+        if (Error Err = F->materialize())
+          return std::move(Err);
         OptimizationRemarkEmitter ORE(F, nullptr);
         ORE.emit(OptimizationRemark(DEBUG_TYPE, "deadfunction", F)
                  << ore::NV("Function", F)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109737.372393.patch
Type: text/x-patch
Size: 578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210914/be5e88c5/attachment.bin>


More information about the llvm-commits mailing list