MLIR  20.0.0git
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
mlir::OpState Class Reference

This is the concrete base class that holds the operation pointer and has non-generic methods that only depend on State (to avoid having them instantiated on template types that don't affect them. More...

#include "mlir/IR/OpDefinition.h"

+ Inheritance diagram for mlir::OpState:

Public Member Functions

 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

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...
 

Protected Member Functions

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

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

This is the concrete base class that holds the operation pointer and has non-generic methods that only depend on State (to avoid having them instantiated on template types that don't affect them.

This also has the fallback implementations of customization hooks for when they aren't customized.

Definition at line 96 of file OpDefinition.h.

Constructor & Destructor Documentation

◆ OpState()

mlir::OpState::OpState ( Operation state)
inlineexplicitprotected

Mutability management is handled by the OpWrapper/OpConstWrapper classes, so we can cast it away here.

Definition at line 240 of file OpDefinition.h.

Member Function Documentation

◆ dump()

void mlir::OpState::dump ( )
inline

Dump this operation.

Definition at line 122 of file OpDefinition.h.

References mlir::Operation::dump().

Referenced by mlir::spirv::ElementwiseOpPattern< Op, SPIRVOp >::matchAndRewrite().

◆ emitError()

InFlightDiagnostic OpState::emitError ( const Twine &  message = {})

◆ emitOpError()

InFlightDiagnostic OpState::emitOpError ( const Twine &  message = {})

Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.

Definition at line 832 of file Operation.cpp.

Referenced by mlir::spirv::verifyAccessChain(), verifyDeviceTypeAndSegmentCountMatch(), verifyDeviceTypeCountMatch(), mlir::spirv::verifyGroupOp(), and mlir::verifyReshapeLikeTypes().

◆ emitRemark()

InFlightDiagnostic OpState::emitRemark ( const Twine &  message = {})

Emit a remark about this operation, reporting up to any diagnostic handlers that may be listening.

Definition at line 844 of file Operation.cpp.

◆ emitWarning()

InFlightDiagnostic OpState::emitWarning ( const Twine &  message = {})

Emit a warning about this operation, reporting up to any diagnostic handlers that may be listening.

Definition at line 838 of file Operation.cpp.

◆ erase()

void mlir::OpState::erase ( )
inline

Remove this operation from its parent block and delete it.

Definition at line 131 of file OpDefinition.h.

References mlir::Operation::erase().

◆ genericParseProperties()

ParseResult OpState::genericParseProperties ( OpAsmParser parser,
Attribute result 
)
staticprotected

◆ genericPrintProperties()

void OpState::genericPrintProperties ( OpAsmPrinter p,
Attribute  properties,
ArrayRef< StringRef >  elidedProps = {} 
)
staticprotected

Print the properties as a Attribute with names not included within 'elidedProps'.

Definition at line 802 of file Operation.cpp.

References mlir::NamedAttribute::getName(), and mlir::OpAsmPrinter::printOptionalAttrDict().

◆ getCanonicalizationPatterns()

static void mlir::OpState::getCanonicalizationPatterns ( RewritePatternSet results,
MLIRContext context 
)
inlinestatic

This hook returns any canonicalization pattern rewrites that the operation supports, for use by the canonicalization pass.

Definition at line 201 of file OpDefinition.h.

◆ getContext()

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

◆ getEmptyProperties()

static EmptyProperties& mlir::OpState::getEmptyProperties ( )
inlinestaticprotected

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.

Definition at line 245 of file OpDefinition.h.

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

◆ getLoc()

Location mlir::OpState::getLoc ( )
inline

◆ getOperation()

Operation* mlir::OpState::getOperation ( )
inline

Return the operation that this refers to.

Definition at line 108 of file OpDefinition.h.

Referenced by getContext(), operator bool(), mlir::operator!=(), and mlir::operator==().

◆ operator bool()

mlir::OpState::operator bool ( )
inlineexplicit

Ops are pointer-like, so we allow conversion to bool.

Definition at line 99 of file OpDefinition.h.

References getOperation().

◆ operator Operation *()

mlir::OpState::operator Operation * ( ) const
inline

This implicitly converts to Operation*.

Definition at line 102 of file OpDefinition.h.

◆ operator->()

Operation* mlir::OpState::operator-> ( ) const
inline

Shortcut of -> to access a member of Operation.

Definition at line 105 of file OpDefinition.h.

◆ parse()

ParseResult OpState::parse ( OpAsmParser parser,
OperationState result 
)
staticprotected

Parse the custom form of an operation.

Unless overridden, this method will first try to get an operation parser from the op's dialect. Otherwise the custom assembly form of an op is always rejected. Op implementations should implement this to return failure. On success, they should fill in result with the fields to use.

Definition at line 762 of file Operation.cpp.

References mlir::AsmParser::emitError(), mlir::OperationName::getDialect(), mlir::AsmParser::getNameLoc(), mlir::Dialect::getParseOperationHook(), mlir::OperationName::getStringRef(), and mlir::OperationState::name.

◆ populateDefaultAttrs()

static void mlir::OpState::populateDefaultAttrs ( const OperationName ,
NamedAttrList  
)
inlinestatic

This hook populates any unset default attrs.

Definition at line 205 of file OpDefinition.h.

◆ print() [1/3]

void OpState::print ( Operation op,
OpAsmPrinter p,
StringRef  defaultDialect 
)
staticprotected

Print the operation.

Unless overridden, this method will first try to get an operation printer from the dialect. Otherwise, it prints the operation in generic form.

Definition at line 771 of file Operation.cpp.

References mlir::Operation::getDialect(), mlir::Dialect::getOperationPrinter(), and mlir::OpAsmPrinter::printGenericOp().

◆ print() [2/3]

void mlir::OpState::print ( raw_ostream &  os,
AsmState asmState 
)
inline

Definition at line 117 of file OpDefinition.h.

References mlir::Operation::print().

◆ print() [3/3]

void mlir::OpState::print ( raw_ostream &  os,
OpPrintingFlags  flags = std::nullopt 
)
inline

Print the operation to the given stream.

Definition at line 114 of file OpDefinition.h.

References mlir::Operation::print().

Referenced by mlir::operator<<().

◆ printOpName()

void OpState::printOpName ( Operation op,
OpAsmPrinter p,
StringRef  defaultDialect 
)
staticprotected

Print an operation name, eliding the dialect prefix if necessary.

Print an operation name, eliding the dialect prefix if necessary and doesn't lead to ambiguities.

Definition at line 782 of file Operation.cpp.

References mlir::Operation::getName(), mlir::AsmPrinter::getStream(), and mlir::OperationName::getStringRef().

◆ use_empty()

bool mlir::OpState::use_empty ( )
inline

Return true if there are no users of any results of this operation.

Definition at line 128 of file OpDefinition.h.

References mlir::Operation::use_empty().

◆ verify()

LogicalResult mlir::OpState::verify ( )
inlineprotected

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()

LogicalResult mlir::OpState::verifyRegions ( )
inlineprotected

Definition at line 211 of file OpDefinition.h.

◆ walk() [1/2]

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> mlir::OpState::walk ( FnT &&  callback)
inline

Walk the operation by calling the callback for each nested operation (including this one), block or region, depending on the callback provided.

The order in which regions, blocks and operations the same nesting level are visited (e.g., lexicographical or reverse lexicographical order) is determined by 'Iterator'. The walk order for enclosing regions, blocks and operations with respect to their nested ones is specified by 'Order' (post-order by default). A callback on a block or operation is allowed to erase that block or operation if either:

  • the walk is in post-order, or
  • the walk is in pre-order and the walk is skipped after the erasure. See Operation::walk for more details.

Definition at line 165 of file OpDefinition.h.

References mlir::Operation::walk().

◆ walk() [2/2]

template<typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if_t<llvm::function_traits<std::decay_t<FnT> >::num_args == 2, RetT> mlir::OpState::walk ( FnT &&  callback)
inline

Generic walker with a stage aware callback.

Walk the operation by calling the callback for each nested operation (including this one) N+1 times, where N is the number of regions attached to that operation.

The callback method can take any of the following forms: void(Operation *, const WalkStage &) : Walk all operation opaquely

Definition at line 193 of file OpDefinition.h.

References mlir::Operation::walk().


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