-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[DebugInfo] Helper method for finding the deepest inlining location #161696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-debuginfo Author: Akshay Deodhar (akshayrdeodhar) ChangesDebugInfoMetadata.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:
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.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
4bfd729
to
394b18e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, I'm surprised this doesn't already exist.
Could you add some unittest coverage? getInlinedAtScope
doesn't look particularly well covered as is, but is at least called in llvm/unittests/Transforms/Utils/CloningTest.cpp
- checking multiple levels of inlining would probably be ideal, but doing something similar to the getInlinedAtScope
should probably be a minimum.
I'm planning to add a test to DebugInfoTest.cpp- does that work? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple nits
9420e2c
to
3a5ea6a
Compare
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.