Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -10,13 +10,13 @@ #include "Driver.h" #include "Config.h" #include "InputFiles.h" -#include "Memory.h" #include "MinGW.h" #include "SymbolTable.h" #include "Symbols.h" #include "Writer.h" #include "lld/Common/Driver.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Version.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" @@ -50,10 +50,6 @@ Configuration *Config; LinkerDriver *Driver; -BumpPtrAllocator BAlloc; -StringSaver Saver{BAlloc}; -std::vector SpecificAllocBase::Instances; - bool link(ArrayRef Args, bool CanExitEarly, raw_ostream &Diag) { errorHandler().LogName = Args[0]; errorHandler().ErrorOS = &Diag; Index: lld/trunk/COFF/DriverUtils.cpp =================================================================== --- lld/trunk/COFF/DriverUtils.cpp +++ lld/trunk/COFF/DriverUtils.cpp @@ -15,9 +15,9 @@ #include "Config.h" #include "Driver.h" -#include "Memory.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/BinaryFormat/COFF.h" Index: lld/trunk/COFF/InputFiles.cpp =================================================================== --- lld/trunk/COFF/InputFiles.cpp +++ lld/trunk/COFF/InputFiles.cpp @@ -11,10 +11,10 @@ #include "Chunks.h" #include "Config.h" #include "Driver.h" -#include "Memory.h" #include "SymbolTable.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm-c/lto.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Triple.h" Index: lld/trunk/COFF/Memory.h =================================================================== --- lld/trunk/COFF/Memory.h +++ lld/trunk/COFF/Memory.h @@ -1,52 +0,0 @@ -//===- Memory.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// See ELF/Memory.h -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_COFF_MEMORY_H -#define LLD_COFF_MEMORY_H - -#include "llvm/Support/Allocator.h" -#include "llvm/Support/StringSaver.h" -#include - -namespace lld { -namespace coff { - -extern llvm::BumpPtrAllocator BAlloc; -extern llvm::StringSaver Saver; - -struct SpecificAllocBase { - SpecificAllocBase() { Instances.push_back(this); } - virtual ~SpecificAllocBase() = default; - virtual void reset() = 0; - static std::vector Instances; -}; - -template struct SpecificAlloc : public SpecificAllocBase { - void reset() override { Alloc.DestroyAll(); } - llvm::SpecificBumpPtrAllocator Alloc; -}; - -template T *make(U &&... Args) { - static SpecificAlloc Alloc; - return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); -} - -inline void freeArena() { - for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) - Alloc->reset(); - BAlloc.Reset(); -} -} -} - -#endif Index: lld/trunk/COFF/SymbolTable.cpp =================================================================== --- lld/trunk/COFF/SymbolTable.cpp +++ lld/trunk/COFF/SymbolTable.cpp @@ -11,9 +11,9 @@ #include "Config.h" #include "Driver.h" #include "LTO.h" -#include "Memory.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/IR/LLVMContext.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" Index: lld/trunk/COFF/Symbols.h =================================================================== --- lld/trunk/COFF/Symbols.h +++ lld/trunk/COFF/Symbols.h @@ -12,8 +12,8 @@ #include "Chunks.h" #include "Config.h" -#include "Memory.h" #include "lld/Common/LLVM.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" Index: lld/trunk/COFF/Symbols.cpp =================================================================== --- lld/trunk/COFF/Symbols.cpp +++ lld/trunk/COFF/Symbols.cpp @@ -9,9 +9,9 @@ #include "Symbols.h" #include "InputFiles.h" -#include "Memory.h" #include "Strings.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" Index: lld/trunk/COFF/Writer.cpp =================================================================== --- lld/trunk/COFF/Writer.cpp +++ lld/trunk/COFF/Writer.cpp @@ -12,11 +12,11 @@ #include "DLL.h" #include "InputFiles.h" #include "MapFile.h" -#include "Memory.h" #include "PDB.h" #include "SymbolTable.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" Index: lld/trunk/Common/CMakeLists.txt =================================================================== --- lld/trunk/Common/CMakeLists.txt +++ lld/trunk/Common/CMakeLists.txt @@ -5,6 +5,7 @@ add_lld_library(lldCommon Args.cpp ErrorHandler.cpp + Memory.cpp Reproduce.cpp Strings.cpp TargetOptionsCommandFlags.cpp Index: lld/trunk/Common/Memory.cpp =================================================================== --- lld/trunk/Common/Memory.cpp +++ lld/trunk/Common/Memory.cpp @@ -0,0 +1,23 @@ +//===- Memory.cpp ---------------------------------------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lld/Common/Memory.h" + +using namespace llvm; +using namespace lld; + +BumpPtrAllocator lld::BAlloc; +StringSaver lld::Saver{BAlloc}; +std::vector lld::SpecificAllocBase::Instances; + +void lld::freeArena() { + for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) + Alloc->reset(); + BAlloc.Reset(); +} Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -30,7 +30,6 @@ #include "InputFiles.h" #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "ScriptParser.h" #include "Strings.h" @@ -41,6 +40,7 @@ #include "lld/Common/Args.h" #include "lld/Common/Driver.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "lld/Common/Version.h" #include "llvm/ADT/StringExtras.h" @@ -65,10 +65,6 @@ Configuration *elf::Config; LinkerDriver *elf::Driver; -BumpPtrAllocator elf::BAlloc; -StringSaver elf::Saver{BAlloc}; -std::vector elf::SpecificAllocBase::Instances; - static void setConfigs(); bool elf::link(ArrayRef Args, bool CanExitEarly, Index: lld/trunk/ELF/DriverUtils.cpp =================================================================== --- lld/trunk/ELF/DriverUtils.cpp +++ lld/trunk/ELF/DriverUtils.cpp @@ -14,8 +14,8 @@ //===----------------------------------------------------------------------===// #include "Driver.h" -#include "Memory.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Reproduce.h" #include "lld/Common/Version.h" #include "llvm/ADT/Optional.h" Index: lld/trunk/ELF/GdbIndex.cpp =================================================================== --- lld/trunk/ELF/GdbIndex.cpp +++ lld/trunk/ELF/GdbIndex.cpp @@ -15,7 +15,7 @@ //===----------------------------------------------------------------------===// #include "GdbIndex.h" -#include "Memory.h" +#include "lld/Common/Memory.h" #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h" #include "llvm/Object/ELFObjectFile.h" Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -10,11 +10,11 @@ #include "InputFiles.h" #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "SymbolTable.h" #include "Symbols.h" #include "SyntheticSections.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/Analysis.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" Index: lld/trunk/ELF/InputSection.cpp =================================================================== --- lld/trunk/ELF/InputSection.cpp +++ lld/trunk/ELF/InputSection.cpp @@ -12,13 +12,13 @@ #include "EhFrame.h" #include "InputFiles.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Relocations.h" #include "SyntheticSections.h" #include "Target.h" #include "Thunks.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/Object/Decompressor.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Compression.h" Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -14,7 +14,6 @@ #include "LinkerScript.h" #include "Config.h" #include "InputSection.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" @@ -22,6 +21,7 @@ #include "SyntheticSections.h" #include "Target.h" #include "Writer.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" Index: lld/trunk/ELF/MarkLive.cpp =================================================================== --- lld/trunk/ELF/MarkLive.cpp +++ lld/trunk/ELF/MarkLive.cpp @@ -22,13 +22,13 @@ #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" #include "Symbols.h" #include "Target.h" #include "Writer.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Object/ELF.h" #include Index: lld/trunk/ELF/Memory.h =================================================================== --- lld/trunk/ELF/Memory.h +++ lld/trunk/ELF/Memory.h @@ -1,67 +0,0 @@ -//===- Memory.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines arena allocators. -// -// Almost all large objects, such as files, sections or symbols, are -// used for the entire lifetime of the linker once they are created. -// This usage characteristic makes arena allocator an attractive choice -// where the entire linker is one arena. With an arena, newly created -// objects belong to the arena and freed all at once when everything is done. -// Arena allocators are efficient and easy to understand. -// Most objects are allocated using the arena allocators defined by this file. -// -// If you edit this file, please edit COFF/Memory.h too. -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_ELF_MEMORY_H -#define LLD_ELF_MEMORY_H - -#include "llvm/Support/Allocator.h" -#include "llvm/Support/StringSaver.h" -#include - -namespace lld { -namespace elf { - -// Use this arena if your object doesn't have a destructor. -extern llvm::BumpPtrAllocator BAlloc; -extern llvm::StringSaver Saver; - -// These two classes are hack to keep track of all -// SpecificBumpPtrAllocator instances. -struct SpecificAllocBase { - SpecificAllocBase() { Instances.push_back(this); } - virtual ~SpecificAllocBase() = default; - virtual void reset() = 0; - static std::vector Instances; -}; - -template struct SpecificAlloc : public SpecificAllocBase { - void reset() override { Alloc.DestroyAll(); } - llvm::SpecificBumpPtrAllocator Alloc; -}; - -// Use this arena if your object has a destructor. -// Your destructor will be invoked from freeArena(). -template T *make(U &&... Args) { - static SpecificAlloc Alloc; - return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); -} - -inline void freeArena() { - for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) - Alloc->reset(); - BAlloc.Reset(); -} -} // namespace elf -} // namespace lld - -#endif Index: lld/trunk/ELF/OutputSections.cpp =================================================================== --- lld/trunk/ELF/OutputSections.cpp +++ lld/trunk/ELF/OutputSections.cpp @@ -10,11 +10,11 @@ #include "OutputSections.h" #include "Config.h" #include "LinkerScript.h" -#include "Memory.h" #include "Strings.h" #include "SymbolTable.h" #include "SyntheticSections.h" #include "Target.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Support/Compression.h" Index: lld/trunk/ELF/Relocations.cpp =================================================================== --- lld/trunk/ELF/Relocations.cpp +++ lld/trunk/ELF/Relocations.cpp @@ -44,13 +44,13 @@ #include "Relocations.h" #include "Config.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" #include "SyntheticSections.h" #include "Target.h" #include "Thunks.h" +#include "lld/Common/Memory.h" #include "llvm/Support/Endian.h" #include "llvm/Support/raw_ostream.h" Index: lld/trunk/ELF/ScriptParser.cpp =================================================================== --- lld/trunk/ELF/ScriptParser.cpp +++ lld/trunk/ELF/ScriptParser.cpp @@ -17,11 +17,11 @@ #include "Driver.h" #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "ScriptLexer.h" #include "Symbols.h" #include "Target.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -17,10 +17,10 @@ #include "SymbolTable.h" #include "Config.h" #include "LinkerScript.h" -#include "Memory.h" #include "Symbols.h" #include "SyntheticSections.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Strings.h" #include "llvm/ADT/STLExtras.h" Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -19,13 +19,13 @@ #include "Config.h" #include "InputFiles.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" #include "Target.h" #include "Writer.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "lld/Common/Version.h" #include "llvm/BinaryFormat/Dwarf.h" Index: lld/trunk/ELF/Thunks.cpp =================================================================== --- lld/trunk/ELF/Thunks.cpp +++ lld/trunk/ELF/Thunks.cpp @@ -24,12 +24,12 @@ #include "Thunks.h" #include "Config.h" #include "InputSection.h" -#include "Memory.h" #include "OutputSections.h" #include "Symbols.h" #include "SyntheticSections.h" #include "Target.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Endian.h" Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -12,13 +12,13 @@ #include "Filesystem.h" #include "LinkerScript.h" #include "MapFile.h" -#include "Memory.h" #include "OutputSections.h" #include "Relocations.h" #include "Strings.h" #include "SymbolTable.h" #include "SyntheticSections.h" #include "Target.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" Index: lld/trunk/include/lld/Common/Memory.h =================================================================== --- lld/trunk/include/lld/Common/Memory.h +++ lld/trunk/include/lld/Common/Memory.h @@ -0,0 +1,60 @@ +//===- Memory.h -------------------------------------------------*- C++ -*-===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines arena allocators. +// +// Almost all large objects, such as files, sections or symbols, are +// used for the entire lifetime of the linker once they are created. +// This usage characteristic makes arena allocator an attractive choice +// where the entire linker is one arena. With an arena, newly created +// objects belong to the arena and freed all at once when everything is done. +// Arena allocators are efficient and easy to understand. +// Most objects are allocated using the arena allocators defined by this file. +// +//===----------------------------------------------------------------------===// + +#ifndef LLD_COMMON_MEMORY_H +#define LLD_COMMON_MEMORY_H + +#include "llvm/Support/Allocator.h" +#include "llvm/Support/StringSaver.h" +#include + +namespace lld { + +// Use this arena if your object doesn't have a destructor. +extern llvm::BumpPtrAllocator BAlloc; +extern llvm::StringSaver Saver; + +void freeArena(); + +// These two classes are hack to keep track of all +// SpecificBumpPtrAllocator instances. +struct SpecificAllocBase { + SpecificAllocBase() { Instances.push_back(this); } + virtual ~SpecificAllocBase() = default; + virtual void reset() = 0; + static std::vector Instances; +}; + +template struct SpecificAlloc : public SpecificAllocBase { + void reset() override { Alloc.DestroyAll(); } + llvm::SpecificBumpPtrAllocator Alloc; +}; + +// Use this arena if your object has a destructor. +// Your destructor will be invoked from freeArena(). +template T *make(U &&... Args) { + static SpecificAlloc Alloc; + return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); +} + +} // namespace lld + +#endif Index: lld/trunk/wasm/Driver.cpp =================================================================== --- lld/trunk/wasm/Driver.cpp +++ lld/trunk/wasm/Driver.cpp @@ -9,11 +9,11 @@ #include "lld/Common/Driver.h" #include "Config.h" -#include "Memory.h" #include "SymbolTable.h" #include "Writer.h" #include "lld/Common/Args.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "lld/Common/Version.h" #include "llvm/ADT/Twine.h" @@ -61,9 +61,7 @@ } // anonymous namespace -std::vector lld::wasm::SpecificAllocBase::Instances; Configuration *lld::wasm::Config; -BumpPtrAllocator lld::wasm::BAlloc; bool lld::wasm::link(ArrayRef Args, bool CanExitEarly, raw_ostream &Error) { Index: lld/trunk/wasm/InputFiles.cpp =================================================================== --- lld/trunk/wasm/InputFiles.cpp +++ lld/trunk/wasm/InputFiles.cpp @@ -11,10 +11,10 @@ #include "Config.h" #include "InputSegment.h" -#include "Memory.h" #include "Strings.h" #include "SymbolTable.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/Object/Binary.h" #include "llvm/Object/Wasm.h" #include "llvm/Support/raw_ostream.h" Index: lld/trunk/wasm/Memory.h =================================================================== --- lld/trunk/wasm/Memory.h +++ lld/trunk/wasm/Memory.h @@ -1,52 +0,0 @@ -//===- Memory.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// See WASM/Memory.h -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_WASM_MEMORY_H -#define LLD_WASM_MEMORY_H - -#include "llvm/Support/Allocator.h" -#include "llvm/Support/StringSaver.h" -#include - -namespace lld { -namespace wasm { - -extern llvm::BumpPtrAllocator BAlloc; -extern llvm::StringSaver Saver; - -struct SpecificAllocBase { - SpecificAllocBase() { Instances.push_back(this); } - virtual ~SpecificAllocBase() = default; - virtual void reset() = 0; - static std::vector Instances; -}; - -template struct SpecificAlloc : public SpecificAllocBase { - void reset() override { Alloc.DestroyAll(); } - llvm::SpecificBumpPtrAllocator Alloc; -}; - -template T *make(U &&... Args) { - static SpecificAlloc Alloc; - return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); -} - -inline void freeArena() { - for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) - Alloc->reset(); - BAlloc.Reset(); -} -} // namespace wasm -} // namespace lld - -#endif Index: lld/trunk/wasm/OutputSections.cpp =================================================================== --- lld/trunk/wasm/OutputSections.cpp +++ lld/trunk/wasm/OutputSections.cpp @@ -11,10 +11,10 @@ #include "Config.h" #include "InputFiles.h" -#include "Memory.h" #include "OutputSegment.h" #include "SymbolTable.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/LEB128.h" Index: lld/trunk/wasm/SymbolTable.cpp =================================================================== --- lld/trunk/wasm/SymbolTable.cpp +++ lld/trunk/wasm/SymbolTable.cpp @@ -10,9 +10,9 @@ #include "SymbolTable.h" #include "Config.h" -#include "Memory.h" #include "Strings.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include Index: lld/trunk/wasm/Writer.cpp =================================================================== --- lld/trunk/wasm/Writer.cpp +++ lld/trunk/wasm/Writer.cpp @@ -10,12 +10,12 @@ #include "Writer.h" #include "Config.h" -#include "Memory.h" #include "OutputSections.h" #include "OutputSegment.h" #include "SymbolTable.h" #include "WriterUtils.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/Format.h"