MLIR  19.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
mlir::Op< ConcreteType, Traits > Class Template Reference

This provides public APIs that all operations should have. More...

#include "mlir/IR/OpDefinition.h"

+ Inheritance diagram for mlir::Op< ConcreteType, Traits >:

Public Types

using ConcreteOpType = ConcreteType
 Expose the type we are instantiated on to template machinery that may want to introspect traits on this operation. More...
 
template<typename T >
using InferredProperties = typename PropertiesSelector< T >::type
 

Public Member Functions

ConcreteType clone ()
 Create a deep copy of this operation. More...
 
ConcreteType cloneWithoutRegions ()
 Create a partial copy of this operation without traversing into attached regions. More...
 
 Op ()
 This is a public constructor. Any op can be initialized to null. More...
 
 Op (std::nullptr_t)
 
 Op (Operation *state)
 This is a public constructor to enable access via the llvm::cast family of methods. More...
 
const void * getAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits. More...
 
template<typename T = ConcreteType>
InferredProperties< T > & getProperties ()
 
OperationgetOperation ()
 Inherit getOperation from OpState. More...
 
LogicalResult verify ()
 If the concrete type didn't implement a custom verifier hook, just fall back to this one which accepts everything. More...
 
LogicalResult verifyRegions ()
 
- Public Member Functions inherited from mlir::OpState
 operator bool ()
 Ops are pointer-like, so we allow conversion to bool. More...
 
 operator Operation * () const
 This implicitly converts to Operation*. More...
 
Operationoperator-> () const
 Shortcut of -> to access a member of Operation. More...
 
OperationgetOperation ()
 Return the operation that this refers to. More...
 
MLIRContextgetContext ()
 Return the context this operation belongs to. More...
 
void print (raw_ostream &os, OpPrintingFlags flags=std::nullopt)
 Print the operation to the given stream. More...
 
void print (raw_ostream &os, AsmState &asmState)
 
void dump ()
 Dump this operation. More...
 
Location getLoc ()
 The source location the operation was defined or derived from. More...
 
bool use_empty ()
 Return true if there are no users of any results of this operation. More...
 
void erase ()
 Remove this operation from its parent block and delete it. More...
 
InFlightDiagnostic emitOpError (const Twine &message={})
 Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers. More...
 
InFlightDiagnostic emitError (const Twine &message={})
 Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers that may be listening. More...
 
InFlightDiagnostic emitWarning (const Twine &message={})
 Emit a warning about this operation, reporting up to any diagnostic handlers that may be listening. More...
 
InFlightDiagnostic emitRemark (const Twine &message={})
 Emit a remark about this operation, reporting up to any diagnostic handlers that may be listening. More...
 
template<WalkOrder Order = WalkOrder::PostOrder, typename Iterator = ForwardIterator, typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk (FnT &&callback)
 Walk the operation by calling the callback for each nested operation (including this one), block or region, depending on the callback provided. More...
 
template<typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==2, RetT > walk (FnT &&callback)
 Generic walker with a stage aware callback. More...
 

Static Public Member Functions

template<template< typename T > class Trait>
static constexpr bool hasTrait ()
 Return if this operation contains the provided trait. More...
 
static bool classof (Operation *op)
 Return true if this "op class" can match against the specified operation. More...
 
template<typename T >
static std::enable_if_t< std::is_base_of< OpState, T >::value, bool > classof (const T *op)
 Provide classof support for other OpBase derived classes, such as Interfaces. More...
 
static ConcreteOpType getFromOpaquePointer (const void *pointer)
 
template<typename... Models>
static void attachInterface (MLIRContext &context)
 Attach the given models as implementations of the corresponding interfaces for the concrete operation. More...
 
template<typename PropertiesTy >
static LogicalResult setPropertiesFromAttr (PropertiesTy &prop, Attribute attr, function_ref< InFlightDiagnostic()> emitError)
 Convert the provided attribute to a property and assigned it to the provided properties. More...
 
template<typename PropertiesTy >
static Attribute getPropertiesAsAttr (MLIRContext *ctx, const PropertiesTy &prop)
 Convert the provided properties to an attribute. More...
 
template<typename PropertiesTy >
static llvm::hash_code computePropertiesHash (const PropertiesTy &prop)
 Hash the provided properties. More...
 
static constexpr bool hasProperties ()
 Returns true if this operation defines a Properties inner type. More...
 
template<typename T = ConcreteType>
static void populateDefaultProperties (OperationName opName, InferredProperties< T > &properties)
 This hook populates any unset default attrs when mapped to properties. More...
 
template<typename T >
static void printProperties (MLIRContext *ctx, OpAsmPrinter &p, const T &properties, ArrayRef< StringRef > elidedProps={})
 Print the operation properties with names not included within 'elidedProps'. More...
 
template<typename T = ConcreteType>
static ParseResult parseProperties (OpAsmParser &parser, OperationState &result)
 Parses 'prop-dict' for the operation. More...
 
- Static Public Member Functions inherited from mlir::OpState
static void getCanonicalizationPatterns (RewritePatternSet &results, MLIRContext *context)
 This hook returns any canonicalization pattern rewrites that the operation supports, for use by the canonicalization pass. More...
 
static void populateDefaultAttrs (const OperationName &, NamedAttrList &)
 This hook populates any unset default attrs. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mlir::OpState
LogicalResult verify ()
 If the concrete type didn't implement a custom verifier hook, just fall back to this one which accepts everything. More...
 
LogicalResult verifyRegions ()
 
 OpState (Operation *state)
 Mutability management is handled by the OpWrapper/OpConstWrapper classes, so we can cast it away here. More...
 
- Static Protected Member Functions inherited from mlir::OpState
static ParseResult parse (OpAsmParser &parser, OperationState &result)
 Parse the custom form of an operation. More...
 
static void print (Operation *op, OpAsmPrinter &p, StringRef defaultDialect)
 Print the operation. More...
 
static ParseResult genericParseProperties (OpAsmParser &parser, Attribute &result)
 Parse properties as a Attribute. More...
 
static void genericPrintProperties (OpAsmPrinter &p, Attribute properties, ArrayRef< StringRef > elidedProps={})
 Print the properties as a Attribute with names not included within 'elidedProps'. More...
 
static void printOpName (Operation *op, OpAsmPrinter &p, StringRef defaultDialect)
 Print an operation name, eliding the dialect prefix if necessary. More...
 
static EmptyPropertiesgetEmptyProperties ()
 For all op which don't have properties, we keep a single instance of EmptyProperties to be used where a reference to a properties is needed: this allow to bind a pointer to the reference without triggering UB. More...
 

Detailed Description

template<typename ConcreteType, template< typename T > class... Traits>
class mlir::Op< ConcreteType, Traits >

This provides public APIs that all operations should have.

The template argument 'ConcreteType' should be the concrete type by CRTP and the others are base classes by the policy pattern.

Definition at line 1665 of file OpDefinition.h.

Member Typedef Documentation

◆ ConcreteOpType

template<typename ConcreteType , template< typename T > class... Traits>
using mlir::Op< ConcreteType, Traits >::ConcreteOpType = ConcreteType

Expose the type we are instantiated on to template machinery that may want to introspect traits on this operation.

Definition at line 1710 of file OpDefinition.h.

◆ InferredProperties

template<typename ConcreteType , template< typename T > class... Traits>
template<typename T >
using mlir::Op< ConcreteType, Traits >::InferredProperties = typename PropertiesSelector<T>::type

Definition at line 1967 of file OpDefinition.h.

Constructor & Destructor Documentation

◆ Op() [1/3]

template<typename ConcreteType , template< typename T > class... Traits>
mlir::Op< ConcreteType, Traits >::Op ( )
inlineexplicit

This is a public constructor. Any op can be initialized to null.

