Skip to content

Commit

Permalink
[ADT] Make sure the PageSize is a power of two
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 2, 2023
1 parent 3b25407 commit fa54294
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/ADT/PagedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace llvm {
/// while iterating, therefore materialising them and losing the gains in terms
/// of memory usage this container provides. If you have such a use case, you
/// probably want to use a normal std::vector or a llvm::SmallVector.
template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
template <typename T, size_t PageSize = PowerOf2Ceil(1024 / sizeof(T))>
class PagedVector {
static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
"you want it to be greater than 16.");
/// The actual number of elements in the vector which can be accessed.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/MathExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ constexpr inline uint64_t NextPowerOf2(uint64_t A) {

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

0 comments on commit fa54294

Please sign in to comment.