LLVM  14.0.0git
RecyclingAllocator.h
Go to the documentation of this file.
1 //==- llvm/Support/RecyclingAllocator.h - Recycling Allocator ----*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the RecyclingAllocator class. See the doxygen comment for
10 // RecyclingAllocator for more details on the implementation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_RECYCLINGALLOCATOR_H
15 #define LLVM_SUPPORT_RECYCLINGALLOCATOR_H
16 
17 #include "llvm/Support/Recycler.h"
18 
19 namespace llvm {
20 
21 /// RecyclingAllocator - This class wraps an Allocator, adding the
22 /// functionality of recycling deleted objects.
23 ///
24 template <class AllocatorType, class T, size_t Size = sizeof(T),
25  size_t Align = alignof(T)>
27 private:
28  /// Base - Implementation details.
29  ///
31 
32  /// Allocator - The wrapped allocator.
33  ///
34  AllocatorType Allocator;
35 
36 public:
38 
39  /// Allocate - Return a pointer to storage for an object of type
40  /// SubClass. The storage may be either newly allocated or recycled.
41  ///
42  template<class SubClass>
43  SubClass *Allocate() { return Base.template Allocate<SubClass>(Allocator); }
44 
45  T *Allocate() { return Base.Allocate(Allocator); }
46 
47  /// Deallocate - Release storage for the pointed-to object. The
48  /// storage will be kept track of and may be recycled.
49  ///
50  template<class SubClass>
51  void Deallocate(SubClass* E) { return Base.Deallocate(Allocator, E); }
52 
53  void PrintStats() {
54  Allocator.PrintStats();
55  Base.PrintStats();
56  }
57 };
58 
59 }
60 
61 template<class AllocatorType, class T, size_t Size, size_t Align>
62 inline void *operator new(size_t size,
63  llvm::RecyclingAllocator<AllocatorType,
64  T, Size, Align> &Allocator) {
65  assert(size <= Size && "allocation size exceeded");
66  return Allocator.Allocate();
67 }
68 
69 template<class AllocatorType, class T, size_t Size, size_t Align>
70 inline void operator delete(void *E,
71  llvm::RecyclingAllocator<AllocatorType,
72  T, Size, Align> &A) {
73  A.Deallocate(E);
74 }
75 
76 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::RecyclingAllocator::Allocate
T * Allocate()
Definition: RecyclingAllocator.h:45
llvm::RecyclingAllocator::PrintStats
void PrintStats()
Definition: RecyclingAllocator.h:53
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::RecyclingAllocator::~RecyclingAllocator
~RecyclingAllocator()
Definition: RecyclingAllocator.h:37
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::RecyclingAllocator::Deallocate
void Deallocate(SubClass *E)
Deallocate - Release storage for the pointed-to object.
Definition: RecyclingAllocator.h:51
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
size
i< reg-> size
Definition: README.txt:166
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Recycler
Recycler - This class manages a linked-list of deallocated nodes and facilitates reusing deallocated ...
Definition: Recycler.h:34
A
* A
Definition: README_ALTIVEC.txt:89
llvm::RecyclingAllocator
RecyclingAllocator - This class wraps an Allocator, adding the functionality of recycling deleted obj...
Definition: RecyclingAllocator.h:26
llvm::RecyclingAllocator::Allocate
SubClass * Allocate()
Allocate - Return a pointer to storage for an object of type SubClass.
Definition: RecyclingAllocator.h:43
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
Recycler.h
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58