summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-08-31 21:26:22 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-08-31 21:26:22 +0000
commit6a150a87ef7d7d546b34ab0b7fe58729da1d6c3e (patch)
tree9aa973a3c4d4ab73f98cb480430e0de3aa2fd47b /llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
parenta8efaf96d4eef19946b53d62ef8c68badc9cab6c (diff)
downloadbcm5719-llvm-6a150a87ef7d7d546b34ab0b7fe58729da1d6c3e.tar.gz
bcm5719-llvm-6a150a87ef7d7d546b34ab0b7fe58729da1d6c3e.zip
DebugInfo: Elide lexical scopes which only contain other (inline or lexical) scopes.
DW_TAG_lexical_scopes inform debuggers about the instruction range for which a given variable (or imported declaration/module/etc) is valid. If the scope doesn't itself contain any such entities, it's a waste of space and should be omitted. We were correctly doing this for entirely empty leaves, but not for intermediate nodes. Reduces total (not just debug sections) .o file size for a bootstrap -gmlt LLVM by 22% and bootstrap -gmlt clang executable by 13%. The wins for a full -g build will be less as a % (and in absolute terms), but should still be substantial - with some of that win being fewer relocations, thus more substantiall reducing link times than fewer bytes alone would have. llvm-svn: 216861
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index defae5d920b..2f0e8181ed5 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -455,15 +455,21 @@ static std::unique_ptr<DIE> constructVariableDIE(DwarfCompileUnit &TheCU,
DIE *DwarfDebug::createScopeChildrenDIE(
DwarfCompileUnit &TheCU, LexicalScope *Scope,
- SmallVectorImpl<std::unique_ptr<DIE>> &Children) {
+ SmallVectorImpl<std::unique_ptr<DIE>> &Children,
+ unsigned *ChildScopeCount) {
DIE *ObjectPointer = nullptr;
for (DbgVariable *DV : ScopeVariables.lookup(Scope))
Children.push_back(constructVariableDIE(TheCU, *DV, *Scope, ObjectPointer));
+ unsigned ChildCountWithoutScopes = Children.size();
+
for (LexicalScope *LS : Scope->getChildren())
- if (std::unique_ptr<DIE> Nested = constructScopeDIE(TheCU, LS))
- Children.push_back(std::move(Nested));
+ constructScopeDIE(TheCU, LS, Children);
+
+ if (ChildScopeCount)
+ *ChildScopeCount = Children.size() - ChildCountWithoutScopes;
+
return ObjectPointer;
}
@@ -565,10 +571,11 @@ DIE &DwarfDebug::constructSubprogramScopeDIE(DwarfCompileUnit &TheCU,
}
// Construct a DIE for this scope.
-std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
- LexicalScope *Scope) {
+void DwarfDebug::constructScopeDIE(
+ DwarfCompileUnit &TheCU, LexicalScope *Scope,
+ SmallVectorImpl<std::unique_ptr<DIE>> &FinalChildren) {
if (!Scope || !Scope->getScopeNode())
- return nullptr;
+ return;
DIScope DS(Scope->getScopeNode());
@@ -586,17 +593,19 @@ std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
if (Scope->getParent() && DS.isSubprogram()) {
ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);
if (!ScopeDIE)
- return nullptr;
+ return;
// We create children when the scope DIE is not null.
createScopeChildrenDIE(TheCU, Scope, Children);
} else {
// Early exit when we know the scope DIE is going to be null.
if (isLexicalScopeDIENull(Scope))
- return nullptr;
+ return;
+
+ unsigned ChildScopeCount;
// We create children here when we know the scope DIE is not going to be
// null and the children will be added to the scope DIE.
- createScopeChildrenDIE(TheCU, Scope, Children);
+ createScopeChildrenDIE(TheCU, Scope, Children, &ChildScopeCount);
// There is no need to emit empty lexical block DIE.
std::pair<ImportedEntityMap::const_iterator,
@@ -609,8 +618,14 @@ std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
++i)
Children.push_back(
constructImportedEntityDIE(TheCU, DIImportedEntity(i->second)));
- if (Children.empty())
- return nullptr;
+ // If there are only other scopes as children, put them directly in the
+ // parent instead, as this scope would serve no purpose.
+ if (Children.size() == ChildScopeCount) {
+ FinalChildren.insert(FinalChildren.end(),
+ std::make_move_iterator(Children.begin()),
+ std::make_move_iterator(Children.end()));
+ return;
+ }
ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);
assert(ScopeDIE && "Scope DIE should not be null.");
}
@@ -619,7 +634,7 @@ std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
for (auto &I : Children)
ScopeDIE->addChild(std::move(I));
- return ScopeDIE;
+ FinalChildren.push_back(std::move(ScopeDIE));
}
void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE &D) const {
OpenPOWER on IntegriCloud