[llvm] [DebugInfo] Helper method for finding the deepest inlining location (PR #161696)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 09:33:43 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-debuginfo
Author: Akshay Deodhar (akshayrdeodhar)
<details>
<summary>Changes</summary>
DebugInfoMetadata.h has a way to reach the scope of the deepest caller location, but not to the location itself. Having it is handy for debugging and debug printing.
---
Full diff: https://github.com/llvm/llvm-project/pull/161696.diff
1 Files Affected:
- (modified) llvm/include/llvm/IR/DebugInfoMetadata.h (+12-3)
``````````diff
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 6652e303a6648..d63e71d246fe0 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2600,14 +2600,23 @@ class DILocation : public MDNode {
StringRef getDirectory() const { return getScope()->getDirectory(); }
std::optional<StringRef> getSource() const { return getScope()->getSource(); }
+
+ /// Get the location where this is inlined
+ ///
+ /// Walk through \a getInlinedAt() and return the \a DILocation where this is inlined.
+ DILocation *getInlinedAtLocation() const {
+ DILocation *Current = this, Next = nullptr;
+ while (Next = Current->getInlinedAt())
+ Current = Next;
+ return Current;
+ }
+
/// Get the scope where this is inlined.
///
/// Walk through \a getInlinedAt() and return \a getScope() from the deepest
/// location.
DILocalScope *getInlinedAtScope() const {
- if (auto *IA = getInlinedAt())
- return IA->getInlinedAtScope();
- return getScope();
+ return getInlinedAtLocation()->getScope();
}
/// Get the DWARF discriminator.
``````````
</details>
https://github.com/llvm/llvm-project/pull/161696
More information about the llvm-commits
mailing list