Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:33

0001 //==- llvm/Support/RecyclingAllocator.h - Recycling Allocator ----*- C++ -*-==//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the RecyclingAllocator class.  See the doxygen comment for
0010 // RecyclingAllocator for more details on the implementation.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_SUPPORT_RECYCLINGALLOCATOR_H
0015 #define LLVM_SUPPORT_RECYCLINGALLOCATOR_H
0016 
0017 #include "llvm/Support/Recycler.h"
0018 
0019 namespace llvm {
0020 
0021 /// RecyclingAllocator - This class wraps an Allocator, adding the
0022 /// functionality of recycling deleted objects.
0023 ///
0024 template <class AllocatorType, class T, size_t Size = sizeof(T),
0025           size_t Align = alignof(T)>
0026 class RecyclingAllocator {
0027 private:
0028   /// Base - Implementation details.
0029   ///
0030   Recycler<T, Size, Align> Base;
0031 
0032   /// Allocator - The wrapped allocator.
0033   ///
0034   AllocatorType Allocator;
0035 
0036 public:
0037   ~RecyclingAllocator() { Base.clear(Allocator); }
0038 
0039   /// Allocate - Return a pointer to storage for an object of type
0040   /// SubClass. The storage may be either newly allocated or recycled.
0041   ///
0042   template<class SubClass>
0043   SubClass *Allocate() { return Base.template Allocate<SubClass>(Allocator); }
0044 
0045   T *Allocate() { return Base.Allocate(Allocator); }
0046 
0047   /// Deallocate - Release storage for the pointed-to object. The
0048   /// storage will be kept track of and may be recycled.
0049   ///
0050   template<class SubClass>
0051   void Deallocate(SubClass* E) { return Base.Deallocate(Allocator, E); }
0052 
0053   void PrintStats() {
0054     Allocator.PrintStats();
0055     Base.PrintStats();
0056   }
0057 };
0058 
0059 }
0060 
0061 template<class AllocatorType, class T, size_t Size, size_t Align>
0062 inline void *operator new(size_t size,
0063                           llvm::RecyclingAllocator<AllocatorType,
0064                                                    T, Size, Align> &Allocator) {
0065   assert(size <= Size && "allocation size exceeded");
0066   return Allocator.Allocate();
0067 }
0068 
0069 template<class AllocatorType, class T, size_t Size, size_t Align>
0070 inline void operator delete(void *E,
0071                             llvm::RecyclingAllocator<AllocatorType,
0072                                                      T, Size, Align> &A) {
0073   A.Deallocate(E);
0074 }
0075 
0076 #endif