[lld] r285205 - Reduce the number of allocators.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 26 11:27:00 PDT 2016
Actually, I think this is where we want to use a global variable, instead
of passing around Alloc everywhere.
On Wed, Oct 26, 2016 at 8:34 AM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: rafael
> Date: Wed Oct 26 10:34:24 2016
> New Revision: 285205
>
> URL: http://llvm.org/viewvc/llvm-project?rev=285205&view=rev
> Log:
> Reduce the number of allocators.
>
> We used to have one allocator per file, which reduces the advantage of
> using an allocator in the first place.
>
> This is a small speed up is most cases. The largest speedup was in
> 1.014X in chromium no-gc. The largest slowdown was scylla at 1.003X.
>
> Modified:
> lld/trunk/ELF/Driver.cpp
> lld/trunk/ELF/InputFiles.cpp
> lld/trunk/ELF/InputFiles.h
> lld/trunk/ELF/LTO.cpp
> lld/trunk/ELF/LTO.h
> lld/trunk/ELF/SymbolTable.cpp
> lld/trunk/ELF/Symbols.cpp
> lld/trunk/ELF/Symbols.h
>
> Modified: lld/trunk/ELF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.
> cpp?rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Wed Oct 26 10:34:24 2016
> @@ -137,7 +137,7 @@ void LinkerDriver::addFile(StringRef Pat
> case file_magic::archive:
> if (InWholeArchive) {
> for (MemoryBufferRef MB : getArchiveMembers(MBRef))
> - Files.push_back(createObjectFile(MB, Path));
> + Files.push_back(createObjectFile(Alloc, MB, Path));
> return;
> }
> Files.push_back(new ArchiveFile(MBRef));
> @@ -147,13 +147,13 @@ void LinkerDriver::addFile(StringRef Pat
> error("attempted static link of dynamic object " + Path);
> return;
> }
> - Files.push_back(createSharedFile(MBRef));
> + Files.push_back(createSharedFile(Alloc, MBRef));
> return;
> default:
> if (InLib)
> Files.push_back(new LazyObjectFile(MBRef));
> else
> - Files.push_back(createObjectFile(MBRef));
> + Files.push_back(createObjectFile(Alloc, MBRef));
> }
> }
>
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> InputFiles.cpp?rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Wed Oct 26 10:34:24 2016
> @@ -140,8 +140,8 @@ template <class ELFT> void ELFFileBase<E
> }
>
> template <class ELFT>
> -elf::ObjectFile<ELFT>::ObjectFile(MemoryBufferRef M)
> - : ELFFileBase<ELFT>(Base::ObjectKind, M) {}
> +elf::ObjectFile<ELFT>::ObjectFile(BumpPtrAllocator &Alloc,
> MemoryBufferRef M)
> + : ELFFileBase<ELFT>(Base::ObjectKind, M), Alloc(Alloc) {}
>
> template <class ELFT>
> ArrayRef<SymbolBody *> elf::ObjectFile<ELFT>::getNonLocalSymbols() {
> @@ -547,7 +547,7 @@ ArchiveFile::getMember(const Archive::Sy
> }
>
> template <class ELFT>
> -SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
> +SharedFile<ELFT>::SharedFile(BumpPtrAllocator &Alloc, MemoryBufferRef M)
> : ELFFileBase<ELFT>(Base::SharedKind, M), AsNeeded(Config->AsNeeded)
> {}
>
> template <class ELFT>
> @@ -793,7 +793,7 @@ void BitcodeFile::parse(DenseSet<CachedH
> }
>
> template <template <class> class T>
> -static InputFile *createELFFile(MemoryBufferRef MB) {
> +static InputFile *createELFFile(BumpPtrAllocator &Alloc, MemoryBufferRef
> MB) {
> unsigned char Size;
> unsigned char Endian;
> std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
> @@ -802,13 +802,13 @@ static InputFile *createELFFile(MemoryBu
>
> InputFile *Obj;
> if (Size == ELFCLASS32 && Endian == ELFDATA2LSB)
> - Obj = new T<ELF32LE>(MB);
> + Obj = new T<ELF32LE>(Alloc, MB);
> else if (Size == ELFCLASS32 && Endian == ELFDATA2MSB)
> - Obj = new T<ELF32BE>(MB);
> + Obj = new T<ELF32BE>(Alloc, MB);
> else if (Size == ELFCLASS64 && Endian == ELFDATA2LSB)
> - Obj = new T<ELF64LE>(MB);
> + Obj = new T<ELF64LE>(Alloc, MB);
> else if (Size == ELFCLASS64 && Endian == ELFDATA2MSB)
> - Obj = new T<ELF64BE>(MB);
> + Obj = new T<ELF64BE>(Alloc, MB);
> else
> fatal("invalid file class: " + MB.getBufferIdentifier());
>
> @@ -825,7 +825,7 @@ template <class ELFT> InputFile *BinaryF
> Buffer = wrapBinaryWithElfHeader<ELFT>(Blob, Filename);
>
> return createELFFile<ObjectFile>(
> - MemoryBufferRef(toStringRef(Buffer), Filename));
> + Alloc, MemoryBufferRef(toStringRef(Buffer), Filename));
> }
>
> static bool isBitcode(MemoryBufferRef MB) {
> @@ -833,17 +833,18 @@ static bool isBitcode(MemoryBufferRef MB
> return identify_magic(MB.getBuffer()) == file_magic::bitcode;
> }
>
> -InputFile *elf::createObjectFile(MemoryBufferRef MB, StringRef
> ArchiveName,
> +InputFile *elf::createObjectFile(BumpPtrAllocator &Alloc,
> MemoryBufferRef MB,
> + StringRef ArchiveName,
> uint64_t OffsetInArchive) {
> - InputFile *F =
> - isBitcode(MB) ? new BitcodeFile(MB) : createELFFile<ObjectFile>(MB);
> + InputFile *F = isBitcode(MB) ? new BitcodeFile(MB)
> + : createELFFile<ObjectFile>(Alloc, MB);
> F->ArchiveName = ArchiveName;
> F->OffsetInArchive = OffsetInArchive;
> return F;
> }
>
> -InputFile *elf::createSharedFile(MemoryBufferRef MB) {
> - return createELFFile<SharedFile>(MB);
> +InputFile *elf::createSharedFile(BumpPtrAllocator &Alloc,
> MemoryBufferRef MB) {
> + return createELFFile<SharedFile>(Alloc, MB);
> }
>
> MemoryBufferRef LazyObjectFile::getBuffer() {
>
> Modified: lld/trunk/ELF/InputFiles.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> InputFiles.h?rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/InputFiles.h (original)
> +++ lld/trunk/ELF/InputFiles.h Wed Oct 26 10:34:24 2016
> @@ -167,7 +167,7 @@ public:
> ArrayRef<SymbolBody *> getLocalSymbols();
> ArrayRef<SymbolBody *> getNonLocalSymbols();
>
> - explicit ObjectFile(MemoryBufferRef M);
> + explicit ObjectFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M);
> void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
>
> ArrayRef<InputSectionBase<ELFT> *> getSections() const { return
> Sections; }
> @@ -202,7 +202,7 @@ public:
>
> // SymbolBodies and Thunks for sections in this file are allocated
> // using this buffer.
> - llvm::BumpPtrAllocator Alloc;
> + llvm::BumpPtrAllocator &Alloc;
>
> // Name of source file obtained from STT_FILE symbol value,
> // or empty string if there is no such symbol in object file
> @@ -324,7 +324,7 @@ public:
> return F->kind() == Base::SharedKind;
> }
>
> - explicit SharedFile(MemoryBufferRef M);
> + explicit SharedFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M);
>
> void parseSoName();
> void parseRest();
> @@ -356,11 +356,13 @@ public:
>
> private:
> std::vector<uint8_t> Buffer;
> + llvm::BumpPtrAllocator Alloc;
> };
>
> -InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName =
> "",
> +InputFile *createObjectFile(llvm::BumpPtrAllocator &Alloc,
> MemoryBufferRef MB,
> + StringRef ArchiveName = "",
> uint64_t OffsetInArchive = 0);
> -InputFile *createSharedFile(MemoryBufferRef MB);
> +InputFile *createSharedFile(llvm::BumpPtrAllocator &Alloc,
> MemoryBufferRef MB);
>
> } // namespace elf
> } // namespace lld
>
> Modified: lld/trunk/ELF/LTO.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?
> rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/LTO.cpp (original)
> +++ lld/trunk/ELF/LTO.cpp Wed Oct 26 10:34:24 2016
> @@ -137,7 +137,8 @@ std::vector<InputFile *> BitcodeCompiler
> else
> saveBuffer(Buff[I], Config->OutputFile + Twine(I) + ".lto.o");
> }
> - InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I],
> "lto.tmp"));
> + InputFile *Obj =
> + createObjectFile(Alloc, MemoryBufferRef(Buff[I], "lto.tmp"));
> Ret.push_back(Obj);
> }
> return Ret;
>
> Modified: lld/trunk/ELF/LTO.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?
> rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/LTO.h (original)
> +++ lld/trunk/ELF/LTO.h Wed Oct 26 10:34:24 2016
> @@ -49,6 +49,7 @@ public:
> private:
> std::unique_ptr<llvm::lto::LTO> LtoObj;
> std::vector<SmallString<0>> Buff;
> + llvm::BumpPtrAllocator Alloc;
> };
> }
> }
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> SymbolTable.cpp?rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Wed Oct 26 10:34:24 2016
> @@ -293,7 +293,7 @@ Symbol *SymbolTable<ELFT>::addUndefined(
> // its type. See also comment in addLazyArchive.
> if (S->isWeak())
> L->Type = Type;
> - else if (InputFile *F = L->fetch())
> + else if (InputFile *F = L->fetch(Alloc))
> addFile(F);
> }
> return S;
> @@ -510,7 +510,7 @@ void SymbolTable<ELFT>::addLazyArchive(A
> }
> std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
> if (!MBInfo.first.getBuffer().empty())
> - addFile(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
> + addFile(createObjectFile(Alloc, MBInfo.first, F->getName(),
> MBInfo.second));
> }
>
> template <class ELFT>
> @@ -531,7 +531,7 @@ void SymbolTable<ELFT>::addLazyObject(St
> } else {
> MemoryBufferRef MBRef = Obj.getBuffer();
> if (!MBRef.getBuffer().empty())
> - addFile(createObjectFile(MBRef));
> + addFile(createObjectFile(Alloc, MBRef));
> }
> }
>
> @@ -539,7 +539,7 @@ void SymbolTable<ELFT>::addLazyObject(St
> template <class ELFT> void SymbolTable<ELFT>::scanUndefinedFlags() {
> for (StringRef S : Config->Undefined)
> if (auto *L = dyn_cast_or_null<Lazy>(find(S)))
> - if (InputFile *File = L->fetch())
> + if (InputFile *File = L->fetch(Alloc))
> addFile(File);
> }
>
>
> Modified: lld/trunk/ELF/Symbols.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.
> cpp?rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Symbols.cpp (original)
> +++ lld/trunk/ELF/Symbols.cpp Wed Oct 26 10:34:24 2016
> @@ -227,10 +227,10 @@ DefinedCommon::DefinedCommon(StringRef N
> this->File = File;
> }
>
> -InputFile *Lazy::fetch() {
> +InputFile *Lazy::fetch(BumpPtrAllocator &Alloc) {
> if (auto *S = dyn_cast<LazyArchive>(this))
> - return S->fetch();
> - return cast<LazyObject>(this)->fetch();
> + return S->fetch(Alloc);
> + return cast<LazyObject>(this)->fetch(Alloc);
> }
>
> LazyArchive::LazyArchive(ArchiveFile &File,
> @@ -244,21 +244,22 @@ LazyObject::LazyObject(StringRef Name, L
> this->File = &File;
> }
>
> -InputFile *LazyArchive::fetch() {
> +InputFile *LazyArchive::fetch(BumpPtrAllocator &Alloc) {
> std::pair<MemoryBufferRef, uint64_t> MBInfo = file()->getMember(&Sym);
>
> // getMember returns an empty buffer if the member was already
> // read from the library.
> if (MBInfo.first.getBuffer().empty())
> return nullptr;
> - return createObjectFile(MBInfo.first, file()->getName(), MBInfo.second);
> + return createObjectFile(Alloc, MBInfo.first, file()->getName(),
> + MBInfo.second);
> }
>
> -InputFile *LazyObject::fetch() {
> +InputFile *LazyObject::fetch(BumpPtrAllocator &Alloc) {
> MemoryBufferRef MBRef = file()->getBuffer();
> if (MBRef.getBuffer().empty())
> return nullptr;
> - return createObjectFile(MBRef);
> + return createObjectFile(Alloc, MBRef);
> }
>
> bool Symbol::includeInDynsym() const {
>
> Modified: lld/trunk/ELF/Symbols.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.
> h?rev=285205&r1=285204&r2=285205&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Symbols.h (original)
> +++ lld/trunk/ELF/Symbols.h Wed Oct 26 10:34:24 2016
> @@ -328,7 +328,7 @@ public:
>
> // Returns an object file for this symbol, or a nullptr if the file
> // was already returned.
> - InputFile *fetch();
> + InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
>
> protected:
> Lazy(SymbolBody::Kind K, StringRef Name, uint8_t Type)
> @@ -346,7 +346,7 @@ public:
> }
>
> ArchiveFile *file() { return (ArchiveFile *)this->File; }
> - InputFile *fetch();
> + InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
>
> private:
> const llvm::object::Archive::Symbol Sym;
> @@ -363,7 +363,7 @@ public:
> }
>
> LazyObjectFile *file() { return (LazyObjectFile *)this->File; }
> - InputFile *fetch();
> + InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
> };
>
> // Some linker-generated symbols need to be created as
>
>
> _______________________________________________
> 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/20161026/f147b72c/attachment.html>
More information about the llvm-commits
mailing list