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#include

15

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 \

96 using ::llvm::BitmaskEnumDetail::any

97

98namespace llvm {

99

100

101

102template <typename E, typename Enable = void>

104

105template

107 E, std::enable_if_t<sizeof(E::LLVM_BITMASK_LARGEST_ENUMERATOR) >= 0>>

108 : std::true_type {};

109

110

112

113template

115 E, std::enable_if_t<sizeof(E::LLVM_BITMASK_LARGEST_ENUMERATOR) >= 0>> {

118 static_cast<UnderlyingTy>(E::LLVM_BITMASK_LARGEST_ENUMERATOR);

119};

120

121namespace BitmaskEnumDetail {

122

123

124

125template constexpr std::underlying_type_t Mask() {

126

127

129}

130

131

132

133template constexpr std::underlying_type_t Underlying(E Val) {

135 assert(U >= 0 && "Negative enum values are not allowed.");

136 assert(U <= Mask() && "Enum value too large (or largest val too small?)");

137 return U;

138}

139

142}

143

144template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

145constexpr bool any(E Val) {

146 return Val != static_cast<E>(0);

147}

148

149template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

151 return static_cast<E>(~Underlying(Val) & Mask());

152}

153

154template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

157}

158

159template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

162}

163

164template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

167}

168

169template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

172}

173

174template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

177}

178

179

180

181

182template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

185 return LHS;

186}

187

188template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

191 return LHS;

192}

193

194template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

197 return LHS;

198}

199

200template <typename e, typename = std::enable_if_t<is_bitmask_enum::value>>

202 lhs = lhs << rhs;

203 return lhs;

204}

205

206template <typename e, typename = std::enable_if_t<is_bitmask_enum::value>>

208 lhs = lhs >> rhs;

209 return lhs;

210}

211

212}

213

214

216template <typename E, typename = std::enable_if_t<is_bitmask_enum::value>>

219

220}

221

222#endif

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

Given that RA is a live value

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file contains library features backported from future STL versions.

LLVM Value Representation.

e & operator>>=(e &lhs, e rhs)

constexpr E operator>>(E LHS, E RHS)

constexpr E operator^(E LHS, E RHS)

constexpr bool any(E Val)

constexpr E operator~(E Val)

constexpr unsigned bitWidth(uint64_t Value)

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.

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.

E & operator^=(E &LHS, E RHS)

E & operator&=(E &LHS, E RHS)

constexpr E operator&(E LHS, E RHS)

e & operator<<=(e &lhs, e rhs)

constexpr E operator<<(E LHS, E RHS)

E & operator|=(E &LHS, E RHS)

constexpr E operator|(E LHS, E RHS)

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

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.

std::underlying_type_t< E > UnderlyingTy

Trait class to determine bitmask enumeration largest bit.