[llvm-commits] [llvm] r43087 - /llvm/trunk/include/llvm/Support/Allocator.h

Ted Kremenek kremenek at apple.com
Wed Oct 17 14:10:21 PDT 2007


Author: kremenek
Date: Wed Oct 17 16:10:21 2007
New Revision: 43087

URL: http://llvm.org/viewvc/llvm-project?rev=43087&view=rev
Log:
Added member template functions to MallocAllocator and
BumpPtrAllocator that implement allocations that return a properly
typed pointer.  For BumpPtrAllocator, the allocated memory is
automatically aligned to the minimum alignment of the type (as
calculated by llvm::AlignOf::Alignment).

Modified:
    llvm/trunk/include/llvm/Support/Allocator.h

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=43087&r1=43086&r2=43087&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Wed Oct 17 16:10:21 2007
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/Support/AlignOf.h"
 #include <cstdlib>
 
 namespace llvm {
@@ -25,6 +26,10 @@
   
   void Reset() {}
   void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
+  
+  template <typename T>
+  T* Allocate() { return reinterpret_cast<T*>(malloc(sizeof(T))); }
+  
   void Deallocate(void *Ptr) { free(Ptr); }
   void PrintStats() const {}
 };
@@ -41,6 +46,13 @@
   
   void Reset();
   void *Allocate(unsigned Size, unsigned Alignment);
+
+  template <typename T>
+  T* Allocate() { 
+    return reinterpret_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
+  }
+
+  
   void Deallocate(void *Ptr) {}
   void PrintStats() const;
 };





More information about the llvm-commits mailing list