Make 'Insert' set the name for Loads, instead of passing the name into the
[oota-llvm.git] / include / llvm / Support / Allocator.h
index 527d4c6e2cbf30f2cb55fc2f122726bec636c8d9..bc3653503caf8715ccc7fce2f0f136e789151f84 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/Support/AlignOf.h"
 #include <cstdlib>
 
 namespace llvm {
@@ -23,8 +24,15 @@ public:
   MallocAllocator() {}
   ~MallocAllocator() {}
   
-  void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
+  void Reset() {}
+
+  void *Allocate(size_t Size, size_t /*Alignment*/) { return malloc(Size); }
+  
+  template <typename T>
+  T *Allocate() { return static_cast<T*>(malloc(sizeof(T))); }
+  
   void Deallocate(void *Ptr) { free(Ptr); }
+
   void PrintStats() const {}
 };
 
@@ -33,16 +41,33 @@ public:
 /// allocating memory, and never deletes it until the entire block is dead. This
 /// makes allocation speedy, but must only be used when the trade-off is ok.
 class BumpPtrAllocator {
+  BumpPtrAllocator(const BumpPtrAllocator &); // do not implement
+  void operator=(const BumpPtrAllocator &);   // do not implement
+
   void *TheMemory;
 public:
   BumpPtrAllocator();
   ~BumpPtrAllocator();
   
-  void *Allocate(unsigned Size, unsigned Alignment);
-  void Deallocate(void *Ptr) {}
+  void Reset();
+
+  void *Allocate(size_t Size, size_t Alignment);
+
+  template <typename T>
+  T *Allocate() { 
+    return static_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
+  }
+  
+  template <typename T>
+  T *Allocate(size_t Num) { 
+    return static_cast<T*>(Allocate(Num * sizeof(T), AlignOf<T>::Alignment));
+  }
+  
+  void Deallocate(void * /*Ptr*/) {}
+
   void PrintStats() const;
 };
 
-}  // end namespace clang
+}  // end namespace llvm
 
 #endif