Skip to content

Commit fa54294

Browse files
committed
[ADT] Make sure the PageSize is a power of two
1 parent 3b25407 commit fa54294

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

llvm/include/llvm/ADT/PagedVector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ namespace llvm {
3939
/// while iterating, therefore materialising them and losing the gains in terms
4040
/// of memory usage this container provides. If you have such a use case, you
4141
/// probably want to use a normal std::vector or a llvm::SmallVector.
42-
template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
42+
template <typename T, size_t PageSize = PowerOf2Ceil(1024 / sizeof(T))>
43+
class PagedVector {
4344
static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
4445
"you want it to be greater than 16.");
4546
/// The actual number of elements in the vector which can be accessed.

llvm/include/llvm/Support/MathExtras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ constexpr inline uint64_t NextPowerOf2(uint64_t A) {
358358

359359
/// Returns the power of two which is greater than or equal to the given value.
360360
/// Essentially, it is a ceil operation across the domain of powers of two.
361-
inline uint64_t PowerOf2Ceil(uint64_t A) {
361+
constexpr inline uint64_t PowerOf2Ceil(uint64_t A) {
362362
if (!A)
363363
return 0;
364364
return NextPowerOf2(A - 1);

0 commit comments

Comments
 (0)