MLIR
20.0.0git
|
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the entire group. More...
#include "mlir/IR/Dialect.h"
Public Types | |
using | ParseOpHook = function_ref< ParseResult(OpAsmParser &parser, OperationState &result)> |
Type for a callback provided by the dialect to parse a custom operation. More... | |
Public Member Functions | |
virtual | ~Dialect () |
MLIRContext * | getContext () const |
StringRef | getNamespace () const |
TypeID | getTypeID () const |
Returns the unique identifier that corresponds to this dialect. More... | |
bool | allowsUnknownOperations () const |
Returns true if this dialect allows for unregistered operations, i.e. More... | |
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. More... | |
virtual void | getCanonicalizationPatterns (RewritePatternSet &results) const |
Register dialect-wide canonicalization patterns. More... | |
virtual Operation * | materializeConstant (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. More... | |
virtual Attribute | parseAttribute (DialectAsmParser &parser, Type type) const |
Parse an attribute registered to this dialect. More... | |
virtual void | printAttribute (Attribute, DialectAsmPrinter &) const |
Print an attribute registered to this dialect. More... | |
virtual Type | parseType (DialectAsmParser &parser) const |
Parse a type registered to this dialect. More... | |
virtual void | printType (Type, DialectAsmPrinter &) const |
Print a type registered to this dialect. More... | |
virtual std::optional< ParseOpHook > | getParseOperationHook (StringRef opName) const |
Return the hook to parse an operation registered to this dialect, if any. More... | |
virtual llvm::unique_function< void(Operation *, OpAsmPrinter &printer)> | getOperationPrinter (Operation *op) const |
Print an operation registered to this dialect. More... | |
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. More... | |
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. More... | |
virtual LogicalResult | verifyOperationAttribute (Operation *, NamedAttribute) |
Verify an attribute from this dialect on the given operation. More... | |
DialectInterface * | getRegisteredInterface (TypeID interfaceID) |
Lookup an interface for the given ID if one is registered, otherwise nullptr. More... | |
template<typename InterfaceT > | |
InterfaceT * | getRegisteredInterface () |
virtual void * | getRegisteredInterfaceForOp (TypeID interfaceID, OperationName opName) |
Lookup an op interface for the given ID if one is registered, otherwise nullptr. More... | |
template<typename InterfaceT > | |
InterfaceT::Concept * | getRegisteredInterfaceForOp (OperationName opName) |
void | addInterface (std::unique_ptr< DialectInterface > interface) |
Register a dialect interface with this dialect instance. More... | |
template<typename... Args> | |
void | addInterfaces () |
Register a set of dialect interfaces with this dialect instance. More... | |
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. More... | |
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. More... | |
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. More... | |
bool | hasPromisedInterface (TypeID interfaceRequestorID, TypeID interfaceID) const |
Checks if a promise has been made for the interface/requestor pair. More... | |
template<typename ConcreteT , typename InterfaceT > | |
bool | hasPromisedInterface () const |
Checks if a promise has been made for the interface/requestor pair. More... | |
Static Public Member Functions | |
static bool | isValidNamespace (StringRef str) |
Utility function that returns if the given string is a valid dialect namespace. More... | |
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. More... | |
template<typename... Args> | |
void | addOperations () |
This method is used by derived classes to add their operations to the set. More... | |
template<typename... Args> | |
void | addTypes () |
Register a set of type classes with this dialect. More... | |
void | addType (TypeID typeID, AbstractType &&typeInfo) |
Register a type instance with this dialect. More... | |
template<typename... Args> | |
void | addAttributes () |
Register a set of attribute classes with this dialect. More... | |
void | addAttribute (TypeID typeID, AbstractAttribute &&attrInfo) |
Register an attribute instance with this dialect. More... | |
void | allowUnknownOperations (bool allow=true) |
Enable support for unregistered operations. More... | |
void | allowUnknownTypes (bool allow=true) |
Enable support for unregistered types. More... | |
Friends | |
class | DialectRegistry |
class | MLIRContext |
void | registerDialect () |
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.
using mlir::Dialect::ParseOpHook = function_ref<ParseResult(OpAsmParser &parser, OperationState &result)> |
|
virtualdefault |
|
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:
Definition at line 38 of file Dialect.cpp.
References isValidNamespace().
|
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 757 of file MLIRContext.cpp.
References mlir::MLIRContext::getImpl().
Referenced by mlir::ExtensibleDialect::registerDynamicAttr().
|
inlineprotected |
|
inline |
Definition at line 200 of file Dialect.h.
References addInterface().
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 104 of file Dialect.cpp.
References getTypeID(), and handleAdditionOfUndefinedPromisedInterface().
Referenced by addInterface(), and addInterfaces().
|
inline |
Register a set of dialect interfaces with this dialect instance.
Definition at line 196 of file Dialect.h.
References addInterface().
|
inlineprotected |
|
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 742 of file MLIRContext.cpp.
References mlir::MLIRContext::getImpl().
Referenced by mlir::ExtensibleDialect::registerDynamicType().
|
inlineprotected |
|
inline |
|
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().
|
inlineprotected |
|
inlineprotected |
|
inline |
|
inline |
|
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.
|
inline |
Definition at line 52 of file Dialect.h.
Referenced by mlir::DialectRegistry::applyExtensions(), mlir::DialectInterface::getContext(), parseType(), mlir::ExtensibleDialect::registerDynamicAttr(), and mlir::ExtensibleDialect::registerDynamicType().
|
inline |
Definition at line 54 of file Dialect.h.
Referenced by mlir::DialectRegistry::applyExtensions(), handleUseOfUndefinedPromisedInterface(), parseAttribute(), mlir::detail::Parser::parseResourceHandle(), mlir::detail::AsmParserImpl< BaseT >::parseResourceHandle(), parseType(), mlir::ExtensibleDialect::registerDynamicAttr(), mlir::ExtensibleDialect::registerDynamicType(), mlir::irdl::DynParametricAttrConstraint::verify(), mlir::irdl::DynParametricTypeConstraint::verify(), and mlir::detail::verifyTargetSystemSpec().
|
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 90 of file Dialect.cpp.
References mlir::Operation::getDialect().
Referenced by mlir::OpState::print().
|
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 85 of file Dialect.cpp.
Referenced by mlir::OpState::parse().
|
inline |
Definition at line 167 of file Dialect.h.
References getTypeID(), and handleUseOfUndefinedPromisedInterface().
|
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 llvm::cast_convert_val< T, ::mlir::Dialect, ::mlir::Dialect >::doitImpl().
|
inline |
Definition at line 186 of file Dialect.h.
References getRegisteredInterfaceForOp().
|
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().
|
inline |
Returns the unique identifier that corresponds to this dialect.
Definition at line 57 of file Dialect.h.
Referenced by addInterface(), and getRegisteredInterface().
|
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().
|
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(), and mlir::dialect_extension_detail::handleUseOfUndefinedPromisedInterface().
|
inline |
|
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().
|
static |
Utility function that returns if the given string is a valid dialect namespace.
Definition at line 98 of file Dialect.cpp.
Referenced by Dialect().
|
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(), maybeReplaceWithConstant(), movePaddingToFillOrGenericOp(), and mlir::OpBuilder::tryFold().
|
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 64 of file Dialect.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getNameLoc(), and getNamespace().
|
virtual |
Parse a type registered to this dialect.
Reimplemented in mlir::DynamicDialect.
Definition at line 72 of file Dialect.cpp.
References allowsUnknownTypes(), mlir::AsmParser::emitError(), mlir::get(), getContext(), mlir::DialectAsmParser::getFullSymbolSpec(), mlir::AsmParser::getNameLoc(), and getNamespace().
|
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.
|
inlinevirtual |
Print a type registered to this dialect.
Reimplemented in mlir::DynamicDialect.
|
inlinevirtual |
|
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 49 of file Dialect.cpp.
|
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 58 of file Dialect.cpp.
|
friend |
|
friend |
|
friend |