mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 19:52:54 +01:00
[cleanup] Run clang-format over these routines to remove formatting
differences from subsequent diffs, and ease review. Going to be performing some major surgery to simplify this stuff. llvm-svn: 204908
This commit is contained in:
parent
ea044b55f6
commit
179b6d46c2
@ -23,8 +23,12 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
template <typename T> struct ReferenceAdder { typedef T& result; };
|
template <typename T> struct ReferenceAdder {
|
||||||
template <typename T> struct ReferenceAdder<T&> { typedef T result; };
|
typedef T &result;
|
||||||
|
};
|
||||||
|
template <typename T> struct ReferenceAdder<T &> {
|
||||||
|
typedef T result;
|
||||||
|
};
|
||||||
|
|
||||||
class MallocAllocator {
|
class MallocAllocator {
|
||||||
public:
|
public:
|
||||||
@ -35,15 +39,15 @@ public:
|
|||||||
|
|
||||||
void *Allocate(size_t Size, size_t /*Alignment*/) { return malloc(Size); }
|
void *Allocate(size_t Size, size_t /*Alignment*/) { return malloc(Size); }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> T *Allocate() {
|
||||||
T *Allocate() { return static_cast<T*>(malloc(sizeof(T))); }
|
return static_cast<T *>(malloc(sizeof(T)));
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T *Allocate(size_t Num) {
|
|
||||||
return static_cast<T*>(malloc(sizeof(T)*Num));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Deallocate(const void *Ptr) { free(const_cast<void*>(Ptr)); }
|
template <typename T> T *Allocate(size_t Num) {
|
||||||
|
return static_cast<T *>(malloc(sizeof(T) * Num));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Deallocate(const void *Ptr) { free(const_cast<void *>(Ptr)); }
|
||||||
|
|
||||||
void PrintStats() const {}
|
void PrintStats() const {}
|
||||||
};
|
};
|
||||||
@ -77,7 +81,7 @@ class MallocSlabAllocator : public SlabAllocator {
|
|||||||
MallocAllocator Allocator;
|
MallocAllocator Allocator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MallocSlabAllocator() : Allocator() { }
|
MallocSlabAllocator() : Allocator() {}
|
||||||
virtual ~MallocSlabAllocator();
|
virtual ~MallocSlabAllocator();
|
||||||
MemSlab *Allocate(size_t Size) override;
|
MemSlab *Allocate(size_t Size) override;
|
||||||
void Deallocate(MemSlab *Slab) override;
|
void Deallocate(MemSlab *Slab) override;
|
||||||
@ -141,7 +145,8 @@ class BumpPtrAllocator {
|
|||||||
/// \brief Deallocate all memory slabs after and including this one.
|
/// \brief Deallocate all memory slabs after and including this one.
|
||||||
void DeallocateSlabs(MemSlab *Slab);
|
void DeallocateSlabs(MemSlab *Slab);
|
||||||
|
|
||||||
template<typename T> friend class SpecificBumpPtrAllocator;
|
template <typename T> friend class SpecificBumpPtrAllocator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BumpPtrAllocator(size_t size = 4096, size_t threshold = 4096);
|
BumpPtrAllocator(size_t size = 4096, size_t threshold = 4096);
|
||||||
BumpPtrAllocator(size_t size, size_t threshold, SlabAllocator &allocator);
|
BumpPtrAllocator(size_t size, size_t threshold, SlabAllocator &allocator);
|
||||||
@ -155,24 +160,21 @@ public:
|
|||||||
void *Allocate(size_t Size, size_t Alignment);
|
void *Allocate(size_t Size, size_t Alignment);
|
||||||
|
|
||||||
/// \brief Allocate space for one object without constructing it.
|
/// \brief Allocate space for one object without constructing it.
|
||||||
template <typename T>
|
template <typename T> T *Allocate() {
|
||||||
T *Allocate() {
|
return static_cast<T *>(Allocate(sizeof(T), AlignOf<T>::Alignment));
|
||||||
return static_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Allocate space for an array of objects without constructing them.
|
/// \brief Allocate space for an array of objects without constructing them.
|
||||||
template <typename T>
|
template <typename T> T *Allocate(size_t Num) {
|
||||||
T *Allocate(size_t Num) {
|
return static_cast<T *>(Allocate(Num * sizeof(T), AlignOf<T>::Alignment));
|
||||||
return static_cast<T*>(Allocate(Num * sizeof(T), AlignOf<T>::Alignment));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Allocate space for an array of objects with the specified alignment
|
/// \brief Allocate space for an array of objects with the specified alignment
|
||||||
/// and without constructing them.
|
/// and without constructing them.
|
||||||
template <typename T>
|
template <typename T> T *Allocate(size_t Num, size_t Alignment) {
|
||||||
T *Allocate(size_t Num, size_t Alignment) {
|
|
||||||
// Round EltSize up to the specified alignment.
|
// Round EltSize up to the specified alignment.
|
||||||
size_t EltSize = (sizeof(T)+Alignment-1)&(-Alignment);
|
size_t EltSize = (sizeof(T) + Alignment - 1) & (-Alignment);
|
||||||
return static_cast<T*>(Allocate(Num * EltSize, Alignment));
|
return static_cast<T *>(Allocate(Num * EltSize, Alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Deallocate(const void * /*Ptr*/) {}
|
void Deallocate(const void * /*Ptr*/) {}
|
||||||
@ -190,9 +192,9 @@ public:
|
|||||||
///
|
///
|
||||||
/// This allows calling the destructor in DestroyAll() and when the allocator is
|
/// This allows calling the destructor in DestroyAll() and when the allocator is
|
||||||
/// destroyed.
|
/// destroyed.
|
||||||
template <typename T>
|
template <typename T> class SpecificBumpPtrAllocator {
|
||||||
class SpecificBumpPtrAllocator {
|
|
||||||
BumpPtrAllocator Allocator;
|
BumpPtrAllocator Allocator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpecificBumpPtrAllocator(size_t size = 4096, size_t threshold = 4096)
|
SpecificBumpPtrAllocator(size_t size = 4096, size_t threshold = 4096)
|
||||||
: Allocator(size, threshold) {}
|
: Allocator(size, threshold) {}
|
||||||
@ -200,9 +202,7 @@ public:
|
|||||||
SlabAllocator &allocator)
|
SlabAllocator &allocator)
|
||||||
: Allocator(size, threshold, allocator) {}
|
: Allocator(size, threshold, allocator) {}
|
||||||
|
|
||||||
~SpecificBumpPtrAllocator() {
|
~SpecificBumpPtrAllocator() { DestroyAll(); }
|
||||||
DestroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Call the destructor of each allocated object and deallocate all but the
|
/// Call the destructor of each allocated object and deallocate all but the
|
||||||
/// current slab and reset the current pointer to the beginning of it, freeing
|
/// current slab and reset the current pointer to the beginning of it, freeing
|
||||||
@ -210,12 +210,12 @@ public:
|
|||||||
void DestroyAll() {
|
void DestroyAll() {
|
||||||
MemSlab *Slab = Allocator.CurSlab;
|
MemSlab *Slab = Allocator.CurSlab;
|
||||||
while (Slab) {
|
while (Slab) {
|
||||||
char *End = Slab == Allocator.CurSlab ? Allocator.CurPtr :
|
char *End = Slab == Allocator.CurSlab ? Allocator.CurPtr
|
||||||
(char *)Slab + Slab->Size;
|
: (char *)Slab + Slab->Size;
|
||||||
for (char *Ptr = (char*)(Slab+1); Ptr < End; Ptr += sizeof(T)) {
|
for (char *Ptr = (char *)(Slab + 1); Ptr < End; Ptr += sizeof(T)) {
|
||||||
Ptr = Allocator.AlignPtr(Ptr, alignOf<T>());
|
Ptr = Allocator.AlignPtr(Ptr, alignOf<T>());
|
||||||
if (Ptr + sizeof(T) <= End)
|
if (Ptr + sizeof(T) <= End)
|
||||||
reinterpret_cast<T*>(Ptr)->~T();
|
reinterpret_cast<T *>(Ptr)->~T();
|
||||||
}
|
}
|
||||||
Slab = Slab->NextPtr;
|
Slab = Slab->NextPtr;
|
||||||
}
|
}
|
||||||
@ -223,9 +223,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Allocate space for an array of objects without constructing them.
|
/// \brief Allocate space for an array of objects without constructing them.
|
||||||
T *Allocate(size_t num = 1) {
|
T *Allocate(size_t num = 1) { return Allocator.Allocate<T>(num); }
|
||||||
return Allocator.Allocate<T>(num);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
Loading…
Reference in New Issue
Block a user