[llvm] [DebugInfo] Helper method for finding the deepest inlining location (PR #161696)

Akshay Deodhar via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 2 09:33:08 PDT 2025


https://github.com/akshayrdeodhar created https://github.com/llvm/llvm-project/pull/161696

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. 

>From a3caad6ccd05c9a2e924fae470c4deb9cf3eead7 Mon Sep 17 00:00:00 2001
From: Akshay Deodhar <adeodhar at nvidia.com>
Date: Thu, 25 Sep 2025 21:21:01 +0000
Subject: [PATCH] [DebugInfo] Helper method for finding the deepest inlining
 location

---
 llvm/include/llvm/IR/DebugInfoMetadata.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

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.



More information about the llvm-commits mailing list