[PATCH] D31904: [StripDeadDebug/DIFinder] Track inlined SPs

Keno Fischer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 13:05:15 PDT 2017


loladiro created this revision.

In https://reviews.llvm.org/rL299692 I improved strip-dead-debug-info's ability to drop CUs that are not
referenced from the current module. However, in doing so I neglected to realize
that some SPs could be referenced entirely from inlined functions. It appears
I was not the only one to make this mistake, because DebugInfoFinder, doesn't
find those SPs either. Fix this in DebugInfoFinder and then use that to make
sure not to drop those CUs in strip-dead-debug-info.


https://reviews.llvm.org/D31904

Files:
  lib/IR/DebugInfo.cpp
  lib/Transforms/IPO/StripSymbols.cpp
  test/Transforms/StripSymbols/strip-dead-debug-info.ll


Index: test/Transforms/StripSymbols/strip-dead-debug-info.ll
===================================================================
--- test/Transforms/StripSymbols/strip-dead-debug-info.ll
+++ test/Transforms/StripSymbols/strip-dead-debug-info.ll
@@ -24,15 +24,15 @@
 define i32 @foo(i32 %i) #2 !dbg !15 {
 entry:
   tail call void @llvm.dbg.value(metadata i32 %i, i64 0, metadata !18, metadata !19), !dbg !20
-  %.0 = load i32, i32* @xyz, align 4
+  %.0 = load i32, i32* @xyz, align 4, !dbg !30
   ret i32 %.0, !dbg !21
 }
 
 attributes #0 = { nounwind readnone }
 attributes #1 = { nounwind readnone ssp }
 attributes #2 = { nounwind readonly ssp }
 
-!llvm.dbg.cu = !{!4, !23, !24}
+!llvm.dbg.cu = !{!4, !23, !24, !28}
 !llvm.module.flags = !{!9}
 
 !0 = !DIGlobalVariableExpression(var: !1)
@@ -63,3 +63,6 @@
 !25 = !{!26}
 !26 = !DIGlobalVariableExpression(var: !27, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
 !27 = !DIGlobalVariable(name: "abcd2", scope: !2, file: !2, line: 2, type: !3, isLocal: true, isDefinition: true)
+!28 = distinct !DICompileUnit(language: DW_LANG_C89, file: !2, producer: "InlineTest", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !5)
+!29 = distinct !DISubprogram(name: "inlinefunc", linkageName: "inlinefunc", scope: null, file: !2, line: 7, type: !16, isLocal: false, isDefinition: true, isOptimized: true, unit: !28)
+!30 = !DILocation(line: 100, scope: !29, inlinedAt: !21)
Index: lib/Transforms/IPO/StripSymbols.cpp
===================================================================
--- lib/Transforms/IPO/StripSymbols.cpp
+++ lib/Transforms/IPO/StripSymbols.cpp
@@ -324,10 +324,9 @@
   }
 
   std::set<DICompileUnit *> LiveCUs;
-  // Any CU referenced from a function is live.
-  for (Function &F : M.functions()) {
-    DISubprogram *SP = F.getSubprogram();
-    if (SP && SP->getUnit())
+  // Any CU referenced from a subprogram is live.
+  for (DISubprogram *SP : F.subprograms()) {
+    if (SP->getUnit())
       LiveCUs.insert(SP->getUnit());
   }
 
Index: lib/IR/DebugInfo.cpp
===================================================================
--- lib/IR/DebugInfo.cpp
+++ lib/IR/DebugInfo.cpp
@@ -79,9 +79,19 @@
         processScope(M->getScope());
     }
   }
-  for (auto &F : M.functions())
+  for (auto &F : M.functions()) {
     if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
       processSubprogram(SP);
+    // There could be subprograms from inlined functions referenced from
+    // instructions only. Walk the function to find them.
+    for (const BasicBlock &BB : F) {
+      for (const Instruction &I : BB) {
+        if (!I.getDebugLoc())
+          continue;
+        processLocation(M, I.getDebugLoc().get());
+      }
+    }
+  }
 }
 
 void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31904.94727.patch
Type: text/x-patch
Size: 2867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170410/c3a84ab2/attachment.bin>


More information about the llvm-commits mailing list