[llvm] r265876 - Drop debug info for DISubprograms that are not referenced by anything

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 9 11:10:26 PDT 2016


Author: adrian
Date: Sat Apr  9 13:10:22 2016
New Revision: 265876

URL: http://llvm.org/viewvc/llvm-project?rev=265876&view=rev
Log:
Drop debug info for DISubprograms that are not referenced by anything

This patch drops the debug info for all DISubprograms that are
(a) not attached to an llvm::Function and
(b) not indirectly reachable via inline scopes from any surviving Function and
(c) not reachable from a type (i.e.: member functions).

Background: I'm currently working on a patch to reverse the pointers
between DICompileUnit and DISubprogram (for more info check Duncan's RFC
on lazy-loading of debug info metadata
http://lists.llvm.org/pipermail/llvm-dev/2016-March/097419.html).
The idea is to remove the list of subprograms from DICompileUnit and
instead point to the owning compile unit from each DISubprogram.
After doing this all DISubprograms fulfilling the above criteria will be
implicitly dropped unless we go through an extra effort to preserve them.

http://reviews.llvm.org/D18477
<rdar://problem/25256815>

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
    llvm/trunk/test/DebugInfo/Generic/nodebug.ll
    llvm/trunk/test/DebugInfo/X86/debug-dead-local-var.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Sat Apr  9 13:10:22 2016
@@ -695,25 +695,6 @@ void DwarfCompileUnit::finishSubprogramD
       applySubprogramAttributesToDefinition(SP, *D);
   }
 }
