[lld] r311056 - Remove a lock and use a std::unique_ptr instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 6 17:11:54 PDT 2017


That's true -- I'll change the type so that UncompressedBuf is just a
std::vector<uint8_t>.

On Wed, Sep 6, 2017 at 3:08 PM, David Blaikie <dblaikie at gmail.com> wrote:

> yeah, sounds good to me (well, unique_ptr<uint8_t[]>, I guess)
>
> On Wed, Sep 6, 2017 at 3:01 PM Rafael Avila de Espindola <
> rafael.espindola at gmail.com> wrote:
>
>> Alternativelly it can also just be a std::unique_ptr<uint8_t>, no?
>>
>> Cheers,
>> Rafael
>>
>> David Blaikie via llvm-commits <llvm-commits at lists.llvm.org> writes:
>>
>> > Is it really worth/necessary to indirect this vector through a
>> unique_ptr?
>> > Saves two words in the InputSection, I guess, in the common (not
>> > compressed) case? (could save the other word too, if you used a separate
>> > map to only store these things when needed)
>> >
>> > But maybe this is the sweet spot of convenience and memory usage. Just
>> > curious/checking :)
>> >
>> > On Wed, Aug 16, 2017 at 5:28 PM Rui Ueyama via llvm-commits <
>> > llvm-commits at lists.llvm.org> wrote:
>> >
>> >> Author: ruiu
>> >> Date: Wed Aug 16 17:27:55 2017
>> >> New Revision: 311056
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=311056&view=rev
>> >> Log:
>> >> Remove a lock and use a std::unique_ptr instead.
>> >>
>> >> We had a lock to guard BAlloc from being used concurrently, but that
>> >> is not very easy to understand. This patch replaces it with a
>> >> std::unique_ptr.
>> >>
>> >> Modified:
>> >>     lld/trunk/ELF/InputSection.cpp
>> >>     lld/trunk/ELF/InputSection.h
>> >>
>> >> Modified: lld/trunk/ELF/InputSection.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
>> InputSection.cpp?rev=311056&r1=311055&r2=311056&view=diff
>> >>
>> >> ============================================================
>> ==================
>> >> --- lld/trunk/ELF/InputSection.cpp (original)
>> >> +++ lld/trunk/ELF/InputSection.cpp Wed Aug 16 17:27:55 2017
>> >> @@ -200,17 +200,12 @@ void InputSectionBase::uncompress() {
>> >>                                                  Config->IsLE,
>> >> Config->Is64));
>> >>
>> >>    size_t Size = Dec.getDecompressedSize();
>> >> -  char *OutputBuf;
>> >> -  {
>> >> -    static std::mutex Mu;
>> >> -    std::lock_guard<std::mutex> Lock(Mu);
>> >> -    OutputBuf = BAlloc.Allocate<char>(Size);
>> >> -  }
>> >> -
>> >> -  if (Error E = Dec.decompress({OutputBuf, Size}))
>> >> +  UncompressBuf.reset(new std::vector<uint8_t>(Size));
>> >> +  if (Error E = Dec.decompress({(char *)UncompressBuf->data(), Size}))
>> >>      fatal(toString(this) +
>> >>            ": decompress failed: " + llvm::toString(std::move(E)));
>> >> -  this->Data = ArrayRef<uint8_t>((uint8_t *)OutputBuf, Size);
>> >> +
>> >> +  this->Data = *UncompressBuf;
>> >>    this->Flags &= ~(uint64_t)SHF_COMPRESSED;
>> >>  }
>> >>
>> >>
>> >> Modified: lld/trunk/ELF/InputSection.h
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
>> InputSection.h?rev=311056&r1=311055&r2=311056&view=diff
>> >>
>> >> ============================================================
>> ==================
>> >> --- lld/trunk/ELF/InputSection.h (original)
>> >> +++ lld/trunk/ELF/InputSection.h Wed Aug 16 17:27:55 2017
>> >> @@ -183,6 +183,11 @@ public:
>> >>      assert(S % sizeof(T) == 0);
>> >>      return llvm::makeArrayRef<T>((const T *)Data.data(), S /
>> sizeof(T));
>> >>    }
>> >> +
>> >> +private:
>> >> +  // A pointer that owns uncompressed data if a section is compressed
>> by
>> >> zlib.
>> >> +  // Since the feature is not used often, this is usually a nullptr.
>> >> +  std::unique_ptr<std::vector<uint8_t>> UncompressBuf;
>> >>  };
>> >>
>> >>  // SectionPiece represents a piece of splittable section contents.
>> >>
>> >>
>> >> _______________________________________________
>> >> llvm-commits mailing list
>> >> llvm-commits at lists.llvm.org
>> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>> >>
>> > _______________________________________________
>> > 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/20170906/c8d49c15/attachment.html>


More information about the llvm-commits mailing list