[Allocator] Make the underlying allocator a template instead of an

abstract interface. The only user of this functionality is the JIT
memory manager and it is quite happy to have a custom type here. This
removes a virtual function call and a lot of unnecessary abstraction
from the common case where this is just a *very* thin vaneer around
a call to malloc.

Hopefully still no functionality changed here. =]

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206149 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth
2014-04-14 05:11:27 +00:00
parent e20c45d2d8
commit 17f9c2e35b
4 changed files with 44 additions and 73 deletions

View File

@@ -269,13 +269,12 @@ namespace {
class DefaultJITMemoryManager;
class JITSlabAllocator : public SlabAllocator {
class JITSlabAllocator {
DefaultJITMemoryManager &JMM;
public:
JITSlabAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
virtual ~JITSlabAllocator() { }
void *Allocate(size_t Size) override;
void Deallocate(void *Slab, size_t Size) override;
void *Allocate(size_t Size);
void Deallocate(void *Slab, size_t Size);
};
/// DefaultJITMemoryManager - Manage memory for the JIT code generation.
@@ -313,9 +312,10 @@ namespace {
// Memory slabs allocated by the JIT. We refer to them as slabs so we don't
// confuse them with the blocks of memory described above.
std::vector<sys::MemoryBlock> CodeSlabs;
JITSlabAllocator BumpSlabAllocator;
BumpPtrAllocatorImpl<DefaultSlabSize, DefaultSizeThreshold> StubAllocator;
BumpPtrAllocatorImpl<DefaultSlabSize, DefaultSizeThreshold> DataAllocator;
BumpPtrAllocatorImpl<JITSlabAllocator, DefaultSlabSize,
DefaultSizeThreshold> StubAllocator;
BumpPtrAllocatorImpl<JITSlabAllocator, DefaultSlabSize,
DefaultSizeThreshold> DataAllocator;
// Circular list of free blocks.
FreeRangeHeader *FreeMemoryList;
@@ -579,16 +579,13 @@ void JITSlabAllocator::Deallocate(void *Slab, size_t Size) {
}
DefaultJITMemoryManager::DefaultJITMemoryManager()
:
:
#ifdef NDEBUG
PoisonMemory(false),
PoisonMemory(false),
#else
PoisonMemory(true),
PoisonMemory(true),
#endif
LastSlab(0, 0),
BumpSlabAllocator(*this),
StubAllocator(BumpSlabAllocator),
DataAllocator(BumpSlabAllocator) {
LastSlab(0, 0), StubAllocator(*this), DataAllocator(*this) {
// Allocate space for code.
sys::MemoryBlock MemBlock = allocateNewSlab(DefaultCodeSlabSize);