MLIR  17.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
mlir::OperationName Class Reference

#include "mlir/IR/OperationSupport.h"

+ Inheritance diagram for mlir::OperationName:

Classes

class  Impl
 
struct  InterfaceConcept
 This class represents a type erased version of an operation. More...
 
struct  UnregisteredOpModel
 Default implementation for unregistered operations. More...
 

Public Types

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 &)>
 
using PopulateDefaultAttrsFn = llvm::unique_function< void(const OperationName &, 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 >
 

Public Member Functions

 OperationName (StringRef name, MLIRContext *context)
 
bool isRegistered () const
 Return if this operation is registered. More...
 
TypeID getTypeID () const
 Return the unique identifier of the derived Op class, or null if not registered. More...
 
std::optional< RegisteredOperationNamegetRegisteredInfo () const
 If this operation is registered, returns the registered information, std::nullopt otherwise. More...
 
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<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
 
ParseAssemblyFn getParseAssemblyFn () const
 Return the static hook for parsing this operation assembly. More...
 
void populateDefaultAttrs (NamedAttrList &attrs) const
 This hook implements the method to populate defaults attributes that are unset. 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
 
ArrayRef< StringAttr > getAttributeNames () const
 Return the list of cached attribute names registered to this operation. More...
 
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... Models>
void attachInterface ()
 Attach the given models as implementations of the corresponding interfaces for the concrete operation. 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...
 
MLIRContextgetContext ()
 Return the context this operation is associated with. 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
 
void * getAsOpaquePointer () 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 OperationName getFromOpaquePointer (const void *pointer)
 

Protected Member Functions

 OperationName (Impl *impl)
 
ImplgetImpl () const
 
void setImpl (Impl *rhs)
 

Detailed Description

Definition at line 66 of file OperationSupport.h.

Member Typedef Documentation

◆ FoldHookFn

Definition at line 68 of file OperationSupport.h.

◆ HasTraitFn

using mlir::OperationName::HasTraitFn = llvm::unique_function<bool(TypeID) const>

Definition at line 70 of file OperationSupport.h.

◆ ParseAssemblyFn

Definition at line 71 of file OperationSupport.h.

◆ PopulateDefaultAttrsFn

using mlir::OperationName::PopulateDefaultAttrsFn = llvm::unique_function<void(const OperationName &, NamedAttrList &) const>

Definition at line 75 of file OperationSupport.h.

◆ PrintAssemblyFn

using mlir::OperationName::PrintAssemblyFn = llvm::unique_function<void(Operation *, OpAsmPrinter &, StringRef) const>

Definition at line 77 of file OperationSupport.h.

◆ VerifyInvariantsFn

using mlir::OperationName::VerifyInvariantsFn = llvm::unique_function<LogicalResult(Operation *) const>

Definition at line 79 of file OperationSupport.h.

◆ VerifyRegionInvariantsFn

Definition at line 81 of file OperationSupport.h.

Constructor & Destructor Documentation

◆ OperationName() [1/2]

OperationName::OperationName ( StringRef  name,
MLIRContext context 
)

◆ OperationName() [2/2]

mlir::OperationName::OperationName ( Impl impl)
inlineprotected

Definition at line 349 of file OperationSupport.h.

Member Function Documentation

◆ attachInterface()

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

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

Definition at line 288 of file OperationSupport.h.

References getImpl(), mlir::OperationName::Impl::getInterfaceMap(), and mlir::detail::InterfaceMap::insertModels().

◆ dump()

void OperationName::dump ( ) const

Definition at line 57 of file AsmPrinter.cpp.

References print().

◆ foldHook()

LogicalResult mlir::OperationName::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 198 of file OperationSupport.h.

References mlir::OperationName::InterfaceConcept::foldHook(), and getImpl().

Referenced by mlir::Operation::fold().

◆ getAsOpaquePointer()

void* mlir::OperationName::getAsOpaquePointer ( ) const
inline

Represent the operation name as an opaque pointer.

(Used to support PointerLikeTypeTraits).

Definition at line 339 of file OperationSupport.h.

Referenced by llvm::PointerLikeTypeTraits< mlir::OperationName >::getAsVoidPointer(), llvm::DenseMapInfo< mlir::OperationName >::getHashValue(), and mlir::hash_value().

◆ getAttributeNames()

ArrayRef<StringAttr> mlir::OperationName::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 273 of file OperationSupport.h.

References mlir::OperationName::Impl::getAttributeNames(), and getImpl().

◆ getCanonicalizationPatterns()

void mlir::OperationName::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 205 of file OperationSupport.h.

References mlir::OperationName::InterfaceConcept::getCanonicalizationPatterns(), and getImpl().

◆ getContext()

MLIRContext* mlir::OperationName::getContext ( )
inline

Return the context this operation is associated with.

Definition at line 326 of file OperationSupport.h.

References getIdentifier().

◆ getDialect()

Dialect* mlir::OperationName::getDialect ( ) const
inline

Return the dialect this operation is registered to if the dialect is loaded in the context, or nullptr if the dialect isn't loaded.

Definition at line 314 of file OperationSupport.h.

References mlir::OperationName::Impl::getDialect(), getImpl(), mlir::OperationName::Impl::getName(), and isRegistered().

Referenced by mlir::Operation::getDialect(), getDialectNamespace(), mlir::OpInterface< ConcreteType, Traits >::getInterfaceFor(), and mlir::OpState::parse().

◆ getDialectNamespace()

StringRef OperationName::getDialectNamespace ( ) const

Return the name of the dialect this operation is registered to.

Definition at line 768 of file MLIRContext.cpp.

References getDialect(), and getStringRef().

◆ getFromOpaquePointer()

static OperationName mlir::OperationName::getFromOpaquePointer ( const void *  pointer)
inlinestatic

◆ getIdentifier()

StringAttr mlir::OperationName::getIdentifier ( ) const
inline

Return the name of this operation as a StringAttr.

Definition at line 332 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::Impl::getName().

Referenced by cloneOpWithOperandsAndTypes(), getContext(), getStringRef(), mlir::impl::scalarizeVectorOp(), vectorizeOneOp(), and widenOp().

◆ getImpl()

Impl* mlir::OperationName::getImpl ( ) const
inlineprotected

◆ getInterface()

template<typename T >
T::Concept* mlir::OperationName::getInterface ( ) const
inline

◆ getParseAssemblyFn()

ParseAssemblyFn mlir::OperationName::getParseAssemblyFn ( ) const
inline

Return the static hook for parsing this operation assembly.

Definition at line 231 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::InterfaceConcept::getParseAssemblyFn().

◆ getRegisteredInfo()

std::optional< RegisteredOperationName > mlir::OperationName::getRegisteredInfo ( ) const
inline

If this operation is registered, returns the registered information, std::nullopt otherwise.

Definition at line 456 of file OperationSupport.h.

References isRegistered().

Referenced by mlir::OpInterface< ConcreteType, Traits >::getInterfaceFor(), mlir::Operation::getRegisteredInfo(), and inferOperationTypes().

◆ getStringRef()

StringRef mlir::OperationName::getStringRef ( ) const
inline

◆ getTypeID()

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

Return the unique identifier of the derived Op class, or null if not registered.

Definition at line 171 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::Impl::getTypeID().

◆ hasInterface() [1/2]

template<typename T >
bool mlir::OperationName::hasInterface ( ) const
inline

Returns true if this operation has the given interface registered to it.

Definition at line 294 of file OperationSupport.h.

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

◆ hasInterface() [2/2]

bool mlir::OperationName::hasInterface ( TypeID  interfaceID) const
inline

◆ hasTrait() [1/2]

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

◆ hasTrait() [2/2]

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

◆ isRegistered()

bool mlir::OperationName::isRegistered ( ) const
inline

Return if this operation is registered.

Definition at line 167 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::Impl::isRegistered().

Referenced by getDialect(), getRegisteredInfo(), mlir::Operation::isRegistered(), mightHaveInterface(), and mightHaveTrait().

◆ mightHaveInterface() [1/2]

template<typename T >
bool mlir::OperationName::mightHaveInterface ( ) const
inline

Returns true if the operation might have the provided interface.

This means that either the operation is unregistered, or it was registered with the provide interface.

Definition at line 305 of file OperationSupport.h.

◆ mightHaveInterface() [2/2]

bool mlir::OperationName::mightHaveInterface ( TypeID  interfaceID) const
inline

Definition at line 308 of file OperationSupport.h.

References hasInterface(), and isRegistered().

◆ mightHaveTrait() [1/2]

template<template< typename T > class Trait>
bool mlir::OperationName::mightHaveTrait ( ) const
inline

Returns true if the operation might have the provided trait.

This means that either the operation is unregistered, or it was registered with the provide trait.

Definition at line 223 of file OperationSupport.h.

Referenced by mlir::Operation::mightHaveTrait().

◆ mightHaveTrait() [2/2]

bool mlir::OperationName::mightHaveTrait ( TypeID  traitID) const
inline

◆ operator!=()

bool mlir::OperationName::operator!= ( const OperationName rhs) const
inline

Definition at line 346 of file OperationSupport.h.

◆ operator==()

bool mlir::OperationName::operator== ( const OperationName rhs) const
inline

Definition at line 345 of file OperationSupport.h.

◆ populateDefaultAttrs()

void mlir::OperationName::populateDefaultAttrs ( NamedAttrList attrs) const
inline

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

Definition at line 237 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::InterfaceConcept::populateDefaultAttrs().

Referenced by mlir::Operation::create(), and mlir::Operation::populateDefaultAttrs().

◆ print()

void OperationName::print ( raw_ostream &  os) const

Definition at line 55 of file AsmPrinter.cpp.

Referenced by mlir::operator<<().

◆ printAssembly()

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

This hook implements the AsmPrinter for this operation.

Definition at line 242 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::InterfaceConcept::printAssembly().

◆ setImpl()

void mlir::OperationName::setImpl ( Impl rhs)
inlineprotected

Definition at line 351 of file OperationSupport.h.

◆ stripDialect()

StringRef mlir::OperationName::stripDialect ( ) const
inline

Return the operation name with dialect name stripped, if it has one.

Definition at line 323 of file OperationSupport.h.

References getStringRef().

◆ verifyInvariants()

LogicalResult mlir::OperationName::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 250 of file OperationSupport.h.

References getImpl(), and mlir::OperationName::InterfaceConcept::verifyInvariants().

◆ verifyRegionInvariants()

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

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