-void DwarfCompileUnit::collectDeadVariables(const DISubprogram *SP) {
-  assert(SP && "CU's subprogram list contains a non-subprogram");
-  assert(SP->isDefinition() &&
-         "CU's subprogram list contains a subprogram declaration");
-  auto Variables = SP->getVariables();
-  if (Variables.size() == 0)
-    return;
-
-  DIE *SPDIE = DU->getAbstractSPDies().lookup(SP);
-  if (!SPDIE)
-    SPDIE = getDIE(SP);
-  assert(SPDIE);
-  for (const DILocalVariable *DV : Variables) {
-    DbgVariable NewVar(DV, /* IA */ nullptr, DD);
-    auto VariableDie = constructVariableDIE(NewVar);
-    applyVariableAttributes(NewVar, *VariableDie);
-    SPDIE->addChild(std::move(VariableDie));
-  }
-}
 
 void DwarfCompileUnit::emitHeader(bool UseOffsets) {
   // Don't bother labeling the .dwo unit, as its offset isn't used.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h Sat Apr  9 13:10:22 2016
@@ -180,8 +180,6 @@ public:
 
   void finishSubprogramDefinition(const DISubprogram *SP);
 
-  void collectDeadVariables(const DISubprogram *SP);
-
   /// Set the skeleton unit associated with this unit.
   void setSkeleton(DwarfCompileUnit &Skel) { Skeleton = &Skel; }
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Sat Apr  9 13:10:22 2016
@@ -526,32 +526,10 @@ void DwarfDebug::finishVariableDefinitio
 
 void DwarfDebug::finishSubprogramDefinitions() {
   for (const auto &P : SPMap)
-    forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
-      CU.finishSubprogramDefinition(cast<DISubprogram>(P.first));
-    });
-}
-
-// Collect info for variables that were optimized out.
-void DwarfDebug::collectDeadVariables() {
-  const Module *M = MMI->getModule();
-
-  if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
-    for (MDNode *N : CU_Nodes->operands()) {
-      auto *TheCU = cast<DICompileUnit>(N);
-      if (TheCU->getEmissionKind() == DICompileUnit::NoDebug)
-        continue;
-
-      // Construct subprogram DIE and add variables DIEs.
-      DwarfCompileUnit *SPCU =
-          static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
-      assert(SPCU && "Unable to find Compile Unit!");
-      for (auto *SP : TheCU->getSubprograms()) {
-        if (ProcessedSPNodes.count(SP) != 0)
-          continue;
-        SPCU->collectDeadVariables(SP);
-      }
-    }
-  }
+    if (ProcessedSPNodes.count(P.first))
+      forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
+          CU.finishSubprogramDefinition(cast<DISubprogram>(P.first));
+        });
 }
 
 void DwarfDebug::finalizeModuleInfo() {
@@ -561,9 +539,6 @@ void DwarfDebug::finalizeModuleInfo() {
 
   finishVariableDefinitions();
 
-  // Collect info for variables that were optimized out.
-  collectDeadVariables();
-
   // Handle anything that needs to be done on a per-unit basis after
   // all other generation.
   for (const auto &P : CUMap) {
@@ -1129,6 +1104,10 @@ void DwarfDebug::endFunction(const Machi
     PrevCU = nullptr;
     CurFn = nullptr;
     DebugHandlerBase::endFunction(MF);
+    // Mark functions with no debug info on any instructions, but a
+    // valid DISubprogram as processed.
+    if (auto *SP = MF->getFunction()->getSubprogram())
+      ProcessedSPNodes.insert(SP);
     return;
   }
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Sat Apr  9 13:10:22 2016
@@ -320,9 +320,6 @@ class DwarfDebug : public DebugHandlerBa
   /// Construct a DIE for this abstract scope.
   void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
 
-  /// Collect info for variables that were optimized out.
-  void collectDeadVariables();
-
   void finishVariableDefinitions();
 
   void finishSubprogramDefinitions();

Modified: llvm/trunk/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll Sat Apr  9 13:10:22 2016
@@ -26,24 +26,16 @@
 ; }
 ; int (*y)(int) = &func;
 
+; The DISubprogram should show up in compile unit a.
 ; CHECK: DW_TAG_compile_unit
-; CHECK:   DW_TAG_subprogram
 ; CHECK-NOT: DW_TAG
-; CHECK:     DW_AT_name {{.*}} "func"
-; CHECK: DW_TAG_compile_unit
-
-; FIXME: Maybe we should drop the subprogram here - since the function was
-; emitted in one CU, due to linkonce_odr uniquing. We certainly don't emit the
-; subprogram here if the source location for this definition is the same (see
-; test/DebugInfo/cross-cu-linkonce.ll), though it's very easy to tickle that
-; into failing even without duplicating the source as has been done in this
-; case (two cpp files in different directories, including the same header that
-; contains an inline function - clang will produce distinct subprogram metadata
-; that won't deduplicate owing to the file location information containing the
-; directory of the source file even though the file name is absolute, not
-; relative)
+; CHECK:    DW_AT_name {{.*}}"b.cpp"
+; CHECK-NOT: DW_TAG_subprogram
 
-; CHECK: DW_TAG_subprogram
+; CHECK: DW_TAG_compile_unit
+; CHECK-NOT: DW_TAG
+; CHECK:     DW_AT_name {{.*}}"a.cpp"
+; CHECK:     DW_AT_name {{.*}} "func"
 
 @x = global i32 (i32)* @_Z4funci, align 8
 @y = global i32 (i32)* @_Z4funci, align 8
@@ -61,7 +53,7 @@ define linkonce_odr i32 @_Z4funci(i32 %i
 ; Function Attrs: nounwind readnone
 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
 
-attributes #0 = { inlinehint nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #0 = { inlinehint nounwind uwtable }
 attributes #1 = { nounwind readnone }
 
 !llvm.dbg.cu = !{!12, !0}

Modified: llvm/trunk/test/DebugInfo/Generic/nodebug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/nodebug.ll?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/nodebug.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/nodebug.ll Sat Apr  9 13:10:22 2016
@@ -16,10 +16,8 @@
 ;   f1();
 ; }
 
-; Check that there's only one DW_TAG_subprogram, nothing for the 'f2' function.
-; CHECK: DW_TAG_subprogram
-; CHECK-NOT: DW_TAG
-; CHECK:   DW_AT_name {{.*}} "f1"
+; Check that there's no DW_TAG_subprogram, not even for the 'f2' function.
+; CHECK: DW_TAG_compile_unit
 ; CHECK-NOT: DW_TAG_subprogram
 
 @i = external global i32

Modified: llvm/trunk/test/DebugInfo/X86/debug-dead-local-var.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/debug-dead-local-var.ll?rev=265876&r1=265875&r2=265876&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/debug-dead-local-var.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/debug-dead-local-var.ll Sat Apr  9 13:10:22 2016
@@ -11,9 +11,12 @@
 ;   return 1;
 ; }
 
-; Check that we still have the structure type for X even though we're not
-; going to emit a low/high_pc for foo.
-; CHECK: DW_TAG_structure_type
+; Check that we don't have the structure type for X since its scope has
+; been optimized away.
+; CHECK-NOT: DW_TAG_structure_type
+; CHECK: DW_TAG_subprogram
+; CHECK: DW_AT_name {{.*}}"bar"
+; CHECK-NOT: DW_TAG_structure_type
 
 ; Function Attrs: nounwind readnone uwtable
 define i32 @bar() #0 !dbg !4 {




More information about the llvm-commits mailing list