9#ifndef MLIR_IR_DIALECTINTERFACE_H
10#define MLIR_IR_DIALECTINTERFACE_H
13#include "llvm/ADT/DenseSet.h"
14#include "llvm/ADT/STLExtras.h"
28template <
typename ConcreteType,
typename BaseT>
48 template <
typename ConcreteType>
62 : dialect(dialect), interfaceID(id) {}
81 struct InterfaceKeyInfo :
public DenseMapInfo<const DialectInterface *> {
84 static unsigned getHashValue(
Dialect *key) {
return llvm::hash_value(key); }
90 if (
rhs == getEmptyKey() ||
rhs == getTombstoneKey())
92 return lhs ==
rhs->getDialect();
98 using InterfaceVectorT = std::vector<const DialectInterface *>;
102 StringRef interfaceName);
112 auto it = interfaces.find_as(dialect);
113 return it == interfaces.end() ?
nullptr : *it;
118 template <
typename InterfaceT>
120 :
public llvm::mapped_iterator_base<iterator<InterfaceT>,
121 InterfaceVectorT::const_iterator,
122 const InterfaceT &> {
124 InterfaceVectorT::const_iterator,
125 const InterfaceT &>::mapped_iterator_base;
129 return *
static_cast<const InterfaceT *
>(interface);
134 template <
typename InterfaceT>
138 template <
typename InterfaceT>
145 InterfaceSetT interfaces;
149 InterfaceVectorT orderedInterfaces;
155template <
typename InterfaceType>
164 ctx, InterfaceType::getInterfaceID(),
165 llvm::getTypeName<InterfaceType>()) {}
169 template <
typename Object>
171 return static_cast<const InterfaceType *
>(
DialectInterfaceCollection< InterfaceType > Base
detail::DialectInterfaceCollectionBase::iterator< InterfaceType > iterator
Iterator access to the held interfaces.
DialectInterfaceCollection(MLIRContext *ctx)
Collect the registered dialect interfaces within the provided context.
const InterfaceType * getInterfaceFor(Object *obj) const
Get the interface for a given object, or null if one is not registered.
This class represents an interface overridden for a single dialect.
virtual ~DialectInterface()
MLIRContext * getContext() const
Return the context that holds the parent dialect of this interface.
Dialect * getDialect() const
Return the dialect that this interface represents.
DialectInterface(Dialect *dialect, TypeID id)
detail::DialectInterfaceBase< ConcreteType, DialectInterface > Base
The base class used for all derived interface types.
TypeID getID() const
Return the derived interface id.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
This class provides an efficient unique identifier for a specific C++ type.
static TypeID get()
Construct a type info object for the given type T.
The base class used for all derived interface types.
DialectInterfaceBase(Dialect *dialect)
DialectInterfaceBase< ConcreteType, BaseT > Base
static TypeID getInterfaceID()
Get a unique id for the derived interface type.
This class is the base class for a collection of instances for a specific interface kind.
const DialectInterface * getInterfaceFor(Operation *op) const
Get the interface for the dialect of given operation, or null if one is not registered.
iterator< InterfaceT > interface_end() const
const DialectInterface * getInterfaceFor(Dialect *dialect) const
Get the interface for the given dialect.
iterator< InterfaceT > interface_begin() const
Iterator access to the held interfaces.
virtual ~DialectInterfaceCollectionBase()
DialectInterfaceCollectionBase(MLIRContext *ctx, TypeID interfaceKind, StringRef interfaceName)
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
An iterator class that iterates the held interface objects of the given derived interface type.
const InterfaceT & mapElement(const DialectInterface *interface) const
Map the element to the iterator result type.