Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.
llvm-svn: 289084
diff --git a/lld/ELF/CMakeLists.txt b/lld/ELF/CMakeLists.txt
index 39cf8ec..9780e1e 100644
--- a/lld/ELF/CMakeLists.txt
+++ b/lld/ELF/CMakeLists.txt
@@ -14,7 +14,6 @@
LTO.cpp
LinkerScript.cpp
MarkLive.cpp
- Memory.cpp
Mips.cpp
OutputSections.cpp
Relocations.cpp
@@ -50,6 +49,7 @@
LINK_LIBS
lldConfig
lldCore
+ lldSupport
${PTHREAD_LIB}
DEPENDS
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 2095e73..a2c96b8 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -14,7 +14,6 @@
#include "InputFiles.h"
#include "InputSection.h"
#include "LinkerScript.h"
-#include "Memory.h"
#include "Strings.h"
#include "SymbolTable.h"
#include "Target.h"
@@ -22,6 +21,7 @@
#include "Writer.h"
#include "lld/Config/Version.h"
#include "lld/Driver/Driver.h"
+#include "lld/Support/Memory.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/CommandLine.h"
diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index 6a270a6..179dfd3 100644
--- a/lld/ELF/DriverUtils.cpp
+++ b/lld/ELF/DriverUtils.cpp
@@ -15,10 +15,10 @@
#include "Driver.h"
#include "Error.h"
-#include "Memory.h"
#include "ScriptParser.h"
#include "lld/Config/Version.h"
#include "lld/Core/Reproduce.h"
+#include "lld/Support/Memory.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Triple.h"
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 06a19f5..37ebfa7 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -12,9 +12,9 @@
#include "Error.h"
#include "InputSection.h"
#include "LinkerScript.h"
-#include "Memory.h"
#include "SymbolTable.h"
#include "Symbols.h"
+#include "lld/Support/Memory.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/CodeGen/Analysis.h"
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index f11b7b7..975882e 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -13,13 +13,12 @@
#include "Error.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/Support/Memory.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Endian.h"
#include <mutex>
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 50ce955..1a19f55 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -15,7 +15,6 @@
#include "Config.h"
#include "Driver.h"
#include "InputSection.h"
-#include "Memory.h"
#include "OutputSections.h"
#include "ScriptParser.h"
#include "Strings.h"
@@ -24,6 +23,7 @@
#include "SyntheticSections.h"
#include "Target.h"
#include "Writer.h"
+#include "lld/Support/Memory.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
diff --git a/lld/ELF/Memory.cpp b/lld/ELF/Memory.cpp
deleted file mode 100644
index 7771317..0000000
--- a/lld/ELF/Memory.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- Memory.cpp -----------------------------------------------*- C++ -*-===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Memory.h"
-
-using namespace llvm;
-using namespace lld;
-using namespace lld::elf;
-
-namespace lld {
-BumpPtrAllocator elf::BAlloc;
-StringSaver elf::Saver{elf::BAlloc};
-
-SpecificAllocBase::SpecificAllocBase() { Instances.push_back(this); }
-
-std::vector<SpecificAllocBase *> SpecificAllocBase::Instances;
-
-void elf::freeArena() {
- for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances)
- Alloc->reset();
- BAlloc.Reset();
-}
-}
diff --git a/lld/ELF/Memory.h b/lld/ELF/Memory.h
deleted file mode 100644
index 9479fd0..0000000
--- a/lld/ELF/Memory.h
+++ /dev/null
@@ -1,61 +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.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_ELF_MEMORY_H
-#define LLD_ELF_MEMORY_H
-
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/StringSaver.h"
-#include <vector>
-
-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();
- virtual ~SpecificAllocBase() = default;
- virtual void reset() = 0;
- static std::vector<SpecificAllocBase *> Instances;
-};
-
-template <class T> struct SpecificAlloc : public SpecificAllocBase {
- void reset() override { Alloc.DestroyAll(); }
- llvm::SpecificBumpPtrAllocator<T> Alloc;
-};
-
-// Use this arena if your object has a destructor.
-// Your destructor will be invoked from freeArena().
-template <typename T, typename... U> inline T *make(U &&... Args) {
- static SpecificAlloc<T> Alloc;
- return new (Alloc.Alloc.Allocate()) T(std::forward<U>(Args)...);
-}
-
-void freeArena();
-}
-}
-
-#endif
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index cfb8ac9..f8daa57 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -11,12 +11,12 @@
#include "Config.h"
#include "EhFrame.h"
#include "LinkerScript.h"
-#include "Memory.h"
#include "Strings.h"
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "Threads.h"
+#include "lld/Support/Memory.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MathExtras.h"
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 078fbb3..25e435d 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -18,8 +18,8 @@
#include "Config.h"
#include "Error.h"
#include "LinkerScript.h"
-#include "Memory.h"
#include "Symbols.h"
+#include "lld/Support/Memory.h"
#include "llvm/ADT/STLExtras.h"
using namespace llvm;
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index d69100a..e833251 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -19,15 +19,14 @@
#include "Error.h"
#include "InputFiles.h"
#include "LinkerScript.h"
-#include "Memory.h"
#include "OutputSections.h"
#include "Strings.h"
#include "SymbolTable.h"
#include "Target.h"
#include "Threads.h"
#include "Writer.h"
-
#include "lld/Config/Version.h"
+#include "lld/Support/Memory.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/MD5.h"
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 73fab27..aa88736 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -27,17 +27,16 @@
#include "Target.h"
#include "Error.h"
#include "InputFiles.h"
-#include "Memory.h"
#include "OutputSections.h"
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Thunks.h"
#include "Writer.h"
-
+#include "lld/Support/Memory.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Object/ELF.h"
-#include "llvm/Support/Endian.h"
#include "llvm/Support/ELF.h"
+#include "llvm/Support/Endian.h"
using namespace llvm;
using namespace llvm::object;
diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp
index 34b630a..e7a1efe 100644
--- a/lld/ELF/Thunks.cpp
+++ b/lld/ELF/Thunks.cpp
@@ -25,10 +25,10 @@
#include "Config.h"
#include "Error.h"
#include "InputSection.h"
-#include "Memory.h"
#include "OutputSections.h"
#include "Symbols.h"
#include "Target.h"
+#include "lld/Support/Memory.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Endian.h"
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index be9be49..c63b883 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -10,14 +10,13 @@
#include "Writer.h"
#include "Config.h"
#include "LinkerScript.h"
-#include "Memory.h"
#include "OutputSections.h"
#include "Relocations.h"
#include "Strings.h"
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "Target.h"
-
+#include "lld/Support/Memory.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FileOutputBuffer.h"