MLIR  20.0.0git
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
mlir::TypeID Class Reference

This class provides an efficient unique identifier for a specific C++ type. More...

#include "mlir/Support/TypeID.h"

Public Member Functions

 TypeID ()
 
bool operator== (const TypeID &other) const
 Comparison operations. More...
 
bool operator!= (const TypeID &other) const
 
const void * getAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits. More...
 

Static Public Member Functions

template<typename T >
static TypeID get ()
 Construct a type info object for the given type T. More...
 
template<template< typename > class Trait>
static TypeID get ()
 
static TypeID getFromOpaquePointer (const void *pointer)
 

Friends

class TypeIDAllocator
 
::llvm::hash_code hash_value (TypeID id)
 Enable hashing TypeID. More...
 

Detailed Description

This class provides an efficient unique identifier for a specific C++ type.

This allows for a C++ type to be compared, hashed, and stored in an opaque context. This class is similar in some ways to std::type_index, but can be used for any type. For example, this class could be used to implement LLVM style isa/dyn_cast functionality for a type hierarchy:

struct Base { Base(TypeID typeID) : typeID(typeID) {} TypeID typeID; };

struct DerivedA : public Base { DerivedA() : Base(TypeID::get<DerivedA>()) {}

static bool classof(const Base *base) { return base->typeID == TypeID::get<DerivedA>(); } };

void foo(Base *base) { if (DerivedA *a = llvm::dyn_cast<DerivedA>(base)) ... }

C++ RTTI is a notoriously difficult topic; given the nature of shared libraries many different approaches fundamentally break down in either the area of support (i.e. only certain types of classes are supported), or in terms of performance (e.g. by using string comparison). This class intends to strike a balance between performance and the setup required to enable its use.

Assume we are adding support for some class Foo, below are the set of ways in which a given c++ type may be supported:

Definition at line 104 of file TypeID.h.

Constructor & Destructor Documentation

◆ TypeID()

mlir::TypeID::TypeID ( )
inline

Definition at line 112 of file TypeID.h.

Referenced by getFromOpaquePointer().

Member Function Documentation

◆ get() [1/2]

template<template< typename > class Trait>
TypeID mlir::TypeID::get
static

Construct a type info object for the given type T.

Definition at line 232 of file TypeID.h.

References mlir::detail::TypeIDResolver< T, Enable >::resolveTypeID().

◆ get() [2/2]

template<template< typename > class Trait>
static TypeID mlir::TypeID::get ( )
static

◆ getAsOpaquePointer()

const void* mlir::TypeID::getAsOpaquePointer ( ) const
inline

Methods for supporting PointerLikeTypeTraits.

Definition at line 129 of file TypeID.h.

Referenced by llvm::PointerLikeTypeTraits< mlir::TypeID >::getAsVoidPointer().

◆ getFromOpaquePointer()

static TypeID mlir::TypeID::getFromOpaquePointer ( const void *  pointer)
inlinestatic

◆ operator!=()

bool mlir::TypeID::operator!= ( const TypeID other) const
inline

Definition at line 118 of file TypeID.h.

◆ operator==()

bool mlir::TypeID::operator== ( const TypeID other) const
inline

Comparison operations.

Definition at line 115 of file TypeID.h.

Friends And Related Function Documentation

◆ hash_value

::llvm::hash_code hash_value ( TypeID  id)
friend

Enable hashing TypeID.

Definition at line 149 of file TypeID.h.

◆ TypeIDAllocator

friend class TypeIDAllocator
friend

Definition at line 145 of file TypeID.h.


The documentation for this class was generated from the following file: