[llvm] r193657 - Debug Info: instead of calling addToContextOwner which constructs the context

Manman Ren manman.ren at gmail.com
Tue Oct 29 15:49:29 PDT 2013


Author: mren
Date: Tue Oct 29 17:49:29 2013
New Revision: 193657

URL: http://llvm.org/viewvc/llvm-project?rev=193657&view=rev
Log:
Debug Info: instead of calling addToContextOwner which constructs the context
after the DIE creation, we construct the context first.

Ensure that we create the context before we create a type so that we can add
the newly created type to the parent. Remove last use of addToContextOwner
now that it's not needed.

We use createAndAddDIE to wrap around "new DIE(". Now all shareable DIEs
should be added to their parents right after the creation.

Reviewed off-list by Eric, Thanks.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
    llvm/trunk/test/DebugInfo/X86/DW_AT_byte_size.ll
    llvm/trunk/test/DebugInfo/X86/debug-info-blocks.ll
    llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll
    llvm/trunk/test/DebugInfo/X86/empty-array.ll
    llvm/trunk/test/DebugInfo/X86/gnu-public-names.ll
    llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll
    llvm/trunk/test/DebugInfo/X86/subrange-type.ll
    llvm/trunk/test/DebugInfo/member-pointers.ll
    llvm/trunk/test/DebugInfo/tu-member-pointer.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Tue Oct 29 17:49:29 2013
@@ -826,34 +826,26 @@ DIE *CompileUnit::getOrCreateContextDIE(
     return getDIE(Context);
 }
 
-/// addToContextOwner - Add Die into the list of its context owner's children.
-void CompileUnit::addToContextOwner(DIE *Die, DIScope 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
-    addDie(Die);
-}
-
 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
 /// given DIType.
 DIE *CompileUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
   DIType Ty(TyNode);
   if (!Ty.isType())
     return NULL;
+
+  // Construct the context before querying for the existence of the DIE in case
+  // such construction creates the DIE.
+  DIE *ContextDIE = getOrCreateContextDIE(resolve(Ty.getContext()));
+  if (!ContextDIE)
+    ContextDIE = CUDie.get();
+
   DIE *TyDIE = getDIE(Ty);
   if (TyDIE)
     return TyDIE;
 
   // Create new type.
-  TyDIE = new DIE(Ty.getTag());
-  insertDIE(Ty, TyDIE);
+  TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
+
   if (Ty.isBasicType())
     constructTypeDIE(*TyDIE, DIBasicType(Ty));
   else if (Ty.isCompositeType())
@@ -876,7 +868,6 @@ DIE *CompileUnit::getOrCreateTypeDIE(con
     addAccelType(Ty.getName(), std::make_pair(TyDIE, Flags));
   }
 
-  addToContextOwner(TyDIE, resolve(Ty.getContext()));
   return TyDIE;
 }
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h Tue Oct 29 17:49:29 2013
@@ -280,9 +280,6 @@ public:
   void addVariableAddress(const DbgVariable &DV, DIE *Die,
                           MachineLocation Location);
 
-  /// addToContextOwner - Add Die into the list of its context owner's children.
-  void addToContextOwner(DIE *Die, DIScope Context);
-
   /// addType - Add a new type attribute to the specified entity. This takes
   /// and attribute parameter because DW_AT_friend attributes are also
   /// type references.

Modified: llvm/trunk/test/DebugInfo/X86/DW_AT_byte_size.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/DW_AT_byte_size.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/DW_AT_byte_size.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/DW_AT_byte_size.ll Tue Oct 29 17:49:29 2013
@@ -5,6 +5,7 @@
 ; CHECK: DW_TAG_pointer_type
 ; CHECK-NEXT: DW_AT_type
 ; CHECK-NOT: DW_AT_byte_size
+; CHECK: DW_TAG
 ; CHECK: .debug_info contents
 
 %struct.A = type { i32 }

