MLIR 22.0.0git
mlir::Dialect Class Reference

Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the entire group. More...

#include "mlir/IR/Dialect.h"

Inheritance diagram for mlir::Dialect:

Public Types

using ParseOpHook
 Type for a callback provided by the dialect to parse a custom operation.

Public Member Functions

virtual ~Dialect ()
MLIRContextgetContext () const
StringRef getNamespace () const
TypeID getTypeID () const
 Returns the unique identifier that corresponds to this dialect.
bool allowsUnknownOperations () const
 Returns true if this dialect allows for unregistered operations, i.e.
bool allowsUnknownTypes () const
 Return true if this dialect allows for unregistered types, i.e., types prefixed with the dialect namespace but not registered with addType.
virtual void getCanonicalizationPatterns (RewritePatternSet &results) const
 Register dialect-wide canonicalization patterns.
virtual OperationmaterializeConstant (OpBuilder &builder, Attribute value, Type type, Location loc)
 Registered hook to materialize a single constant operation from a given attribute value with the desired resultant type.
virtual Attribute parseAttribute (DialectAsmParser &parser, Type type) const
 Parse an attribute registered to this dialect.
virtual void printAttribute (Attribute, DialectAsmPrinter &) const
 Print an attribute registered to this dialect.
virtual Type parseType (DialectAsmParser &parser) const
 Parse a type registered to this dialect.
virtual void printType (Type, DialectAsmPrinter &) const
 Print a type registered to this dialect.
virtual std::optional< ParseOpHookgetParseOperationHook (StringRef opName) const
 Return the hook to parse an operation registered to this dialect, if any.
virtual llvm::unique_function< void(Operation *, OpAsmPrinter &printer)> getOperationPrinter (Operation *op) const
 Print an operation registered to this dialect.
virtual LogicalResult verifyRegionArgAttribute (Operation *, unsigned regionIndex, unsigned argIndex, NamedAttribute)
 Verify an attribute from this dialect on the argument at 'argIndex' for the region at 'regionIndex' on the given operation.
virtual LogicalResult verifyRegionResultAttribute (Operation *, unsigned regionIndex, unsigned resultIndex, NamedAttribute)
 Verify an attribute from this dialect on the result at 'resultIndex' for the region at 'regionIndex' on the given operation.
virtual LogicalResult verifyOperationAttribute (Operation *, NamedAttribute)
 Verify an attribute from this dialect on the given operation.
DialectInterfacegetRegisteredInterface (TypeID interfaceID)
 Lookup an interface for the given ID if one is registered, otherwise nullptr.
template<typename InterfaceT>
InterfaceT * getRegisteredInterface ()
virtual voidgetRegisteredInterfaceForOp (TypeID interfaceID, OperationName opName)
 Lookup an op interface for the given ID if one is registered, otherwise nullptr.
template<typename InterfaceT>
InterfaceT::Concept * getRegisteredInterfaceForOp (OperationName opName)
void addInterface (std::unique_ptr< DialectInterface > interface)
 Register a dialect interface with this dialect instance.
template<typename... Args>
void addInterfaces ()
 Register a set of dialect interfaces with this dialect instance.
template<typename InterfaceT, typename... Args>
InterfaceT & addInterface (Args &&...args)
template<typename InterfaceT, typename ConcreteT>
void declarePromisedInterface ()
 Declare that the given interface will be implemented, but has a delayed registration.
template<typename InterfaceT, typename... ConcreteT>
void declarePromisedInterfaces ()
void handleUseOfUndefinedPromisedInterface (TypeID interfaceRequestorID, TypeID interfaceID, StringRef interfaceName="")
 Checks if the given interface, which is attempting to be used, is a promised interface of this dialect that has yet to be implemented.
void handleAdditionOfUndefinedPromisedInterface (TypeID interfaceRequestorID, TypeID interfaceID)
 Checks if the given interface, which is attempting to be attached to a construct owned by this dialect, is a promised interface of this dialect that has yet to be implemented.
bool hasPromisedInterface (TypeID interfaceRequestorID, TypeID interfaceID) const
 Checks if a promise has been made for the interface/requestor pair.
template<typename ConcreteT, typename InterfaceT>
bool hasPromisedInterface () const
 Checks if a promise has been made for the interface/requestor pair.

Static Public Member Functions

static bool isValidNamespace (StringRef str)
 Utility function that returns if the given string is a valid dialect namespace.

Protected Member Functions

 Dialect (StringRef name, MLIRContext *context, TypeID id)
 The constructor takes a unique namespace for this dialect as well as the context to bind to.
template<typename... Args>
void addOperations ()
 This method is used by derived classes to add their operations to the set.
template<typename... Args>
void addTypes ()
 Register a set of type classes with this dialect.
void addType (TypeID typeID, AbstractType &&typeInfo)
 Register a type instance with this dialect.
