From be1cec0cb76bf6c56145dc9c33761bbc46eee89d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 18 Nov 2015 00:34:10 +0000 Subject: [PATCH] Generalize ownership/passing semantics to allow dsymutil to own abbreviations via unique_ptr While still allowing CodeGen/AsmPrinter in llvm to own them using a bump ptr allocator. (might be nice to replace the pointers there with something that at least automatically calls their dtors, if that's necessary/useful, rather than having it done explicitly (I think a typed BumpPtrAllocator already does this, or maybe a unique_ptr with a custom deleter, etc)) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253409 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 11 ++++++++++- lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp | 17 +++++------------ tools/dsymutil/DwarfLinker.cpp | 16 ++++++---------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 13755ffaa42..f5e778b2f26 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -453,7 +453,16 @@ public: void emitCFIInstruction(const MCCFIInstruction &Inst) const; /// \brief Emit Dwarf abbreviation table. - void emitDwarfAbbrevs(const std::vector& Abbrevs) const; + template void emitDwarfAbbrevs(const T &Abbrevs) const { + // For each abbreviation. + for (const auto &Abbrev : Abbrevs) + emitDwarfAbbrev(*Abbrev); + + // Mark end of abbreviations. + EmitULEB128(0, "EOM(3)"); + } + + void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const; /// \brief Recursively emit Dwarf DIE tree. void emitDwarfDIE(const DIE &Die) const; diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp index 9ede04c4c1b..504c5d283cb 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp @@ -281,17 +281,10 @@ void AsmPrinter::emitDwarfDIE(const DIE &Die) const { } } -void -AsmPrinter::emitDwarfAbbrevs(const std::vector& Abbrevs) const { - // For each abbreviation. - for (const DIEAbbrev *Abbrev : Abbrevs) { - // Emit the abbreviations code (base 1 index.) - EmitULEB128(Abbrev->getNumber(), "Abbreviation Code"); - - // Emit the abbreviations data. - Abbrev->Emit(this); - } +void AsmPrinter::emitDwarfAbbrev(const DIEAbbrev &Abbrev) const { + // Emit the abbreviations code (base 1 index.) + EmitULEB128(Abbrev.getNumber(), "Abbreviation Code"); - // Mark end of abbreviations. - EmitULEB128(0, "EOM(3)"); + // Emit the abbreviations data. + Abbrev.Emit(this); } diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index 33be88c09c2..7ac6f8ed5e3 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -519,7 +519,7 @@ public: /// \brief Emit the abbreviation table \p Abbrevs to the /// debug_abbrev section. - void emitAbbrevs(const std::vector &Abbrevs); + void emitAbbrevs(const std::vector> &Abbrevs); /// \brief Emit the string table described by \p Pool. void emitStrings(const NonRelocatableStringpool &Pool); @@ -683,7 +683,8 @@ void DwarfStreamer::emitCompileUnitHeader(CompileUnit &Unit) { /// \brief Emit the \p Abbrevs array as the shared abbreviation table /// for the linked Dwarf file. -void DwarfStreamer::emitAbbrevs(const std::vector &Abbrevs) { +void DwarfStreamer::emitAbbrevs( + const std::vector> &Abbrevs) { MS->SwitchSection(MOFI->getDwarfAbbrevSection()); Asm->emitDwarfAbbrevs(Abbrevs); } @@ -1111,11 +1112,6 @@ public: : OutputFilename(OutputFilename), Options(Options), BinHolder(Options.Verbose), LastCIEOffset(0) {} - ~DwarfLinker() { - for (auto *Abbrev : Abbreviations) - delete Abbrev; - } - /// \brief Link the contents of the DebugMap. bool link(const DebugMap &); @@ -1379,7 +1375,7 @@ private: /// \brief Storage for the unique Abbreviations. /// This is passed to AsmPrinter::emitDwarfAbbrevs(), thus it cannot /// be changed to a vecot of unique_ptrs. - std::vector Abbreviations; + std::vector> Abbreviations; /// \brief Compute and emit debug_ranges section for \p Unit, and /// patch the attributes referencing it. @@ -2282,10 +2278,10 @@ void DwarfLinker::AssignAbbrev(DIEAbbrev &Abbrev) { } else { // Add to abbreviation list. Abbreviations.push_back( - new DIEAbbrev(Abbrev.getTag(), Abbrev.hasChildren())); + llvm::make_unique(Abbrev.getTag(), Abbrev.hasChildren())); for (const auto &Attr : Abbrev.getData()) Abbreviations.back()->AddAttribute(Attr.getAttribute(), Attr.getForm()); - AbbreviationsSet.InsertNode(Abbreviations.back(), InsertToken); + AbbreviationsSet.InsertNode(Abbreviations.back().get(), InsertToken); // Assign the unique abbreviation number. Abbrev.setNumber(Abbreviations.size()); Abbreviations.back()->setNumber(Abbreviations.size()); -- 2.34.1