[PATCH] D31720: [StripDeadDebugInfo] Drop dead CUs entirely
Keno Fischer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 12:11:53 PDT 2017
loladiro created this revision.
Prior to this while it would delete the dead DIGlobalVariables, it would
leave dead DICompileUnits and everything referenced therefrom. For a bit
bitcode file with thousands of compile units those dead nodes easily
outnumbered the real ones. Clean that up.
https://reviews.llvm.org/D31720
Files:
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
@@ -3,6 +3,7 @@
; CHECK: ModuleID = '{{.*}}'
; CHECK-NOT: "bar"
; CHECK-NOT: "abcd"
+; CHECK-NOT: "GCC"
source_filename = "test/Transforms/StripSymbols/strip-dead-debug-info.ll"
@@ -29,7 +30,7 @@
attributes #1 = { nounwind readnone ssp }
attributes #2 = { nounwind readonly ssp }
-!llvm.dbg.cu = !{!4}
+!llvm.dbg.cu = !{!4, !23}
!llvm.module.flags = !{!9}
!0 = !DIGlobalVariableExpression(var: !1)
@@ -55,4 +56,4 @@
!20 = !DILocation(line: 7, scope: !15)
!21 = !DILocation(line: 10, scope: !22)
!22 = distinct !DILexicalBlock(scope: !15, file: !2, line: 7)
-
+!23 = distinct !DICompileUnit(language: DW_LANG_C89, file: !2, producer: "GCC", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !5)
Index: lib/Transforms/IPO/StripSymbols.cpp
===================================================================
--- lib/Transforms/IPO/StripSymbols.cpp
+++ lib/Transforms/IPO/StripSymbols.cpp
@@ -323,6 +323,15 @@
LiveGVs.insert(GVE);
}
+ 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())
+ LiveCUs.insert(SP->getUnit());
+ }
+
+ bool HasDeadCUs = false;
for (DICompileUnit *DIC : F.compile_units()) {
// Create our live global variable list.
bool GlobalVariableChange = false;
@@ -341,6 +350,12 @@
GlobalVariableChange = true;
}
+ if (!LiveGlobalVariables.empty()) {
+ LiveCUs.insert(DIC);
+ } else if (!LiveCUs.count(DIC)) {
+ HasDeadCUs = true;
+ }
+
// If we found dead global variables, replace the current global
// variable list with our new live global variable list.
if (GlobalVariableChange) {
@@ -352,5 +367,17 @@
LiveGlobalVariables.clear();
}
+ if (HasDeadCUs) {
+ // Delete the old node and replace it with a new one
+ NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
+ NMD->eraseFromParent();
+ if (!LiveCUs.empty()) {
+ NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
+ for (DICompileUnit *CU : LiveCUs)
+ NMD->addOperand(CU);
+ }
+ Changed = true;
+ }
+
return Changed;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31720.94267.patch
Type: text/x-patch
Size: 2490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170405/ea3d3486/attachment.bin>
More information about the llvm-commits
mailing list