14 #ifndef MLIR_SUPPORT_TYPEID_H
15 #define MLIR_SUPPORT_TYPEID_H
18 #include "llvm/ADT/DenseMapInfo.h"
19 #include "llvm/ADT/Hashing.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/Support/Allocator.h"
22 #include "llvm/Support/Compiler.h"
23 #include "llvm/Support/PointerLikeTypeTraits.h"
24 #include "llvm/Support/TypeName.h"
112 struct alignas(8) Storage {};
119 return storage == other.storage;
122 return !(*
this == other);
126 template <
typename T>
128 template <
template <
typename>
class Trait>
133 return static_cast<const void *
>(storage);
136 return TypeID(
reinterpret_cast<const Storage *
>(pointer));
143 TypeID(
const Storage *storage) : storage(storage) {}
146 const Storage *storage;
170 template <
typename T>
178 template <
typename U>
180 template <
typename U>
185 template <
typename T>
202 template <
typename T,
typename Enable =
void>
206 static_assert(is_fully_resolved<T>(),
207 "TypeID::get<> requires the complete definition of `T`");
221 template <
typename T>
223 template <
typename T>
226 template <
typename T>
228 return T::resolveTypeID();
234 template <
typename T>
236 T, std::enable_if_t<InlineTypeIDResolver::has_resolve_typeid<T>::value>> {
239 return InlineTypeIDResolver::resolveTypeID<T>();
244 template <
typename T>
248 template <
template <
typename>
class Trait>
252 return TypeID::get<Trait<Empty>>();
262 #define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME) \
266 class TypeIDResolver<CLASS_NAME> { \
268 static TypeID resolveTypeID() { return id; } \
271 static SelfOwningTypeID id; \
276 #define MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME) \
279 SelfOwningTypeID TypeIDResolver<CLASS_NAME>::id = {}; \
291 #define MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME) \
295 class TypeIDResolver<CLASS_NAME> : public FallbackTypeIDResolver { \
297 static TypeID resolveTypeID() { \
298 static_assert(is_fully_resolved<CLASS_NAME>(), \
299 "TypeID::get<> requires the complete definition of `T`"); \
301 registerImplicitTypeID(llvm::getTypeName<CLASS_NAME>()); \
308 #define MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)
311 #ifndef MLIR_USE_FALLBACK_TYPE_IDS
312 #define MLIR_USE_FALLBACK_TYPE_IDS false
315 #if MLIR_USE_FALLBACK_TYPE_IDS
316 #define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME) \
317 MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)
318 #define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME) \
319 MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)
321 #define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME) \
322 MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
323 #define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME) \
324 MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
331 #define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME) \
332 static ::mlir::TypeID resolveTypeID() { \
333 static ::mlir::SelfOwningTypeID id; \
337 ::mlir::detail::InlineTypeIDResolver::has_resolve_typeid< \
338 CLASS_NAME>::value, \
339 "`MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` must be placed in a " \
340 "public section of `" #CLASS_NAME "`");
358 llvm::SpecificBumpPtrAllocator<TypeID::Storage> ids;
413 struct PointerLikeTypeTraits<
mlir::TypeID> {
420 static constexpr
int NumLowBitsAvailable = 3;
#define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
Defines a TypeID for each instance of this class by using a pointer to the instance.
SelfOwningTypeID(SelfOwningTypeID &&)=delete
TypeID getTypeID() const
Return the TypeID owned by this object.
SelfOwningTypeID & operator=(SelfOwningTypeID &&)=delete
SelfOwningTypeID & operator=(const SelfOwningTypeID &)=delete
SelfOwningTypeID(const SelfOwningTypeID &)=delete
SelfOwningTypeID()=default
This class provides a way to define new TypeIDs at runtime.
TypeID allocate()
Allocate a new TypeID, that is ensured to be unique for the lifetime of the TypeIDAllocator.
This class provides an efficient unique identifier for a specific C++ type.
bool operator==(const TypeID &other) const
Comparison operations.
static TypeID get()
Construct a type info object for the given type T.
friend ::llvm::hash_code hash_value(TypeID id)
Enable hashing TypeID.
static TypeID getFromOpaquePointer(const void *pointer)
bool operator!=(const TypeID &other) const
const void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
This class provides a fallback for resolving TypeIDs.
static LLVM_ALWAYS_EXPORT TypeID registerImplicitTypeID(StringRef name)
Register an implicit type ID for the given type name.
static TypeID resolveTypeID()
This class provides a resolver for getting the ID for a given class T.
static TypeID resolveTypeID()
The OpAsmOpInterface, see OpAsmInterface.td for more details.
constexpr bool is_fully_resolved()
Include the generated interface declarations.
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
static unsigned getHashValue(mlir::TypeID val)
static bool isEqual(mlir::TypeID lhs, mlir::TypeID rhs)
static mlir::TypeID getEmptyKey()
static mlir::TypeID getTombstoneKey()
static void * getAsVoidPointer(mlir::TypeID info)
static mlir::TypeID getFromVoidPointer(void *ptr)
This class provides utilities for resolving the TypeID of a class that provides a static TypeID resol...
decltype(T::resolveTypeID()) has_resolve_typeid_trait
Trait to check if T provides a static resolveTypeID method.
static TypeID resolveTypeID()
llvm::is_detected< has_resolve_typeid_trait, T > has_resolve_typeid
decltype(sizeof(U)) is_fully_resolved_trait
Trait to check if U is fully resolved.
llvm::is_detected< is_fully_resolved_trait, U > is_fully_resolved
static constexpr bool value