MLIR  16.0.0git
Public Member Functions | Static Public Member Functions | List of all members
mlir::RegisteredOperationName Class Reference

This is a "type erased" representation of a registered operation. More...

#include "mlir/IR/OperationSupport.h"

+ Inheritance diagram for mlir::RegisteredOperationName:
+ Collaboration diagram for mlir::RegisteredOperationName:

Public Member Functions

DialectgetDialect () const
 Return the dialect this operation is registered to. More...
 
TypeID getTypeID () const
 Return the unique identifier of the derived Op class. More...
 
ParseResult parseAssembly (OpAsmParser &parser, OperationState &result) const
 Use the specified object to parse this ops custom assembly format. More...
 
const ParseAssemblyFngetParseAssemblyFn () const
 Return the static hook for parsing this operation assembly. More...
 
void printAssembly (Operation *op, OpAsmPrinter &p, StringRef defaultDialect) const
 This hook implements the AsmPrinter for this operation. More...
 
LogicalResult verifyInvariants (Operation *op) const
 These hooks implement the verifiers for this operation. More...
 
LogicalResult verifyRegionInvariants (Operation *op) const
 
LogicalResult foldHook (Operation *op, ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results) const
 This hook implements a generalized folder for this operation. More...
 
void getCanonicalizationPatterns (RewritePatternSet &results, MLIRContext *context) const
 This hook returns any canonicalization pattern rewrites that the operation supports, for use by the canonicalization pass. More...
 
template<typename... Models>
void attachInterface ()
 Attach the given models as implementations of the corresponding interfaces for the concrete operation. More...
 
template<template< typename T > class Trait>
bool hasTrait () const
 Returns true if the operation has a particular trait. More...
 
bool hasTrait (TypeID traitID) const
 Returns true if the operation has a particular trait. More...
 
ArrayRef< StringAttr > getAttributeNames () const
 Return the list of cached attribute names registered to this operation. More...
 
void populateDefaultAttrs (NamedAttrList &attrs) const
 This hook implements the method to populate defaults attributes that are unset. More...
 
- Public Member Functions inherited from mlir::OperationName
 OperationName (StringRef name, MLIRContext *context)
 
bool isRegistered () const
 Return if this operation is registered. More...
 
Optional< RegisteredOperationNamegetRegisteredInfo () const
 If this operation is registered, returns the registered information, None otherwise. More...
 
template<template< typename T > class Trait>
bool hasTrait () const
 Returns true if the operation was registered with a particular trait, e.g. More...
 
bool hasTrait (TypeID traitID) const
 
template<template< typename T > class Trait>
bool mightHaveTrait () const
 Returns true if the operation might have the provided trait. More...
 
bool mightHaveTrait (TypeID traitID) const
 
template<typename T >
T::Concept * getInterface () const
 Returns an instance of the concept object for the given interface if it was registered to this operation, null otherwise. More...
 
template<typename T >
bool hasInterface () const
 Returns true if this operation has the given interface registered to it. More...
 
bool hasInterface (TypeID interfaceID) const
 
template<typename T >
bool mightHaveInterface () const
 Returns true if the operation might have the provided interface. More...
 
bool mightHaveInterface (TypeID interfaceID) const
 
DialectgetDialect () const
 Return the dialect this operation is registered to if the dialect is loaded in the context, or nullptr if the dialect isn't loaded. More...
 
StringRef getDialectNamespace () const
 Return the name of the dialect this operation is registered to. More...
 
StringRef stripDialect () const
 Return the operation name with dialect name stripped, if it has one. More...
 
StringRef getStringRef () const
 Return the name of this operation. This always succeeds. More...
 
StringAttr getIdentifier () const
 Return the name of this operation as a StringAttr. More...
 
void print (raw_ostream &os) const
 
void dump () const
 
voidgetAsOpaquePointer () const
 Represent the operation name as an opaque pointer. More...
 
bool operator== (const OperationName &rhs) const
 
bool operator!= (const OperationName &rhs) const
 

Static Public Member Functions

static Optional< RegisteredOperationNamelookup (StringRef name, MLIRContext *ctx)
 Lookup the registered operation information for the given operation. More...
 
template<typename T >
static void insert (Dialect &dialect)
 Register a new operation in a Dialect object. More...
 
