LLVM: include/llvm/Support/AllocatorBase.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19#ifndef LLVM_SUPPORT_ALLOCATORBASE_H

20#define LLVM_SUPPORT_ALLOCATORBASE_H

21

22#ifdef _MSC_VER

23#define LLVM_ALLOCATORHOLDER_EMPTYBASE __declspec(empty_bases)

24#else

25#define LLVM_ALLOCATORHOLDER_EMPTYBASE

26#endif

27

30#include <type_traits>

31#include

32

33namespace llvm {

34

35

36

37

38

39

40

42public:

43

44

46#ifdef __clang__

47 static_assert(static_cast<void *(AllocatorBase::*)(size_t, size_t)>(

49 static_cast<void *(DerivedT::*)(size_t, size_t)>(

50 &DerivedT::Allocate),

51 "Class derives from AllocatorBase without implementing the "

52 "core Allocate(size_t, size_t) overload!");

53#endif

54 return static_cast<DerivedT *>(this)->Allocate(Size, Alignment);

55 }

56

57

58

59 void Deallocate(const void *Ptr, size_t Size, size_t Alignment) {

60#ifdef __clang__

61 static_assert(

62 static_cast<void (AllocatorBase::*)(const void *, size_t, size_t)>(

64 static_cast<void (DerivedT::*)(const void *, size_t, size_t)>(

65 &DerivedT::Deallocate),

66 "Class derives from AllocatorBase without implementing the "

67 "core Deallocate(void *) overload!");

68#endif

69 return static_cast<DerivedT *>(this)->Deallocate(Ptr, Size, Alignment);

70 }

71

72

73

74

75

76 template T *Allocate(size_t Num = 1) {

77 return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));

78 }

79

80

81 template

82 std::enable_if_t<!std::is_same_v<std::remove_cv_t, void>, void>

84 Deallocate(static_cast<const void *>(Ptr), Num * sizeof(T), alignof(T));

85 }

86};

87

89public:

91

95

96

98

102

103

105

107};

108

110

119

128

129}

130

131}

132

133#endif

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

#define LLVM_ATTRIBUTE_RETURNS_NONNULL

This file defines counterparts of C library allocation functions defined in the namespace 'std'.

CRTP base class providing obvious overloads for the core Allocate() methods of LLVM-style allocators.

Definition AllocatorBase.h:41

void * Allocate(size_t Size, size_t Alignment)

Allocate Size bytes of Alignment aligned memory.

Definition AllocatorBase.h:45

T * Allocate(size_t Num=1)

Allocate space for a sequence of objects without constructing them.

Definition AllocatorBase.h:76

void Deallocate(const void *Ptr, size_t Size, size_t Alignment)

Deallocate Ptr to Size bytes of memory allocated by this allocator.

Definition AllocatorBase.h:59

std::enable_if_t<!std::is_same_v< std::remove_cv_t< T >, void >, void > Deallocate(T *Ptr, size_t Num=1)

Deallocate space for a sequence of objects without constructing them.

Definition AllocatorBase.h:83

Definition AllocatorBase.h:88

void Deallocate(const void *Ptr, size_t Size, size_t Alignment)

Definition AllocatorBase.h:99

LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, size_t Alignment)

Definition AllocatorBase.h:92

void Reset()

Definition AllocatorBase.h:90

void PrintStats() const

Definition AllocatorBase.h:106

Alloc & getAllocator()

Definition AllocatorBase.h:125

AllocatorHolder(Alloc &A)

Definition AllocatorBase.h:124

const Alloc & getAllocator() const

Definition AllocatorBase.h:126

AllocatorHolder(Alloc &&A)

Definition AllocatorBase.h:115

Alloc & getAllocator()

Definition AllocatorBase.h:116

const Alloc & getAllocator() const

Definition AllocatorBase.h:117

AllocatorHolder(const Alloc &A)

Definition AllocatorBase.h:114

AllocatorHolder()=default

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer(size_t Size, size_t Alignment)

Allocate a buffer of memory with the given size and alignment.

LLVM_ABI void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)

Deallocate a buffer of memory with the given size and alignment.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.