Modified: llvm/trunk/test/DebugInfo/X86/debug-info-blocks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/debug-info-blocks.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/debug-info-blocks.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/debug-info-blocks.ll Tue Oct 29 17:49:29 2013
@@ -26,7 +26,7 @@
 ; 0x23 = DW_OP_uconst
 ; 0x91 = DW_OP_fbreg
 ; CHECK: DW_AT_location{{.*}}91 {{[0-9]+}} 06 23 {{[0-9]+}} )
-; CHECK: DW_TAG_structure_type
+
 ; CHECK: [[A:.*]]:   DW_TAG_structure_type
 ; CHECK-NEXT: DW_AT_APPLE_objc_complete_type
 ; CHECK-NEXT: DW_AT_name{{.*}}"A"

Modified: llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll Tue Oct 29 17:49:29 2013
@@ -28,37 +28,41 @@ declare void @llvm.dbg.declare(metadata,
 ; An empty array should not have an AT_upper_bound attribute. But an array of 1
 ; should.
 
-; CHECK:      DW_TAG_base_type [5]
+; CHECK:      DW_TAG_base_type
 ; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[{{.*}}] = "int")
 ; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1]   (0x05)
 ; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1]  (0x04)
 
+; int foo::b[1]:
+; CHECK: DW_TAG_structure_type
+; CHECK: DW_AT_name{{.*}}"foo"
+; CHECK:      DW_TAG_member
+; CHECK:      DW_TAG_member
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[{{.*}}] = "b")
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
+
 ; int[1]:
-; CHECK:      DW_TAG_array_type [7] *
+; CHECK:      DW_TAG_array_type [{{.*}}] *
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-; CHECK:      DW_TAG_subrange_type [8]
+; CHECK:      DW_TAG_subrange_type [{{.*}}]
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
 ; CHECK-NEXT: DW_AT_upper_bound [DW_FORM_data1]  (0x00)
 
-; int foo::b[1]:
-; CHECK:      DW_TAG_member [10]
-; CHECK:      DW_TAG_member [10]
+; int bar::b[0]:
+; CHECK: DW_TAG_structure_type
+; CHECK: DW_AT_name{{.*}}"bar"
+; CHECK:      DW_TAG_member
+; CHECK:      DW_TAG_member
 ; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[{{.*}}] = "b")
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
 
 ; int[0]:
-; CHECK:      DW_TAG_array_type [7] *
+; CHECK:      DW_TAG_array_type [{{.*}}] *
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
 ; CHECK:      DW_TAG_subrange_type [11]
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
 ; CHECK-NOT:  DW_AT_upper_bound
 
-; int bar::b[0]:
-; CHECK:      DW_TAG_member [10]
-; CHECK:      DW_TAG_member [10]
-; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[{{.*}}] = "b")
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-
 !llvm.dbg.cu = !{!0}
 
 !0 = metadata !{i32 786449, metadata !32, i32 12, metadata !"clang version 3.3 (trunk 169136)", i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !3, metadata !1,  metadata !1, metadata !""} ; [ DW_TAG_compile_unit ] [/Volumes/Sandbox/llvm/test.c] [DW_LANG_C99]

Modified: llvm/trunk/test/DebugInfo/X86/empty-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/empty-array.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/empty-array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/empty-array.ll Tue Oct 29 17:49:29 2013
@@ -6,22 +6,23 @@
 
 @a = global %class.A zeroinitializer, align 4
 
-; CHECK: [[BASETYPE:0x[0-9a-f]*]]: DW_TAG_base_type
-; CHECK: [[BASE2:0x[0-9a-f]*]]: DW_TAG_base_type
-; CHECK-NEXT: DW_AT_name
-; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1]  (0x04)
-; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1]   (0x05)
+; CHECK: DW_TAG_class_type
+; CHECK:      DW_TAG_member
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[0x{{[0-9a-f]*}}] = "x")
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[ARRAY:0x[0-9a-f]*]]})
 
