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 return lhs ==
rhs->getDialect();
96 using InterfaceVectorT = std::vector<const DialectInterface *>;
100 StringRef interfaceName);
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 &> {
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;
153template <
typename InterfaceType>
162 ctx, InterfaceType::getInterfaceID(),
163 llvm::getTypeName<InterfaceType>()) {}
167 template <
typename Object>
169 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.