Remove LLVM_CONSTEXPR.

Summary: With MSVC 2013 and GCC < 4.8 gone, we can use the "constexpr" keyword.

Reviewers: bkramer, mehdi_amini

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25901

llvm-svn: 284947
This commit is contained in:
Justin Lebar 2016-10-23 19:39:16 +00:00
parent 878e7e2ff6
commit a45e6fde58
12 changed files with 56 additions and 113 deletions

View File

@ -883,8 +883,8 @@ public:
StopAtCodeCompletion = 1 << 2 ///< Stop at code completion
};
friend LLVM_CONSTEXPR SkipUntilFlags operator|(SkipUntilFlags L,
SkipUntilFlags R) {
friend constexpr SkipUntilFlags operator|(SkipUntilFlags L,
SkipUntilFlags R) {
return static_cast<SkipUntilFlags>(static_cast<unsigned>(L) |
static_cast<unsigned>(R));
}

View File

@ -81,13 +81,12 @@ namespace llvm {
/// Construct an ArrayRef from a std::array
template <size_t N>
/*implicit*/ LLVM_CONSTEXPR ArrayRef(const std::array<T, N> &Arr)
: Data(Arr.data()), Length(N) {}
/*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr)
: Data(Arr.data()), Length(N) {}
/// Construct an ArrayRef from a C array.
template <size_t N>
/*implicit*/ LLVM_CONSTEXPR ArrayRef(const T (&Arr)[N])
: Data(Arr), Length(N) {}
/*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
/// Construct an ArrayRef from a std::initializer_list.
/*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
@ -291,13 +290,12 @@ namespace llvm {
/// Construct an ArrayRef from a std::array
template <size_t N>
/*implicit*/ LLVM_CONSTEXPR MutableArrayRef(std::array<T, N> &Arr)
: ArrayRef<T>(Arr) {}
/*implicit*/ constexpr MutableArrayRef(std::array<T, N> &Arr)
: ArrayRef<T>(Arr) {}
/// Construct an MutableArrayRef from a C array.
template <size_t N>
/*implicit*/ LLVM_CONSTEXPR MutableArrayRef(T (&Arr)[N])
: ArrayRef<T>(Arr) {}
/*implicit*/ constexpr MutableArrayRef(T (&Arr)[N]) : ArrayRef<T>(Arr) {}
T *data() const { return const_cast<T*>(ArrayRef<T>::data()); }

View File

@ -129,7 +129,7 @@ public:
T& operator*() LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); }
template <typename U>
LLVM_CONSTEXPR T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
return hasValue() ? getValue() : std::forward<U>(value);
}

View File