template<typename... Args>
void addAttributes ()
 Register a set of attribute classes with this dialect.
void addAttribute (TypeID typeID, AbstractAttribute &&attrInfo)
 Register an attribute instance with this dialect.
void allowUnknownOperations (bool allow=true)
 Enable support for unregistered operations.
void allowUnknownTypes (bool allow=true)
 Enable support for unregistered types.

Friends

class DialectRegistry
class MLIRContext

Detailed Description

Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the entire group.

For example, hooks into other systems for constant folding, interfaces, default named types for asm printing, etc.

Instances of the dialect object are loaded in a specific MLIRContext.

Definition at line 38 of file Dialect.h.

Member Typedef Documentation

◆ ParseOpHook

Initial value:
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152
This represents an operation in an abstracted form, suitable for use with the builder APIs.

Type for a callback provided by the dialect to parse a custom operation.

This is used for the dialect to provide an alternative way to parse custom operations, including unregistered ones.

Definition at line 43 of file Dialect.h.

Constructor & Destructor Documentation

◆ ~Dialect()

Dialect::~Dialect ( )
virtualdefault

◆ Dialect()

Dialect::Dialect ( StringRef name,
MLIRContext * context,
TypeID id )
protected

The constructor takes a unique namespace for this dialect as well as the context to bind to.

Note: The namespace must not contain '.' characters. Note: All operations belonging to this dialect must have names starting with the namespace followed by '.'. Example:

  • "tf" for the TensorFlow ops like "tf.add".

Definition at line 35 of file Dialect.cpp.

References isValidNamespace(), and MLIRContext.

Referenced by mlir::ExtensibleDialect::classof(), and mlir::ExtensibleDialect::ExtensibleDialect().

Member Function Documentation

◆ addAttribute()

void Dialect::addAttribute ( TypeID typeID,
AbstractAttribute && attrInfo )
protected

Register an attribute instance with this dialect.

The use of this method is in general discouraged in favor of 'addAttributes<CustomAttr>()'.

Definition at line 750 of file MLIRContext.cpp.

Referenced by addAttributes(), and mlir::ExtensibleDialect::registerDynamicAttr().

◆ addAttributes()

template<typename... Args>
void mlir::Dialect::addAttributes ( )
inlineprotected

Register a set of attribute classes with this dialect.

Definition at line 303 of file Dialect.h.

References addAttribute().

◆ addInterface() [1/2]

template<typename InterfaceT, typename... Args>
InterfaceT & mlir::Dialect::addInterface ( Args &&... args)
inline

Definition at line 200 of file Dialect.h.

References addInterface().

◆ addInterface() [2/2]

void Dialect::addInterface ( std::unique_ptr< DialectInterface > interface)

Register a dialect interface with this dialect instance.

Register a set of dialect interfaces with this dialect instance.

Definition at line 101 of file Dialect.cpp.

References getNamespace(), getTypeID(), and handleAdditionOfUndefinedPromisedInterface().

Referenced by addInterface(), and addInterfaces().

◆ addInterfaces()

template<typename... Args>
void mlir::Dialect::addInterfaces ( )
inline

Register a set of dialect interfaces with this dialect instance.

Definition at line 196 of file Dialect.h.

References addInterface().

Referenced by mlir::DynamicDialect::DynamicDialect(), and mlir::ExtensibleDialect::ExtensibleDialect().

◆ addOperations()

template<typename... Args>
void mlir::Dialect::addOperations ( )
inlineprotected

This method is used by derived classes to add their operations to the set.

Definition at line 277 of file Dialect.h.

References mlir::RegisteredOperationName::insert().

◆ addType()

void Dialect::addType ( TypeID typeID,
AbstractType && typeInfo )
protected

Register a type instance with this dialect.

The use of this method is in general discouraged in favor of 'addTypes<CustomType>()'.

Definition at line 735 of file MLIRContext.cpp.

Referenced by addTypes(), and mlir::ExtensibleDialect::registerDynamicType().

◆ addTypes()

template<typename... Args>
void mlir::Dialect::addTypes ( )
inlineprotected

Register a set of type classes with this dialect.

Definition at line 288 of file Dialect.h.

References addType().

◆ allowsUnknownOperations()

bool mlir::Dialect::allowsUnknownOperations ( ) const
inline

Returns true if this dialect allows for unregistered operations, i.e.

operations prefixed with the dialect namespace but not registered with addOperation.

Definition at line 62 of file Dialect.h.

◆ allowsUnknownTypes()

bool mlir::Dialect::allowsUnknownTypes ( ) const
inline

Return true if this dialect allows for unregistered types, i.e., types prefixed with the dialect namespace but not registered with addType.

These are represented with OpaqueType.

Definition at line 67 of file Dialect.h.

Referenced by parseType().

◆ allowUnknownOperations()

