From d8f0ac7b4aa79e1d643f5469874603d53d9e6a33 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 28 Apr 2014 20:27:02 +0000 Subject: 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 --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 77 +++++++++++++++++++----------- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 2 + 2 files changed, 52 insertions(+), 27 deletions(-) (limited to 'llvm/lib/CodeGen') 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, 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, 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::pairsecond, 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); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 1c4903c948d..e9c656e5da8 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -367,6 +367,8 @@ class DwarfDebug : public AsmPrinterHandler { /// \brief Construct a DIE for this scope. DIE *constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope); + /// \brief Construct a DIE for this scope. + DIE *constructSubprogramScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope); /// A helper function to create children of a Scope DIE. DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope, SmallVectorImpl> &Children); -- cgit v1.2.3