<br><br><div>On Sun Dec 29 2013 at 7:08:41 PM, Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: echristo<br>
Date: Sun Dec 29 21:02:12 2013<br>
New Revision: 198196<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=198196&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=198196&view=rev</a><br>
Log:<br>
Use a pointer to keep track of the skeleton unit for each normal unit<br>
and construct it up front. Add address ranges at the end and a helper<br>
routine so that we're not needlessly using an indirction in the case<br>
of split dwarf.<br>
<br>
Update testcases according to the new ordering of attributes on<br>
the compile unit.<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.cpp<br>
    llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.h<br>
    llvm/trunk/test/DebugInfo/X86/<u></u>fission-cu.ll<br>
    llvm/trunk/test/DebugInfo/X86/<u></u>stmt-list-multiple-compile-<u></u>units.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=198196&r1=198195&r2=198196&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/<u></u>CodeGen/AsmPrinter/DwarfDebug.<u></u>cpp?rev=198196&r1=198195&r2=<u></u>198196&view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfDebug.cpp Sun Dec 29 21:02:12 2013<br>
@@ -773,12 +773,6 @@ DwarfCompileUnit *DwarfDebug::constructD<br>
                  DIUnit.getLanguage());<br>
   NewCU->addString(Die, dwarf::DW_AT_name, FN);<br>
<br>
-  // 2.17.1 requires that we use DW_AT_low_pc for a single entry point<br>
-  // into an entity. We're using 0 (or a NULL label) for this. For<br>
-  // split dwarf it's in the skeleton CU so omit it here.<br>
-  if (!useSplitDwarf())<br>
-    NewCU->addLabelAddress(Die, dwarf::DW_AT_low_pc, NULL);<br>
-<br>
   // Define start line table label for each Compile Unit.<br>
   MCSymbol *LineTableStartSym =<br>
       Asm->GetTempSymbol("line_<u></u>table_start", NewCU->getUniqueID());<br>
@@ -837,6 +831,10 @@ DwarfCompileUnit *DwarfDebug::constructD<br>
       // skeleton units, not full units, if it's going to reference skeletons<br>
       DwarfInfoSectionSym);<br>
<br>
+  // If we're splitting the dwarf then construct the skeleton CU now.<br>
+  if (useSplitDwarf())<br>
+    NewCU->setSkeleton(<u></u>constructSkeletonCU(NewCU));<br>
+<br>
   CUMap.insert(std::make_pair(<u></u>DIUnit, NewCU));<br>
   CUDieMap.insert(std::make_<u></u>pair(Die, NewCU));<br>
   return NewCU;<br>
