LLVM: include/llvm/ADT/PointerUnion.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_ADT_POINTERUNION_H
16#define LLVM_ADT_POINTERUNION_H
17
23#include
24#include
25#include
26#include
27
28namespace llvm {
29
31
32
36
40
41
42
49
50 template <typename Derived, typename ValTy, int I, typename ...Types>
52
53 template <typename Derived, typename ValTy, int I>
62
63 template <typename Derived, typename ValTy, int I, typename Type,
64 typename ...Types>
68 public:
69 using Base::Base;
72 : Base(ValTy(const_cast<void *>(
74 I)) {}
75
76 using Base::operator=;
78 this->Val = ValTy(
80 I);
81 return static_cast<Derived &>(*this);
82 };
83 };
84}
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103template <typename... PTs>
106 PointerUnion<PTs...>,
107 PointerIntPair<
108 void *, pointer_union_detail::bitsRequired(sizeof...(PTs)), int,
109 pointer_union_detail::PointerUnionUIntTraits<PTs...>>,
110 0, PTs...> {
112 "PointerUnion alternative types cannot be repeated");
113
114
115
116
117
119 using Base = typename PointerUnion::PointerUnionMembers;
120
121
122
123
124
125
126 template <typename To, typename From, typename Enable> friend struct CastInfo;
127
128public:
130
132 using Base::Base;
133
134
135
136 bool isNull() const { return !this->Val.getPointer(); }
137
138 explicit operator bool() const { return (); }
139
140
141
142
143
144 template
145 [[deprecated("Use isa instead")]]
147 return isa(*this);
148 }
149
150
151
152
153 template
154 [[deprecated("Use cast instead")]]
156 assert(isa(*this) && "Invalid accessor called");
158 }
159
160
161
165
166
167
171
172
173
178 this->Val.getPointer() &&
179 "Can't get the address because PointerLikeTypeTraits changes the ptr");
180 return const_cast<First *>(
181 reinterpret_cast<const First *>(this->Val.getAddrOfPointer()));
182 }
183
184
186 this->Val.initWithPointer(nullptr);
187 return *this;
188 }
189
190
191 using Base::operator=;
192
193 void *getOpaqueValue() const { return this->Val.getOpaqueValue(); }
199};
200
201template <typename ...PTs>
205
206template <typename ...PTs>
210
211template <typename ...PTs>
215
216
217template <typename To, typename... PTs>
220 CastInfo<To, PointerUnion<PTs...>>> {
222
226
231
233};
234
235template <typename To, typename... PTs>
238 CastInfo<To, PointerUnion<PTs...>>> {
239};
240
241
242
243template <typename ...PTs>
246 return P.getOpaqueValue();
247 }
248
252
253
254
257};
258
259
263
265
267 return Union(FirstInfo::getTombstoneKey());
268 }
269
274
278};
279
280}
281
282#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines DenseMapInfo traits for DenseMap.
This file defines the PointerIntPair class.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition PointerUnion.h:110
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition PointerUnion.h:136
T get() const
Returns the value of the specified pointer type.
Definition PointerUnion.h:155
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition PointerUnion.h:162
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
Definition PointerUnion.h:168
bool is() const
Test if the Union currently holds the type matching T.
Definition PointerUnion.h:146
void * getOpaqueValue() const
Definition PointerUnion.h:193
friend struct CastInfo
Definition PointerUnion.h:126
PointerUnion(std::nullptr_t)
Definition PointerUnion.h:131
const PointerUnion & operator=(std::nullptr_t)
Assignment from nullptr which just clears the union.
Definition PointerUnion.h:185
First * getAddrOfPtr1()
If the union is set to the first pointer type get an address pointing to it.
Definition PointerUnion.h:174
static PointerUnion getFromOpaqueValue(void *VP)
Definition PointerUnion.h:194
The instances of the Type class are immutable: once they are created, they are never changed.
PointerUnionMembers()=default
PointerUnionMembers(Type V)
Definition PointerUnion.h:71
Derived & operator=(Type V)
Definition PointerUnion.h:77
ValTy Val
Definition PointerUnion.h:56
PointerUnionMembers()=default
Definition PointerUnion.h:51
Provide PointerLikeTypeTraits for void* that is used by PointerUnion for the template arguments.
Definition PointerUnion.h:43
static void * getFromVoidPointer(void *P)
Definition PointerUnion.h:46
static constexpr int NumLowBitsAvailable
Definition PointerUnion.h:47
static void * getAsVoidPointer(void *P)
Definition PointerUnion.h:45
Definition PointerUnion.h:30
constexpr int bitsRequired(unsigned n)
Determine the number of bits required to store integers with values < n.
Definition PointerUnion.h:33
constexpr int lowBitsAvailable()
Definition PointerUnion.h:37
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
bool operator!=(uint64_t V1, const APInt &V2)
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present - Functionally identical to dyn_cast, except that a null (or none in the case ...
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
constexpr int bit_width_constexpr(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
static To castFailed()
Definition PointerUnion.h:232
static bool isPossible(From &f)
Definition PointerUnion.h:223
PointerUnion< PTs... > From
Definition PointerUnion.h:221
static To doCast(From &f)
Definition PointerUnion.h:227
This struct provides a method for customizing the way a cast is performed.
static bool isPossible(const From &f)
Provides a cast trait that strips const from types to make it easier to implement a const-version of ...
This cast trait just provides the default implementation of doCastIfPossible to make CastInfo special...
PointerUnion< PTs... > Union
Definition PointerUnion.h:261
static Union getEmptyKey()
Definition PointerUnion.h:264
static unsigned getHashValue(const Union &UnionVal)
Definition PointerUnion.h:270
static Union getTombstoneKey()
Definition PointerUnion.h:266
static bool isEqual(const Union &LHS, const Union &RHS)
Definition PointerUnion.h:275
DenseMapInfo< TypeAtIndex< 0, PTs... > > FirstInfo
Definition PointerUnion.h:262
An information struct used to provide DenseMap with the various necessary components for a given valu...
Find the first index where a type appears in a list of types.
static PointerUnion< PTs... > getFromVoidPointer(void *P)
Definition PointerUnion.h:249
static constexpr int NumLowBitsAvailable
Definition PointerUnion.h:255
static void * getAsVoidPointer(const PointerUnion< PTs... > &P)
Definition PointerUnion.h:245
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Determine if all types in Ts are distinct.