[llvm] r191928 - DebugInfo: Avoid redundantly adding child DIEs to parents.

David Blaikie dblaikie at gmail.com
Thu Oct 3 13:07:20 PDT 2013


Author: dblaikie
Date: Thu Oct  3 15:07:20 2013
New Revision: 191928

URL: http://llvm.org/viewvc/llvm-project?rev=191928&view=rev
Log:
DebugInfo: Avoid redundantly adding child DIEs to parents.

DIE::addChild had a shortcircuit that silently no-op'd when a child was
readded to the same parent. This hid some quirky/redundant code in
DwarfDebug/CompileUnit. By removing that functionality and replacing it
with an assert I was able to find and cleanup those cases, mostly
centering around adding members to types in various circumstances.

1) The original oddity I noticed while working on type units (which
actually was helping me in the short term, by accident) was the
addToContextOwner call in constructTypeDIE. This call was completely
bogus (why was it only done for non-virtual types? what relevance does
that have at all) and redundant with the more uniform addToContextOwner
made in getOrCreateTypeDIE.

2) If a member function definition was visited (createSubprogramDIE), it
would attempt to build the member function declaration. The declaration
DIE would then be added to its context, but in building the context (the
type for which this function is a member) the members of the type would
be added to the type automatically, so by the time the context was
constructed, the member function was already associated with it.

3) The same as (2) but without the member function being constructed
first. Whenever a type was constructed, the members would be created and
member functions would be created by getOrCreateSubprogramDIE - this
would lead to the subprogram being added to the (incomplete) type
already, then the general member-construction code would add it again.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h?rev=191928&r1=191927&r2=191928&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h Thu Oct  3 15:07:20 2013
@@ -169,10 +169,7 @@ namespace llvm {
     /// addChild - Add a child to the DIE.
     ///
     void addChild(DIE *Child) {
-      if (Child->getParent()) {
-        assert (Child->getParent() == this && "Unexpected DIE Parent!");
-        return;
-      }
+      assert(!Child->getParent());
       Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
       Children.push_back(Child);
       Child->Parent = this;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=191928&r1=191927&r2=191928&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Thu Oct  3 15:07:20 2013
@@ -808,9 +808,16 @@ DIE *CompileUnit::getOrCreateContextDIE(
 
 /// addToContextOwner - Add Die into the list of its context owner's children.
 void CompileUnit::addToContextOwner(DIE *Die, DIDescriptor Context) {
-  if (DIE *ContextDIE = getOrCreateContextDIE(Context))
+  assert(!Die->getParent());
+  if (DIE *ContextDIE = getOrCreateContextDIE(Context)) {
+    if (Die->getParent()) {
+      // While creating the context, if this is a type member, we will have
+      // added the child to the context already.
+      assert(Die->getParent() == ContextDIE);
+      return;
+    }
     ContextDIE->addChild(Die);
-  else
+  } else
     addDie(Die);
 }
 
@@ -1124,6 +1131,7 @@ void CompileUnit::constructTypeDIE(DIE &
           ElemDie = createStaticMemberDIE(DDTy);
         else
           ElemDie = createMemberDIE(DDTy);
+        Buffer.addChild(ElemDie);
       } else if (Element.isObjCProperty()) {
         DIObjCProperty Property(Element);
         ElemDie = new DIE(Property.getTag());
@@ -1159,9 +1167,9 @@ void CompileUnit::constructTypeDIE(DIE &
           Entry = createDIEEntry(ElemDie);
           insertDIEEntry(Element, Entry);
         }
+        Buffer.addChild(ElemDie);
       } else
         continue;
-      Buffer.addChild(ElemDie);
     }
 
     if (CTy.isAppleBlockExtension())
@@ -1171,8 +1179,6 @@ void CompileUnit::constructTypeDIE(DIE &
     if (DIDescriptor(ContainingType).isCompositeType())
       addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
                   getOrCreateTypeDIE(DIType(ContainingType)));
-    else
-      addToContextOwner(&Buffer, DD->resolve(CTy.getContext()));
 
     if (CTy.isObjcClassComplete())
       addFlag(&Buffer, dwarf::DW_AT_APPLE_objc_complete_type);

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=191928&r1=191927&r2=191928&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Oct  3 15:07:20 2013
@@ -838,12 +838,6 @@ void DwarfDebug::constructSubprogramDIE(
 
   DIE *SubprogramDie = TheCU->getOrCreateSubprogramDIE(SP);
 
-  // Add to map.
-  TheCU->insertDIE(N, SubprogramDie);
-
-  // Add to context owner.
-  TheCU->addToContextOwner(SubprogramDie, SP.getContext());
-
   // Expose as a global name.
   TheCU->addGlobalName(SP.getName(), SubprogramDie);
 }





More information about the llvm-commits mailing list