LLVM: include/llvm/ADT/PointerSumType.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ADT_POINTERSUMTYPE_H

10#define LLVM_ADT_POINTERSUMTYPE_H

11

15#include

16#include

17#include

18

19namespace llvm {

20

21

22

23

24

25template <uintptr_t N, typename PointerArgT,

32

34

35template <typename TagT, typename... MemberTs> struct PointerSumTypeHelper;

36

37}

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70template <typename TagT, typename... MemberTs> class PointerSumType {

72

73

74

75

76

77

78

79

80

81

82 union StorageT {

83

84

85

86 StorageT() : Value(0) {}

87

89

91 };

92

93 StorageT Storage;

94

95public:

97

98

99 template

103 "Pointer is insufficiently aligned to store the discriminant!");

104 Storage.Value = reinterpret_cast<uintptr_t>(V) | N;

105 }

106

107

108 template

112 Result.set<N>(Pointer);

113 return Result;

114 }

115

116

118

122

123 template bool is() const { return N == getTag(); }

124

129

130 template

132 assert(is() && "This instance has a different active member.");

135 }

136

137

138

139

144

145

146

147

150 static_assert(HelperT::MinTag == 0, "Non-zero minimum tag value!");

152

154

155

156

157 Storage.MinTagPointer = InitialPtr;

158

159

161 "Switching to typed storage changed the pointer returned!");

162

163 return &Storage.MinTagPointer;

164 }

165

166 explicit operator bool() const {

168 }

187

193

194protected:

198};

199

201

202

203

204

205template <typename TagT, typename... MemberTs>

207

208

209

210

211

212 template <TagT N, typename PointerT, typename TraitsT>

216 template struct Lookup {

217

220

221

222 using PointerT = typename MemberT::PointerT;

223

224

225 using TraitsT = typename MemberT::TraitsT;

226 };

227

228

229

231 std::min({MemberTs::TraitsT::NumLowBitsAvailable...});

232

233

235 static_cast<TagT>(std::min({static_cast<TagT>(MemberTs::Tag)...}));

239 };

240

241

242 static_assert(((MemberTs::Tag < (1 << NumTagBits)) && ...),

243 "A discriminant value requires too many bits!");

244};

245

246}

247

248

249template <typename TagT, typename... MemberTs>

257

259 return SumType::template create(SomePointerInfo::getEmptyKey());

260 }

261

263 return SumType::template create(

264 SomePointerInfo::getTombstoneKey());

265 }

266

271

275};

276

277}

278

279#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines DenseMapInfo traits for DenseMap.

static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)

This file implements the C++20 header.

A sum type over pointer-like types.

Definition PointerSumType.h:70

bool operator<=(const PointerSumType &R) const

Definition PointerSumType.h:181

HelperT::template Lookup< N >::PointerT cast() const

Definition PointerSumType.h:131

TagT getTag() const

Definition PointerSumType.h:119

bool operator==(const PointerSumType &R) const

Definition PointerSumType.h:169

bool operator>=(const PointerSumType &R) const

Definition PointerSumType.h:184

static PointerSumType create(typename HelperT::template Lookup< N >::PointerT Pointer)

A typed constructor for a specific tagged member of the sum type.

Definition PointerSumType.h:110

bool operator!=(const PointerSumType &R) const

Definition PointerSumType.h:172

HelperT::template Lookup< HelperT::MinTag >::PointerT * getAddrOfZeroTagPointer()

If the tag is zero and the pointer's value isn't changed when being stored, get the address of the st...

Definition PointerSumType.h:149

void clear()

Clear the value to null with the min tag type.

Definition PointerSumType.h:117

HelperT::template Lookup< HelperT::MinTag >::PointerT const * getAddrOfZeroTagPointer() const

If the tag is zero and the pointer's value isn't changed when being stored, get the address of the st...

Definition PointerSumType.h:141

uintptr_t getOpaqueValue() const

Definition PointerSumType.h:188

HelperT::template Lookup< N >::PointerT get() const

Definition PointerSumType.h:125

bool operator>(const PointerSumType &R) const

Definition PointerSumType.h:178

bool is() const

Definition PointerSumType.h:123

bool operator<(const PointerSumType &R) const

Definition PointerSumType.h:175

constexpr PointerSumType()=default

void * getVoidPtr() const

Definition PointerSumType.h:195

void set(typename HelperT::template Lookup< N >::PointerT Pointer)

A typed setter to a given tagged member of the sum type.

Definition PointerSumType.h:100

LLVM Value Representation.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

To bit_cast(const From &from) noexcept

DenseMapInfo< SomePointerT > SomePointerInfo

Definition PointerSumType.h:256

detail::PointerSumTypeHelper< TagT, MemberTs... > HelperT

Definition PointerSumType.h:252

@ SomeTag

Definition PointerSumType.h:253

typename HelperT::template Lookup< HelperT::MinTag >::PointerT SomePointerT

Definition PointerSumType.h:254

PointerSumType< TagT, MemberTs... > SumType

Definition PointerSumType.h:251

static bool isEqual(const SumType &LHS, const SumType &RHS)

Definition PointerSumType.h:272

static unsigned getHashValue(const SumType &Arg)

Definition PointerSumType.h:267

static SumType getTombstoneKey()

Definition PointerSumType.h:262

static SumType getEmptyKey()

Definition PointerSumType.h:258

An information struct used to provide DenseMap with the various necessary components for a given valu...

A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...

A compile time pair of an integer tag and the pointer-like type which it indexes within a sum type.

Definition PointerSumType.h:27

@ Tag

Definition PointerSumType.h:28

TraitsArgT TraitsT

Definition PointerSumType.h:30

PointerArgT PointerT

Definition PointerSumType.h:29

Definition PointerSumType.h:216

typename MemberT::PointerT PointerT

The Nth member's pointer type.

Definition PointerSumType.h:222

decltype( LookupOverload< N >(static_cast< PointerSumTypeHelper * >(nullptr))) MemberT

Definition PointerSumType.h:218

typename MemberT::TraitsT TraitsT

The Nth member's traits type.

Definition PointerSumType.h:225

A helper template for implementing PointerSumType.

Definition PointerSumType.h:206

static void LookupOverload(...)

static constexpr TagT MinTag

Definition PointerSumType.h:234

static constexpr int NumTagBits

Definition PointerSumType.h:230

@ PointerMask

Definition PointerSumType.h:237

@ TagMask

Definition PointerSumType.h:238

static PointerSumTypeMember< N, PointerT, TraitsT > LookupOverload(PointerSumTypeMember< N, PointerT, TraitsT > *)