diff options
| author | Keno Fischer <keno@alumni.harvard.edu> | 2017-04-06 19:26:22 +0000 |
|---|---|---|
| committer | Keno Fischer <keno@alumni.harvard.edu> | 2017-04-06 19:26:22 +0000 |
| commit | bacc64b5fae4b8716a6f0313927932182d0d815b (patch) | |
| tree | 7fff6cf6f4e8284d2532e974fbc350e3b1f7c261 /llvm/lib | |
| parent | b122ed918195b46c2aa860c3cf9c6e7371ea03e8 (diff) | |
| download | bcm5719-llvm-bacc64b5fae4b8716a6f0313927932182d0d815b.tar.gz bcm5719-llvm-bacc64b5fae4b8716a6f0313927932182d0d815b.zip | |
[StripDeadDebugInfo] Drop dead CUs entirely
Summary:
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.
Reviewed By: aprantl
Differential Revision: https://reviews.llvm.org/D31720
llvm-svn: 299692
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/IPO/StripSymbols.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp index 8f6f161428e..4d52f5f3110 100644 --- a/llvm/lib/Transforms/IPO/StripSymbols.cpp +++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp @@ -323,6 +323,15 @@ bool StripDeadDebugInfo::runOnModule(Module &M) { 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,11 @@ bool StripDeadDebugInfo::runOnModule(Module &M) { 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 +366,16 @@ bool StripDeadDebugInfo::runOnModule(Module &M) { LiveGlobalVariables.clear(); } + if (HasDeadCUs) { + // Delete the old node and replace it with a new one + NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); + NMD->clearOperands(); + if (!LiveCUs.empty()) { + for (DICompileUnit *CU : LiveCUs) + NMD->addOperand(CU); + } + Changed = true; + } + return Changed; } |

