<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 31, 2014 at 2:40 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Not sure if you guys have found binary size of -gmlt to be an issue - but if you have, this might be of interest.<br>
</div></blockquote><div><br></div><div>For -gline-tables-only we did see issues with binary size, but then Alexey added compression and the issue reduced significantly, IIRC</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br>(the numbers here are uncompressed debug info)</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sun, Aug 31, 2014 at 2:26 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Author: dblaikie<br>
Date: Sun Aug 31 16:26:22 2014<br>
New Revision: 216861<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=216861&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=216861&view=rev</a><br>
Log:<br>
DebugInfo: Elide lexical scopes which only contain other (inline or lexical) scopes.<br>
<br>
DW_TAG_lexical_scopes inform debuggers about the instruction range for<br>
which a given variable (or imported declaration/module/etc) is valid. If<br>
the scope doesn't itself contain any such entities, it's a waste of<br>
space and should be omitted.<br>
<br>
We were correctly doing this for entirely empty leaves, but not for<br>
intermediate nodes.<br>
<br>
Reduces total (not just debug sections) .o file size for a bootstrap<br>
-gmlt LLVM by 22% and bootstrap -gmlt clang executable by 13%. The wins<br>
for a full -g build will be less as a % (and in absolute terms), but<br>
should still be substantial - with some of that win being fewer<br>
relocations, thus more substantiall reducing link times than fewer bytes<br>
alone would have.<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
    llvm/trunk/test/DebugInfo/PR20038.ll<br>
    llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll<br>
    llvm/trunk/test/DebugInfo/X86/fission-ranges.ll<br>
    llvm/trunk/test/DebugInfo/missing-abstract-variable.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=216861&r1=216860&r2=216861&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=216861&r1=216860&r2=216861&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Sun Aug 31 16:26:22 2014<br>
@@ -455,15 +455,21 @@ static std::unique_ptr<DIE> constructVar<br>
<br>
 DIE *DwarfDebug::createScopeChildrenDIE(<br>
     DwarfCompileUnit &TheCU, LexicalScope *Scope,<br>
-    SmallVectorImpl<std::unique_ptr<DIE>> &Children) {<br>
+    SmallVectorImpl<std::unique_ptr<DIE>> &Children,<br>
+    unsigned *ChildScopeCount) {<br>
   DIE *ObjectPointer = nullptr;<br>
<br>
   for (DbgVariable *DV : ScopeVariables.lookup(Scope))<br>
     Children.push_back(constructVariableDIE(TheCU, *DV, *Scope, ObjectPointer));<br>
<br>
+  unsigned ChildCountWithoutScopes = Children.size();<br>
+<br>
   for (LexicalScope *LS : Scope->getChildren())<br>
-    if (std::unique_ptr<DIE> Nested = constructScopeDIE(TheCU, LS))<br>
-      Children.push_back(std::move(Nested));<br>
+    constructScopeDIE(TheCU, LS, Children);<br>
+<br>
+  if (ChildScopeCount)<br>
+    *ChildScopeCount = Children.size() - ChildCountWithoutScopes;<br>
+<br>
   return ObjectPointer;<br>
 }<br>
<br>
@@ -565,10 +571,11 @@ DIE &DwarfDebug::constructSubprogramScop<br>
 }<br>
<br>
 // Construct a DIE for this scope.<br>
-std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,<br>
-                                                   LexicalScope *Scope) {<br>
+void DwarfDebug::constructScopeDIE(<br>
+    DwarfCompileUnit &TheCU, LexicalScope *Scope,<br>
+    SmallVectorImpl<std::unique_ptr<DIE>> &FinalChildren) {<br>
   if (!Scope || !Scope->getScopeNode())<br>
-    return nullptr;<br>
+    return;<br>
<br>
   DIScope DS(Scope->getScopeNode());<br>
<br>
@@ -586,17 +593,19 @@ std::unique_ptr<DIE> DwarfDebug::constru<br>
   if (Scope->getParent() && DS.isSubprogram()) {<br>
     ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);<br>
     if (!ScopeDIE)<br>
-      return nullptr;<br>
+      return;<br>
     // We create children when the scope DIE is not null.<br>
     createScopeChildrenDIE(TheCU, Scope, Children);<br>
   } else {<br>
     // Early exit when we know the scope DIE is going to be null.<br>
     if (isLexicalScopeDIENull(Scope))<br>
-      return nullptr;<br>
+      return;<br>
+<br>
+    unsigned ChildScopeCount;<br>
<br>
     // We create children here when we know the scope DIE is not going to be<br>
     // null and the children will be added to the scope DIE.<br>
-    createScopeChildrenDIE(TheCU, Scope, Children);<br>
+    createScopeChildrenDIE(TheCU, Scope, Children, &ChildScopeCount);<br>
<br>
     // There is no need to emit empty lexical block DIE.<br>
     std::pair<ImportedEntityMap::const_iterator,<br>
@@ -609,8 +618,14 @@ std::unique_ptr<DIE> DwarfDebug::constru<br>
          ++i)<br>
       Children.push_back(<br>
           constructImportedEntityDIE(TheCU, DIImportedEntity(i->second)));<br>
-    if (Children.empty())<br>
-      return nullptr;<br>
+    // If there are only other scopes as children, put them directly in the<br>
+    // parent instead, as this scope would serve no purpose.<br>
+    if (Children.size() == ChildScopeCount) {<br>
+      FinalChildren.insert(FinalChildren.end(),<br>
+                           std::make_move_iterator(Children.begin()),<br>
+                           std::make_move_iterator(Children.end()));<br>
+      return;<br>
+    }<br>
     ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);<br>
     assert(ScopeDIE && "Scope DIE should not be null.");<br>
   }<br>
