9 #ifndef MLIR_IR_DIALECTINTERFACE_H
10 #define MLIR_IR_DIALECTINTERFACE_H
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/STLExtras.h"
27 template <
typename ConcreteType,
typename BaseT>
47 template <
typename ConcreteType>
61 : dialect(dialect), interfaceID(id) {}
80 struct InterfaceKeyInfo :
public DenseMapInfo<const DialectInterface *> {
89 if (rhs == getEmptyKey() || rhs == getTombstoneKey())
97 using InterfaceVectorT = std::vector<const DialectInterface *>;
110 auto it = interfaces.find_as(dialect);
111 return it == interfaces.end() ? nullptr : *it;
116 template <
typename InterfaceT>
118 :
public llvm::mapped_iterator_base<iterator<InterfaceT>,
119 InterfaceVectorT::const_iterator,
120 const InterfaceT &> {
121 using llvm::mapped_iterator_base<iterator<InterfaceT>,
122 InterfaceVectorT::const_iterator,
123 const InterfaceT &>::mapped_iterator_base;
127 return *
static_cast<const InterfaceT *
>(interface);
132 template <
typename InterfaceT>
136 template <
typename InterfaceT>
143 InterfaceSetT interfaces;
147 InterfaceVectorT orderedInterfaces;
153 template <
typename InterfaceType>
162 ctx, InterfaceType::getInterfaceID()) {}
166 template <
typename Object>
168 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
DialectInterfaceCollectionBase(MLIRContext *ctx, TypeID interfaceKind)
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.
llvm::hash_code hash_value(const MPInt &x)
Redeclarations of friend declaration above to make it discoverable by lookups.
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.