DebugInfo: Implement MDLocation::getInlinedAtScope()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 30 Mar 2015 17:41:24 +0000 (17:41 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 30 Mar 2015 17:41:24 +0000 (17:41 +0000)
Write `MDLocation::getInlinedAtScope()` and use it to re-implement
`DebugLoc::getScopeNode()` (and simplify `DISubprogram::Verify()`).
This follows the inlined-at linked list and returns the scope of the
deepest/last location.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233568 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DebugInfoMetadata.h
lib/IR/DebugInfo.cpp
lib/IR/DebugLoc.cpp

index 5097ecf4c8b17065744a15c48e6e093dbcebd39c..a1e229e3743b7f6ee9299ec4d86d71b8b847cd74 100644 (file)
@@ -949,6 +949,16 @@ public:
     return cast_or_null<MDLocation>(getRawInlinedAt());
   }
 
+  /// \brief Get the scope where this is inlined.
+  ///
+  /// Walk through \a getInlinedAt() and return \a getScope() from the deepest
+  /// location.
+  MDLocalScope *getInlinedAtScope() const {
+    if (auto *IA = getInlinedAt())
+      return IA->getInlinedAtScope();
+    return getScope();
+  }
+
   Metadata *getRawScope() const { return getOperand(0); }
   Metadata *getRawInlinedAt() const {
     if (getNumOperands() == 2)
index ec4f95eb71f1c3d6b2b94ce73a48f5a59e4f095b..e16ac8c20f6717990c4a04f5d275e4ca2d6b97c3 100644 (file)
@@ -349,9 +349,7 @@ bool DISubprogram::Verify() const {
           continue;
 
         // walk the inlined-at scopes
-        while (MDLocation *IA = DL->getInlinedAt())
-          DL = IA;
-        MDScope *Scope = DL->getScope();
+        MDScope *Scope = DL->getInlinedAtScope();
         if (!Scope)
           return false;
         while (!isa<MDSubprogram>(Scope)) {
index e1bf7951a5882142f8bf062e92a59e4769a0044f..6b2a53959300e6c5e752e080789bcf9c7185d0c5 100644 (file)
@@ -33,9 +33,7 @@ void DebugLoc::getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const {
 }
 
 MDNode *DebugLoc::getScopeNode() const {
-  if (MDNode *InlinedAt = getInlinedAt())
-    return DebugLoc::getFromDILocation(InlinedAt).getScopeNode();
-  return getScope();
+  return cast<MDLocation>(Loc)->getInlinedAtScope();
 }
 
 DebugLoc DebugLoc::getFnDebugLoc() const {