]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Memory.h
Merge ^/head r311812 through r311939.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / COFF / Memory.h
1 //===- Memory.h -------------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // See ELF/Memory.h
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLD_COFF_MEMORY_H
15 #define LLD_COFF_MEMORY_H
16
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/StringSaver.h"
19 #include <vector>
20
21 namespace lld {
22 namespace coff {
23
24 extern llvm::BumpPtrAllocator BAlloc;
25 extern llvm::StringSaver Saver;
26
27 struct SpecificAllocBase {
28   SpecificAllocBase() { Instances.push_back(this); }
29   virtual ~SpecificAllocBase() = default;
30   virtual void reset() = 0;
31   static std::vector<SpecificAllocBase *> Instances;
32 };
33
34 template <class T> struct SpecificAlloc : public SpecificAllocBase {
35   void reset() override { Alloc.DestroyAll(); }
36   llvm::SpecificBumpPtrAllocator<T> Alloc;
37 };
38
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)...);
42 }
43
44 inline void freeArena() {
45   for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances)
46     Alloc->reset();
47   BAlloc.Reset();
48 }
49 }
50 }
51
52 #endif