-; CHECK:      [[ARRAY:0x[0-9a-f]*]]: DW_TAG_array_type [{{.*}}] *
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]    (cu + 0x{{[0-9a-f]*}} => {[[BASETYPE]]})
+; CHECK:      [[ARRAY]]: DW_TAG_array_type [{{.*}}] *
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]    (cu + 0x{{[0-9a-f]*}} => {[[BASETYPE:0x[0-9a-f]*]]})
 
 ; CHECK:      DW_TAG_subrange_type
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[BASE2]]})
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]})
 ; CHECK-NOT:  DW_AT_upper_bound
 
-; CHECK:      DW_TAG_member
-; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[0x{{[0-9a-f]*}}] = "x")
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[ARRAY]]})
+; CHECK: [[BASETYPE]]: DW_TAG_base_type
+; CHECK: [[BASE2]]: DW_TAG_base_type
+; CHECK-NEXT: DW_AT_name
+; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1]  (0x04)
+; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1]   (0x05)
 
 !llvm.dbg.cu = !{!0}
 

Modified: llvm/trunk/test/DebugInfo/X86/gnu-public-names.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/gnu-public-names.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/gnu-public-names.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/gnu-public-names.ll Tue Oct 29 17:49:29 2013
@@ -48,9 +48,6 @@
 ; CHECK: DW_AT_GNU_pubnames [DW_FORM_sec_offset]   (0x00000000)
 ; CHECK: DW_AT_GNU_pubtypes [DW_FORM_sec_offset]   (0x00000000)
 
-; CHECK: [[INT:[0-9a-f]+]]: DW_TAG_base_type
-; CHECK-NEXT: DW_AT_name {{.*}} "int"
-
 ; CHECK: [[C:[0-9a-f]+]]: DW_TAG_structure_type
 ; CHECK-NEXT: DW_AT_name {{.*}} "C"
 
@@ -65,6 +62,9 @@
 ; CHECK-NEXT: DW_AT_MIPS_linkage_name
 ; CHECK-NEXT: DW_AT_name {{.*}} "static_member_function"
 
+; CHECK: [[INT:[0-9a-f]+]]: DW_TAG_base_type
+; CHECK-NEXT: DW_AT_name {{.*}} "int"
+
 ; CHECK: [[STATIC_MEM_VAR:[0-9a-f]+]]: DW_TAG_variable
 ; CHECK-NEXT: DW_AT_specification {{.*}}[[STATIC_MEM_DECL]]
 

Modified: llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll Tue Oct 29 17:49:29 2013
@@ -8,23 +8,24 @@
 ; Check that we can handle non-default array bounds. In this case, the array
 ; goes from [-3, 38].
 
-; CHECK: [[BASE:0x[0-9a-f]*]]: DW_TAG_base_type
-; CHECK: [[BASE2:0x[0-9a-f]*]]: DW_TAG_base_type
-; CHECK-NEXT:                 DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "int")
-; CHECK-NEXT:                 DW_AT_byte_size [DW_FORM_data1] (0x04)
-; CHECK-NEXT:                 DW_AT_encoding [DW_FORM_data1]  (0x05)
+; CHECK: DW_TAG_class_type
+; CHECK: DW_TAG_member
+; CHECK-NEXT:                   DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "x")
+; CHECK-NEXT:                   DW_AT_type [DW_FORM_ref4]       (cu + 0x{{[0-9a-f]*}} => {[[ARRAY:0x[0-9a-f]*]]})
 
-; CHECK: [[ARRAY:0x[0-9a-f]*]]: DW_TAG_array_type [{{.*}}] *
-; CHECK-NEXT:                 DW_AT_type [DW_FORM_ref4]    (cu + 0x{{[0-9a-f]*}} => {[[BASE]]})
+; CHECK: [[ARRAY]]: DW_TAG_array_type [{{.*}}] *
+; CHECK-NEXT:                 DW_AT_type [DW_FORM_ref4]    (cu + 0x{{[0-9a-f]*}} => {[[BASE:0x[0-9a-f]*]]})
 
 ; CHECK: DW_TAG_subrange_type
-; CHECK-NEXT:                   DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[BASE2]]})
+; CHECK-NEXT:                   DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]})
 ; CHECK-NEXT:                   DW_AT_lower_bound [DW_FORM_data8]       (0xfffffffffffffffd)
 ; CHECK-NEXT:                   DW_AT_upper_bound [DW_FORM_data1]       (0x26)
 
-; CHECK: DW_TAG_member
-; CHECK-NEXT:                   DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "x")
-; CHECK-NEXT:                   DW_AT_type [DW_FORM_ref4]       (cu + 0x{{[0-9a-f]*}} => {[[ARRAY]]})
+; CHECK: [[BASE]]: DW_TAG_base_type
+; CHECK: [[BASE2]]: DW_TAG_base_type
+; CHECK-NEXT:                 DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "int")
+; CHECK-NEXT:                 DW_AT_byte_size [DW_FORM_data1] (0x04)
+; CHECK-NEXT:                 DW_AT_encoding [DW_FORM_data1]  (0x05)
 
 !llvm.dbg.cu = !{!0}
 

Modified: llvm/trunk/test/DebugInfo/X86/subrange-type.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/subrange-type.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/subrange-type.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/subrange-type.ll Tue Oct 29 17:49:29 2013
@@ -2,10 +2,10 @@
 ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
 
 ; Make sure that the base type from the subrange type has a name.
-; CHECK: 0x0000006b:   DW_TAG_base_type [6]
+; CHECK: DW_TAG_subrange_type
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]     (cu + 0x{{[0-9a-f]+}} => {[[SUBTYPE:0x[0-9a-f]*]]})
+; CHECK: [[SUBTYPE]]: DW_TAG_base_type
 ; CHECK-NEXT: DW_AT_name
-; CHECK: DW_TAG_subrange_type [8]
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]     (cu + 0x006b => {0x0000006b})
 
 define i32 @main() nounwind uwtable {
 entry:

Modified: llvm/trunk/test/DebugInfo/member-pointers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/member-pointers.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/member-pointers.ll (original)
+++ llvm/trunk/test/DebugInfo/member-pointers.ll Tue Oct 29 17:49:29 2013
@@ -4,12 +4,12 @@
 ; RUN: llc -filetype=obj -O0 < %s > %t
 ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
 ; CHECK: DW_TAG_ptr_to_member_type
-; CHECK: [[TYPE:.*]]:   DW_TAG_subroutine_type
+; CHECK: DW_TAG_ptr_to_member_type
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]       (cu + {{.*}} => {[[TYPE:0x[0-9a-f]+]]})
+; CHECK: [[TYPE]]:   DW_TAG_subroutine_type
 ; CHECK: DW_TAG_formal_parameter
 ; CHECK-NEXT: DW_AT_type
 ; CHECK-NEXT: DW_AT_artificial [DW_FORM_flag
-; CHECK: DW_TAG_ptr_to_member_type
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]       (cu + {{.*}} => {[[TYPE]]})
 ; IR generated from clang -g with the following source:
 ; struct S {
 ; };

Modified: llvm/trunk/test/DebugInfo/tu-member-pointer.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/tu-member-pointer.ll?rev=193657&r1=193656&r2=193657&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/tu-member-pointer.ll (original)
+++ llvm/trunk/test/DebugInfo/tu-member-pointer.ll Tue Oct 29 17:49:29 2013
@@ -2,9 +2,9 @@
 
 ; RUN: llc -filetype=obj -O0 < %s > %t
 ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
-; CHECK: [[TYPE:.*]]:   DW_TAG_base_type
 ; CHECK: DW_TAG_ptr_to_member_type
-; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]       (cu + {{.*}} => {[[TYPE]]})
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]       (cu + {{.*}} => {[[TYPE:0x[0-9a-f]+]]})
+; CHECK: [[TYPE]]:   DW_TAG_base_type
 ; IR generated from clang -g with the following source:
 ; struct Foo {
 ;   int e;





More information about the llvm-commits mailing list