@@ -619,7 +634,7 @@ std::unique_ptr<DIE> DwarfDebug::constru<br>
   for (auto &I : Children)<br>
     ScopeDIE->addChild(std::move(I));<br>
<br>
-  return ScopeDIE;<br>
+  FinalChildren.push_back(std::move(ScopeDIE));<br>
 }<br>
<br>
 void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE &D) const {<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=216861&r1=216860&r2=216861&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=216861&r1=216860&r2=216861&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Sun Aug 31 16:26:22 2014<br>
@@ -377,8 +377,8 @@ class DwarfDebug : public AsmPrinterHand<br>
                                                 LexicalScope *Scope);<br>
<br>
   /// \brief Construct a DIE for this scope.<br>
-  std::unique_ptr<DIE> constructScopeDIE(DwarfCompileUnit &TheCU,<br>
-                                         LexicalScope *Scope);<br>
+  void constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,<br>
+                         SmallVectorImpl<std::unique_ptr<DIE>> &FinalChildren);<br>
   DIE *createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope,<br>
                                  DIE &ScopeDIE);<br>
   /// \brief Construct a DIE for this abstract scope.<br>
@@ -389,7 +389,8 @@ class DwarfDebug : public AsmPrinterHand<br>
                                    LexicalScope *Scope);<br>
   /// A helper function to create children of a Scope DIE.<br>
   DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,<br>
-                              SmallVectorImpl<std::unique_ptr<DIE>> &Children);<br>
+                              SmallVectorImpl<std::unique_ptr<DIE>> &Children,<br>
+                              unsigned *ChildScopeCount = nullptr);<br>
<br>
   /// \brief Emit initial Dwarf sections with a label at the start of each one.<br>
   void emitSectionLabels();<br>
<br>
Modified: llvm/trunk/test/DebugInfo/PR20038.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PR20038.ll?rev=216861&r1=216860&r2=216861&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PR20038.ll?rev=216861&r1=216860&r2=216861&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/test/DebugInfo/PR20038.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/PR20038.ll Sun Aug 31 16:26:22 2014<br>
@@ -30,23 +30,19 @@<br>
 ; CHECK-NOT: DW_TAG<br>
 ; CHECK:   DW_AT_name {{.*}} "fun4"<br>
 ; CHECK-NOT: {{DW_TAG|NULL}}<br>
-; CHECK:   DW_TAG_lexical_block<br>
-; CHECK-NOT: {{DW_TAG|NULL}}<br>
-; CHECK:     DW_TAG_inlined_subroutine<br>
+; CHECK:   DW_TAG_inlined_subroutine<br>
 ; CHECK-NOT: DW_TAG<br>
-; CHECK:       DW_AT_abstract_origin {{.*}} {[[D1_ABS]]}<br>
+; CHECK:     DW_AT_abstract_origin {{.*}} {[[D1_ABS]]}<br>
 ; CHECK-NOT: {{DW_TAG|NULL}}<br>
-; CHECK:       DW_TAG_formal_parameter<br>
+; CHECK:     DW_TAG_formal_parameter<br>
 ; CHECK-NOT: DW_TAG<br>
