diff options
author | Snehasish Kumar <snehasishk@google.com> | 2025-04-04 10:37:25 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-04 09:37:25 -0700 |
commit | f9193f3b18f08547e2f92b5e354a44655bfc1b94 (patch) | |
tree | 76b1dc44c4fad8b1d12438d9f3f72eb11ced2f05 /llvm/lib/IR/DebugInfoMetadata.cpp | |
parent | 5acab1bd15004e0ab7af60d2c4919c189bd38520 (diff) | |
download | llvm-f9193f3b18f08547e2f92b5e354a44655bfc1b94.zip llvm-f9193f3b18f08547e2f92b5e354a44655bfc1b94.tar.gz llvm-f9193f3b18f08547e2f92b5e354a44655bfc1b94.tar.bz2 |
[DebugInfo] Preserve line and column number when merging debug info. (#129960)
This patch introduces a new option `-preserve-merged-debug-info` to
preserve an arbitrary but deterministic version of debug information
when DILocations are merged. This is intended to be used in production
environments from which sample based profiles are derived such as
AutoFDO and MemProf.
With this patch we have see a 0.2% improvement on an internal workload
at Google when generating AutoFDO profiles. It also significantly
improves the ability for MemProf by preserving debug info for merged
call instructions used in the contextual profile.
---------
Co-authored-by: Krzysztof Pszeniczny <kpszeniczny@google.com>
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index f8c24d8..12aba7d 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -21,6 +21,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" +#include "llvm/Support/CommandLine.h" #include <numeric> #include <optional> @@ -34,6 +35,12 @@ cl::opt<bool> EnableFSDiscriminator( cl::desc("Enable adding flow sensitive discriminators")); } // namespace llvm +// When true, preserves line and column number by picking one of the merged +// location info in a deterministic manner to assist sample based PGO. +static cl::opt<bool> PickMergedSourceLocations( + "pick-merged-source-locations", cl::init(false), cl::Hidden, + cl::desc("Preserve line and column number when merging locations.")); + uint32_t DIType::getAlignInBits() const { return (getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ? 0 : SubclassData32); } @@ -125,6 +132,20 @@ DILocation *DILocation::getMergedLocation(DILocation *LocA, DILocation *LocB) { if (LocA == LocB) return LocA; + // For some use cases (SamplePGO), it is important to retain distinct source + // locations. When this flag is set, we choose arbitrarily between A and B, + // rather than computing a merged location using line 0, which is typically + // not useful for PGO. + if (PickMergedSourceLocations) { + auto A = std::make_tuple(LocA->getLine(), LocA->getColumn(), + LocA->getDiscriminator(), LocA->getFilename(), + LocA->getDirectory()); + auto B = std::make_tuple(LocB->getLine(), LocB->getColumn(), + LocB->getDiscriminator(), LocB->getFilename(), + LocB->getDirectory()); + return A < B ? LocA : LocB; + } + LLVMContext &C = LocA->getContext(); using LocVec = SmallVector<const DILocation *>; |