Define placement new wrappers for BumpPtrAllocator and
[oota-llvm.git] / include / llvm / Support / Allocator.h
index b0ed33d6ed5a4f62088c0aa46fe23ea926d1a4f9..e39c5c121f157c9c841d138da15a7d98adb26d70 100644 (file)
 #define LLVM_SUPPORT_ALLOCATOR_H
 
 #include "llvm/Support/AlignOf.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/System/DataTypes.h"
+#include <algorithm>
 #include <cassert>
 #include <cstdlib>
+#include <cstddef>
 
 namespace llvm {
 
@@ -175,4 +178,22 @@ public:
 
 }  // end namespace llvm
 
+inline void *operator new(size_t Size, llvm::BumpPtrAllocator &Allocator) {
+  struct S {
+    char c;
+#ifdef __GNUC__
+    char x __attribute__((aligned));
+#else
+    union {
+      double D;
+      long double LD;
+      long long L;
+      void *P;
+    } x;
+#endif
+  };
+  return Allocator.Allocate(Size, std::min(llvm::NextPowerOf2(Size),
+                                           offsetof(S, x)));
+}
+
 #endif // LLVM_SUPPORT_ALLOCATOR_H