LLVM: include/llvm/ADT/BitmaskEnum.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_ADT_BITMASKENUM_H
10#define LLVM_ADT_BITMASKENUM_H
11
12#include
13#include <type_traits>
14
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42#define LLVM_MARK_AS_BITMASK_ENUM(LargestValue) \
43 LLVM_BITMASK_LARGEST_ENUMERATOR = LargestValue
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66#define LLVM_DECLARE_ENUM_AS_BITMASK(Enum, LargestValue) \
67 template <> struct is_bitmask_enum : std::true_type {}; \
68 template <> struct largest_bitmask_enum_bit { \
69 static constexpr std::underlying_type_t value = LargestValue; \
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83#define LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE() \
84 using ::llvm::BitmaskEnumDetail::operator~; \
85 using ::llvm::BitmaskEnumDetail::operator|; \
86 using ::llvm::BitmaskEnumDetail::operator&; \
87 using ::llvm::BitmaskEnumDetail::operator^; \
88 using ::llvm::BitmaskEnumDetail::operator<<; \
89 using ::llvm::BitmaskEnumDetail::operator>>; \
90 using ::llvm::BitmaskEnumDetail::operator|=; \
91 using ::llvm::BitmaskEnumDetail::operator&=; \
92 using ::llvm::BitmaskEnumDetail::operator^=; \
93 using ::llvm::BitmaskEnumDetail::operator<<=; \
94 using ::llvm::BitmaskEnumDetail::operator>>=; \
95 using ::llvm::BitmaskEnumDetail::operator!; \
96 \
97 using ::llvm::BitmaskEnumDetail::any
98
99namespace llvm {
100
101
102
103template <typename E, typename Enable = void>
105
106template
108 E, std::void_t<decltype(E::LLVM_BITMASK_LARGEST_ENUMERATOR)>>
109 : std::true_type {};
110
111
113
114template
116 E, std::void_t<decltype(E::LLVM_BITMASK_LARGEST_ENUMERATOR)>> {
119 static_cast<UnderlyingTy>(E::LLVM_BITMASK_LARGEST_ENUMERATOR);
120};
121
123
124
125
126template constexpr std::underlying_type_t Mask() {
127
128
130}
131
132
133
134template constexpr std::underlying_type_t Underlying(E Val) {
136 assert(U >= 0 && "Negative enum values are not allowed.");
137 assert(U <= Mask() && "Enum value too large (or largest val too small?)");
138 return U;
139}
140
141template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
143 return Val == static_cast<E>(0);
144}
145
146template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
147constexpr bool any(E Val) {
148 return Val != static_cast<E>(0);
149}
150
151template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
155
156template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
160
161template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
165
166template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
170
171template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
175
176template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
180
181
182
183
184template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
189
190template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
195
196template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
201
202template <typename e, typename = std::enable_if_t<is_bitmask_enum::value>>
204 lhs = lhs << rhs;
205 return lhs;
206}
207
208template <typename e, typename = std::enable_if_t<is_bitmask_enum::value>>
210 lhs = lhs >> rhs;
211 return lhs;
212}
213
214}
215
216
218template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>
221
222}
223
224#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains library features backported from future STL versions.
This file implements the C++20 header.
Definition BitmaskEnum.h:122
e & operator>>=(e &lhs, e rhs)
Definition BitmaskEnum.h:209
constexpr E operator>>(E LHS, E RHS)
Definition BitmaskEnum.h:177
constexpr E operator^(E LHS, E RHS)
Definition BitmaskEnum.h:167
constexpr bool any(E Val)
Definition BitmaskEnum.h:147
constexpr E operator~(E Val)
Definition BitmaskEnum.h:152
constexpr std::underlying_type_t< E > Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
Definition BitmaskEnum.h:134
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition BitmaskEnum.h:126
constexpr bool operator!(E Val)
Definition BitmaskEnum.h:142
E & operator^=(E &LHS, E RHS)
Definition BitmaskEnum.h:197
E & operator&=(E &LHS, E RHS)
Definition BitmaskEnum.h:191
constexpr E operator&(E LHS, E RHS)
Definition BitmaskEnum.h:162
e & operator<<=(e &lhs, e rhs)
Definition BitmaskEnum.h:203
constexpr E operator<<(E LHS, E RHS)
Definition BitmaskEnum.h:172
E & operator|=(E &LHS, E RHS)
Definition BitmaskEnum.h:185
constexpr E operator|(E LHS, E RHS)
Definition BitmaskEnum.h:157
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
constexpr unsigned BitWidth
Definition BitmaskEnum.h:219
constexpr int bit_width_constexpr(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Implement std::hash so that hash_code can be used in STL containers.
Traits class to determine whether an enum has a LLVM_BITMASK_LARGEST_ENUMERATOR enumerator.
Definition BitmaskEnum.h:104
static constexpr UnderlyingTy value
Definition BitmaskEnum.h:118
std::underlying_type_t< E > UnderlyingTy
Definition BitmaskEnum.h:117
Trait class to determine bitmask enumeration largest bit.
Definition BitmaskEnum.h:112