[llvm-commits] [llvm] r99848 - in /llvm/trunk/lib/Target/X86: SSEDomainFix.cpp X86InstrInfo.cpp X86InstrInfo.h
Chris Lattner
clattner at apple.com
Wed Mar 31 11:16:01 PDT 2010
Hey Jakob,
Can this use the normal bump pointer + recycler interface?
-Chris
On Mar 29, 2010, at 4:24 PM, Jakob Stoklund Olesen wrote:
> +++ llvm/trunk/lib/Target/X86/SSEDomainFix.cpp Mon Mar 29 18:24:21 2010
> @@ -29,12 +29,108 @@
> using namespace llvm;
>
> namespace {
> +
> +/// Allocate objects from a pool, allow objects to be recycled, and provide a
> +/// way of deleting everything.
> +template<typename T, unsigned PageSize = 64>
> +class PoolAllocator {
> + std::vector<T*> Pages, Avail;
> +public:
> + ~PoolAllocator() { Clear(); }
> +
> + T* Alloc() {
> + if (Avail.empty()) {
> + T *p = new T[PageSize];
> + Pages.push_back(p);
> + Avail.reserve(PageSize);
> + for (unsigned n = 0; n != PageSize; ++n)
> + Avail.push_back(p+n);
> + }
> + T *p = Avail.back();
> + Avail.pop_back();
> + return p;
> + }
> +
> + // Allow object to be reallocated. It won't be reconstructed.
> + void Recycle(T *p) {
> + p->clear();
> + Avail.push_back(p);
> + }
> +
> + // Destroy all objects, make sure there are no external pointers to them.
> + void Clear() {
> + Avail.clear();
> + while (!Pages.empty()) {
> + delete[] Pages.back();
> + Pages.pop_back();
> + }
> + }
> +};
More information about the llvm-commits
mailing list