static void insert (StringRef name, Dialect &dialect, TypeID typeID, ParseAssemblyFn &&parseAssembly, PrintAssemblyFn &&printAssembly, VerifyInvariantsFn &&verifyInvariants, VerifyRegionInvariantsFn &&verifyRegionInvariants, FoldHookFn &&foldHook, GetCanonicalizationPatternsFn &&getCanonicalizationPatterns, detail::InterfaceMap &&interfaceMap, HasTraitFn &&hasTrait, ArrayRef< StringRef > attrNames, PopulateDefaultAttrsFn &&populateDefaultAttrs)
 The use of this method is in general discouraged in favor of 'insert<CustomOp>(dialect)'. More...
 
static RegisteredOperationName getFromOpaquePointer (const void *pointer)
 Represent the operation name as an opaque pointer. More...
 
- Static Public Member Functions inherited from mlir::OperationName
static OperationName getFromOpaquePointer (const void *pointer)
 

Additional Inherited Members

- Public Types inherited from mlir::OperationName
using GetCanonicalizationPatternsFn = llvm::unique_function< void(RewritePatternSet &, MLIRContext *) const >
 
using FoldHookFn = llvm::unique_function< LogicalResult(Operation *, ArrayRef< Attribute >, SmallVectorImpl< OpFoldResult > &) const >
 
using HasTraitFn = llvm::unique_function< bool(TypeID) const >
 
using ParseAssemblyFn = llvm::unique_function< ParseResult(OpAsmParser &, OperationState &) const >
 
using PopulateDefaultAttrsFn = llvm::unique_function< void(const RegisteredOperationName &, NamedAttrList &) const >
 
using PrintAssemblyFn = llvm::unique_function< void(Operation *, OpAsmPrinter &, StringRef) const >
 
using VerifyInvariantsFn = llvm::unique_function< LogicalResult(Operation *) const >
 
using VerifyRegionInvariantsFn = llvm::unique_function< LogicalResult(Operation *) const >
 
- Protected Member Functions inherited from mlir::OperationName
 OperationName (Impl *impl)
 
- Protected Attributes inherited from mlir::OperationName
Implimpl
 The internal implementation of the operation name. More...
 
friend MLIRContextImpl
 Allow access to the Impl struct. More...
 

Detailed Description

This is a "type erased" representation of a registered operation.

This should only be used by things like the AsmPrinter and other things that need to be parameterized by generic operation hooks. Most user code should use the concrete operation types.

Definition at line 251 of file OperationSupport.h.

Member Function Documentation

◆ attachInterface()

template<typename... Models>
void mlir::RegisteredOperationName::attachInterface ( )
inline

Attach the given models as implementations of the corresponding interfaces for the concrete operation.

Definition at line 347 of file OperationSupport.h.

◆ foldHook()

LogicalResult mlir::RegisteredOperationName::foldHook ( Operation op,
ArrayRef< Attribute operands,
SmallVectorImpl< OpFoldResult > &  results 
) const
inline

This hook implements a generalized folder for this operation.

Operations can implement this to provide simplifications rules that are applied by the Builder::createOrFold API and the canonicalization pass.

This is an intentionally limited interface - implementations of this hook can only perform the following changes to the operation:

  1. They can leave the operation alone and without changing the IR, and return failure.
  2. They can mutate the operation in place, without changing anything else in the IR. In this case, return success.
  3. They can return a list of existing values that can be used instead of the operation. In this case, fill in the results list and return success. The caller will remove the operation and use those results instead.

This allows expression of some simple in-place canonicalizations (e.g. "x+0 -> x", "min(x,y,x,z) -> min(x,y,z)", "x+y-x -> y", etc), as well as generalized constant folding.

Definition at line 332 of file OperationSupport.h.

◆ getAttributeNames()

ArrayRef<StringAttr> mlir::RegisteredOperationName::getAttributeNames ( ) const
inline

Return the list of cached attribute names registered to this operation.

The order of attributes cached here is unique to each type of operation, and the interpretation of this attribute list should generally be driven by the respective operation. In many cases, this caching removes the need to use the raw string name of a known attribute.

For example the ODS generator, with an op defining the following attributes:

let arguments = (ins I32Attr:$attr1, I32Attr:$attr2);

... may produce an order here of ["attr1", "attr2"]. This allows for the ODS generator to directly access the cached name for a known attribute, greatly simplifying the cost and complexity of attribute usage produced by the generator.

Definition at line 376 of file OperationSupport.h.

◆ getCanonicalizationPatterns()

void mlir::RegisteredOperationName::getCanonicalizationPatterns ( RewritePatternSet results,
MLIRContext context 
) const
inline

