MLIR
20.0.0git
|
#include "mlir/IR/OperationSupport.h"
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< RegisteredOperationName > | getRegisteredInfo () 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< Attribute > | getInherentAttr (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 |
Dialect * | getDialect () 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... | |
MLIRContext * | getContext () |
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) | |
Impl * | getImpl () const |
void | setImpl (Impl *rhs) |
Definition at line 88 of file OperationSupport.h.
using mlir::OperationName::FoldHookFn = llvm::unique_function<LogicalResult( Operation *, ArrayRef<Attribute>, SmallVectorImpl<OpFoldResult> &) const> |
Definition at line 90 of file OperationSupport.h.
using mlir::OperationName::HasTraitFn = llvm::unique_function<bool(TypeID) const> |
Definition at line 92 of file OperationSupport.h.
using mlir::OperationName::ParseAssemblyFn = llvm::unique_function<ParseResult(OpAsmParser &, OperationState &)> |
Definition at line 93 of file OperationSupport.h.
using mlir::OperationName::PopulateDefaultAttrsFn = llvm::unique_function<void(const OperationName &, NamedAttrList &) const> |
Definition at line 97 of file OperationSupport.h.
using mlir::OperationName::PrintAssemblyFn = llvm::unique_function<void(Operation *, OpAsmPrinter &, StringRef) const> |
Definition at line 99 of file OperationSupport.h.
using mlir::OperationName::VerifyInvariantsFn = llvm::unique_function<LogicalResult(Operation *) const> |
Definition at line 101 of file OperationSupport.h.
using mlir::OperationName::VerifyRegionInvariantsFn = llvm::unique_function<LogicalResult(Operation *) const> |
Definition at line 103 of file OperationSupport.h.
OperationName::OperationName | ( | StringRef | name, |
MLIRContext * | context | ||
) |
Definition at line 787 of file MLIRContext.cpp.
References mlir::get(), mlir::MLIRContext::getImpl(), mlir::MLIRContext::isMultithreadingEnabled(), mlir::MLIRContextImpl::operationInfoMutex, mlir::MLIRContextImpl::operations, and mlir::MLIRContextImpl::registeredOperationsByName.
Referenced by getFromOpaquePointer().
|
inlineprotected |
Definition at line 495 of file OperationSupport.h.
|
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().
|
inline |
Definition at line 450 of file OperationSupport.h.
References mlir::OperationName::InterfaceConcept::compareProperties(), and getImpl().
Referenced by mlir::OperationEquivalence::isEquivalentTo().
|
inline |
Definition at line 446 of file OperationSupport.h.
References mlir::OperationName::InterfaceConcept::copyProperties(), and getImpl().
Referenced by mlir::Operation::copyProperties().
|
inline |
This hooks destroy the op properties.
Definition at line 419 of file OperationSupport.h.
References mlir::OperationName::InterfaceConcept::deleteProperties(), and getImpl().
void OperationName::dump | ( | ) | const |
Definition at line 63 of file AsmPrinter.cpp.
References print().
|
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:
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().
|
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().
|
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().
|
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().
|
inline |
Return the context this operation is associated with.
Definition at line 472 of file OperationSupport.h.
References getIdentifier().
|
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().
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().
|
inlinestatic |
Definition at line 486 of file OperationSupport.h.
References OperationName().
Referenced by llvm::DenseMapInfo< mlir::OperationName >::getEmptyKey(), llvm::PointerLikeTypeTraits< mlir::OperationName >::getFromVoidPointer(), mlir::Pattern::getRootKind(), and llvm::DenseMapInfo< mlir::OperationName >::getTombstoneKey().
|
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().
|
inlineprotected |
Definition at line 496 of file OperationSupport.h.
Referenced by attachInterface(), compareOpProperties(), copyOpProperties(), destroyOpProperties(), mlir::AffineMap::get(), mlir::MLIRContext::getAffineUniquer(), getAttributeNames(), mlir::MLIRContext::getAttributeUniquer(), getCanonicalizationPatterns(), getDialect(), mlir::RegisteredOperationName::getDialect(), getIdentifier(), getInterface(), getOpPropertyByteSize(), getParseAssemblyFn(), getTypeID(), mlir::MLIRContext::getTypeUniquer(), hashOpProperties(), hasInterface(), hasTrait(), initOpProperties(), isRegistered(), mightHaveTrait(), populateDefaultAttrs(), populateDefaultProperties(), setOpPropertiesFromAttribute(), and verifyInherentAttrs().
|
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().
|
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().
Return the op properties converted to an Attribute.
Definition at line 434 of file OperationSupport.h.
|
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().
|
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().
|
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().
|
inline |
Return the name of this operation. This always succeeds.
Definition at line 475 of file OperationSupport.h.
References getIdentifier().
Referenced by addBodyWithPayloadOp(), mlir::ExternalPass::canScheduleOn(), mlir::transform::detail::checkApplyToOne(), getDialectNamespace(), mlir::Diagnostic::operator<<(), mlir::OpState::parse(), mlir::Op< ConcreteType, Traits >::parseProperties(), printShortForm(), and stripDialect().
|
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().
|
inline |
Definition at line 454 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::InterfaceConcept::hashProperties().
Referenced by mlir::Operation::hashProperties().
|
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().
|
inline |
Definition at line 376 of file OperationSupport.h.
References mlir::detail::InterfaceMap::contains(), getImpl(), and mlir::OperationName::Impl::getInterfaceMap().
|
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().
|
inline |
Returns true if the operation was registered with a particular trait, e.g.
hasTrait<OperandsAreSignlessIntegerLike>(). Returns false if the operation is unregistered.
Definition at line 279 of file OperationSupport.h.
Referenced by mlir::transform::detail::checkImplementsTransformOpInterface(), mlir::Operation::create(), mlir::FrozenRewritePatternSet::FrozenRewritePatternSet(), mlir::Operation::hasTrait(), and mlir::AsmParserState::Impl::PartialOpDef::PartialOpDef().
|
inline |
Definition at line 282 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::InterfaceConcept::hasTrait().
|
inline |
Initialize the op properties.
Definition at line 424 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::InterfaceConcept::initProperties().
|
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().
|
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.
|
inline |
Definition at line 387 of file OperationSupport.h.
References hasInterface(), and isRegistered().
|
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().
|
inline |
Definition at line 291 of file OperationSupport.h.
References getImpl(), mlir::OperationName::InterfaceConcept::hasTrait(), and isRegistered().
|
inline |
Definition at line 492 of file OperationSupport.h.
|
inline |
Definition at line 491 of file OperationSupport.h.
|
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().
|
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().
|
inline |
Definition at line 402 of file OperationSupport.h.
Referenced by mlir::Operation::getAttrDictionary().
void OperationName::print | ( | raw_ostream & | os | ) | const |
Definition at line 61 of file AsmPrinter.cpp.
Referenced by mlir::operator<<().
|
inline |
This hook implements the AsmPrinter for this operation.
Definition at line 307 of file OperationSupport.h.
|
inlineprotected |
Definition at line 497 of file OperationSupport.h.
|
inline |
Definition at line 398 of file OperationSupport.h.
Referenced by mlir::Operation::setInherentAttr().
|
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().
|
inline |
Return the operation name with dialect name stripped, if it has one.
Definition at line 469 of file OperationSupport.h.
References getStringRef().
|
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().
|
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.
|
inline |
Definition at line 318 of file OperationSupport.h.