MLIR  20.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 InterfaceT >
bool hasPromiseOrImplementsInterface () const
 Returns true if InterfaceT has been promised by the dialect or implemented. 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
 
std::optional< AttributegetInherentAttr (Operation *op, StringRef name) const
 Lookup an inherent attribute by name, this method isn't recommended and may be removed in the future. More...
 
void setInherentAttr (Operation *op, StringAttr name, Attribute value) const
 
void populateInherentAttrs (Operation *op, NamedAttrList &attrs) const
 
LogicalResult verifyInherentAttrs (NamedAttrList &attributes, function_ref< InFlightDiagnostic()> emitError) const
 This method exists for backward compatibility purpose when using properties to store inherent attributes, it enables validating the attributes when parsed from the older generic syntax pre-Properties. More...
 
int getOpPropertyByteSize () const
 This hooks return the number of bytes to allocate for the op properties. More...
 
void destroyOpProperties (OpaqueProperties properties) const
 This hooks destroy the op properties. More...
 
void initOpProperties (OpaqueProperties storage, OpaqueProperties init) const
 Initialize the op properties. More...
 
void populateDefaultProperties (OpaqueProperties properties) const
 Set the default values on the ODS attribute in the properties. More...
 
Attribute getOpPropertiesAsAttribute (Operation *op) const
 Return the op properties converted to an Attribute. More...
 
LogicalResult setOpPropertiesFromAttribute (OperationName opName, OpaqueProperties properties, Attribute attr, function_ref< InFlightDiagnostic()> emitError) const
 Define the op properties from the provided Attribute. More...
 
void copyOpProperties (OpaqueProperties lhs, OpaqueProperties rhs) const
 
bool compareOpProperties (OpaqueProperties lhs, OpaqueProperties rhs) const
 
llvm::hash_code hashOpProperties (OpaqueProperties properties) 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 88 of file OperationSupport.h.

Member Typedef Documentation

◆ FoldHookFn

using mlir::OperationName::FoldHookFn = llvm::unique_function<LogicalResult( Operation *, ArrayRef<Attribute>, SmallVectorImpl<OpFoldResult> &) const>

Definition at line 90 of file OperationSupport.h.

◆ HasTraitFn

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

Definition at line 92 of file OperationSupport.h.

◆ ParseAssemblyFn

using mlir::OperationName::ParseAssemblyFn = llvm::unique_function<ParseResult(OpAsmParser &, OperationState &)>

Definition at line 93 of file OperationSupport.h.

◆ PopulateDefaultAttrsFn

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

Definition at line 97 of file OperationSupport.h.

◆ PrintAssemblyFn

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

Definition at line 99 of file OperationSupport.h.

◆ VerifyInvariantsFn

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

Definition at line 101 of file OperationSupport.h.

◆ VerifyRegionInvariantsFn

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

Definition at line 103 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 495 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 353 of file OperationSupport.h.

References getDialect(), getImpl(), mlir::OperationName::Impl::getInterfaceMap(), getTypeID(), mlir::dialect_extension_detail::handleAdditionOfUndefinedPromisedInterface(), and mlir::detail::InterfaceMap::insertModels().

◆ compareOpProperties()

bool mlir::OperationName::compareOpProperties ( OpaqueProperties  lhs,
OpaqueProperties  rhs 
) const
inline

◆ copyOpProperties()

void mlir::OperationName::copyOpProperties ( OpaqueProperties  lhs,
OpaqueProperties  rhs 
) const
inline

◆ destroyOpProperties()

void mlir::OperationName::destroyOpProperties ( OpaqueProperties  properties) const
inline

This hooks destroy the op properties.

Definition at line 419 of file OperationSupport.h.

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

◆ dump()

void OperationName::dump ( ) const

Definition at line 63 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 263 of file OperationSupport.h.

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 485 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 338 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 270 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 472 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 460 of file OperationSupport.h.

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

Referenced by attachInterface(), mlir::Operation::getDialect(), getDialectNamespace(), hasPromiseOrImplementsInterface(), and mlir::OpState::parse().

◆ getDialectNamespace()

StringRef OperationName::getDialectNamespace ( ) const

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

Definition at line 823 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 478 of file OperationSupport.h.

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

Referenced by getContext(), and getStringRef().

◆ getImpl()

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

◆ getInherentAttr()

std::optional<Attribute> mlir::OperationName::getInherentAttr ( Operation op,
StringRef  name 
) const
inline

