diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-28 20:27:02 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-28 20:27:02 +0000 |
commit | d8f0ac7b4aa79e1d643f5469874603d53d9e6a33 (patch) | |
tree | 86c216476296a7bf72e85a814f43846c78c73de0 /llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | |
parent | 295b5e74819be8c4f45dcf57cc6686544763eba8 (diff) | |
download | bcm5719-llvm-d8f0ac7b4aa79e1d643f5469874603d53d9e6a33.tar.gz bcm5719-llvm-d8f0ac7b4aa79e1d643f5469874603d53d9e6a33.zip |
DwarfDebug: Omit DW_AT_object_pointer on inlined_subroutines
While refactoring out constructScopeDIE into two functions I realized we
were emitting DW_AT_object_pointer in the inlined subroutine when we
didn't need to (GCC doesn't, and the abstract subprogram definition has
the information already).
So here's the refactoring and the bug fix. This is one step of
refactoring to remove some subtle memory ownership semantics. It turns
out the original constructScopeDIE returned ownership in its return
value in some cases and not in others. The split into two functions now
separates those two semantics - further cleanup (unique_ptr, etc) will
follow.
llvm-svn: 207441
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 948d7fd3807..c0b8044ba17 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -544,6 +544,43 @@ DIE *DwarfDebug::createScopeChildrenDIE( return ObjectPointer; } +DIE *DwarfDebug::constructSubprogramScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope) { + assert(Scope && Scope->getScopeNode()); + + DIScope DS(Scope->getScopeNode()); + + assert(!Scope->getInlinedAt()); + assert(DS.isSubprogram()); + + ProcessedSPNodes.insert(DS); + + SmallVector<std::unique_ptr<DIE>, 8> Children; + DIE *ScopeDIE; + + if (Scope->isAbstractScope()) { + ScopeDIE = TheCU.getDIE(DS); + // Note down abstract DIE. + if (ScopeDIE) + AbstractSPDies.insert(std::make_pair(DS, ScopeDIE)); + else { + assert(Children.empty() && + "We create children only when the scope DIE is not null."); + return nullptr; + } + } else + ScopeDIE = updateSubprogramScopeDIE(TheCU, DISubprogram(DS)); + + // We create children when the scope DIE is not null. + if (DIE *ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children)) + TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer); + + // Add children + for (auto &I : Children) + ScopeDIE->addChild(std::move(I)); + + return ScopeDIE; +} + // Construct a DIE for this scope. DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope) { @@ -552,25 +589,23 @@ DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU, DIScope DS(Scope->getScopeNode()); + assert(Scope->getInlinedAt() || + !DS.isSubprogram() && "Only handle inlined subprograms here, use " + "constructSubprogramScopeDIE for non-inlined " + "subprograms"); + SmallVector<std::unique_ptr<DIE>, 8> Children; - DIE *ObjectPointer = nullptr; - bool ChildrenCreated = false; // We try to create the scope DIE first, then the children DIEs. This will // avoid creating un-used children then removing them later when we find out // the scope DIE is null. DIE *ScopeDIE = nullptr; - if (Scope->getInlinedAt()) + if (Scope->getInlinedAt()) { ScopeDIE = constructInlinedScopeDIE(TheCU, Scope); - else if (DS.isSubprogram()) { - ProcessedSPNodes.insert(DS); - if (Scope->isAbstractScope()) { - ScopeDIE = TheCU.getDIE(DS); - // Note down abstract DIE. - if (ScopeDIE) - AbstractSPDies.insert(std::make_pair(DS, ScopeDIE)); - } else - ScopeDIE = updateSubprogramScopeDIE(TheCU, DISubprogram(DS)); + if (!ScopeDIE) + return nullptr; + // 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)) @@ -578,8 +613,7 @@ DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU, // 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. - ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children); - ChildrenCreated = true; + createScopeChildrenDIE(TheCU, Scope, Children); // There is no need to emit empty lexical block DIE. std::pair<ImportedEntityMap::const_iterator, @@ -596,24 +630,13 @@ DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU, for (ImportedEntityMap::const_iterator i = Range.first; i != Range.second; ++i) constructImportedEntityDIE(TheCU, i->second, ScopeDIE); - } - if (!ScopeDIE) { - assert(Children.empty() && - "We create children only when the scope DIE is not null."); - return nullptr; } - if (!ChildrenCreated) - // We create children when the scope DIE is not null. - ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children); // Add children for (auto &I : Children) ScopeDIE->addChild(std::move(I)); - if (DS.isSubprogram() && ObjectPointer != nullptr) - TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer); - return ScopeDIE; } @@ -1655,10 +1678,10 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { } } if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0) - constructScopeDIE(TheCU, AScope); + constructSubprogramScopeDIE(TheCU, AScope); } - DIE &CurFnDIE = *constructScopeDIE(TheCU, FnScope); + DIE &CurFnDIE = *constructSubprogramScopeDIE(TheCU, FnScope); if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn)) TheCU.addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr); |