Skip to content

Commit ae78957

Browse files
[Support] Rename CTLog2 to ConstantLog2 in MathExtras.h (#158006)
This patch renames CTLog2 to ConstantLog2 for readability. This patch provides a forwarder under LLVM_DEPRECATED because CTLog2 is used downstream.
1 parent 808f5d1 commit ae78957

File tree

7 files changed

+33
-26
lines changed

7 files changed

+33
-26
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ class Expr : public ValueStmt {
10381038
// PointerLikeTypeTraits is specialized so it can be used with a forward-decl of
10391039
// Expr. Verify that we got it right.
10401040
static_assert(llvm::PointerLikeTypeTraits<Expr *>::NumLowBitsAvailable <=
1041-
llvm::CTLog2<alignof(Expr)>(),
1041+
llvm::ConstantLog2<alignof(Expr)>(),
10421042
"PointerLikeTypeTraits<Expr*> assumes too much alignment.");
10431043

10441044
using ConstantExprKind = Expr::ConstantExprKind;

lld/MachO/Target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TargetInfo {
4949
pageZeroSize = LP::pageZeroSize;
5050
headerSize = sizeof(typename LP::mach_header);
5151
wordSize = LP::wordSize;
52-
p2WordSize = llvm::CTLog2<LP::wordSize>();
52+
p2WordSize = llvm::ConstantLog2<LP::wordSize>();
5353
}
5454

5555
virtual ~TargetInfo() = default;

llvm/include/llvm/Support/Alignment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct Align {
9494

9595
/// Allow constructions of constexpr Align.
9696
template <size_t kValue> constexpr static Align Constant() {
97-
return LogValue{static_cast<uint8_t>(CTLog2<kValue>())};
97+
return LogValue{static_cast<uint8_t>(ConstantLog2<kValue>())};
9898
}
9999

100100
/// Allow constructions of constexpr Align from types.

llvm/include/llvm/Support/MathExtras.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,18 @@ inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx,
323323

324324
/// Compile time Log2.
325325
/// Valid only for positive powers of two.
326-
template <size_t kValue> constexpr size_t CTLog2() {
326+
template <size_t kValue> constexpr size_t ConstantLog2() {
327327
static_assert(llvm::isPowerOf2_64(kValue), "Value is not a valid power of 2");
328-
return 1 + CTLog2<kValue / 2>();
328+
return 1 + ConstantLog2<kValue / 2>();
329329
}
330330

331-
template <> constexpr size_t CTLog2<1>() { return 0; }
331+
template <> constexpr size_t ConstantLog2<1>() { return 0; }
332+
333+
template <size_t kValue>
334+
LLVM_DEPRECATED("Use ConstantLog2 instead", "ConstantLog2")
335+
constexpr size_t CTLog2() {
336+
return ConstantLog2<kValue>();
337+
}
332338

333339
/// Return the floor log base 2 of the specified value, -1 if the value is zero.
334340
/// (32 bit edition.)

llvm/include/llvm/Support/PointerLikeTypeTraits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ template <typename T> struct PointerLikeTypeTraits<T *> {
5151
static inline void *getAsVoidPointer(T *P) { return P; }
5252
static inline T *getFromVoidPointer(void *P) { return static_cast<T *>(P); }
5353

54-
static constexpr int NumLowBitsAvailable = CTLog2<alignof(T)>();
54+
static constexpr int NumLowBitsAvailable = ConstantLog2<alignof(T)>();
5555
};
5656

5757
template <> struct PointerLikeTypeTraits<void *> {
@@ -116,7 +116,7 @@ template <> struct PointerLikeTypeTraits<uintptr_t> {
116116
/// potentially use alignment attributes on functions to satisfy that.
117117
template <int Alignment, typename FunctionPointerT>
118118
struct FunctionPointerLikeTypeTraits {
119-
static constexpr int NumLowBitsAvailable = CTLog2<Alignment>();
119+
static constexpr int NumLowBitsAvailable = ConstantLog2<Alignment>();
120120
static inline void *getAsVoidPointer(FunctionPointerT P) {
121121
assert((reinterpret_cast<uintptr_t>(P) &
122122
~((uintptr_t)-1 << NumLowBitsAvailable)) == 0 &&

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8561,7 +8561,8 @@ struct AAMemoryLocationImpl : public AAMemoryLocation {
85618561
/// Mapping from *single* memory location kinds, e.g., LOCAL_MEM with the
85628562
/// value of NO_LOCAL_MEM, to the accesses encountered for this memory kind.
85638563
using AccessSet = SmallSet<AccessInfo, 2, AccessInfo>;
8564-
std::array<AccessSet *, llvm::CTLog2<VALID_STATE>()> AccessKind2Accesses;
8564+
std::array<AccessSet *, llvm::ConstantLog2<VALID_STATE>()>
8565+
AccessKind2Accesses;
85658566

85668567
/// Categorize the pointer arguments of CB that might access memory in
85678568
/// AccessedLoc and update the state and access map accordingly.

llvm/unittests/Support/MathExtrasTest.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ TEST(MathExtras, PowerOf2Ceil) {
152152
EXPECT_EQ(8U, PowerOf2Ceil(7U));
153153
}
154154

155-
TEST(MathExtras, CTLog2) {
156-
EXPECT_EQ(CTLog2<1ULL << 0>(), 0U);
157-
EXPECT_EQ(CTLog2<1ULL << 1>(), 1U);
158-
EXPECT_EQ(CTLog2<1ULL << 2>(), 2U);
159-
EXPECT_EQ(CTLog2<1ULL << 3>(), 3U);
160-
EXPECT_EQ(CTLog2<1ULL << 4>(), 4U);
161-
EXPECT_EQ(CTLog2<1ULL << 5>(), 5U);
162-
EXPECT_EQ(CTLog2<1ULL << 6>(), 6U);
163-
EXPECT_EQ(CTLog2<1ULL << 7>(), 7U);
164-
EXPECT_EQ(CTLog2<1ULL << 8>(), 8U);
165-
EXPECT_EQ(CTLog2<1ULL << 9>(), 9U);
166-
EXPECT_EQ(CTLog2<1ULL << 10>(), 10U);
167-
EXPECT_EQ(CTLog2<1ULL << 11>(), 11U);
168-
EXPECT_EQ(CTLog2<1ULL << 12>(), 12U);
169-
EXPECT_EQ(CTLog2<1ULL << 13>(), 13U);
170-
EXPECT_EQ(CTLog2<1ULL << 14>(), 14U);
171-
EXPECT_EQ(CTLog2<1ULL << 15>(), 15U);
155+
TEST(MathExtras, ConstantLog2) {
156+
EXPECT_EQ(ConstantLog2<1ULL << 0>(), 0U);
157+
EXPECT_EQ(ConstantLog2<1ULL << 1>(), 1U);
158+
EXPECT_EQ(ConstantLog2<1ULL << 2>(), 2U);
159+
EXPECT_EQ(ConstantLog2<1ULL << 3>(), 3U);
160+
EXPECT_EQ(ConstantLog2<1ULL << 4>(), 4U);
161+
EXPECT_EQ(ConstantLog2<1ULL << 5>(), 5U);
162+
EXPECT_EQ(ConstantLog2<1ULL << 6>(), 6U);
163+
EXPECT_EQ(ConstantLog2<1ULL << 7>(), 7U);
164+
EXPECT_EQ(ConstantLog2<1ULL << 8>(), 8U);
165+
EXPECT_EQ(ConstantLog2<1ULL << 9>(), 9U);
166+
EXPECT_EQ(ConstantLog2<1ULL << 10>(), 10U);
167+
EXPECT_EQ(ConstantLog2<1ULL << 11>(), 11U);
168+
EXPECT_EQ(ConstantLog2<1ULL << 12>(), 12U);
169+
EXPECT_EQ(ConstantLog2<1ULL << 13>(), 13U);
170+
EXPECT_EQ(ConstantLog2<1ULL << 14>(), 14U);
171+
EXPECT_EQ(ConstantLog2<1ULL << 15>(), 15U);
172172
}
173173

174174
TEST(MathExtras, MinAlign) {

0 commit comments

Comments
 (0)