15 #ifndef LLVM_SUPPORT_CASTING_H 16 #define LLVM_SUPPORT_CASTING_H 22 #include <type_traits> 34 template<
typename From>
struct simplify_type {
56 template <
typename To,
typename From,
typename Enabler =
void>
59 return To::classof(&Val);
64 template <
typename To,
typename From>
66 To,
From, typename
std::enable_if<std::is_base_of<To, From>::value>
::type> {
67 static inline bool doit(
const From &) {
return true; }
82 template <
typename To,
typename From>
84 static inline bool doit(
const std::unique_ptr<From> &Val) {
85 assert(Val &&
"isa<> used on a null pointer");
92 assert(Val &&
"isa<> used on a null pointer");
99 assert(Val &&
"isa<> used on a null pointer");
106 assert(Val &&
"isa<> used on a null pointer");
113 assert(Val &&
"isa<> used on a null pointer");
118 template<
typename To,
typename From,
typename SimpleFrom>
129 template<
typename To,
typename FromTy>
132 static bool doit(
const FromTy &Val) {
174 template <
class To,
class From>
178 using ResultType =
typename std::remove_pointer<PointerType>::type;
184 template<
class To,
class From,
class SimpleFrom>
192 template<
class To,
class FromTy>
198 template<
class To,
class From>
226 static const bool value =
227 std::is_same<X, typename simplify_type<X>::SimpleType>::value;
237 template <
class X,
class Y>
238 inline typename std::enable_if<!is_simple_type<Y>::value,
241 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
246 template <
class X,
class Y>
248 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
253 template <
class X,
class Y>
255 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
260 template <
class X,
class Y>
262 cast(std::unique_ptr<Y> &&Val) {
263 assert(isa<X>(Val.get()) &&
"cast<Ty>() argument of incompatible type!");
273 template <
class X,
class Y>
275 typename std::enable_if<!is_simple_type<Y>::value,
280 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
284 template <
class X,
class Y>
286 typename std::enable_if<!is_simple_type<Y>::value,
291 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
295 template <
class X,
class Y>
298 if (!Val)
return nullptr;
299 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
303 template <
class X,
class Y>
308 return cast<X>(std::move(Val));
319 template <
class X,
class Y>
321 typename std::enable_if<!is_simple_type<Y>::value,
324 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
327 template <
class X,
class Y>
329 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
332 template <
class X,
class Y>
334 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
340 template <
class X,
class Y>
342 typename std::enable_if<!is_simple_type<Y>::value,
345 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
348 template <
class X,
class Y>
350 typename std::enable_if<!is_simple_type<Y>::value,
353 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
356 template <
class X,
class Y>
359 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
367 template <
class X,
class Y>
369 -> decltype(cast<X>(Val)) {
372 return cast<X>(std::move(Val));
375 template <
class X,
class Y>
377 -> decltype(cast<X>(Val)) {
383 template <
class X,
class Y>
385 -> decltype(cast<X>(Val)) {
391 template <
class X,
class Y>
393 -> decltype(cast<X>(Val)) {
394 return unique_dyn_cast_or_null<X, Y>(Val);
399 #endif // LLVM_SUPPORT_CASTING_H
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
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")
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
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)
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)