diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-03-28 09:08:14 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-03-28 09:08:14 +0000 |
commit | 0e4c26eedc81713f2cfdaa25c48ae59eec4322fa (patch) | |
tree | efc3ac2134fa066b017b548e25ceebc24ee2b475 /include | |
parent | 415a008ad210bd20caa251fab68c4a5a21477b5d (diff) | |
download | llvm-0e4c26eedc81713f2cfdaa25c48ae59eec4322fa.tar.gz llvm-0e4c26eedc81713f2cfdaa25c48ae59eec4322fa.tar.bz2 llvm-0e4c26eedc81713f2cfdaa25c48ae59eec4322fa.tar.xz |
[Allocator Cleanup] Move generic pointer alignment helper out of an
out-of-line private static method and into the collection of inline
alignment helpers in MathExtras.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204995 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Support/Allocator.h | 8 | ||||
-rw-r--r-- | include/llvm/Support/MathExtras.h | 13 |
2 files changed, 14 insertions, 7 deletions
diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index a3ed5994af..f3592f7fe9 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -138,12 +138,6 @@ class BumpPtrAllocator { /// for extremely heavy memory use scenarios. size_t NumSlabs; - /// \brief Aligns \c Ptr to \c Alignment bytes, rounding up. - /// - /// Alignment should be a power of two. This method rounds up, so - /// AlignPtr(7, 4) == 8 and AlignPtr(8, 4) == 8. - static char *AlignPtr(char *Ptr, size_t Alignment); - /// \brief Allocate a new slab and move the bump pointers over into the new /// slab, modifying CurPtr and End. void StartNewSlab(); @@ -219,7 +213,7 @@ public: char *End = Slab == Allocator.CurSlab ? Allocator.CurPtr : (char *)Slab + Slab->Size; for (char *Ptr = (char *)(Slab + 1); Ptr < End; Ptr += sizeof(T)) { - Ptr = Allocator.AlignPtr(Ptr, alignOf<T>()); + Ptr = alignPtr(Ptr, alignOf<T>()); if (Ptr + sizeof(T) <= End) reinterpret_cast<T *>(Ptr)->~T(); } diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index 5db22f43f7..f1f7b4feb5 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -16,6 +16,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/SwapByteOrder.h" +#include <cassert> #include <cstring> #include <type_traits> @@ -540,6 +541,18 @@ inline uint64_t MinAlign(uint64_t A, uint64_t B) { return (A | B) & (1 + ~(A | B)); } +/// \brief Aligns \c Ptr to \c Alignment bytes, rounding up. +/// +/// Alignment should be a power of two. This method rounds up, so +/// AlignPtr(7, 4) == 8 and AlignPtr(8, 4) == 8. +inline char *alignPtr(char *Ptr, size_t Alignment) { + assert(Alignment && isPowerOf2_64((uint64_t)Alignment) && + "Alignment is not a power of two!"); + + return (char *)(((uintptr_t)Ptr + Alignment - 1) & + ~(uintptr_t)(Alignment - 1)); +} + /// NextPowerOf2 - Returns the next power of two (in 64-bits) /// that is strictly greater than A. Returns zero on overflow. inline uint64_t NextPowerOf2(uint64_t A) { |