diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index d2b872458ae82..7554089810336 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1038,7 +1038,7 @@ class Expr : public ValueStmt { // PointerLikeTypeTraits is specialized so it can be used with a forward-decl of // Expr. Verify that we got it right. static_assert(llvm::PointerLikeTypeTraits::NumLowBitsAvailable <= - llvm::CTLog2(), + llvm::ConstantLog2(), "PointerLikeTypeTraits assumes too much alignment."); using ConstantExprKind = Expr::ConstantExprKind; diff --git a/lld/MachO/Target.h b/lld/MachO/Target.h index 27e5178593c87..20e6af1b2130b 100644 --- a/lld/MachO/Target.h +++ b/lld/MachO/Target.h @@ -49,7 +49,7 @@ class TargetInfo { pageZeroSize = LP::pageZeroSize; headerSize = sizeof(typename LP::mach_header); wordSize = LP::wordSize; - p2WordSize = llvm::CTLog2(); + p2WordSize = llvm::ConstantLog2(); } virtual ~TargetInfo() = default; diff --git a/llvm/include/llvm/Support/Alignment.h b/llvm/include/llvm/Support/Alignment.h index 61f8febe882fd..84773f1d9c37b 100644 --- a/llvm/include/llvm/Support/Alignment.h +++ b/llvm/include/llvm/Support/Alignment.h @@ -94,7 +94,7 @@ struct Align { /// Allow constructions of constexpr Align. template constexpr static Align Constant() { - return LogValue{static_cast(CTLog2())}; + return LogValue{static_cast(ConstantLog2())}; } /// Allow constructions of constexpr Align from types. diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index 96ebbd61e367c..c2716a9704563 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -323,12 +323,18 @@ inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx, /// Compile time Log2. /// Valid only for positive powers of two. -template constexpr size_t CTLog2() { +template constexpr size_t ConstantLog2() { static_assert(llvm::isPowerOf2_64(kValue), "Value is not a valid power of 2"); - return 1 + CTLog2(); + return 1 + ConstantLog2(); } -template <> constexpr size_t CTLog2<1>() { return 0; } +template <> constexpr size_t ConstantLog2<1>() { return 0; } + +template +LLVM_DEPRECATED("Use ConstantLog2 instead", "ConstantLog2") +constexpr size_t CTLog2() { + return ConstantLog2(); +} /// Return the floor log base 2 of the specified value, -1 if the value is zero. /// (32 bit edition.) diff --git a/llvm/include/llvm/Support/PointerLikeTypeTraits.h b/llvm/include/llvm/Support/PointerLikeTypeTraits.h index 0ac919fd9c0b9..320f6b63b447e 100644 --- a/llvm/include/llvm/Support/PointerLikeTypeTraits.h +++ b/llvm/include/llvm/Support/PointerLikeTypeTraits.h @@ -51,7 +51,7 @@ template struct PointerLikeTypeTraits { static inline void *getAsVoidPointer(T *P) { return P; } static inline T *getFromVoidPointer(void *P) { return static_cast(P); } - static constexpr int NumLowBitsAvailable = CTLog2(); + static constexpr int NumLowBitsAvailable = ConstantLog2(); }; template <> struct PointerLikeTypeTraits { @@ -116,7 +116,7 @@ template <> struct PointerLikeTypeTraits { /// potentially use alignment attributes on functions to satisfy that. template struct FunctionPointerLikeTypeTraits { - static constexpr int NumLowBitsAvailable = CTLog2(); + static constexpr int NumLowBitsAvailable = ConstantLog2(); static inline void *getAsVoidPointer(FunctionPointerT P) { assert((reinterpret_cast(P) & ~((uintptr_t)-1 << NumLowBitsAvailable)) == 0 && diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index ff4da3378f82d..6d16599580588 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -8561,7 +8561,8 @@ struct AAMemoryLocationImpl : public AAMemoryLocation { /// Mapping from *single* memory location kinds, e.g., LOCAL_MEM with the /// value of NO_LOCAL_MEM, to the accesses encountered for this memory kind. using AccessSet = SmallSet; - std::array()> AccessKind2Accesses; + std::array()> + AccessKind2Accesses; /// Categorize the pointer arguments of CB that might access memory in /// AccessedLoc and update the state and access map accordingly. diff --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp index 984185fece4aa..5cb85fc55da92 100644 --- a/llvm/unittests/Support/MathExtrasTest.cpp +++ b/llvm/unittests/Support/MathExtrasTest.cpp @@ -152,23 +152,23 @@ TEST(MathExtras, PowerOf2Ceil) { EXPECT_EQ(8U, PowerOf2Ceil(7U)); } -TEST(MathExtras, CTLog2) { - EXPECT_EQ(CTLog2<1ULL << 0>(), 0U); - EXPECT_EQ(CTLog2<1ULL << 1>(), 1U); - EXPECT_EQ(CTLog2<1ULL << 2>(), 2U); - EXPECT_EQ(CTLog2<1ULL << 3>(), 3U); - EXPECT_EQ(CTLog2<1ULL << 4>(), 4U); - EXPECT_EQ(CTLog2<1ULL << 5>(), 5U); - EXPECT_EQ(CTLog2<1ULL << 6>(), 6U); - EXPECT_EQ(CTLog2<1ULL << 7>(), 7U); - EXPECT_EQ(CTLog2<1ULL << 8>(), 8U); - EXPECT_EQ(CTLog2<1ULL << 9>(), 9U); - EXPECT_EQ(CTLog2<1ULL << 10>(), 10U); - EXPECT_EQ(CTLog2<1ULL << 11>(), 11U); - EXPECT_EQ(CTLog2<1ULL << 12>(), 12U); - EXPECT_EQ(CTLog2<1ULL << 13>(), 13U); - EXPECT_EQ(CTLog2<1ULL << 14>(), 14U); - EXPECT_EQ(CTLog2<1ULL << 15>(), 15U); +TEST(MathExtras, ConstantLog2) { + EXPECT_EQ(ConstantLog2<1ULL << 0>(), 0U); + EXPECT_EQ(ConstantLog2<1ULL << 1>(), 1U); + EXPECT_EQ(ConstantLog2<1ULL << 2>(), 2U); + EXPECT_EQ(ConstantLog2<1ULL << 3>(), 3U); + EXPECT_EQ(ConstantLog2<1ULL << 4>(), 4U); + EXPECT_EQ(ConstantLog2<1ULL << 5>(), 5U); + EXPECT_EQ(ConstantLog2<1ULL << 6>(), 6U); + EXPECT_EQ(ConstantLog2<1ULL << 7>(), 7U); + EXPECT_EQ(ConstantLog2<1ULL << 8>(), 8U); + EXPECT_EQ(ConstantLog2<1ULL << 9>(), 9U); + EXPECT_EQ(ConstantLog2<1ULL << 10>(), 10U); + EXPECT_EQ(ConstantLog2<1ULL << 11>(), 11U); + EXPECT_EQ(ConstantLog2<1ULL << 12>(), 12U); + EXPECT_EQ(ConstantLog2<1ULL << 13>(), 13U); + EXPECT_EQ(ConstantLog2<1ULL << 14>(), 14U); + EXPECT_EQ(ConstantLog2<1ULL << 15>(), 15U); } TEST(MathExtras, MinAlign) {