summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2016-04-09 18:10:22 +0000
committerAdrian Prantl <aprantl@apple.com>2016-04-09 18:10:22 +0000
commit3891e9e859e76dec82f88a9ed902fe7e016147cd (patch)
treeda3080840db67a29d4270cced162335e3c3ea913 /llvm/lib/CodeGen/AsmPrinter
parent4abae4e0faea4930ca7d941358ba535835cba1c0 (diff)
downloadbcm5719-llvm-3891e9e859e76dec82f88a9ed902fe7e016147cd.tar.gz
bcm5719-llvm-3891e9e859e76dec82f88a9ed902fe7e016147cd.zip
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> llvm-svn: 265876
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp19
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp37
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h3
4 files changed, 8 insertions, 53 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index a51342a7fee..0daca72b30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -695,25 +695,6 @@ void DwarfCompileUnit::finishSubprogramDefinition(const DISubprogram *SP) {
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.
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
index bacf87d95c4..1170b379080 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
@@ -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; }
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index d9d265ef2b9..9195ca310a2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -526,32 +526,10 @@ void DwarfDebug::finishVariableDefinitions() {
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 MachineFunction *MF) {
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;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index f0859ec1a8f..1f83434c530 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -320,9 +320,6 @@ class DwarfDebug : public DebugHandlerBase {
/// 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();
OpenPOWER on IntegriCloud