2006-10-29 22:08:03 +00:00
|
|
|
//===--- Allocator.cpp - Simple memory allocation abstraction -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-29 22:08:03 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the BumpPtrAllocator interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/Allocator.h"
|
2013-01-31 09:58:59 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/Memory.h"
|
2009-07-23 18:34:13 +00:00
|
|
|
#include "llvm/Support/Recycler.h"
|
2009-07-24 04:01:01 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-07-23 18:34:13 +00:00
|
|
|
#include <cstring>
|
2006-10-29 22:08:03 +00:00
|
|
|
|
2009-07-23 18:34:13 +00:00
|
|
|
namespace llvm {
|
2009-07-23 00:30:41 +00:00
|
|
|
|
2014-03-30 12:07:07 +00:00
|
|
|
SlabAllocator::~SlabAllocator() { }
|
2009-07-23 18:34:13 +00:00
|
|
|
|
2014-03-30 12:07:07 +00:00
|
|
|
MallocSlabAllocator::~MallocSlabAllocator() { }
|
2009-07-23 00:30:41 +00:00
|
|
|
|
2014-03-30 12:07:07 +00:00
|
|
|
MemSlab *MallocSlabAllocator::Allocate(size_t Size) {
|
|
|
|
MemSlab *Slab = (MemSlab*)Allocator.Allocate(Size, 0);
|
|
|
|
Slab->Size = Size;
|
|
|
|
Slab->NextPtr = 0;
|
|
|
|
return Slab;
|
2009-07-23 00:30:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 12:07:07 +00:00
|
|
|
void MallocSlabAllocator::Deallocate(MemSlab *Slab) {
|
|
|
|
Allocator.Deallocate(Slab);
|
2009-07-23 00:30:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 12:07:07 +00:00
|
|
|
void BumpPtrAllocatorBase::PrintStats() const {
|
2009-07-23 18:34:13 +00:00
|
|
|
unsigned NumSlabs = 0;
|
|
|
|
size_t TotalMemory = 0;
|
|
|
|
for (MemSlab *Slab = CurSlab; Slab != 0; Slab = Slab->NextPtr) {
|
|
|
|
TotalMemory += Slab->Size;
|
|
|
|
++NumSlabs;
|
|
|
|
}
|
|
|
|
|
2009-07-24 04:01:01 +00:00
|
|
|
errs() << "\nNumber of memory regions: " << NumSlabs << '\n'
|
|
|
|
<< "Bytes used: " << BytesAllocated << '\n'
|
|
|
|
<< "Bytes allocated: " << TotalMemory << '\n'
|
|
|
|
<< "Bytes wasted: " << (TotalMemory - BytesAllocated)
|
|
|
|
<< " (includes alignment, etc)\n";
|
2009-07-23 18:34:13 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 12:07:07 +00:00
|
|
|
size_t BumpPtrAllocatorBase::getTotalMemory() const {
|
|
|
|
size_t TotalMemory = 0;
|
|
|
|
for (MemSlab *Slab = CurSlab; Slab != 0; Slab = Slab->NextPtr) {
|
|
|
|
TotalMemory += Slab->Size;
|
|
|
|
}
|
|
|
|
return TotalMemory;
|
2009-07-23 18:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintRecyclerStats(size_t Size,
|
|
|
|
size_t Align,
|
|
|
|
size_t FreeListSize) {
|
2009-07-24 04:01:01 +00:00
|
|
|
errs() << "Recycler element size: " << Size << '\n'
|
|
|
|
<< "Recycler element alignment: " << Align << '\n'
|
|
|
|
<< "Number of elements free for recycling: " << FreeListSize << '\n';
|
2006-10-29 22:08:03 +00:00
|
|
|
}
|
2008-07-07 22:58:06 +00:00
|
|
|
|
|
|
|
}
|