aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DebugInfoMetadata.cpp
diff options
context:
space:
mode:
authorSnehasish Kumar <snehasishk@google.com>2025-05-02 09:36:52 -0700
committerGitHub <noreply@github.com>2025-05-02 09:36:52 -0700
commit5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab (patch)
tree64f6d856ebb5309bcda3c9ed75e2b1b1f9ba8a43 /llvm/lib/IR/DebugInfoMetadata.cpp
parent8313d2a8dbc5e23741d7c67c3b009fc3f6de4875 (diff)
downloadllvm-5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab.zip
llvm-5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab.tar.gz
llvm-5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab.tar.bz2
[Metadata] Return the valid DebugLoc if one of them is null with -pick-merged-source-locations. (#138148)
Previously when getMergedLocation was passed nullptr as one of the parameters we returned nullptr. Change that behaviour to instead return a valid DebugLoc. This is beneficial for binaries from which SamplePGO profiles are obtained.
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index bfe956d..e8a58f1 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -33,13 +33,13 @@ namespace llvm {
cl::opt<bool> EnableFSDiscriminator(
"enable-fs-discriminator", cl::Hidden,
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(
+cl::opt<bool> PickMergedSourceLocations(
"pick-merged-source-locations", cl::init(false), cl::Hidden,
cl::desc("Preserve line and column number when merging locations."));
+} // namespace llvm
uint32_t DIType::getAlignInBits() const {
return (getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ? 0 : SubclassData32);
@@ -228,17 +228,18 @@ struct ScopeLocationsMatcher {
};
DILocation *DILocation::getMergedLocation(DILocation *LocA, DILocation *LocB) {
- if (!LocA || !LocB)
- return nullptr;
-
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.
+ // not useful for PGO. If one of them is null, then try to return one which is
+ // valid.
if (PickMergedSourceLocations) {
+ if (!LocA || !LocB)
+ return LocA ? LocA : LocB;
+
auto A = std::make_tuple(LocA->getLine(), LocA->getColumn(),
LocA->getDiscriminator(), LocA->getFilename(),
LocA->getDirectory());
@@ -248,6 +249,9 @@ DILocation *DILocation::getMergedLocation(DILocation *LocA, DILocation *LocB) {
return A < B ? LocA : LocB;
}
+ if (!LocA || !LocB)
+ return nullptr;
+
LLVMContext &C = LocA->getContext();
using LocVec = SmallVector<const DILocation *>;