backend: Use alignof keyword when supported
authorFeng, Boqun <boqun.feng@intel.com>
Wed, 10 Apr 2013 06:29:33 +0000 (14:29 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Wed, 10 Apr 2013 11:54:14 +0000 (19:54 +0800)
the keyword alignof of C++11 is supported after gcc 4.8, other than use
old template way to calculate the align of a class, the keyword is used.

Signed-off-by: Feng, Boqun <boqun.feng@intel.com>
Reviewed-by: Zhigang, Gong <zhigang.gong@linux.intel.com>
backend/src/ir/instruction.cpp
backend/src/sys/alloc.hpp
backend/src/sys/platform.hpp

index a523d46..d76aa74 100644 (file)
@@ -33,7 +33,7 @@ namespace ir {
   ///////////////////////////////////////////////////////////////////////////
   namespace internal
   {
-#define ALIGNED_INSTRUCTION ALIGNED(AlignOf<Instruction>::value) 
+#define ALIGNED_INSTRUCTION ALIGNED(ALIGNOF(Instruction))
 
     /*! Policy shared by all the internal instructions */
     struct BasePolicy {
index a6305a0..52a37a2 100644 (file)
@@ -139,13 +139,13 @@ namespace gbe
     INLINE pointer address(reference r) { return &r; }
     INLINE const_pointer address(const_reference r) { return &r; }
     INLINE pointer allocate(size_type n, void_allocator_ptr = 0) {
-      if (AlignOf<T>::value > sizeof(uintptr_t))
-        return (pointer) GBE_ALIGNED_MALLOC(n*sizeof(T), AlignOf<T>::value);
+      if (ALIGNOF(T) > sizeof(uintptr_t))
+        return (pointer) GBE_ALIGNED_MALLOC(n*sizeof(T), ALIGNOF(T));
       else
         return (pointer) GBE_MALLOC(n * sizeof(T));
     }
     INLINE void deallocate(pointer p, size_type) {
-      if (AlignOf<T>::value > sizeof(uintptr_t))
+      if (ALIGNOF(T) > sizeof(uintptr_t))
         GBE_ALIGNED_FREE(p);
       else
         GBE_FREE(p);
@@ -181,7 +181,7 @@ namespace gbe
     }
     void *allocate(void) {
 #if GBE_DEBUG_SPECIAL_ALLOCATOR
-      return GBE_ALIGNED_MALLOC(sizeof(T), AlignOf<T>::value);
+      return GBE_ALIGNED_MALLOC(sizeof(T), ALIGNOF(T));
 #else
       // Pick up an element from the free list
       if (this->freeList != NULL) {
@@ -259,7 +259,7 @@ namespace gbe
       friend class GrowingPool;
       GrowingPoolElem(size_t elemNum) {
         const size_t sz = std::max(sizeof(T), sizeof(void*));
-        this->data = (T*) GBE_ALIGNED_MALLOC(elemNum * sz, AlignOf<T>::value);
+        this->data = (T*) GBE_ALIGNED_MALLOC(elemNum * sz, ALIGNOF(T));
         this->next = NULL;
         this->maxElemNum = elemNum;
         this->allocated = 0;
index c52ae90..a665356 100644 (file)
@@ -266,6 +266,13 @@ struct AlignOf {
   enum { value = offsetof(Helper, t) };
 };
 
+//gcc 4.8+ support C++11 alignof keyword
+#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 8)
+#define ALIGNOF(T) (alignof(T))
+#else
+#define ALIGNOF(T) (AlignOf<T>::value)
+#endif
+
 ////////////////////////////////////////////////////////////////////////////////
 /// Visibility parameters (DLL export and so on)
 ////////////////////////////////////////////////////////////////////////////////