[llvm] b2020fe - [DbgHistoryCalculator] Improve debug messages
Felipe de Azevedo Piovezan via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 11 05:49:55 PDT 2023
Author: Felipe de Azevedo Piovezan
Date: 2023-04-11T08:41:29-04:00
New Revision: b2020fe3aab0d9e867d38847de38201a50cf983e
URL: https://github.com/llvm/llvm-project/commit/b2020fe3aab0d9e867d38847de38201a50cf983e
DIFF: https://github.com/llvm/llvm-project/commit/b2020fe3aab0d9e867d38847de38201a50cf983e.diff
LOG: [DbgHistoryCalculator] Improve debug messages
I've found that a frequent source of debug information loss in optimized
code is due to DEBUG_VALUE intrinsics in a position of the instruction
stream that is outside the scope of the variable it describes.
Tracking these is pretty difficult with the existing debug messages of
the history calculator; this patch addresses the issue by making it
obvious when this event happens.
Differential Revision: https://reviews.llvm.org/D147718
Added:
Modified:
llvm/include/llvm/CodeGen/DbgEntityHistoryCalculator.h
llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/DbgEntityHistoryCalculator.h b/llvm/include/llvm/CodeGen/DbgEntityHistoryCalculator.h
index 0cfe04af6f9ef..7708df725180b 100644
--- a/llvm/include/llvm/CodeGen/DbgEntityHistoryCalculator.h
+++ b/llvm/include/llvm/CodeGen/DbgEntityHistoryCalculator.h
@@ -122,7 +122,7 @@ class DbgValueHistoryMap {
EntriesMap::const_iterator end() const { return VarEntries.end(); }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
- LLVM_DUMP_METHOD void dump() const;
+ LLVM_DUMP_METHOD void dump(StringRef FuncName) const;
#endif
};
diff --git a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
index 0b40cdb0c3cc8..55a0afcf7a33f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
@@ -138,6 +138,9 @@ void DbgValueHistoryMap::trimLocationRanges(
// references if any entries are removed.
SmallVector<size_t, 4> Offsets;
+ LLVM_DEBUG(dbgs() << "Trimming location ranges for function '" << MF.getName()
+ << "'\n");
+
for (auto &Record : VarEntries) {
auto &HistoryMapEntries = Record.second;
if (HistoryMapEntries.empty())
@@ -213,6 +216,8 @@ void DbgValueHistoryMap::trimLocationRanges(
// count of the closing entry, if one exists.
if (EndIndex != NoEntry)
ReferenceCount[EndIndex] -= 1;
+ LLVM_DEBUG(dbgs() << "Dropping value outside scope range of variable: ";
+ StartMI->print(llvm::dbgs()););
}
}
@@ -253,6 +258,8 @@ void DbgValueHistoryMap::trimLocationRanges(
// ToRemove indices are valid after each erase.
for (EntryIndex Idx : llvm::reverse(ToRemove))
HistoryMapEntries.erase(HistoryMapEntries.begin() + Idx);
+ LLVM_DEBUG(llvm::dbgs() << "New HistoryMap('" << LocalVar->getName()
+ << "') size: " << HistoryMapEntries.size() << "\n");
}
}
@@ -555,8 +562,8 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const {
- dbgs() << "DbgValueHistoryMap:\n";
+LLVM_DUMP_METHOD void DbgValueHistoryMap::dump(StringRef FuncName) const {
+ dbgs() << "DbgValueHistoryMap('" << FuncName << "'):\n";
for (const auto &VarRangePair : *this) {
const InlinedEntity &Var = VarRangePair.first;
const Entries &Entries = VarRangePair.second;
diff --git a/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp b/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
index 858a3e75e5155..1f1d2430aa0eb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
@@ -273,7 +273,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
InstOrdering.initialize(*MF);
if (TrimVarLocs)
DbgValues.trimLocationRanges(*MF, LScopes, InstOrdering);
- LLVM_DEBUG(DbgValues.dump());
+ LLVM_DEBUG(DbgValues.dump(MF->getName()));
// Request labels for the full history.
for (const auto &I : DbgValues) {
More information about the llvm-commits
mailing list