-; CHECK:         DW_AT_abstract_origin {{.*}} {[[D1_THIS_ABS]]}<br>
+; CHECK:       DW_AT_abstract_origin {{.*}} {[[D1_THIS_ABS]]}<br>
<br>
 ; FIXME: D2 is actually inlined into D1 but doesn't show up here, possibly due<br>
 ; to there being no work in D2 (calling another member function from the dtor<br>
 ; causes D2 to show up, calling a free function doesn't).<br>
<br>
 ; CHECK-NOT: DW_TAG<br>
-; CHECK:       NULL<br>
-; CHECK-NOT: DW_TAG<br>
 ; CHECK:     NULL<br>
 ; CHECK-NOT: DW_TAG<br>
 ; CHECK:   NULL<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll?rev=216861&r1=216860&r2=216861&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll?rev=216861&r1=216860&r2=216861&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll Sun Aug 31 16:26:22 2014<br>
@@ -32,9 +32,6 @@<br>
 ; CHECK: DW_TAG_formal_parameter<br>
 ; CHECK-NOT: NULL<br>
 ; CHECK-NOT: DW_TAG<br>
-; CHECK: DW_TAG_lexical_block<br>
-; CHECK-NOT: NULL<br>
-; CHECK-NOT: DW_TAG<br>
 ; CHECK: DW_TAG_inlined_subroutine<br>
 ; CHECK-NEXT: DW_AT_abstract_origin {{.*}} {[[ASSIGN:0x........]]}<br>
 ; CHECK-NOT: NULL<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/fission-ranges.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/fission-ranges.ll?rev=216861&r1=216860&r2=216861&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/fission-ranges.ll?rev=216861&r1=216860&r2=216861&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/fission-ranges.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/fission-ranges.ll Sun Aug 31 16:26:22 2014<br>
@@ -16,7 +16,7 @@<br>
 ; CHECK: DW_AT_location [DW_FORM_sec_offset]   ([[E:0x[0-9a-z]*]])<br>
 ; CHECK: DW_AT_location [DW_FORM_sec_offset]   ([[B:0x[0-9a-z]*]])<br>
 ; CHECK: DW_AT_location [DW_FORM_sec_offset]   ([[D:0x[0-9a-z]*]])<br>
-; CHECK: DW_AT_ranges [DW_FORM_sec_offset]   (0x000000a0)<br>
+; CHECK: DW_AT_ranges [DW_FORM_sec_offset]   (0x00000000)<br>
 ; CHECK: .debug_loc contents:<br>
 ; CHECK-NOT: Beginning address offset<br>
 ; CHECK: .debug_loc.dwo contents:<br>
<br>
Modified: llvm/trunk/test/DebugInfo/missing-abstract-variable.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/missing-abstract-variable.ll?rev=216861&r1=216860&r2=216861&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/missing-abstract-variable.ll?rev=216861&r1=216860&r2=216861&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/test/DebugInfo/missing-abstract-variable.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/missing-abstract-variable.ll Sun Aug 31 16:26:22 2014<br>
@@ -45,8 +45,6 @@<br>
 ; CHECK-NOT: DW_TAG<br>
 ; CHECK:     DW_AT_name {{.*}} "b"<br>
 ; CHECK-NOT: {{DW_TAG|NULL}}<br>
-; CHECK:     DW_TAG_lexical_block<br>
-; CHECK-NOT: {{DW_TAG|NULL}}<br>
 ; CHECK:       DW_TAG_lexical_block<br>
 ; CHECK-NOT: {{DW_TAG|NULL}}<br>
 ; CHECK: [[ABS_S:.*]]:       DW_TAG_variable<br>
@@ -89,19 +87,12 @@<br>
 ; CHECK-NOT: DW_TAG<br>
 ; CHECK:       DW_AT_abstract_origin {{.*}} {[[ABS_B]]}<br>
<br>
-; The two lexical blocks here are caused by the scope of the if that includes<br>
-; the condition variable, and the scope within the if's composite statement. I'm<br>
-; not sure we really need both of them since there's no variable declared in the<br>
-; outer of the two<br>
-<br>
 ; CHECK-NOT: {{DW_TAG|NULL}}<br>
 ; CHECK:     DW_TAG_lexical_block<br>
 ; CHECK-NOT: {{DW_TAG|NULL}}<br>
-; CHECK:       DW_TAG_lexical_block<br>
-; CHECK-NOT: {{DW_TAG|NULL}}<br>
-; CHECK:         DW_TAG_variable<br>
+; CHECK:       DW_TAG_variable<br>
 ; CHECK-NOT: DW_TAG<br>
-; CHECK:           DW_AT_abstract_origin {{.*}} {[[ABS_S]]}<br>
+; CHECK:         DW_AT_abstract_origin {{.*}} {[[ABS_S]]}<br>
<br>
 @t = external global i32<br>
<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>