aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorXu Mingjie <xumingjie.enna1@bytedance.com>2021-09-21 12:56:50 -0700
committerTeresa Johnson <tejohnson@google.com>2021-09-21 14:50:21 -0700
commit32ab405717ecb92041d8f753a1ccd0e5dd874cb7 (patch)
tree7de0e39fac9f16e54f885254161356a0fe28efb8 /llvm/lib/LTO/LTO.cpp
parente95731cca7ecf5be22ea67a273cb19ba2c14d54c (diff)
downloadllvm-32ab405717ecb92041d8f753a1ccd0e5dd874cb7.zip
llvm-32ab405717ecb92041d8f753a1ccd0e5dd874cb7.tar.gz
llvm-32ab405717ecb92041d8f753a1ccd0e5dd874cb7.tar.bz2
[LTO] Emit DebugLoc for dead function in optimization remarks
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. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D109737
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index deb367b..dfaf3b6 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -857,10 +857,14 @@ Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
for (GlobalValue *GV : Mod.Keep) {
if (LivenessFromIndex && !ThinLTO.CombinedIndex.isGUIDLive(GV->getGUID())) {
if (Function *F = dyn_cast<Function>(GV)) {
- OptimizationRemarkEmitter ORE(F, nullptr);
- ORE.emit(OptimizationRemark(DEBUG_TYPE, "deadfunction", F)
- << ore::NV("Function", F)
- << " not added to the combined module ");
+ if (DiagnosticOutputFile) {
+ if (Error Err = F->materialize())
+ return Err;
+ OptimizationRemarkEmitter ORE(F, nullptr);
+ ORE.emit(OptimizationRemark(DEBUG_TYPE, "deadfunction", F)
+ << ore::NV("Function", F)
+ << " not added to the combined module ");
+ }
}
continue;
}
@@ -1049,6 +1053,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
Conf.RemarksHotnessThreshold);
if (!DiagFileOrErr)
return DiagFileOrErr.takeError();
+ DiagnosticOutputFile = std::move(*DiagFileOrErr);
// Finalize linking of regular LTO modules containing summaries now that
// we have computed liveness information.
@@ -1137,7 +1142,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
return Err;
}
- return finalizeOptimizationRemarks(std::move(*DiagFileOrErr));
+ return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
}
static const char *libcallRoutineNames[] = {