This hook returns any canonicalization pattern rewrites that the operation supports, for use by the canonicalization pass.

Definition at line 339 of file OperationSupport.h.

◆ getDialect()

Dialect& mlir::RegisteredOperationName::getDialect ( ) const
inline

Return the dialect this operation is registered to.

Definition at line 284 of file OperationSupport.h.

◆ getFromOpaquePointer()

static RegisteredOperationName mlir::RegisteredOperationName::getFromOpaquePointer ( const void pointer)
inlinestatic

◆ getParseAssemblyFn()

const ParseAssemblyFn& mlir::RegisteredOperationName::getParseAssemblyFn ( ) const
inline

Return the static hook for parsing this operation assembly.

Definition at line 293 of file OperationSupport.h.

◆ getTypeID()

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

Return the unique identifier of the derived Op class.

Definition at line 287 of file OperationSupport.h.

◆ hasTrait() [1/2]

template<template< typename T > class Trait>
bool mlir::RegisteredOperationName::hasTrait ( ) const
inline

Returns true if the operation has a particular trait.

Definition at line 353 of file OperationSupport.h.

References mlir::op_definition_impl::hasTrait().

Referenced by mlir::transform::detail::checkImplementsTransformInterface(), and mlir::FrozenRewritePatternSet::FrozenRewritePatternSet().

◆ hasTrait() [2/2]

bool mlir::RegisteredOperationName::hasTrait ( TypeID  traitID) const
inline

Returns true if the operation has a particular trait.

Definition at line 358 of file OperationSupport.h.

◆ insert() [1/2]

template<typename T >
static void mlir::RegisteredOperationName::insert ( Dialect dialect)
inlinestatic

Register a new operation in a Dialect object.

This constructor is used by Dialect objects when they register the list of operations they contain.

Definition at line 262 of file OperationSupport.h.

References mlir::op_definition_impl::hasTrait().

Referenced by mlir::ExtensibleDialect::registerDynamicOp().

◆ insert() [2/2]

void RegisteredOperationName::insert ( StringRef  name,
Dialect dialect,
TypeID  typeID,
ParseAssemblyFn &&  parseAssembly,
PrintAssemblyFn &&  printAssembly,
VerifyInvariantsFn &&  verifyInvariants,
VerifyRegionInvariantsFn &&  verifyRegionInvariants,
FoldHookFn &&  foldHook,
GetCanonicalizationPatternsFn &&  getCanonicalizationPatterns,
detail::InterfaceMap &&  interfaceMap,
HasTraitFn &&  hasTrait,
ArrayRef< StringRef >  attrNames,
PopulateDefaultAttrsFn &&  populateDefaultAttrs 
)
static

The use of this method is in general discouraged in favor of 'insert<CustomOp>(dialect)'.

Definition at line 714 of file MLIRContext.cpp.

References mlir::Dialect::getContext(), mlir::MLIRContext::getImpl(), mlir::OperationName::Impl::isRegistered(), and value.

◆ lookup()

Optional< RegisteredOperationName > RegisteredOperationName::lookup ( StringRef  name,
MLIRContext ctx 
)
static

◆ parseAssembly()

ParseResult RegisteredOperationName::parseAssembly ( OpAsmParser parser,
OperationState result 
) const

Use the specified object to parse this ops custom assembly format.

Definition at line 705 of file MLIRContext.cpp.

◆ populateDefaultAttrs()

void RegisteredOperationName::populateDefaultAttrs ( NamedAttrList attrs) const

This hook implements the method to populate defaults attributes that are unset.

Definition at line 710 of file MLIRContext.cpp.

◆ printAssembly()

void mlir::RegisteredOperationName::printAssembly ( Operation op,
OpAsmPrinter p,
StringRef  defaultDialect 
) const
inline

This hook implements the AsmPrinter for this operation.

Definition at line 298 of file OperationSupport.h.

◆ verifyInvariants()

LogicalResult mlir::RegisteredOperationName::verifyInvariants ( Operation op) const
inline

These hooks implement the verifiers for this operation.

It should emits an error message and returns failure if a problem is detected, or returns success if everything is ok.

Definition at line 306 of file OperationSupport.h.

◆ verifyRegionInvariants()

LogicalResult mlir::RegisteredOperationName::verifyRegionInvariants ( Operation op) const
inline

Definition at line 309 of file OperationSupport.h.


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