Go to the documentation of this file.
15 #ifndef LLVM_ADT_TYPESWITCH_H
16 #define LLVM_ADT_TYPESWITCH_H
37 template <
typename CaseT,
typename CaseT2,
typename... CaseTs,
45 DerivedT &derived =
static_cast<DerivedT &
>(*this);
46 return derived.template Case<CaseT>(caseFn)
47 .template
Case<CaseT2, CaseTs...>(caseFn);
54 template <
typename CallableT> DerivedT &
Case(CallableT &&caseFn) {
56 using CaseT = std::remove_cv_t<std::remove_pointer_t<
57 std::remove_reference_t<typename Traits::template arg_t<0>>>>;
59 DerivedT &derived =
static_cast<DerivedT &
>(*this);
60 return derived.template Case<CaseT>(std::forward<CallableT>(caseFn));
66 template <
typename ValueT,
typename CastT>
68 decltype(std::declval<ValueT &>().
template dyn_cast<CastT>());
72 template <
typename CastT,
typename ValueT>
75 typename std::enable_if_t<
77 return value.template dyn_cast<CastT>();
82 template <
typename CastT,
typename ValueT>
85 typename std::enable_if_t<
87 return dyn_cast<CastT>(
value);
106 template <
typename T,
typename ResultT =
void>
115 template <
typename CaseT,
typename CallableT>
121 if (
auto caseValue = BaseT::template castValue<CaseT>(this->
value))
122 result = caseFn(caseValue);
127 template <
typename CallableT>
131 return defaultFn(this->
value);
137 return defaultResult;
142 assert(result &&
"Fell off the end of a type-switch");
153 template <
typename T>
163 template <
typename CaseT,
typename CallableT>
169 if (
auto caseValue = BaseT::template castValue<CaseT>(this->
value)) {
177 template <
typename CallableT>
void Default(CallableT &&defaultFn) {
179 defaultFn(this->
value);
184 bool foundMatch =
false;
188 #endif // LLVM_ADT_TYPESWITCH_H
RTTIExtends< ObjectLinkingLayer, ObjectLayer > BaseT
decltype(std::declval< ValueT & >().template dyn_cast< CastT >()) has_dyn_cast_t
Trait to check whether ValueT provides a 'dyn_cast' method with type CastT.
This is an optimization pass for GlobalISel generic memory operations.
const T value
The root value we are switching on.
TypeSwitch(TypeSwitch &&other)=default
LLVM_NODISCARD ResultT Default(ResultT defaultResult)
As a default, return the given value.
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
#define LLVM_ATTRIBUTE_NODEBUG
LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do so, mark a method "no debug" b...
TypeSwitchBase(const T &value)
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
TypeSwitch< T, void > & Case(CallableT &&caseFn)
Add a case on the given type.
Specialization of TypeSwitch for void returning callables.
TypeSwitchBase(TypeSwitchBase &&other)
This class provides various trait information about a callable object.
void operator=(const TypeSwitchBase &)=delete
~TypeSwitchBase()=default
TypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionalit...
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DerivedT & Case(CallableT &&caseFn)
Invoke a case on the derived class, inferring the type of the Case from the first input of the given ...
static auto castValue(ValueT value, typename std::enable_if_t< is_detected< has_dyn_cast_t, ValueT, CastT >::value > *=nullptr)
Attempt to dyn_cast the given value to CastT.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG DerivedT & Case(CallableT &&caseFn)
Invoke a case on the derived class with multiple case types.
static auto castValue(ValueT value, typename std::enable_if_t< !is_detected< has_dyn_cast_t, ValueT, CastT >::value > *=nullptr)
Attempt to dyn_cast the given value to CastT.
void Default(CallableT &&defaultFn)
As a default, invoke the given callable within the root value.
LLVM_NODISCARD ResultT Default(CallableT &&defaultFn)
As a default, invoke the given callable within the root value.