Definition at line 1713 of file OpDefinition.h.

◆ Op() [2/3]

template<typename ConcreteType , template< typename T > class... Traits>
mlir::Op< ConcreteType, Traits >::Op ( std::nullptr_t  )
inline

Definition at line 1714 of file OpDefinition.h.

◆ Op() [3/3]

template<typename ConcreteType , template< typename T > class... Traits>
mlir::Op< ConcreteType, Traits >::Op ( Operation state)
inlineexplicit

This is a public constructor to enable access via the llvm::cast family of methods.

This should not be used directly.

Definition at line 1718 of file OpDefinition.h.

Member Function Documentation

◆ attachInterface()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename... Models>
static void mlir::Op< ConcreteType, Traits >::attachInterface ( MLIRContext context)
inlinestatic

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

Definition at line 1732 of file OpDefinition.h.

References mlir::RegisteredOperationName::lookup().

◆ classof() [1/2]

template<typename ConcreteType , template< typename T > class... Traits>
template<typename T >
static std::enable_if_t<std::is_base_of<OpState, T>::value, bool> mlir::Op< ConcreteType, Traits >::classof ( const T *  op)
inlinestatic

Provide classof support for other OpBase derived classes, such as Interfaces.

Definition at line 1704 of file OpDefinition.h.

◆ classof() [2/2]

template<typename ConcreteType , template< typename T > class... Traits>
static bool mlir::Op< ConcreteType, Traits >::classof ( Operation op)
inlinestatic

Return true if this "op class" can match against the specified operation.

Definition at line 1689 of file OpDefinition.h.

◆ clone()

template<typename ConcreteType , template< typename T > class... Traits>
ConcreteType mlir::Op< ConcreteType, Traits >::clone ( )
inline

Create a deep copy of this operation.

Definition at line 1679 of file OpDefinition.h.

References mlir::Op< ConcreteType, Traits >::clone(), and mlir::Op< ConcreteType, Traits >::getOperation().

Referenced by mlir::Op< ConcreteType, Traits >::clone().

◆ cloneWithoutRegions()

template<typename ConcreteType , template< typename T > class... Traits>
ConcreteType mlir::Op< ConcreteType, Traits >::cloneWithoutRegions ( )
inline

Create a partial copy of this operation without traversing into attached regions.

The new operation will have the same number of regions as the original one, but they will be left empty.

Definition at line 1684 of file OpDefinition.h.

References mlir::Op< ConcreteType, Traits >::getOperation().

◆ computePropertiesHash()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename PropertiesTy >
static llvm::hash_code mlir::Op< ConcreteType, Traits >::computePropertiesHash ( const PropertiesTy &  prop)
inlinestatic

Hash the provided properties.

This default implementation forwards to a free function computeHash that can be looked up with ADL in the namespace where the properties are defined. It can also be overridden in the derived ConcreteOp.

Definition at line 1767 of file OpDefinition.h.

References computeHash().

◆ getAsOpaquePointer()

template<typename ConcreteType , template< typename T > class... Traits>
const void* mlir::Op< ConcreteType, Traits >::getAsOpaquePointer ( ) const
inline

Methods for supporting PointerLikeTypeTraits.

Definition at line 1721 of file OpDefinition.h.

◆ getFromOpaquePointer()

template<typename ConcreteType , template< typename T > class... Traits>
static ConcreteOpType mlir::Op< ConcreteType, Traits >::getFromOpaquePointer ( const void *  pointer)
inlinestatic

Definition at line 1724 of file OpDefinition.h.

◆ getOperation()

template<typename ConcreteType , template< typename T > class... Traits>
Operation* mlir::OpState::getOperation
inline

◆ getProperties()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename T = ConcreteType>
InferredProperties<T>& mlir::Op< ConcreteType, Traits >::getProperties ( )
inline