void mlir::Dialect::allowUnknownOperations ( bool allow = true)
inlineprotected

Enable support for unregistered operations.

Definition at line 317 of file Dialect.h.

◆ allowUnknownTypes()

void mlir::Dialect::allowUnknownTypes ( bool allow = true)
inlineprotected

Enable support for unregistered types.

Definition at line 320 of file Dialect.h.

◆ declarePromisedInterface()

template<typename InterfaceT, typename ConcreteT>
void mlir::Dialect::declarePromisedInterface ( )
inline

Declare that the given interface will be implemented, but has a delayed registration.

The promised interface type can be an interface of any type not just a dialect interface, i.e. it may also be an AttributeInterface/OpInterface/TypeInterface/etc.

Definition at line 211 of file Dialect.h.

References declarePromisedInterface(), and mlir::TypeID::get().

Referenced by declarePromisedInterface(), and declarePromisedInterfaces().

◆ declarePromisedInterfaces()

template<typename InterfaceT, typename... ConcreteT>
void mlir::Dialect::declarePromisedInterfaces ( )
inline

Definition at line 220 of file Dialect.h.

References declarePromisedInterface().

◆ getCanonicalizationPatterns()

virtual void mlir::Dialect::getCanonicalizationPatterns ( RewritePatternSet & results) const
inlinevirtual

Register dialect-wide canonicalization patterns.

