MLIR
17.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 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 |
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 66 of file OperationSupport.h.
using mlir::OperationName::FoldHookFn = llvm::unique_function<LogicalResult( Operation *, ArrayRef<Attribute>, SmallVectorImpl<OpFoldResult> &) const> |
Definition at line 68 of file OperationSupport.h.
using mlir::OperationName::HasTraitFn = llvm::unique_function<bool(TypeID) const> |
Definition at line 70 of file OperationSupport.h.
using mlir::OperationName::ParseAssemblyFn = llvm::unique_function<ParseResult(OpAsmParser &, OperationState &)> |
Definition at line 71 of file OperationSupport.h.
using mlir::OperationName::PopulateDefaultAttrsFn = llvm::unique_function<void(const OperationName &, NamedAttrList &) const> |
Definition at line 75 of file OperationSupport.h.
using mlir::OperationName::PrintAssemblyFn = llvm::unique_function<void(Operation *, OpAsmPrinter &, StringRef) const> |
Definition at line 77 of file OperationSupport.h.
using mlir::OperationName::VerifyInvariantsFn = llvm::unique_function<LogicalResult(Operation *) const> |
Definition at line 79 of file OperationSupport.h.
using mlir::OperationName::VerifyRegionInvariantsFn = llvm::unique_function<LogicalResult(Operation *) const> |
Definition at line 81 of file OperationSupport.h.
OperationName::OperationName | ( | StringRef | name, |
MLIRContext * | context | ||
) |
Definition at line 732 of file MLIRContext.cpp.
References mlir::MLIRContext::getImpl(), mlir::MLIRContext::isMultithreadingEnabled(), mlir::MLIRContextImpl::operationInfoMutex, mlir::MLIRContextImpl::operations, and mlir::MLIRContextImpl::registeredOperations.
Referenced by getFromOpaquePointer().
|
inlineprotected |
Definition at line 349 of file OperationSupport.h.
|
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().
void OperationName::dump | ( | ) | const |
Definition at line 57 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 198 of file OperationSupport.h.
References mlir::OperationName::InterfaceConcept::foldHook(), and getImpl().
Referenced by mlir::Operation::fold().
|
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().
|
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().
|
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().
|
inline |
Return the context this operation is associated with.
Definition at line 326 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 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().
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().
|
inlinestatic |
Definition at line 340 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 332 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::Impl::getName().
Referenced by cloneOpWithOperandsAndTypes(), getContext(), getStringRef(), mlir::impl::scalarizeVectorOp(), vectorizeOneOp(), and widenOp().
|
inlineprotected |
Definition at line 350 of file OperationSupport.h.
Referenced by attachInterface(), foldHook(), mlir::AffineMap::get(), mlir::MLIRContext::getAffineUniquer(), getAttributeNames(), mlir::MLIRContext::getAttributeUniquer(), getCanonicalizationPatterns(), getDialect(), mlir::RegisteredOperationName::getDialect(), getIdentifier(), getInterface(), getParseAssemblyFn(), getTypeID(), mlir::MLIRContext::getTypeUniquer(), hasInterface(), hasTrait(), isRegistered(), mightHaveTrait(), populateDefaultAttrs(), printAssembly(), verifyInvariants(), and verifyRegionInvariants().
|
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 281 of file OperationSupport.h.
References getImpl(), mlir::OperationName::Impl::getInterfaceMap(), and mlir::detail::InterfaceMap::lookup().
Referenced by mlir::transform::detail::verifyParamProducerTransformOpTrait(), mlir::transform::TransformEachOpTrait< OpTy >::verifyTrait(), mlir::transform::FunctionalStyleTransformOpTrait< OpTy >::verifyTrait(), and mlir::transform::NavigationTransformOpTrait< OpTy >::verifyTrait().
|
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().
|
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().
|
inline |
Return the name of this operation. This always succeeds.
Definition at line 329 of file OperationSupport.h.
References getIdentifier().
Referenced by addBodyWithPayloadOp(), AncestorKey::AncestorKey(), mlir::ExternalPass::canScheduleOn(), mlir::transform::detail::checkApplyToOne(), mlir::Op< ConcreteType, Traits >::classof(), cloneOpWithOperandsAndTypes(), mlir::detail::RecoveryReproducerContext::generate(), mlir::linalg::generateLibraryCallName(), getDialectNamespace(), mlirLinalgFillBuiltinNamedOpRegion(), mlir::Diagnostic::operator<<(), mlir::OpState::parse(), performOptionalDebugActions(), mlir::OpState::printOpName(), printShortForm(), saveReproToTempFile(), stripDialect(), mlir::transform::detail::verifyParamProducerTransformOpTrait(), and mlir::OpTrait::SingleBlockImplicitTerminator< TerminatorOpType >::Impl< ConcreteType >::verifyRegionTrait().
|
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().
|
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().
|
inline |
Definition at line 297 of file OperationSupport.h.
References mlir::detail::InterfaceMap::contains(), getImpl(), and mlir::OperationName::Impl::getInterfaceMap().
|
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 214 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 217 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::InterfaceConcept::hasTrait().
|
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().
|
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.
|
inline |
Definition at line 308 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 223 of file OperationSupport.h.
Referenced by mlir::Operation::mightHaveTrait().
|
inline |
Definition at line 226 of file OperationSupport.h.
References getImpl(), mlir::OperationName::InterfaceConcept::hasTrait(), and isRegistered().
|
inline |
Definition at line 346 of file OperationSupport.h.
|
inline |
Definition at line 345 of file OperationSupport.h.
|
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().
void OperationName::print | ( | raw_ostream & | os | ) | const |
Definition at line 55 of file AsmPrinter.cpp.
Referenced by mlir::operator<<().
|
inline |
This hook implements the AsmPrinter for this operation.
Definition at line 242 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::InterfaceConcept::printAssembly().
|
inlineprotected |
Definition at line 351 of file OperationSupport.h.
|
inline |
Return the operation name with dialect name stripped, if it has one.
Definition at line 323 of file OperationSupport.h.
References getStringRef().
|
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().
|
inline |
Definition at line 253 of file OperationSupport.h.
References getImpl(), and mlir::OperationName::InterfaceConcept::verifyRegionInvariants().