blob: 7c306b2370e6c30fc3e03ee6dd2ac697c228a42e [file] [log] [blame]
Chris Lattnerb9de9032006-10-29 22:08:03 +00001//===--- Allocator.cpp - Simple memory allocation abstraction -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerb9de9032006-10-29 22:08:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the BumpPtrAllocator interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Support/Allocator.h"
Evgeniy Stepanov130fdcd2013-01-31 09:58:59 +000015#include "llvm/Support/Compiler.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000016#include "llvm/Support/DataTypes.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "llvm/Support/Memory.h"
Reid Klecknerc2d882d2009-07-23 18:34:13 +000018#include "llvm/Support/Recycler.h"
Daniel Dunbara3d677b2009-07-24 04:01:01 +000019#include "llvm/Support/raw_ostream.h"
Reid Klecknerc2d882d2009-07-23 18:34:13 +000020#include <cstring>
Chris Lattnerb9de9032006-10-29 22:08:03 +000021
Reid Klecknerc2d882d2009-07-23 18:34:13 +000022namespace llvm {
Chris Lattnerb9de9032006-10-29 22:08:03 +000023
Chandler Carruth1cc90232014-04-14 06:42:56 +000024namespace detail {
25
Chandler Carruthf5babf92014-04-14 03:55:11 +000026void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t BytesAllocated,
27 size_t TotalMemory) {
Daniel Dunbara3d677b2009-07-24 04:01:01 +000028 errs() << "\nNumber of memory regions: " << NumSlabs << '\n'
29 << "Bytes used: " << BytesAllocated << '\n'
30 << "Bytes allocated: " << TotalMemory << '\n'
31 << "Bytes wasted: " << (TotalMemory - BytesAllocated)
32 << " (includes alignment, etc)\n";
Reid Klecknerc2d882d2009-07-23 18:34:13 +000033}
34
Chandler Carruth1cc90232014-04-14 06:42:56 +000035} // End namespace detail.
36
Reid Klecknerc2d882d2009-07-23 18:34:13 +000037void PrintRecyclerStats(size_t Size,
38 size_t Align,
39 size_t FreeListSize) {
Daniel Dunbara3d677b2009-07-24 04:01:01 +000040 errs() << "Recycler element size: " << Size << '\n'
41 << "Recycler element alignment: " << Align << '\n'
42 << "Number of elements free for recycling: " << FreeListSize << '\n';
Reid Klecknerc2d882d2009-07-23 18:34:13 +000043}
44
Dan Gohmane5932e52008-07-07 22:58:06 +000045}