9 #ifndef MLIR_IR_DIALECTINTERFACE_H
10 #define MLIR_IR_DIALECTINTERFACE_H
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/STLExtras.h"
28 template <
typename ConcreteType,
typename BaseT>
48 template <
typename ConcreteType>
62 : dialect(dialect), interfaceID(id) {}
81 struct InterfaceKeyInfo :
public DenseMapInfo<const DialectInterface *> {
90 if (rhs == getEmptyKey() || rhs == getTombstoneKey())
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 &> {
123 using llvm::mapped_iterator_base<iterator<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;
155 template <
typename InterfaceType>
164 ctx, InterfaceType::getInterfaceID(),
165 llvm::getTypeName<InterfaceType>()) {}
169 template <
typename Object>
171 return static_cast<const InterfaceType *
>(
A collection of dialect interfaces within a context, for a given concrete interface type.
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.
DialectInterface(Dialect *dialect, TypeID id)
Dialect * getDialect() const
Return the dialect that this interface represents.
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.
The base class used for all derived interface types.
DialectInterfaceBase(Dialect *dialect)
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.
virtual ~DialectInterfaceCollectionBase()
iterator< InterfaceT > interface_begin() const
Iterator access to the held interfaces.
DialectInterfaceCollectionBase(MLIRContext *ctx, TypeID interfaceKind, StringRef interfaceName)
The OpAsmOpInterface, see OpAsmInterface.td for more details.
inline ::llvm::hash_code hash_value(const PolynomialBase< D, T > &arg)
Include the generated interface declarations.
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.