@@ -1082,7 +1080,9 @@ void DwarfDebug::<u></u>finalizeModuleInfo() {<br>
     // Add CU specific attributes if we need to add any.<br>
     if (TheU->getUnitDie()->getTag() == dwarf::DW_TAG_compile_unit) {<br>
       // If we're splitting the dwarf out now that we've got the entire<br>
-      // CU then construct a skeleton CU based upon it.<br>
+      // CU then add the dwo id to it.<br>
+      DwarfCompileUnit *SkCU =<br>
+          static_cast<DwarfCompileUnit *>(TheU->getSkeleton());<br></blockquote><div><br></div><div>Potentially we could change the check above (== compile_unit) to use dyn_cast on the DwarfUnit itself (would need to add cast machinery to DwarfUnit, I suppose) and add covariant overrides to getSkeleton in Dwarf*Unit so that DwarfCompileUnit::getSkeleton returns a DwarfCompileUnit & you wouldn't need the cast here.</div>
<div><br></div><div>Actually - do you need anything from DwarfCompileUnit specifically here? Or could you just make "SkCU" a DwarfUnit? (self documenting code is a fine reason, just not sure if it's the only one here)</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
       if (useSplitDwarf()) {<br>
         // This should be a unique identifier when we want to build .dwp files.<br>
         uint64_t ID = 0;<br>
@@ -1092,19 +1092,22 @@ void DwarfDebug::<u></u>finalizeModuleInfo() {<br>
         }<br>
         TheU->addUInt(TheU-><u></u>getUnitDie(), dwarf::DW_AT_GNU_dwo_id,<br>
                       dwarf::DW_FORM_data8, ID);<br>
-        // Now construct the skeleton CU associated.<br>
-        DwarfCompileUnit *SkCU =<br>
-            constructSkeletonCU(static_<u></u>cast<DwarfCompileUnit *>(TheU));<br>
         SkCU->addUInt(SkCU-><u></u>getUnitDie(), dwarf::DW_AT_GNU_dwo_id,<br>
                       dwarf::DW_FORM_data8, ID);<br>
-      } else {<br>
-        // Attribute if we've emitted a range list for the compile unit, this<br>
-        // will get constructed for the skeleton CU separately if we have one.<br>
-        if (DwarfCURanges && TheU->getRanges().size())<br>
-          addSectionLabel(Asm, TheU, TheU->getUnitDie(), dwarf::DW_AT_ranges,<br>
-                          Asm->GetTempSymbol("cu_ranges"<u></u>, TheU->getUniqueID()),<br>
-                          DwarfDebugRangeSectionSym);<br>
       }<br>
+<br>
+      // If we've requested ranges and have them emit a DW_AT_ranges attribute<br>
+      // on the unit that will remain in the .o file, otherwise add a DW_AT_low_pc.<br>
+      // FIXME: Also add a high pc if we can.<br>
+      // FIXME: We should use ranges if we have multiple compile units.<br>
+      DwarfCompileUnit *U = SkCU ? SkCU : static_cast<DwarfCompileUnit *>(TheU);<br></blockquote><div><br></div><div>You could just make "U" here a DwarfUnit, since you don't need any DwarfCompileUnit-specific behavior below. Or if you did the cast stuff suggested above, TheU would be a DwarfCompileUnit already.<br>
<br>(could do this half-way, too. Without adding cast machinery to DwarfUnit, you could keep the == compile_unit check, then create a local variable with the static_cast of TheU, then use that both at the first comment (if you added the covariant return overrides) and here)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      if (DwarfCURanges && TheU->getRanges().size())<br>
+        addSectionLabel(Asm, U, U->getUnitDie(), dwarf::DW_AT_ranges,<br>
+                        Asm->GetTempSymbol("cu_ranges"<u></u>, U->getUniqueID()),<br>
+                        DwarfDebugRangeSectionSym);<br>
+      else<br>
+        U->addLocalLabelAddress(U-><u></u>getUnitDie(), dwarf::DW_AT_low_pc,<br>
+                                TextSectionSym);<br>
     }<br>
   }<br>
<br>
@@ -2997,15 +3000,6 @@ DwarfCompileUnit *DwarfDebug::constructS<br>
   else<br>
     NewCU->addSectionOffset(Die, dwarf::DW_AT_GNU_addr_base, 0);<br>
<br>
-  // Attribute if we've emitted a range list for the compile unit, this<br>
-  // will get constructed for the skeleton CU separately if we have one.<br>
-  if (DwarfCURanges && CU->getRanges().size())<br>
-    addSectionLabel(Asm, NewCU, Die, dwarf::DW_AT_ranges,<br>
-                    Asm->GetTempSymbol("cu_ranges"<u></u>, CU->getUniqueID()),<br>
-                    DwarfDebugRangeSectionSym);<br>
-  else<br>
-    NewCU->addUInt(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);<br>
-<br>
   // DW_AT_stmt_list is a offset of line number information for this<br>
   // compile unit in debug_line section.<br>
   // FIXME: Should handle multiple compile units.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=198196&r1=198195&r2=198196&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/<u></u>CodeGen/AsmPrinter/DwarfUnit.<u></u>cpp?rev=198196&r1=198195&r2=<u></u>198196&view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.cpp Sun Dec 29 21:02:12 2013<br>
@@ -293,6 +293,23 @@ void DwarfCompileUnit::<u></u>addLabelAddress(D<br>
   }<br>
 }<br>
<br>
+/// addLocalLabelAddress - Add a dwarf label attribute data and value using<br>
+/// DW_FORM_addr.<br>
+void DwarfCompileUnit::<u></u>addLocalLabelAddress(DIE *Die,<br>
+                                            dwarf::Attribute Attribute,<br>
+                                            MCSymbol *Label) {<br></blockquote><div><br></div><div>Is this refactoring out some common code? I don't see this function being removed from somewhere else. Might've been easier to see the refactor if it were done separately.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  if (Label)<br>
+    DD->addArangeLabel(SymbolCU(<u></u>this, Label));<br>
+<br>
+  if (Label != NULL) {<br></blockquote><div><br></div><div>The same if condition twice? Written in two different ways?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+    DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);<br>
+    Die->addValue(Attribute, dwarf::DW_FORM_addr, Value);<br>
+  } else {<br>
+    DIEValue *Value = new (DIEValueAllocator) DIEInteger(0);<br>
+    Die->addValue(Attribute, dwarf::DW_FORM_addr, Value);<br>
+  }<br>
+}<br>
+<br>
 /// addOpAddress - Add a dwarf op address data and value using the<br>
 /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.<br>
 ///<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=198196&r1=198195&r2=198196&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/<u></u>CodeGen/AsmPrinter/DwarfUnit.<u></u>h?rev=198196&r1=198195&r2=<u></u>198196&view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.h (original)<br>
+++ llvm/trunk/lib/CodeGen/<u></u>AsmPrinter/DwarfUnit.h Sun Dec 29 21:02:12 2013<br>
@@ -146,12 +146,21 @@ protected:<br>
   /// The label for the start of the range sets for the elements of this unit.<br>
   MCSymbol *LabelRange;<br>
<br>
+  /// Skeleton unit associated with this unit.<br>
+  DwarfUnit *Skeleton;<br>
+<br>
   DwarfUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,<br>
             DwarfDebug *DW, DwarfFile *DWU);<br>
