Allocator.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===--- Allocator.cpp - Simple memory allocation abstraction -------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the BumpPtrAllocator interface.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Support/Allocator.h"
  14. #include "llvm/Support/Compiler.h"
  15. #include "llvm/Support/DataTypes.h"
  16. #include "llvm/Support/Memory.h"
  17. #include "llvm/Support/Recycler.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. #include <cstring>
  20. namespace llvm {
  21. SlabAllocator::~SlabAllocator() { }
  22. MallocSlabAllocator::~MallocSlabAllocator() { }
  23. void *MallocSlabAllocator::Allocate(size_t Size) {
  24. return Allocator.Allocate(Size, 0);
  25. }
  26. void MallocSlabAllocator::Deallocate(void *Slab, size_t Size) {
  27. Allocator.Deallocate(Slab);
  28. }
  29. void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t BytesAllocated,
  30. size_t TotalMemory) {
  31. errs() << "\nNumber of memory regions: " << NumSlabs << '\n'
  32. << "Bytes used: " << BytesAllocated << '\n'
  33. << "Bytes allocated: " << TotalMemory << '\n'
  34. << "Bytes wasted: " << (TotalMemory - BytesAllocated)
  35. << " (includes alignment, etc)\n";
  36. }
  37. void PrintRecyclerStats(size_t Size,
  38. size_t Align,
  39. size_t FreeListSize) {
  40. errs() << "Recycler element size: " << Size << '\n'
  41. << "Recycler element alignment: " << Align << '\n'
  42. << "Number of elements free for recycling: " << FreeListSize << '\n';
  43. }
  44. }