[llvm] r253409 - Generalize ownership/passing semantics to allow dsymutil to own abbreviations via unique_ptr

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 17 19:58:17 PST 2015


On Tue, Nov 17, 2015 at 4:34 PM, David Blaikie via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: dblaikie
> Date: Tue Nov 17 18:34:10 2015
> New Revision: 253409
>
> URL: http://llvm.org/viewvc/llvm-project?rev=253409&view=rev
> Log:
> 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,


It does: http://llvm.org/docs/doxygen/html/Allocator_8h_source.html#l00356

```
~SpecificBumpPtrAllocator() { DestroyAll(); }
```

-- Sean Silva


> or maybe a unique_ptr with a custom
> deleter, etc))
>
> Modified:
>     llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
>     llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
>     llvm/trunk/tools/dsymutil/DwarfLinker.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=253409&r1=253408&r2=253409&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Nov 17 18:34:10 2015
> @@ -453,7 +453,16 @@ public:
>    void emitCFIInstruction(const MCCFIInstruction &Inst) const;
>
>    /// \brief Emit Dwarf abbreviation table.
> -  void emitDwarfAbbrevs(const std::vector<DIEAbbrev *>& Abbrevs) const;
> +  template <typename T> 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;
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp?rev=253409&r1=253408&r2=253409&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp Tue Nov 17
> 18:34:10 2015
> @@ -281,17 +281,10 @@ void AsmPrinter::emitDwarfDIE(const DIE
>    }
>  }
>
> -void
> -AsmPrinter::emitDwarfAbbrevs(const std::vector<DIEAbbrev *>& Abbrevs)
> const {
> -  // For each abbreviation.
> -  for (const DIEAbbrev *Abbrev : Abbrevs) {
> -    // Emit the abbreviations code (base 1 index.)
> -    EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
> +void AsmPrinter::emitDwarfAbbrev(const DIEAbbrev &Abbrev) const {
> +  // Emit the abbreviations code (base 1 index.)
> +  EmitULEB128(Abbrev.getNumber(), "Abbreviation Code");
>
> -    // Emit the abbreviations data.
> -    Abbrev->Emit(this);
> -  }
> -
> -  // Mark end of abbreviations.
> -  EmitULEB128(0, "EOM(3)");
> +  // Emit the abbreviations data.
> +  Abbrev.Emit(this);
>  }
>
> Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=253409&r1=253408&r2=253409&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
> +++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Tue Nov 17 18:34:10 2015
> @@ -519,7 +519,7 @@ public:
>
>    /// \brief Emit the abbreviation table \p Abbrevs to the
>    /// debug_abbrev section.
> -  void emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs);
> +  void emitAbbrevs(const std::vector<std::unique_ptr<DIEAbbrev>>
> &Abbrevs);
>
>    /// \brief Emit the string table described by \p Pool.
>    void emitStrings(const NonRelocatableStringpool &Pool);
> @@ -683,7 +683,8 @@ void DwarfStreamer::emitCompileUnitHeade
>
>  /// \brief Emit the \p Abbrevs array as the shared abbreviation table
>  /// for the linked Dwarf file.
> -void DwarfStreamer::emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs) {
> +void DwarfStreamer::emitAbbrevs(
> +    const std::vector<std::unique_ptr<DIEAbbrev>> &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<DIEAbbrev *> Abbreviations;
> +  std::vector<std::unique_ptr<DIEAbbrev>> 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
>    } else {
>      // Add to abbreviation list.
>      Abbreviations.push_back(
> -        new DIEAbbrev(Abbrev.getTag(), Abbrev.hasChildren()));
> +        llvm::make_unique<DIEAbbrev>(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());
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151117/7629ab2f/attachment.html>


More information about the llvm-commits mailing list