<br>
 public:<br>
   virtual ~DwarfUnit();<br>
<br>
+  /// Set the skeleton unit associated with this unit.<br>
+  void setSkeleton(DwarfUnit *Skel) { Skeleton = Skel; }<br>
+<br>
+  /// Get the skeleton unit associated with this unit.<br>
+  DwarfUnit *getSkeleton() const { return Skeleton; }<br>
+<br>
   /// Pass in the SectionSym even though we could recreate it in every compile<br>
   /// unit (type units will have actually distinct symbols once they're in<br>
   /// comdat sections).<br>
@@ -521,6 +530,11 @@ public:<br>
   /// either DW_FORM_addr or DW_FORM_GNU_addr_index.<br>
   void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);<br>
<br>
+  /// addLocalLabelAddress - Add a dwarf label attribute data and value using<br>
+  /// DW_FORM_addr.<br>
+  void addLocalLabelAddress(DIE *Die, dwarf::Attribute Attribute,<br>
+                            MCSymbol *Label);<br>
+<br>
   uint16_t getLanguage() const LLVM_OVERRIDE { return getNode().getLanguage(); }<br>
 };<br>
<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/<u></u>fission-cu.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/fission-cu.ll?rev=198196&r1=198195&r2=198196&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/test/<u></u>DebugInfo/X86/fission-cu.ll?<u></u>rev=198196&r1=198195&r2=<u></u>198196&view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/test/DebugInfo/X86/<u></u>fission-cu.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/<u></u>fission-cu.ll Sun Dec 29 21:02:12 2013<br>
@@ -25,19 +25,19 @@<br>
 ; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_no<br>
 ; CHECK: DW_AT_GNU_dwo_name      DW_FORM_strp<br>
 ; CHECK: DW_AT_GNU_addr_base     DW_FORM_sec_offset<br>
-; CHECK: DW_AT_low_pc    DW_FORM_addr<br>
 ; CHECK: DW_AT_stmt_list DW_FORM_sec_offset<br>
 ; CHECK: DW_AT_comp_dir  DW_FORM_strp<br>
 ; CHECK: DW_AT_GNU_dwo_id        DW_FORM_data8<br>
+; CHECK: DW_AT_low_pc    DW_FORM_addr<br>
<br>
 ; CHECK: .debug_info contents:<br>
 ; CHECK: DW_TAG_compile_unit<br>
 ; CHECK: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000000] = "baz.dwo")<br>
 ; CHECK: DW_AT_GNU_addr_base [DW_FORM_sec_offset]                   (0x00000000)<br>
-; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
 ; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x00000000)<br>
 ; CHECK: DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x00000008] = "/usr/local/google/home/<u></u>echristo/tmp")<br>
 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8]  (0x0000000000000000)<br>
+; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
<br>
 ; CHECK: .debug_str contents:<br>
 ; CHECK: 0x00000000: "baz.dwo"<br>
@@ -110,5 +110,6 @@<br>
 ; OBJ-NEXT: R_X86_64_32 .debug_addr<br>
 ; OBJ-NEXT: R_X86_64_32 .debug_line<br>
 ; OBJ-NEXT: R_X86_64_32 .debug_str<br>
+; OBJ-NEXT: R_X86_64_64 .text 0x0<br>
 ; OBJ-NEXT: }<br>
 !9 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/<u></u>stmt-list-multiple-compile-<u></u>units.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll?rev=198196&r1=198195&r2=198196&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/test/<u></u>DebugInfo/X86/stmt-list-<u></u>multiple-compile-units.ll?rev=<u></u>198196&r1=198195&r2=198196&<u></u>view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/test/DebugInfo/X86/<u></u>stmt-list-multiple-compile-<u></u>units.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/<u></u>stmt-list-multiple-compile-<u></u>units.ll Sun Dec 29 21:02:12 2013<br>
@@ -7,12 +7,12 @@<br>
 ; rdar://13067005<br>
 ; CHECK: .debug_info contents:<br>
 ; CHECK: DW_TAG_compile_unit<br>
-; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
 ; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x00000000)<br>
+; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
<br>
 ; CHECK: DW_TAG_compile_unit<br>
-; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
 ; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x0000003c)<br>
+; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
<br>
 ; CHECK: .debug_line contents:<br>
 ; CHECK-NEXT: Line table prologue:<br>
@@ -25,12 +25,12 @@<br>
<br>
 ; DWARF3: .debug_info contents:<br>
 ; DWARF3: DW_TAG_compile_unit<br>
-; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
 ; DWARF3: DW_AT_stmt_list [DW_FORM_data4]   (0x00000000)<br>
+; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
<br>
 ; DWARF3: DW_TAG_compile_unit<br>
-; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
 ; DWARF3: DW_AT_stmt_list [DW_FORM_data4]   (0x0000003c)<br>
+; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)<br>
<br>
 ; DWARF3: .debug_line contents:<br>
 ; DWARF3-NEXT: Line table prologue:<br>
<br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</blockquote>