/home/arjun/llvm-project/llvm/include/llvm/Support/AllocatorBase.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- AllocatorBase.h - Simple memory allocation abstraction ---*- 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 | | /// \file |
9 | | /// |
10 | | /// This file defines MallocAllocator. MallocAllocator conforms to the LLVM |
11 | | /// "Allocator" concept which consists of an Allocate method accepting a size |
12 | | /// and alignment, and a Deallocate accepting a pointer and size. Further, the |
13 | | /// LLVM "Allocator" concept has overloads of Allocate and Deallocate for |
14 | | /// setting size and alignment based on the final type. These overloads are |
15 | | /// typically provided by a base class template \c AllocatorBase. |
16 | | /// |
17 | | //===----------------------------------------------------------------------===// |
18 | | |
19 | | #ifndef LLVM_SUPPORT_ALLOCATORBASE_H |
20 | | #define LLVM_SUPPORT_ALLOCATORBASE_H |
21 | | |
22 | | #include "llvm/Support/Compiler.h" |
23 | | #include "llvm/Support/MemAlloc.h" |
24 | | |
25 | | namespace llvm { |
26 | | |
27 | | /// CRTP base class providing obvious overloads for the core \c |
28 | | /// Allocate() methods of LLVM-style allocators. |
29 | | /// |
30 | | /// This base class both documents the full public interface exposed by all |
31 | | /// LLVM-style allocators, and redirects all of the overloads to a single core |
32 | | /// set of methods which the derived class must define. |
33 | | template <typename DerivedT> class AllocatorBase { |
34 | | public: |
35 | | /// Allocate \a Size bytes of \a Alignment aligned memory. This method |
36 | | /// must be implemented by \c DerivedT. |
37 | 0 | void *Allocate(size_t Size, size_t Alignment) { |
38 | 0 | #ifdef __clang__ |
39 | 0 | static_assert(static_cast<void *(AllocatorBase::*)(size_t, size_t)>( |
40 | 0 | &AllocatorBase::Allocate) != |
41 | 0 | static_cast<void *(DerivedT::*)(size_t, size_t)>( |
42 | 0 | &DerivedT::Allocate), |
43 | 0 | "Class derives from AllocatorBase without implementing the " |
44 | 0 | "core Allocate(size_t, size_t) overload!"); |
45 | 0 | #endif |
46 | 0 | return static_cast<DerivedT *>(this)->Allocate(Size, Alignment); |
47 | 0 | } Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateEmm Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_15MallocAllocatorEE8AllocateEmm |
48 | | |
49 | | /// Deallocate \a Ptr to \a Size bytes of memory allocated by this |
50 | | /// allocator. |
51 | 0 | void Deallocate(const void *Ptr, size_t Size, size_t Alignment) { |
52 | 0 | #ifdef __clang__ |
53 | 0 | static_assert( |
54 | 0 | static_cast<void (AllocatorBase::*)(const void *, size_t, size_t)>( |
55 | 0 | &AllocatorBase::Deallocate) != |
56 | 0 | static_cast<void (DerivedT::*)(const void *, size_t, size_t)>( |
57 | 0 | &DerivedT::Deallocate), |
58 | 0 | "Class derives from AllocatorBase without implementing the " |
59 | 0 | "core Deallocate(void *) overload!"); |
60 | 0 | #endif |
61 | 0 | return static_cast<DerivedT *>(this)->Deallocate(Ptr, Size, Alignment); |
62 | 0 | } Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE10DeallocateEPKvmm Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_15MallocAllocatorEE10DeallocateEPKvmm |
63 | | |
64 | | // The rest of these methods are helpers that redirect to one of the above |
65 | | // core methods. |
66 | | |
67 | | /// Allocate space for a sequence of objects without constructing them. |
68 | 0 | template <typename T> T *Allocate(size_t Num = 1) { |
69 | 0 | return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T))); |
70 | 0 | } Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIcEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIjEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail20AffineDimExprStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail25AffineConstantExprStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail25AffineBinaryOpExprStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_15MallocAllocatorEE8AllocateINS_18ScopedHashTableValINS_9StringRefEcEEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail25AffineMapAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail21ArrayAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir9AttributeEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail26IntegerSetAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail22OpaqueAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail22StringAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail20TypeAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail35DenseStringElementsAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail36DenseIntOrFPElementsAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail30OpaqueElementsAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail30SparseElementsAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail20BoolAttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail23CallSiteLocationStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail26FileLineColLocationStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail19NameLocationStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail21OpaqueLocationStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail17IntegerSetStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir10AffineExprEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIbEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir11TypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail18IntegerTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir16AttributeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail16AffineMapStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail17OpaqueTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir4TypeEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail19FunctionTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIlEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail17VectorTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail23RankedTensorTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail25UnrankedTensorTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir9AffineMapEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail17MemRefTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail25UnrankedMemRefTypeStorageEEEPT_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE8AllocateIN4mlir6detail18ComplexTypeStorageEEEPT_m |
71 | | |
72 | | /// Deallocate space for a sequence of objects without constructing them. |
73 | | template <typename T> |
74 | | std::enable_if_t<!std::is_same<std::remove_cv_t<T>, void>::value, void> |
75 | 0 | Deallocate(T *Ptr, size_t Num = 1) { |
76 | 0 | Deallocate(static_cast<const void *>(Ptr), Num * sizeof(T), alignof(T)); |
77 | 0 | } Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE10DeallocateINS_13AllocatorListINS_4yaml5TokenES3_E4NodeEEENSt9enable_ifIXntsr3std7is_sameINSt9remove_cvIT_E4typeEvEE5valueEvE4typeEPSD_m Unexecuted instantiation: _ZN4llvm13AllocatorBaseINS_15MallocAllocatorEE10DeallocateINS_18ScopedHashTableValINS_9StringRefEcEEEENSt9enable_ifIXntsr3std7is_sameINSt9remove_cvIT_E4typeEvEE5valueEvE4typeEPS9_m |
78 | | }; |
79 | | |
80 | | class MallocAllocator : public AllocatorBase<MallocAllocator> { |
81 | | public: |
82 | 0 | void Reset() {} |
83 | | |
84 | 40 | LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, size_t Alignment) { |
85 | 40 | return allocate_buffer(Size, Alignment); |
86 | 40 | } |
87 | | |
88 | | // Pull in base class overloads. |
89 | | using AllocatorBase<MallocAllocator>::Allocate; |
90 | | |
91 | 0 | void Deallocate(const void *Ptr, size_t Size, size_t Alignment) { |
92 | 0 | deallocate_buffer(const_cast<void *>(Ptr), Size, Alignment); |
93 | 0 | } |
94 | | |
95 | | // Pull in base class overloads. |
96 | | using AllocatorBase<MallocAllocator>::Deallocate; |
97 | | |
98 | 0 | void PrintStats() const {} |
99 | | }; |
100 | | |
101 | | } // namespace llvm |
102 | | |
103 | | #endif // LLVM_SUPPORT_ALLOCATORBASE_H |