llvm.org GIT mirror llvm / 7fe65d6
Cleanup the simplify_type implementation. As far as simplify_type is concerned, there are 3 kinds of smart pointers: * const correct: A 'const MyPtr<int> &' produces a 'const int*'. A 'MyPtr<int> &' produces a 'int *'. * always const: Even a 'MyPtr<int> &' produces a 'const int*'. * no const: Even a 'const MyPtr<int> &' produces a 'int*'. This patch then does the following: * Removes the unused specializations. Since they are unused, it is hard to know which kind should be implemented. * Make sure we don't drop const. * Fix the default forwarding so that const correct pointer only need one specialization. * Simplifies the existing specializations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178147 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
9 changed file(s) with 83 addition(s) and 130 deletion(s). Raw diff Collapse all Expand all
225225
226226 template struct simplify_type > {
227227 typedef T* SimpleType;
228 static SimpleType getSimplifiedValue(IntrusiveRefCntPtr& Val) {
229 return Val.getPtr();
230 }
231 };
232
233 template struct simplify_type > {
234 typedef /*const*/ T* SimpleType;
228235 static SimpleType getSimplifiedValue(const IntrusiveRefCntPtr& Val) {
229236 return Val.getPtr();
230237 }
231238 };
232239
233 template struct simplify_type > {
234 typedef T* SimpleType;
235 static SimpleType getSimplifiedValue(const IntrusiveRefCntPtr& Val) {
236 return Val.getPtr();
237 }
238 };
239
240240 } // end namespace llvm
241241
242242 #endif // LLVM_ADT_INTRUSIVEREFCNTPTR_H
127127 #endif
128128 };
129129
130 template struct simplify_type;
131
132 template
133 struct simplify_type > {
134 typedef const T* SimpleType;
135 static SimpleType getSimplifiedValue(const Optional &Val) {
136 return Val.getPointer();
137 }
138 };
139
140 template
141 struct simplify_type >
142 : public simplify_type > {};
143
144130 template struct isPodLike;
145131 template struct isPodLike > {
146132 // An Optional is pod-like if T is.
273273 template struct simplify_type > {
274274 typedef NodeTy* SimpleType;
275275
276 static SimpleType getSimplifiedValue(const ilist_iterator &Node) {
276 static SimpleType getSimplifiedValue(ilist_iterator &Node) {
277277 return &*Node;
278278 }
279279 };
280280 template struct simplify_type > {
281 typedef NodeTy* SimpleType;
281 typedef /*const*/ NodeTy* SimpleType;
282282
283283 static SimpleType getSimplifiedValue(const ilist_iterator &Node) {
284284 return &*Node;
195195 /// SDValues as if they were SDNode*'s.
196196 template<> struct simplify_type {
197197 typedef SDNode* SimpleType;
198 static SimpleType getSimplifiedValue(SDValue &Val) {
199 return Val.getNode();
200 }
201 };
202 template<> struct simplify_type {
203 typedef /*const*/ SDNode* SimpleType;
198204 static SimpleType getSimplifiedValue(const SDValue &Val) {
199 return static_cast(Val.getNode());
200 }
201 };
202 template<> struct simplify_type {
203 typedef SDNode* SimpleType;
204 static SimpleType getSimplifiedValue(const SDValue &Val) {
205 return static_cast(Val.getNode());
205 return Val.getNode();
206206 }
207207 };
208208
294294 /// SDValues as if they were SDNode*'s.
295295 template<> struct simplify_type {
296296 typedef SDNode* SimpleType;
297 static SimpleType getSimplifiedValue(const SDUse &Val) {
298 return static_cast(Val.getNode());
299 }
300 };
301 template<> struct simplify_type {
302 typedef SDNode* SimpleType;
303 static SimpleType getSimplifiedValue(const SDUse &Val) {
304 return static_cast(Val.getNode());
297 static SimpleType getSimplifiedValue(SDUse &Val) {
298 return Val.getNode();
305299 }
306300 };
307301
148148 // casting operators.
149149 template<> struct simplify_type {
150150 typedef Value* SimpleType;
151 static SimpleType getSimplifiedValue(Use &Val) {
152 return Val.get();
153 }
154 };
155 template<> struct simplify_type {
156 typedef /*const*/ Value* SimpleType;
151157 static SimpleType getSimplifiedValue(const Use &Val) {
152 return static_cast(Val.get());
153 }
154 };
155 template<> struct simplify_type {
156 typedef Value* SimpleType;
157 static SimpleType getSimplifiedValue(const Use &Val) {
158 return static_cast(Val.get());
158 return Val.get();
159159 }
160160 };
161161
182182
183183 template<> struct simplify_type {
184184 typedef Value* SimpleType;
185
186 static SimpleType getSimplifiedValue(const User::op_iterator &Val) {
187 return static_cast(Val->get());
185 static SimpleType getSimplifiedValue(User::op_iterator &Val) {
186 return Val->get();
188187 }
189188 };
190
191 template<> struct simplify_type
192 : public simplify_type {};
193
194189 template<> struct simplify_type {
195 typedef Value* SimpleType;
196
197 static SimpleType getSimplifiedValue(const User::const_op_iterator &Val) {
198 return static_cast(Val->get());
190 typedef /*const*/ Value* SimpleType;
191 static SimpleType getSimplifiedValue(User::const_op_iterator &Val) {
192 return Val->get();
199193 }
200194 };
201
202 template<> struct simplify_type
203 : public simplify_type {};
204
205195
206196 // value_use_iterator::getOperandNo - Requires the definition of the User class.
207197 template
3535 };
3636
3737 template struct simplify_type {
38 typedef const From SimpleType;
39 static SimpleType &getSimplifiedValue(const From &Val) {
40 return simplify_type::getSimplifiedValue(static_cast(Val));
38 typedef typename simplify_type::SimpleType NonConstSimpleType;
39 typedef typename add_const_past_pointer::type
40 SimpleType;
41 typedef typename add_lvalue_reference_if_not_pointer::type
42 RetType;
43 static RetType getSimplifiedValue(const From& Val) {
44 return simplify_type::getSimplifiedValue(const_cast(Val));
4145 }
4246 };
4347
8084 }
8185 };
8286
87 template struct isa_impl_cl {
88 static inline bool doit(const From *Val) {
89 assert(Val && "isa<> used on a null pointer");
90 return isa_impl::doit(*Val);
91 }
92 };
93
8394 template struct isa_impl_cl {
8495 static inline bool doit(const From *Val) {
8596 assert(Val && "isa<> used on a null pointer");
101112 static bool doit(const From &Val) {
102113 return isa_impl_wrap
103114 typename simplify_type::SimpleType>::doit(
104 simplify_type<From>::getSimplifiedValue(Val));
115 simplify_type<const From>::getSimplifiedValue(Val));
105116 }
106117 };
107118
120131 //
121132 template
122133 inline bool isa(const Y &Val) {
123 return isa_impl_wrapY, typename simplify_type::SimpleType>::doit(Val);
134 return isa_impl_wrapconst Y,
135 typename simplify_type::SimpleType>::doit(Val);
124136 }
125137
126138 //===----------------------------------------------------------------------===//
177189 //
178190 template struct cast_convert_val {
179191 // This is not a simple type, use the template to simplify it...
180 static typename cast_retty::ret_type doit(const From &Val) {
192 static typename cast_retty::ret_type doit(From &Val) {
181193 return cast_convert_val
182194 typename simplify_type::SimpleType>::doit(
183195 simplify_type::getSimplifiedValue(Val));
203215 // cast(myVal)->getParent()
204216 //
205217 template
206 inline typename enable_if_c<
207 !is_same::SimpleType>::value,
208 typename cast_retty::ret_type
209 >::type cast(const Y &Val) {
218 inline typename cast_retty::ret_type cast(const Y &Val) {
210219 assert(isa(Val) && "cast() argument of incompatible type!");
211 return cast_convert_val
212 typename simplify_type::SimpleType>::doit(Val);
213 }
214
215 template
216 inline typename enable_if<
217 is_same::SimpleType>,
218 typename cast_retty::ret_type
219 >::type cast(Y &Val) {
220 return cast_convert_val
221 typename simplify_type::SimpleType>::doit(Val);
222 }
223
224 template
225 inline typename cast_retty::ret_type cast(Y &Val) {
220226 assert(isa(Val) && "cast() argument of incompatible type!");
221227 return cast_convert_val
222228 typename simplify_type::SimpleType>::doit(Val);
252258 //
253259
254260 template
255 inline typename enable_if_c<
256 !is_same::SimpleType>::value,
257 typename cast_retty::ret_type
258 >::type dyn_cast(const Y &Val) {
261 inline typename cast_retty::ret_type dyn_cast(const Y &Val) {
259262 return isa(Val) ? cast(Val) : 0;
260263 }
261264
262265 template
263 inline typename enable_if<
264 is_same::SimpleType>,
265 typename cast_retty::ret_type
266 >::type dyn_cast(Y &Val) {
266 inline typename cast_retty::ret_type dyn_cast(Y &Val) {
267267 return isa(Val) ? cast(Val) : 0;
268268 }
269269
1919
2020 namespace llvm {
2121 class ValueHandleBase;
22 template struct simplify_type;
2223
2324 // ValueHandleBase** is only 4-byte aligned.
2425 template<>
161162
162163 // Specialize simplify_type to allow WeakVH to participate in
163164 // dyn_cast, isa, etc.
164 template struct simplify_type;
165 template<> struct simplify_type<const WeakVH> {
165 template<> struct simplify_type<WeakVH> {
166166 typedef Value* SimpleType;
167 static SimpleType getSimplifiedValue(const WeakVH &WVH) {
168 return static_cast(WVH);
169 }
170 };
171 template<> struct simplify_type : public simplify_type {};
167 static SimpleType getSimplifiedValue(WeakVH &WVH) {
168 return WVH;
169 }
170 };
172171
173172 /// AssertingVH - This is a Value Handle that points to a value and asserts out
174173 /// if the value is destroyed while the handle is still live. This is very
235234 ValueTy &operator*() const { return *getValPtr(); }
236235 };
237236
238 // Specialize simplify_type to allow AssertingVH to participate in
239 // dyn_cast, isa, etc.
240 template struct simplify_type;
241 template<> struct simplify_type > {
242 typedef Value* SimpleType;
243 static SimpleType getSimplifiedValue(const AssertingVH &AVH) {
244 return static_cast(AVH);
245 }
246 };
247 template<> struct simplify_type >
248 : public simplify_type > {};
249
250237 // Specialize DenseMapInfo to allow AssertingVH to participate in DenseMap.
251238 template
252239 struct DenseMapInfo > {
343330 ValueTy *operator->() const { return getValPtr(); }
344331 ValueTy &operator*() const { return *getValPtr(); }
345332 };
346
347 // Specialize simplify_type to allow TrackingVH to participate in
348 // dyn_cast, isa, etc.
349 template struct simplify_type;
350 template<> struct simplify_type > {
351 typedef Value* SimpleType;
352 static SimpleType getSimplifiedValue(const TrackingVH &AVH) {
353 return static_cast(AVH);
354 }
355 };
356 template<> struct simplify_type >
357 : public simplify_type > {};
358333
359334 /// CallbackVH - This is a value handle that allows subclasses to define
360335 /// callbacks that run when the underlying Value has RAUW called on it or is
398373 virtual void allUsesReplacedWith(Value *);
399374 };
400375
401 // Specialize simplify_type to allow CallbackVH to participate in
402 // dyn_cast, isa, etc.
403 template struct simplify_type;
404 template<> struct simplify_type {
405 typedef Value* SimpleType;
406 static SimpleType getSimplifiedValue(const CallbackVH &CVH) {
407 return static_cast(CVH);
408 }
409 };
410 template<> struct simplify_type
411 : public simplify_type {};
412
413376 } // End llvm namespace
414377
415378 #endif
208208 template struct remove_pointer {
209209 typedef T type; };
210210
211 // If T is a pointer, just return it. If it is not, return T&.
212 template
213 struct add_lvalue_reference_if_not_pointer { typedef T &type; };
214
215 template
216 struct add_lvalue_reference_if_not_pointer
217 typename enable_if >::type> {
218 typedef T type;
219 };
220
221 // If T is a pointer to X, return a pointer to const X. If it is not, return
222 // const T.
223 template
224 struct add_const_past_pointer { typedef const T type; };
225
226 template
227 struct add_const_past_pointer >::type> {
228 typedef const typename remove_pointer::type *type;
229 };
230
211231 template
212232 struct conditional { typedef T type; };
213233