[llvm] r210221 - DebugInfo: Reapply r209984 (reverted in r210143), asserting that abstract DbgVariables have DIEs.

David Blaikie dblaikie at gmail.com
Wed Jun 4 16:50:53 PDT 2014


Author: dblaikie
Date: Wed Jun  4 18:50:52 2014
New Revision: 210221

URL: http://llvm.org/viewvc/llvm-project?rev=210221&view=rev
Log:
DebugInfo: Reapply r209984 (reverted in r210143), asserting that abstract DbgVariables have DIEs.

Abstract variables within abstract scopes that are entirely optimized
away in their first inlining are omitted because their scope is not
present so the variable is never created. Instead, we should ensure the
scope is created so the variable can be added, even if it's been
optimized away in its first inlining.

This fixes the incorrect debug info in missing-abstract-variable.ll
(added in r210143) and passes an asserts self-hosting build, so
hopefully there's not more of these issues left behind... *fingers
crossed*.

Modified:
    llvm/trunk/include/llvm/CodeGen/LexicalScopes.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/test/DebugInfo/missing-abstract-variable.ll

Modified: llvm/trunk/include/llvm/CodeGen/LexicalScopes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LexicalScopes.h?rev=210221&r1=210220&r2=210221&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LexicalScopes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LexicalScopes.h Wed Jun  4 18:50:52 2014
@@ -197,6 +197,9 @@ public:
   /// dump - Print data structures to dbgs().
   void dump();
 
+  /// getOrCreateAbstractScope - Find or create an abstract lexical scope.
+  LexicalScope *getOrCreateAbstractScope(const MDNode *N);
+
 private:
   /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
   /// not available then create new lexical scope.
@@ -208,9 +211,6 @@ private:
   /// getOrCreateInlinedScope - Find or create an inlined lexical scope.
   LexicalScope *getOrCreateInlinedScope(MDNode *Scope, MDNode *InlinedAt);
 
-  /// getOrCreateAbstractScope - Find or create an abstract lexical scope.
-  LexicalScope *getOrCreateAbstractScope(const MDNode *N);
-
   /// extractLexicalScopes - Extract instruction ranges for each lexical scopes
   /// for the given machine function.
   void extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges,

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=210221&r1=210220&r2=210221&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Jun  4 18:50:52 2014
@@ -1052,24 +1052,49 @@ DbgVariable *DwarfDebug::findAbstractVar
   return findAbstractVariable(DV, ScopeLoc.getScope(DV->getContext()));
 }
 
-DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
-                                              const MDNode *ScopeNode) {
+DbgVariable *DwarfDebug::getExistingAbstractVariable(DIVariable &DV,
+                                                     DIVariable &Cleansed) {
   LLVMContext &Ctx = DV->getContext();
   // More then one inlined variable corresponds to one abstract variable.
-  DIVariable Var = cleanseInlinedVariable(DV, Ctx);
-  auto I = AbstractVariables.find(Var);
+  // FIXME: This duplication of variables when inlining should probably be
+  // removed. It's done to allow each DIVariable to describe its location
+  // because the DebugLoc on the dbg.value/declare isn't accurate. We should
+  // make it accurate then remove this duplication/cleansing stuff.
+  Cleansed = cleanseInlinedVariable(DV, Ctx);
+  auto I = AbstractVariables.find(Cleansed);
   if (I != AbstractVariables.end())
     return I->second.get();
+  return nullptr;
+}
 
-  LexicalScope *Scope = LScopes.findAbstractScope(ScopeNode);
-  if (!Scope)
-    return nullptr;
-
+DbgVariable *DwarfDebug::createAbstractVariable(DIVariable &Var,
+                                                LexicalScope *Scope) {
   auto AbsDbgVariable = make_unique<DbgVariable>(Var, nullptr, this);
   addScopeVariable(Scope, AbsDbgVariable.get());
   return (AbstractVariables[Var] = std::move(AbsDbgVariable)).get();
 }
 
+DbgVariable *DwarfDebug::getOrCreateAbstractVariable(DIVariable &DV,
+                                                     const MDNode *ScopeNode) {
+  DIVariable Cleansed = DV;
+  if (DbgVariable *Var = getExistingAbstractVariable(DV, Cleansed))
+    return Var;
+
+  return createAbstractVariable(Cleansed,
+                                LScopes.getOrCreateAbstractScope(ScopeNode));
+}
+
+DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
+                                              const MDNode *ScopeNode) {
+  DIVariable Cleansed = DV;
+  if (DbgVariable *Var = getExistingAbstractVariable(DV, Cleansed))
+    return Var;
+
+  if (LexicalScope *Scope = LScopes.findAbstractScope(ScopeNode))
+    return createAbstractVariable(Cleansed, Scope);
+  return nullptr;
+}
+
 // If Var is a current function argument then add it to CurrentFnArguments list.
 bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
   if (!LScopes.isCurrentFunctionScope(Scope))
