From 89e4af7c0bcd7ce4cd10b0f6ab558532bb49df55 Mon Sep 17 00:00:00 2001 From: "Feng, Boqun" Date: Wed, 10 Apr 2013 14:29:33 +0800 Subject: [PATCH] backend: Use alignof keyword when supported 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 Reviewed-by: Zhigang, Gong --- backend/src/ir/instruction.cpp | 2 +- backend/src/sys/alloc.hpp | 10 +++++----- backend/src/sys/platform.hpp | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/src/ir/instruction.cpp b/backend/src/ir/instruction.cpp index a523d46..d76aa74 100644 --- a/backend/src/ir/instruction.cpp +++ b/backend/src/ir/instruction.cpp @@ -33,7 +33,7 @@ namespace ir { /////////////////////////////////////////////////////////////////////////// namespace internal { -#define ALIGNED_INSTRUCTION ALIGNED(AlignOf::value) +#define ALIGNED_INSTRUCTION ALIGNED(ALIGNOF(Instruction)) /*! Policy shared by all the internal instructions */ struct BasePolicy { diff --git a/backend/src/sys/alloc.hpp b/backend/src/sys/alloc.hpp index a6305a0..52a37a2 100644 --- a/backend/src/sys/alloc.hpp +++ b/backend/src/sys/alloc.hpp @@ -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::value > sizeof(uintptr_t)) - return (pointer) GBE_ALIGNED_MALLOC(n*sizeof(T), AlignOf::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::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::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::value); + this->data = (T*) GBE_ALIGNED_MALLOC(elemNum * sz, ALIGNOF(T)); this->next = NULL; this->maxElemNum = elemNum; this->allocated = 0; diff --git a/backend/src/sys/platform.hpp b/backend/src/sys/platform.hpp index c52ae90..a665356 100644 --- a/backend/src/sys/platform.hpp +++ b/backend/src/sys/platform.hpp @@ -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::value) +#endif + //////////////////////////////////////////////////////////////////////////////// /// Visibility parameters (DLL export and so on) //////////////////////////////////////////////////////////////////////////////// -- 2.7.4