This method should only be used to register canonicalization patterns that do not conceptually belong to any single operation in the dialect. (In that case, use the op's canonicalizer.) E.g., canonicalization patterns for op interfaces should be registered here.

Definition at line 74 of file Dialect.h.

◆ getContext()

◆ getNamespace()

◆ getOperationPrinter()

llvm::unique_function< void(Operation *, OpAsmPrinter &printer)> Dialect::getOperationPrinter ( Operation * op) const
virtual

Print an operation registered to this dialect.

This hook is invoked for registered operation which don't override the print() method to define their own custom assembly.

Definition at line 87 of file Dialect.cpp.

References mlir::Operation::getDialect().

Referenced by mlir::OpState::print().

◆ getParseOperationHook()

std::optional< Dialect::ParseOpHook > Dialect::getParseOperationHook ( StringRef opName) const
virtual

Return the hook to parse an operation registered to this dialect, if any.

By default this will lookup for registered operations and return the parse() method registered on the RegisteredOperationName. Dialects can override this behavior and handle unregistered operations as well.

Definition at line 82 of file Dialect.cpp.

◆ getRegisteredInterface() [1/2]

template<typename InterfaceT>
InterfaceT * mlir::Dialect::getRegisteredInterface ( )
inline

◆ getRegisteredInterface() [2/2]

DialectInterface * mlir::Dialect::getRegisteredInterface ( TypeID interfaceID)
inline

Lookup an interface for the given ID if one is registered, otherwise nullptr.

Definition at line 158 of file Dialect.h.

References getTypeID(), and handleUseOfUndefinedPromisedInterface().

Referenced by mlir::DynamicDialect::classof(), mlir::ExtensibleDialect::classof(), and llvm::cast_convert_val< T, ::mlir::Dialect, ::mlir::Dialect >::doitImpl().

◆ getRegisteredInterfaceForOp() [1/2]

template<typename InterfaceT>
InterfaceT::Concept * mlir::Dialect::getRegisteredInterfaceForOp ( OperationName opName)
inline

Definition at line 186 of file Dialect.h.

References getRegisteredInterfaceForOp().

◆ getRegisteredInterfaceForOp() [2/2]

virtual void * mlir::Dialect::getRegisteredInterfaceForOp ( TypeID interfaceID,
OperationName opName )
inlinevirtual

Lookup an op interface for the given ID if one is registered, otherwise nullptr.

Definition at line 180 of file Dialect.h.

Referenced by getRegisteredInterfaceForOp().

◆ getTypeID()

TypeID mlir::Dialect::getTypeID ( ) const
inline

Returns the unique identifier that corresponds to this dialect.

Definition at line 57 of file Dialect.h.

Referenced by addInterface(), getRegisteredInterface(), and getRegisteredInterface().

◆ handleAdditionOfUndefinedPromisedInterface()

void mlir::Dialect::handleAdditionOfUndefinedPromisedInterface ( TypeID interfaceRequestorID,
TypeID interfaceID )
inline

Checks if the given interface, which is attempting to be attached to a construct owned by this dialect, is a promised interface of this dialect that has yet to be implemented.

If so, it resolves the interface promise.

Definition at line 245 of file Dialect.h.

Referenced by addInterface(), and mlir::dialect_extension_detail::handleAdditionOfUndefinedPromisedInterface().

◆ handleUseOfUndefinedPromisedInterface()

void mlir::Dialect::handleUseOfUndefinedPromisedInterface ( TypeID interfaceRequestorID,
TypeID interfaceID,
StringRef interfaceName = "" )
inline

Checks if the given interface, which is attempting to be used, is a promised interface of this dialect that has yet to be implemented.

If so, emits a fatal error. interfaceName is an optional string that contains a more user readable name for the interface (such as the class name).

Definition at line 228 of file Dialect.h.

References getNamespace().

Referenced by getRegisteredInterface(), getRegisteredInterface(), and mlir::dialect_extension_detail::handleUseOfUndefinedPromisedInterface().

◆ hasPromisedInterface() [1/2]

template<typename ConcreteT, typename InterfaceT>
bool mlir::Dialect::hasPromisedInterface ( ) const
inline

Checks if a promise has been made for the interface/requestor pair.

Definition at line 259 of file Dialect.h.

References mlir::TypeID::get(), and hasPromisedInterface().

Referenced by hasPromisedInterface().

◆ hasPromisedInterface() [2/2]

bool mlir::Dialect::hasPromisedInterface ( TypeID interfaceRequestorID,
TypeID interfaceID ) const
inline

Checks if a promise has been made for the interface/requestor pair.

Definition at line 251 of file Dialect.h.

Referenced by mlir::dialect_extension_detail::hasPromisedInterface().

◆ isValidNamespace()

bool Dialect::isValidNamespace ( StringRef str)
static

Utility function that returns if the given string is a valid dialect namespace.

Definition at line 95 of file Dialect.cpp.

Referenced by Dialect().

◆ materializeConstant()

virtual Operation * mlir::Dialect::materializeConstant ( OpBuilder & builder,
Attribute value,
Type type,
Location loc )
inlinevirtual

Registered hook to materialize a single constant operation from a given attribute value with the desired resultant type.

This method should use the provided builder to create the operation without changing the insertion position. The generated operation is expected to be constant like, i.e. single result, zero operands, non side-effecting, etc. On success, this hook should return the value generated to represent the constant value. Otherwise, it should return null on failure.

Definition at line 83 of file Dialect.h.

Referenced by materializeConstant(), mlir::dataflow::maybeReplaceWithConstant(), and movePaddingToFillOrGenericOp().

◆ parseAttribute()

Attribute Dialect::parseAttribute ( DialectAsmParser & parser,
Type type ) const
virtual

Parse an attribute registered to this dialect.

If 'type' is nonnull, it refers to the expected type of the attribute.

Reimplemented in mlir::DynamicDialect.

Definition at line 61 of file Dialect.cpp.

References mlir::AsmParser::emitError(), mlir::AsmParser::getNameLoc(), and getNamespace().

◆ parseType()

Type Dialect::parseType ( DialectAsmParser & parser) const
virtual

◆ printAttribute()

virtual void mlir::Dialect::printAttribute ( Attribute ,
DialectAsmPrinter &  ) const
inlinevirtual

Print an attribute registered to this dialect.

Note: The type of the attribute need not be printed by this method as it is always printed by the caller.

Reimplemented in mlir::DynamicDialect.

Definition at line 99 of file Dialect.h.

◆ printType()

virtual void mlir::Dialect::printType ( Type ,
DialectAsmPrinter &  ) const
inlinevirtual

Print a type registered to this dialect.

Reimplemented in mlir::DynamicDialect.

Definition at line 107 of file Dialect.h.

◆ verifyOperationAttribute()

virtual LogicalResult mlir::Dialect::verifyOperationAttribute ( Operation * ,
NamedAttribute  )
inlinevirtual

Verify an attribute from this dialect on the given operation.

Returns failure if the verification failed, success otherwise.

Definition at line 148 of file Dialect.h.

References success().

◆ verifyRegionArgAttribute()

LogicalResult Dialect::verifyRegionArgAttribute ( Operation * ,
unsigned regionIndex,
unsigned argIndex,
NamedAttribute  )
virtual

Verify an attribute from this dialect on the argument at 'argIndex' for the region at 'regionIndex' on the given operation.

Returns failure if the verification failed, success otherwise. This hook may optionally be invoked from any operation containing a region.

Definition at line 46 of file Dialect.cpp.

References success().

◆ verifyRegionResultAttribute()

LogicalResult Dialect::verifyRegionResultAttribute ( Operation * ,
unsigned regionIndex,
unsigned resultIndex,
NamedAttribute  )
virtual

Verify an attribute from this dialect on the result at 'resultIndex' for the region at 'regionIndex' on the given operation.

Returns failure if the verification failed, success otherwise. This hook may optionally be invoked from any operation containing a region.

Definition at line 55 of file Dialect.cpp.

References success().

◆ DialectRegistry

friend class DialectRegistry
friend

Definition at line 370 of file Dialect.h.

References DialectRegistry.

Referenced by DialectRegistry.

◆ MLIRContext


The documentation for this class was generated from the following files: