<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 17, 2015 at 4:34 PM, David Blaikie via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: dblaikie<br>
Date: Tue Nov 17 18:34:10 2015<br>
New Revision: 253409<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=253409&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=253409&view=rev</a><br>
Log:<br>
Generalize ownership/passing semantics to allow dsymutil to own abbreviations via unique_ptr<br>
<br>
While still allowing CodeGen/AsmPrinter in llvm to own them using a bump<br>
ptr allocator. (might be nice to replace the pointers there with<br>
something that at least automatically calls their dtors, if that's<br>
necessary/useful, rather than having it done explicitly (I think a typed<br>
BumpPtrAllocator already does this,</blockquote><div><br></div><div>It does: <a href="http://llvm.org/docs/doxygen/html/Allocator_8h_source.html#l00356">http://llvm.org/docs/doxygen/html/Allocator_8h_source.html#l00356</a></div><div><br></div><div>```</div><div>~SpecificBumpPtrAllocator() { DestroyAll(); }<br></div><div>```</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> or maybe a unique_ptr with a custom<br>
deleter, etc))<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp<br>
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=253409&r1=253408&r2=253409&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=253409&r1=253408&r2=253409&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Nov 17 18:34:10 2015<br>
@@ -453,7 +453,16 @@ public:<br>
   void emitCFIInstruction(const MCCFIInstruction &Inst) const;<br>
<br>
   /// \brief Emit Dwarf abbreviation table.<br>
-  void emitDwarfAbbrevs(const std::vector<DIEAbbrev *>& Abbrevs) const;<br>
+  template <typename T> void emitDwarfAbbrevs(const T &Abbrevs) const {<br>
+    // For each abbreviation.<br>
+    for (const auto &Abbrev : Abbrevs)<br>
+      emitDwarfAbbrev(*Abbrev);<br>
+<br>
+    // Mark end of abbreviations.<br>
+    EmitULEB128(0, "EOM(3)");<br>
+  }<br>
+<br>
+  void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const;<br>
<br>
   /// \brief Recursively emit Dwarf DIE tree.<br>
   void emitDwarfDIE(const DIE &Die) const;<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp?rev=253409&r1=253408&r2=253409&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp?rev=253409&r1=253408&r2=253409&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp Tue Nov 17 18:34:10 2015<br>
@@ -281,17 +281,10 @@ void AsmPrinter::emitDwarfDIE(const DIE<br>
   }<br>
 }<br>
<br>
-void<br>
-AsmPrinter::emitDwarfAbbrevs(const std::vector<DIEAbbrev *>& Abbrevs) const {<br>
-  // For each abbreviation.<br>
-  for (const DIEAbbrev *Abbrev : Abbrevs) {<br>
-    // Emit the abbreviations code (base 1 index.)<br>
-    EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");<br>
+void AsmPrinter::emitDwarfAbbrev(const DIEAbbrev &Abbrev) const {<br>
+  // Emit the abbreviations code (base 1 index.)<br>
+  EmitULEB128(Abbrev.getNumber(), "Abbreviation Code");<br>
<br>
-    // Emit the abbreviations data.<br>
-    Abbrev->Emit(this);<br>
-  }<br>
-<br>
-  // Mark end of abbreviations.<br>
-  EmitULEB128(0, "EOM(3)");<br>
+  // Emit the abbreviations data.<br>
+  Abbrev.Emit(this);<br>
 }<br>
<br>
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=253409&r1=253408&r2=253409&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=253409&r1=253408&r2=253409&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)<br>
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Tue Nov 17 18:34:10 2015<br>
@@ -519,7 +519,7 @@ public:<br>
<br>
   /// \brief Emit the abbreviation table \p Abbrevs to the<br>
   /// debug_abbrev section.<br>
-  void emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs);<br>
+  void emitAbbrevs(const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs);<br>
<br>
   /// \brief Emit the string table described by \p Pool.<br>
   void emitStrings(const NonRelocatableStringpool &Pool);<br>
@@ -683,7 +683,8 @@ void DwarfStreamer::emitCompileUnitHeade<br>
<br>
 /// \brief Emit the \p Abbrevs array as the shared abbreviation table<br>
 /// for the linked Dwarf file.<br>
-void DwarfStreamer::emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs) {<br>
+void DwarfStreamer::emitAbbrevs(<br>
+    const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs) {<br>
   MS->SwitchSection(MOFI->getDwarfAbbrevSection());<br>
   Asm->emitDwarfAbbrevs(Abbrevs);<br>
 }<br>
@@ -1111,11 +1112,6 @@ public:<br>
       : OutputFilename(OutputFilename), Options(Options),<br>
         BinHolder(Options.Verbose), LastCIEOffset(0) {}<br>
<br>
-  ~DwarfLinker() {<br>
-    for (auto *Abbrev : Abbreviations)<br>
-      delete Abbrev;<br>
-  }<br>
-<br>
   /// \brief Link the contents of the DebugMap.<br>
   bool link(const DebugMap &);<br>
<br>
@@ -1379,7 +1375,7 @@ private:<br>
   /// \brief Storage for the unique Abbreviations.<br>
   /// This is passed to AsmPrinter::emitDwarfAbbrevs(), thus it cannot<br>
   /// be changed to a vecot of unique_ptrs.<br>
-  std::vector<DIEAbbrev *> Abbreviations;<br>
+  std::vector<std::unique_ptr<DIEAbbrev>> Abbreviations;<br>
<br>
   /// \brief Compute and emit debug_ranges section for \p Unit, and<br>
   /// patch the attributes referencing it.<br>
@@ -2282,10 +2278,10 @@ void DwarfLinker::AssignAbbrev(DIEAbbrev<br>
   } else {<br>
     // Add to abbreviation list.<br>
     Abbreviations.push_back(<br>
-        new DIEAbbrev(Abbrev.getTag(), Abbrev.hasChildren()));<br>
+        llvm::make_unique<DIEAbbrev>(Abbrev.getTag(), Abbrev.hasChildren()));<br>
     for (const auto &Attr : Abbrev.getData())<br>
       Abbreviations.back()->AddAttribute(Attr.getAttribute(), Attr.getForm());<br>
-    AbbreviationsSet.InsertNode(Abbreviations.back(), InsertToken);<br>
+    AbbreviationsSet.InsertNode(Abbreviations.back().get(), InsertToken);<br>
     // Assign the unique abbreviation number.<br>
     Abbrev.setNumber(Abbreviations.size());<br>
     Abbreviations.back()->setNumber(Abbreviations.size());<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>