1 //===- Memory.h -------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #ifndef LLD_COFF_MEMORY_H
15 #define LLD_COFF_MEMORY_H
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/StringSaver.h"
24 extern llvm::BumpPtrAllocator BAlloc;
25 extern llvm::StringSaver Saver;
27 struct SpecificAllocBase {
28 SpecificAllocBase() { Instances.push_back(this); }
29 virtual ~SpecificAllocBase() = default;
30 virtual void reset() = 0;
31 static std::vector<SpecificAllocBase *> Instances;
34 template <class T> struct SpecificAlloc : public SpecificAllocBase {
35 void reset() override { Alloc.DestroyAll(); }
36 llvm::SpecificBumpPtrAllocator<T> Alloc;
39 template <typename T, typename... U> T *make(U &&... Args) {
40 static SpecificAlloc<T> Alloc;
41 return new (Alloc.Alloc.Allocate()) T(std::forward<U>(Args)...);
44 inline void freeArena() {
45 for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances)