14 #ifndef LLVM_SUPPORT_CASTING_H 15 #define LLVM_SUPPORT_CASTING_H 21 #include <type_traits> 33 template<
typename From>
struct simplify_type {
55 template <
typename To,
typename From,
typename Enabler =
void>
58 return To::classof(&Val);
63 template <
typename To,
typename From>
65 To,
From, typename
std::enable_if<std::is_base_of<To, From>::value>
::type> {
66 static inline bool doit(
const From &) {
return true; }
81 template <
typename To,
typename From>
83 static inline bool doit(
const std::unique_ptr<From> &Val) {
84 assert(Val &&
"isa<> used on a null pointer");
91 assert(Val &&
"isa<> used on a null pointer");
98 assert(Val &&
"isa<> used on a null pointer");
105 assert(Val &&
"isa<> used on a null pointer");
112 assert(Val &&
"isa<> used on a null pointer");
117 template<
typename To,
typename From,
typename SimpleFrom>
128 template<
typename To,
typename FromTy>
131 static bool doit(
const FromTy &Val) {
149 template <
class X,
class Y>
183 template <
class To,
class From>
187 using ResultType =
typename std::remove_pointer<PointerType>::type;
193 template<
class To,
class From,
class SimpleFrom>
201 template<
class To,
class FromTy>
207 template<
class To,
class From>
235 static const bool value =
236 std::is_same<X, typename simplify_type<X>::SimpleType>::value;
246 template <
class X,
class Y>
247 inline typename std::enable_if<!is_simple_type<Y>::value,
250 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
255 template <
class X,
class Y>
257 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
262 template <
class X,
class Y>
264 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
269 template <
class X,
class Y>
271 cast(std::unique_ptr<Y> &&Val) {
272 assert(isa<X>(Val.get()) &&
"cast<Ty>() argument of incompatible type!");
282 template <
class X,
class Y>
284 typename std::enable_if<!is_simple_type<Y>::value,
289 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
293 template <
class X,
class Y>
295 typename std::enable_if<!is_simple_type<Y>::value,
300 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
304 template <
class X,
class Y>
307 if (!Val)
return nullptr;
308 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
312 template <
class X,
class Y>
317 return cast<X>(std::move(Val));
328 template <
class X,
class Y>
330 typename std::enable_if<!is_simple_type<Y>::value,
333 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
336 template <
class X,
class Y>
338 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
341 template <
class X,
class Y>
343 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
349 template <
class X,
class Y>
351 typename std::enable_if<!is_simple_type<Y>::value,
354 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
357 template <
class X,
class Y>
359 typename std::enable_if<!is_simple_type<Y>::value,
362 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
365 template <
class X,
class Y>
368 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
376 template <
class X,
class Y>
378 -> decltype(cast<X>(Val)) {
381 return cast<X>(std::move(Val));
384 template <
class X,
class Y>
386 -> decltype(cast<X>(Val)) {
392 template <
class X,
class Y>
394 -> decltype(cast<X>(Val)) {
400 template <
class X,
class Y>
402 -> decltype(cast<X>(Val)) {
403 return unique_dyn_cast_or_null<X, Y>(Val);
408 #endif // LLVM_SUPPORT_CASTING_H
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVM_NODISCARD bool isa_and_nonnull(const Y &Val)
This class represents lattice values for constants.
static cast_retty< To, FromTy >::ret_type doit(const FromTy &Val)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast_or_null(const Y &Val)
LLVM_NODISCARD auto unique_dyn_cast(std::unique_ptr< Y > &Val) -> decltype(cast< X >(Val))
static RetType getSimplifiedValue(const From &Val)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
LLVM_NODISCARD auto unique_dyn_cast_or_null(std::unique_ptr< Y > &Val) -> decltype(cast< X >(Val))
static bool doit(const From &Val)
static bool doit(const From &)
typename cast_retty_impl< To, FromTy >::ret_type ret_type
static bool doit(const From *Val)
static bool doit(const From &Val)
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
static cast_retty< To, From >::ret_type doit(From &Val)
static bool doit(const std::unique_ptr< From > &Val)
typename add_lvalue_reference_if_not_pointer< SimpleType >::type RetType
static bool doit(const From &Val)
std::unique_ptr< ResultType > ret_type
static bool doit(const From *Val)
typename cast_retty_wrap< To, From, typename simplify_type< From >::SimpleType >::ret_type ret_type
static bool doit(const From *Val)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast_or_null(const Y &Val)
static bool doit(const From &Val)
BlockVerifier::State From
LLVM_NODISCARD bool isa(const Y &Val)
typename simplify_type< From >::SimpleType NonConstSimpleType
static bool doit(const FromTy &Val)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static SimpleType & getSimplifiedValue(From &Val)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
typename cast_retty< To, SimpleFrom >::ret_type ret_type
typename add_const_past_pointer< NonConstSimpleType >::type SimpleType
static bool doit(const From *Val)