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 *>;
101 StringRef interfaceName);
111 auto it = interfaces.find_as(dialect);
112 return it == interfaces.end() ? nullptr : *it;
117 template <
typename InterfaceT>
119 :
public llvm::mapped_iterator_base<iterator<InterfaceT>,
120 InterfaceVectorT::const_iterator,
121 const InterfaceT &> {
122 using llvm::mapped_iterator_base<iterator<InterfaceT>,
123 InterfaceVectorT::const_iterator,
124 const InterfaceT &>::mapped_iterator_base;
128 return *
static_cast<const InterfaceT *
>(interface);
133 template <
typename InterfaceT>
137 template <
typename InterfaceT>
144 InterfaceSetT interfaces;
148 InterfaceVectorT orderedInterfaces;
154 template <
typename InterfaceType>
163 ctx, InterfaceType::getInterfaceID(),
164 llvm::getTypeName<InterfaceType>()) {}
168 template <
typename Object>
170 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)
Include the generated interface declarations.
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.