@@ -1513,7 +1538,7 @@ void DwarfDebug::endFunction(const Machi
       assert(DV && DV.isVariable());
       if (!ProcessedVars.insert(DV))
         continue;
-      findAbstractVariable(DV, DV.getContext());
+      getOrCreateAbstractVariable(DV, DV.getContext());
     }
     constructAbstractSubprogramScopeDIE(TheCU, AScope);
   }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=210221&r1=210220&r2=210221&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Wed Jun  4 18:50:52 2014
@@ -343,6 +343,11 @@ class DwarfDebug : public AsmPrinterHand
   }
 
   /// \brief Find abstract variable associated with Var.
+  DbgVariable *getExistingAbstractVariable(DIVariable &DV,
+                                           DIVariable &Cleansed);
+  DbgVariable *createAbstractVariable(DIVariable &DV, LexicalScope *Scope);
+  DbgVariable *getOrCreateAbstractVariable(DIVariable &Var,
+                                           const MDNode *Scope);
   DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
   DbgVariable *findAbstractVariable(DIVariable &Var, const MDNode *Scope);
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=210221&r1=210220&r2=210221&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Wed Jun  4 18:50:52 2014
@@ -1782,12 +1782,10 @@ std::unique_ptr<DIE> DwarfUnit::construc
   // Define variable debug information entry.
   auto VariableDie = make_unique<DIE>(DV.getTag());
   DbgVariable *AbsVar = DV.getAbstractVariable();
-  // FIXME: any missing abstract variable missing a DIE will result in incorrect
-  // DWARF. More details in test/DebugInfo/missing-abstract-variable.ll for an
-  // example of why this is happening.
-  if (AbsVar && AbsVar->getDIE())
+  if (AbsVar) {
+    assert(AbsVar->getDIE());
     addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin, *AbsVar->getDIE());
-  else {
+  } else {
     if (!Name.empty())
       addString(*VariableDie, dwarf::DW_AT_name, Name);
     addSourceLine(*VariableDie, DV.getVariable());

Modified: llvm/trunk/test/DebugInfo/missing-abstract-variable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/missing-abstract-variable.ll?rev=210221&r1=210220&r2=210221&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/missing-abstract-variable.ll (original)
+++ llvm/trunk/test/DebugInfo/missing-abstract-variable.ll Wed Jun  4 18:50:52 2014
@@ -44,7 +44,14 @@
 ; CHECK: [[ABS_B:.*]]:   DW_TAG_formal_parameter
 ; CHECK-NOT: DW_TAG
 ; CHECK:     DW_AT_name {{.*}} "b"
-; FIXME: Missing 'x's local 's' variable.
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK:     DW_TAG_lexical_block
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK:       DW_TAG_lexical_block
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK: [[ABS_S:.*]]:       DW_TAG_variable
+; CHECK-NOT: DW_TAG
+; CHECK:         DW_AT_name {{.*}} "s"
 
 ; CHECK: DW_TAG_subprogram
 ; CHECK-NOT: DW_TAG
@@ -75,14 +82,17 @@
 ; CHECK-NOT: DW_TAG
 ; CHECK:     DW_AT_abstract_origin {{.*}} {[[ABS_X]]}
 ; CHECK-NOT: {{DW_TAG|NULL}}
-; FIXME: This formal parameter goes missing at least at -O2, maybe before that.
+; FIXME: This formal parameter goes missing at least at -O2 (& on
+; mips/powerpc), maybe before that. Perhaps SelectionDAG is to blame (and
+; fastisel succeeds).
 ; CHECK:     DW_TAG_formal_parameter
 ; CHECK-NOT: DW_TAG
 ; CHECK:       DW_AT_abstract_origin {{.*}} {[[ABS_B]]}
 
 ; The two lexical blocks here are caused by the scope of the if that includes
 ; the condition variable, and the scope within the if's composite statement. I'm
-; not sure we really need both of them.
+; not sure we really need both of them since there's no variable declared in the
+; outer of the two
 
 ; CHECK-NOT: {{DW_TAG|NULL}}
 ; CHECK:     DW_TAG_lexical_block
@@ -91,12 +101,7 @@
 ; CHECK-NOT: {{DW_TAG|NULL}}
 ; CHECK:         DW_TAG_variable
 ; CHECK-NOT: DW_TAG
-
-; FIXME: This shouldn't have a name here, it should use DW_AT_abstract_origin
-; to reference an abstract variable definition instead
-
-; CHECK:           DW_AT_name {{.*}} "s"
-
+; CHECK:           DW_AT_abstract_origin {{.*}} {[[ABS_S]]}
 
 @t = external global i32
 





More information about the llvm-commits mailing list