Lookup an inherent attribute by name, this method isn't recommended and may be removed in the future.

Definition at line 393 of file OperationSupport.h.

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

◆ getInterface()

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

Returns an instance of the concept object for the given interface if it was registered to this operation, null otherwise.

This should not be used directly.

Definition at line 346 of file OperationSupport.h.

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

◆ getOpPropertiesAsAttribute()

Attribute mlir::OperationName::getOpPropertiesAsAttribute ( Operation op) const
inline

Return the op properties converted to an Attribute.

Definition at line 434 of file OperationSupport.h.

◆ getOpPropertyByteSize()

int mlir::OperationName::getOpPropertyByteSize ( ) const
inline

This hooks return the number of bytes to allocate for the op properties.

Definition at line 414 of file OperationSupport.h.

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

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

◆ getParseAssemblyFn()

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

Return the static hook for parsing this operation assembly.

Definition at line 296 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 716 of file OperationSupport.h.

References isRegistered().

Referenced by mlir::detail::OpPassManagerImpl::canScheduleOn(), mlir::Operation::getRegisteredInfo(), and parseCommonStructuredOpParts().

◆ 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 236 of file OperationSupport.h.

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

Referenced by attachInterface(), and hasPromiseOrImplementsInterface().

◆ hashOpProperties()

llvm::hash_code mlir::OperationName::hashOpProperties ( OpaqueProperties  properties) const
inline

◆ 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 373 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

◆ hasPromiseOrImplementsInterface()

template<typename InterfaceT >
bool mlir::OperationName::hasPromiseOrImplementsInterface ( ) const
inline

Returns true if InterfaceT has been promised by the dialect or implemented.

Definition at line 365 of file OperationSupport.h.

References getDialect(), getTypeID(), and mlir::dialect_extension_detail::hasPromisedInterface().

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

◆ 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

◆ initOpProperties()

void mlir::OperationName::initOpProperties ( OpaqueProperties  storage,
OpaqueProperties  init 
) const
inline

Initialize the op properties.

Definition at line 424 of file OperationSupport.h.

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

◆ isRegistered()

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

Return if this operation is registered.

Definition at line 232 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 384 of file OperationSupport.h.

◆ mightHaveInterface() [2/2]

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

Definition at line 387 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 288 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 492 of file OperationSupport.h.

◆ operator==()

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

Definition at line 491 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 302 of file OperationSupport.h.

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

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

◆ populateDefaultProperties()

void mlir::OperationName::populateDefaultProperties ( OpaqueProperties  properties) const
inline

Set the default values on the ODS attribute in the properties.

Definition at line 429 of file OperationSupport.h.

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

◆ populateInherentAttrs()

void mlir::OperationName::populateInherentAttrs ( Operation op,
NamedAttrList attrs 
) const
inline

Definition at line 402 of file OperationSupport.h.

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

◆ print()

void OperationName::print ( raw_ostream &  os) const

Definition at line 61 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 307 of file OperationSupport.h.

◆ setImpl()

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

Definition at line 497 of file OperationSupport.h.

◆ setInherentAttr()

void mlir::OperationName::setInherentAttr ( Operation op,
StringAttr  name,
Attribute  value 
) const
inline

Definition at line 398 of file OperationSupport.h.

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

◆ setOpPropertiesFromAttribute()

LogicalResult mlir::OperationName::setOpPropertiesFromAttribute ( OperationName  opName,
OpaqueProperties  properties,
Attribute  attr,
function_ref< InFlightDiagnostic()>  emitError 
) const
inline

Define the op properties from the provided Attribute.

Definition at line 439 of file OperationSupport.h.

References mlir::emitError(), getImpl(), and mlir::OperationName::InterfaceConcept::setPropertiesFromAttr().

◆ stripDialect()

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

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

Definition at line 469 of file OperationSupport.h.

References getStringRef().

◆ verifyInherentAttrs()

LogicalResult mlir::OperationName::verifyInherentAttrs ( NamedAttrList attributes,
function_ref< InFlightDiagnostic()>  emitError 
) const
inline

This method exists for backward compatibility purpose when using properties to store inherent attributes, it enables validating the attributes when parsed from the older generic syntax pre-Properties.

Definition at line 409 of file OperationSupport.h.

References mlir::emitError(), getImpl(), and mlir::OperationName::InterfaceConcept::verifyInherentAttrs().

◆ 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 315 of file OperationSupport.h.

◆ verifyRegionInvariants()

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

Definition at line 318 of file OperationSupport.h.


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