@ -456,7 +456,7 @@ struct less_second {
template <class T, T... I> struct integer_sequence {
typedef T value_type;
static LLVM_CONSTEXPR size_t size() { return sizeof...(I); }
static constexpr size_t size() { return sizeof...(I); }
};
/// \brief Alias for the common case of a sequence of size_ts.
@ -483,7 +483,7 @@ template <> struct rank<0> {};
/// Find the length of an array.
template <class T, std::size_t N>
LLVM_CONSTEXPR inline size_t array_lengthof(T (&)[N]) {
constexpr inline size_t array_lengthof(T (&)[N]) {
return N;
}

View File

@ -178,8 +178,8 @@ class MVT {
SimpleValueType SimpleTy;
LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
constexpr MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
constexpr MVT(SimpleValueType SVT) : SimpleTy(SVT) {}
bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }

View File

@ -34,9 +34,9 @@ namespace llvm {
Type *LLVMTy;
public:
LLVM_CONSTEXPR EVT() : V(MVT::INVALID_SIMPLE_VALUE_TYPE), LLVMTy(nullptr) {}
LLVM_CONSTEXPR EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(nullptr) {}
LLVM_CONSTEXPR EVT(MVT S) : V(S), LLVMTy(nullptr) {}
constexpr EVT() : V(MVT::INVALID_SIMPLE_VALUE_TYPE), LLVMTy(nullptr) {}
constexpr EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(nullptr) {}
constexpr EVT(MVT S) : V(S), LLVMTy(nullptr) {}
bool operator==(EVT VT) const {
return !(*this != VT);

View File

@ -93,12 +93,6 @@
#define LLVM_LVALUE_FUNCTION
#endif
#if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__) || LLVM_MSC_PREREQ(1900)
# define LLVM_CONSTEXPR constexpr
#else
# define LLVM_CONSTEXPR
#endif
/// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
/// into a shared library, then the class should be private to the library and
/// not accessible from outside it. Can also be used to mark variables and

View File

@ -245,44 +245,40 @@ T reverseBits(T Val) {
// ambiguity.
/// Hi_32 - This function returns the high 32 bits of a 64 bit value.
LLVM_CONSTEXPR inline uint32_t Hi_32(uint64_t Value) {
constexpr inline uint32_t Hi_32(uint64_t Value) {
return static_cast<uint32_t>(Value >> 32);
}
/// Lo_32 - This function returns the low 32 bits of a 64 bit value.
LLVM_CONSTEXPR inline uint32_t Lo_32(uint64_t Value) {
constexpr inline uint32_t Lo_32(uint64_t Value) {
return static_cast<uint32_t>(Value);
}
/// Make_64 - This functions makes a 64-bit integer from a high / low pair of
/// 32-bit integers.
LLVM_CONSTEXPR inline uint64_t Make_64(uint32_t High, uint32_t Low) {
constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) {
return ((uint64_t)High << 32) | (uint64_t)Low;
}
/// isInt - Checks if an integer fits into the given bit width.
template<unsigned N>
LLVM_CONSTEXPR inline bool isInt(int64_t x) {
template <unsigned N> constexpr inline bool isInt(int64_t x) {
return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
}
// Template specializations to get better code for common cases.
template<>
LLVM_CONSTEXPR inline bool isInt<8>(int64_t x) {
template <> constexpr inline bool isInt<8>(int64_t x) {
return static_cast<int8_t>(x) == x;
}
template<>
LLVM_CONSTEXPR inline bool isInt<16>(int64_t x) {
template <> constexpr inline bool isInt<16>(int64_t x) {
return static_cast<int16_t>(x) == x;
}
template<>
LLVM_CONSTEXPR inline bool isInt<32>(int64_t x) {
template <> constexpr inline bool isInt<32>(int64_t x) {
return static_cast<int32_t>(x) == x;
}
/// isShiftedInt<N,S> - Checks if a signed integer is an N bit number shifted
/// left by S.
template<unsigned N, unsigned S>
LLVM_CONSTEXPR inline bool isShiftedInt(int64_t x) {
template <unsigned N, unsigned S>
constexpr inline bool isShiftedInt(int64_t x) {
static_assert(
N > 0, "isShiftedInt<0> doesn't make sense (refers to a 0-bit number.");
static_assert(N + S <= 64, "isShiftedInt<N, S> with N + S > 64 is too wide.");
@ -298,34 +294,31 @@ LLVM_CONSTEXPR inline bool isShiftedInt(int64_t x) {
/// to keep MSVC from (incorrectly) warning on isUInt<64> that we're shifting
/// left too many places.
template <unsigned N>
LLVM_CONSTEXPR inline typename std::enable_if<(N < 64), bool>::type
constexpr inline typename std::enable_if<(N < 64), bool>::type
isUInt(uint64_t X) {
static_assert(N > 0, "isUInt<0> doesn't make sense");
return X < (UINT64_C(1) << (N));
}
template <unsigned N>
LLVM_CONSTEXPR inline typename std::enable_if<N >= 64, bool>::type
constexpr inline typename std::enable_if<N >= 64, bool>::type
isUInt(uint64_t X) {
return true;
}
// Template specializations to get better code for common cases.
template<>
LLVM_CONSTEXPR inline bool isUInt<8>(uint64_t x) {
template <> constexpr inline bool isUInt<8>(uint64_t x) {
return static_cast<uint8_t>(x) == x;
}
template<>
LLVM_CONSTEXPR inline bool isUInt<16>(uint64_t x) {
template <> constexpr inline bool isUInt<16>(uint64_t x) {
return static_cast<uint16_t>(x) == x;
}
template<>
LLVM_CONSTEXPR inline bool isUInt<32>(uint64_t x) {
template <> constexpr inline bool isUInt<32>(uint64_t x) {
return static_cast<uint32_t>(x) == x;
}
/// Checks if a unsigned integer is an N bit number shifted left by S.
template<unsigned N, unsigned S>
LLVM_CONSTEXPR inline bool isShiftedUInt(uint64_t x) {
template <unsigned N, unsigned S>
constexpr inline bool isShiftedUInt(uint64_t x) {
static_assert(
N > 0, "isShiftedUInt<0> doesn't make sense (refers to a 0-bit number)");
static_assert(N + S <= 64,
@ -377,39 +370,39 @@ inline bool isIntN(unsigned N, int64_t x) {
/// isMask_32 - This function returns true if the argument is a non-empty
/// sequence of ones starting at the least significant bit with the remainder
/// zero (32 bit version). Ex. isMask_32(0x0000FFFFU) == true.
LLVM_CONSTEXPR inline bool isMask_32(uint32_t Value) {
constexpr inline bool isMask_32(uint32_t Value) {
return Value && ((Value + 1) & Value) == 0;
}
/// isMask_64 - This function returns true if the argument is a non-empty
/// sequence of ones starting at the least significant bit with the remainder
/// zero (64 bit version).
LLVM_CONSTEXPR inline bool isMask_64(uint64_t Value) {
constexpr inline bool isMask_64(uint64_t Value) {
return Value && ((Value + 1) & Value) == 0;
}
/// isShiftedMask_32 - This function returns true if the argument contains a
/// non-empty sequence of ones with the remainder zero (32 bit version.)
/// Ex. isShiftedMask_32(0x0000FF00U) == true.
LLVM_CONSTEXPR inline bool isShiftedMask_32(uint32_t Value) {
constexpr inline bool isShiftedMask_32(uint32_t Value) {
return Value && isMask_32((Value - 1) | Value);
}
/// isShiftedMask_64 - This function returns true if the argument contains a
/// non-empty sequence of ones with the remainder zero (64 bit version.)
LLVM_CONSTEXPR inline bool isShiftedMask_64(uint64_t Value) {
constexpr inline bool isShiftedMask_64(uint64_t Value) {
return Value && isMask_64((Value - 1) | Value);
}
/// isPowerOf2_32 - This function returns true if the argument is a power of
/// two > 0. Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.)
LLVM_CONSTEXPR inline bool isPowerOf2_32(uint32_t Value) {
constexpr inline bool isPowerOf2_32(uint32_t Value) {
return Value && !(Value & (Value - 1));
}
/// isPowerOf2_64 - This function returns true if the argument is a power of two
/// > 0 (64 bit edition.)
LLVM_CONSTEXPR inline bool isPowerOf2_64(uint64_t Value) {
constexpr inline bool isPowerOf2_64(uint64_t Value) {
return Value && !(Value & (Value - int64_t(1L)));
}
@ -601,7 +594,7 @@ inline uint32_t FloatToBits(float Float) {
/// MinAlign - A and B are either alignments or offsets. Return the minimum
/// alignment that may be assumed after adding the two together.
LLVM_CONSTEXPR inline uint64_t MinAlign(uint64_t A, uint64_t B) {
constexpr inline uint64_t MinAlign(uint64_t A, uint64_t B) {
// The largest power of 2 that divides both A and B.
//
// Replace "-Value" by "1+~Value" in the following commented code to avoid
@ -676,8 +669,7 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew = 0) {
/// Returns the next integer (mod 2**64) that is greater than or equal to
/// \p Value and is a multiple of \c Align. \c Align must be non-zero.
template <uint64_t Align>
LLVM_CONSTEXPR inline uint64_t alignTo(uint64_t Value) {
template <uint64_t Align> constexpr inline uint64_t alignTo(uint64_t Value) {
static_assert(Align != 0u, "Align must be non-zero");
return (Value + Align - 1) / Align * Align;
}
@ -685,7 +677,7 @@ LLVM_CONSTEXPR inline uint64_t alignTo(uint64_t Value) {
/// \c alignTo for contexts where a constant expression is required.
/// \sa alignTo
///
/// \todo FIXME: remove when \c LLVM_CONSTEXPR becomes really \c constexpr
/// \todo FIXME: remove when \c constexpr becomes really \c constexpr
template <uint64_t Align>
struct AlignTo {
static_assert(Align != 0u, "Align must be non-zero");
@ -712,7 +704,7 @@ inline uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align) {
/// Sign-extend the number in the bottom B bits of X to a 32-bit integer.
/// Requires 0 < B <= 32.
template <unsigned B> LLVM_CONSTEXPR inline int32_t SignExtend32(uint32_t X) {
template <unsigned B> constexpr inline int32_t SignExtend32(uint32_t X) {
static_assert(B > 0, "Bit width can't be 0.");
static_assert(B <= 32, "Bit width out of range.");
return int32_t(X << (32 - B)) >> (32 - B);
@ -728,7 +720,7 @@ inline int32_t SignExtend32(uint32_t X, unsigned B) {
/// Sign-extend the number in the bottom B bits of X to a 64-bit integer.
/// Requires 0 < B < 64.
template <unsigned B> LLVM_CONSTEXPR inline int64_t SignExtend64(uint64_t x) {
template <unsigned B> constexpr inline int64_t SignExtend64(uint64_t x) {
static_assert(B > 0, "Bit width can't be 0.");
static_assert(B <= 64, "Bit width out of range.");
return int64_t(x << (64 - B)) >> (64 - B);

View File

@ -51,7 +51,7 @@ public:
#if defined(_MSC_VER) && _MSC_VER < 1900
#define STL_CONSTEXPR
#else
#define STL_CONSTEXPR LLVM_CONSTEXPR
#define STL_CONSTEXPR constexpr
#endif
static STL_CONSTEXPR result_type min() { return generator_type::min(); }

View File

@ -146,7 +146,7 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
static const bool value = alignof(PrevTy) < alignof(NextTy);
};
static LLVM_CONSTEXPR bool requiresRealignment() {
static constexpr bool requiresRealignment() {
return RequiresRealignment::value;
}
@ -195,7 +195,7 @@ protected:
// Helper function for TrailingObjects::additionalSizeToAlloc: this
// function recurses to superclasses, each of which requires one
// fewer size_t argument, and adds its own size.
static LLVM_CONSTEXPR size_t additionalSizeToAllocImpl(
static constexpr size_t additionalSizeToAllocImpl(
size_t SizeSoFar, size_t Count1,
typename ExtractSecondType<MoreTys, size_t>::type... MoreCounts) {
return ParentType::additionalSizeToAllocImpl(
@ -204,21 +204,6 @@ protected:
sizeof(NextTy) * Count1,
MoreCounts...);
}
// additionalSizeToAllocImpl for contexts where a constant expression is
// required.
// FIXME: remove when LLVM_CONSTEXPR becomes really constexpr
template <size_t SizeSoFar, size_t Count1, size_t... MoreCounts>
struct AdditionalSizeToAllocImpl {
static_assert(sizeof...(MoreTys) == sizeof...(MoreCounts),
"Number of counts do not match number of types");
static const size_t value = ParentType::template AdditionalSizeToAllocImpl<
(RequiresRealignment::value ? llvm::AlignTo<alignof(NextTy)>::
template from_value<SizeSoFar>::value
: SizeSoFar) +
sizeof(NextTy) * Count1,
MoreCounts...>::value;
};
};
// The base case of the TrailingObjectsImpl inheritance recursion,
@ -232,17 +217,10 @@ protected:
// up the inheritance chain to subclasses.
static void getTrailingObjectsImpl();
static LLVM_CONSTEXPR size_t additionalSizeToAllocImpl(size_t SizeSoFar) {
static constexpr size_t additionalSizeToAllocImpl(size_t SizeSoFar) {
return SizeSoFar;
}
// additionalSizeToAllocImpl for contexts where a constant expression is
// required.
// FIXME: remove when LLVM_CONSTEXPR becomes really constexpr
template <size_t SizeSoFar> struct AdditionalSizeToAllocImpl {
static const size_t value = SizeSoFar;
};
template <bool CheckAlignment> static void verifyTrailingObjectsAlignment() {}
};
@ -348,11 +326,10 @@ public:
/// used in the class; they are supplied here redundantly only so
/// that it's clear what the counts are counting in callers.
template <typename... Tys>
static LLVM_CONSTEXPR typename std::enable_if<
static constexpr typename std::enable_if<
std::is_same<Foo<TrailingTys...>, Foo<Tys...>>::value, size_t>::type
additionalSizeToAlloc(
typename trailing_objects_internal::ExtractSecondType<
TrailingTys, size_t>::type... Counts) {
additionalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType<
TrailingTys, size_t>::type... Counts) {
return ParentType::additionalSizeToAllocImpl(0, Counts...);
}
@ -361,28 +338,13 @@ public:
/// additionalSizeToAlloc, except it *does* include the size of the base
/// object.
template <typename... Tys>
static LLVM_CONSTEXPR typename std::enable_if<
static constexpr typename std::enable_if<
std::is_same<Foo<TrailingTys...>, Foo<Tys...>>::value, size_t>::type
totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType<
TrailingTys, size_t>::type... Counts) {
totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType<
TrailingTys, size_t>::type... Counts) {
return sizeof(BaseTy) + ParentType::additionalSizeToAllocImpl(0, Counts...);
}
// totalSizeToAlloc for contexts where a constant expression is required.
// FIXME: remove when LLVM_CONSTEXPR becomes really constexpr
template <typename... Tys> struct TotalSizeToAlloc {
static_assert(
std::is_same<Foo<TrailingTys...>, Foo<Tys...>>::value,
"Arguments to TotalSizeToAlloc do not match with TrailingObjects");
template <size_t... Counts> struct with_counts {
static_assert(sizeof...(TrailingTys) == sizeof...(Counts),
"Number of counts do not match number of types");
static const size_t value =
sizeof(BaseTy) +
ParentType::template AdditionalSizeToAllocImpl<0, Counts...>::value;
};
};
/// A type where its ::with_counts template member has a ::type member
/// suitable for use as uninitialized storage for an object with the given
/// trailing object counts. The template arguments are similar to those
@ -400,9 +362,7 @@ public:
/// \endcode
template <typename... Tys> struct FixedSizeStorage {
template <size_t... Counts> struct with_counts {
enum {
Size = TotalSizeToAlloc<Tys...>::template with_counts<Counts...>::value
};
enum { Size = totalSizeToAlloc<Tys...>(Counts...) };
typedef llvm::AlignedCharArray<alignof(BaseTy), Size> type;
};
};

View File

@ -56,7 +56,7 @@ public:
// may get rid of NDEBUG in this header. Unfortunately there are some
// problems to get this working with MSVC 2013. Change this when
// the support for MSVC 2013 is dropped.
LLVM_CONSTEXPR UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {}
constexpr UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {}
#else
UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {
assert(rangesAreValid());

View File

@ -126,8 +126,7 @@ public:
uint16_t type; // enum AtomType
uint16_t form; // DWARF DW_FORM_ defines
LLVM_CONSTEXPR Atom(uint16_t type, uint16_t form)
: type(type), form(form) {}
constexpr Atom(uint16_t type, uint16_t form) : type(type), form(form) {}
#ifndef NDEBUG
void print(raw_ostream &O) {
O << "Type: " << dwarf::AtomTypeString(type) << "\n"