10 #ifndef LLVM_ADT_BITMASKENUM_H 11 #define LLVM_ADT_BITMASKENUM_H 14 #include <type_traits> 42 #define LLVM_MARK_AS_BITMASK_ENUM(LargestValue) \ 43 LLVM_BITMASK_LARGEST_ENUMERATOR = LargestValue 56 #define LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE() \ 57 using ::llvm::BitmaskEnumDetail::operator~; \ 58 using ::llvm::BitmaskEnumDetail::operator|; \ 59 using ::llvm::BitmaskEnumDetail::operator&; \ 60 using ::llvm::BitmaskEnumDetail::operator^; \ 61 using ::llvm::BitmaskEnumDetail::operator|=; \ 62 using ::llvm::BitmaskEnumDetail::operator&=; \ 64 using ::llvm::BitmaskEnumDetail::operator^= 70 template <
typename E,
typename Enable =
void>
75 E, typename
std::enable_if<sizeof(E::LLVM_BITMASK_LARGEST_ENUMERATOR) >=
76 0>
::type> : std::true_type {};
77 namespace BitmaskEnumDetail {
81 template <
typename E>
typename std::underlying_type<E>::type
Mask() {
84 return NextPowerOf2(
static_cast<typename std::underlying_type<E>::type
>(
85 E::LLVM_BITMASK_LARGEST_ENUMERATOR)) -
91 template <
typename E>
typename std::underlying_type<E>::type
Underlying(
E Val) {
92 auto U =
static_cast<typename std::underlying_type<E>::type
>(Val);
93 assert(U >= 0 &&
"Negative enum values are not allowed.");
94 assert(U <= Mask<E>() &&
"Enum value too large (or largest val too small?)");
99 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
101 return static_cast<E>(~
Underlying(Val) & Mask<E>());
104 template <
typename E,
105 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
110 template <
typename E,
111 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
116 template <
typename E,
117 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
125 template <
typename E,
126 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
132 template <
typename E,
133 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
139 template <
typename E,
140 typename =
typename std::enable_if<is_bitmask_enum<E>::value>
::type>
This class represents lattice values for constants.
APInt operator^(APInt a, const APInt &b)
APInt operator &(APInt a, const APInt &b)
APInt operator~(APInt v)
Unary bitwise complement operator.
E & operator^=(E &LHS, E RHS)
bool operator|=(SparseBitVector< ElementSize > &LHS, const SparseBitVector< ElementSize > *RHS)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::underlying_type< E >::type Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Traits class to determine whether an enum has a LLVM_BITMASK_LARGEST_ENUMERATOR enumerator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
E & operator &=(E &LHS, E RHS)
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
APInt operator|(APInt a, const APInt &b)