◆ getPropertiesAsAttr()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename PropertiesTy >
static Attribute mlir::Op< ConcreteType, Traits >::getPropertiesAsAttr ( MLIRContext ctx,
const PropertiesTy &  prop 
)
inlinestatic

Convert the provided properties to an attribute.

This default implementation forwards to a free function getPropertiesAsAttribute that can be looked up with ADL in the namespace where the properties are defined. It can also be overridden in the derived ConcreteOp.

Definition at line 1758 of file OpDefinition.h.

◆ hasProperties()

template<typename ConcreteType , template< typename T > class... Traits>
static constexpr bool mlir::Op< ConcreteType, Traits >::hasProperties ( )
inlinestaticconstexpr

Returns true if this operation defines a Properties inner type.

Definition at line 1835 of file OpDefinition.h.

Referenced by mlir::Op< ConcreteType, Traits >::getProperties().

◆ hasTrait()

template<typename ConcreteType , template< typename T > class... Traits>
template<template< typename T > class Trait>
static constexpr bool mlir::Op< ConcreteType, Traits >::hasTrait ( )
inlinestaticconstexpr

Return if this operation contains the provided trait.

Definition at line 1674 of file OpDefinition.h.

◆ parseProperties()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename T = ConcreteType>
static ParseResult mlir::Op< ConcreteType, Traits >::parseProperties ( OpAsmParser parser,
OperationState result 
)
inlinestatic

Parses 'prop-dict' for the operation.

Unless overridden, the method will parse the properties using the generic property dictionary using the '<{ ... }>' syntax. The resulting properties are stored within the property structure of 'result', accessible via 'getOrAddProperties'.

Definition at line 2001 of file OpDefinition.h.

References mlir::OpState::emitError(), mlir::emitError(), mlir::failure(), mlir::OpState::genericParseProperties(), mlir::get(), mlir::OperationState::getContext(), mlir::OperationState::getOrAddProperties(), mlir::OperationName::getStringRef(), mlir::OperationState::location, and mlir::OperationState::name.

◆ populateDefaultProperties()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename T = ConcreteType>
static void mlir::Op< ConcreteType, Traits >::populateDefaultProperties ( OperationName  opName,
InferredProperties< T > &  properties 
)
inlinestatic

This hook populates any unset default attrs when mapped to properties.

Definition at line 1979 of file OpDefinition.h.

◆ printProperties()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename T >
static void mlir::Op< ConcreteType, Traits >::printProperties ( MLIRContext ctx,
OpAsmPrinter p,
const T &  properties,
ArrayRef< StringRef >  elidedProps = {} 
)
inlinestatic

Print the operation properties with names not included within 'elidedProps'.

Unless overridden, this method will try to dispatch to a printProperties free-function if it exists, and otherwise by converting the properties to an Attribute.

Definition at line 1987 of file OpDefinition.h.

◆ setPropertiesFromAttr()

template<typename ConcreteType , template< typename T > class... Traits>
template<typename PropertiesTy >
static LogicalResult mlir::Op< ConcreteType, Traits >::setPropertiesFromAttr ( PropertiesTy &  prop,
Attribute  attr,
function_ref< InFlightDiagnostic()>  emitError 
)
inlinestatic

Convert the provided attribute to a property and assigned it to the provided properties.

This default implementation forwards to a free function setPropertiesFromAttribute that can be looked up with ADL in the namespace where the properties are defined. It can also be overridden in the derived ConcreteOp.

Definition at line 1749 of file OpDefinition.h.

References mlir::OpState::emitError().

◆ verify()

template<typename ConcreteType , template< typename T > class... Traits>
LogicalResult mlir::OpState::verify
inline

If the concrete type didn't implement a custom verifier hook, just fall back to this one which accepts everything.

Definition at line 210 of file OpDefinition.h.

◆ verifyRegions()

template<typename ConcreteType , template< typename T > class... Traits>
LogicalResult mlir::OpState::verifyRegions
inline

Definition at line 211 of file OpDefinition.h.


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