MLIR  15.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=llvm::None)
 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 FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT >::type 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< llvm::function_traits< std::decay_t< FnT > >::num_args==2, RetT >::type 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...
 

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 void printOpName (Operation *op, OpAsmPrinter &p, StringRef defaultDialect)
 Print an operation name, eliding the dialect prefix if necessary. 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 79 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 209 of file OpDefinition.h.

Member Function Documentation

◆ dump()

void mlir::OpState::dump ( )
inline

Dump this operation.

Definition at line 105 of file OpDefinition.h.

◆ emitError()

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

Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers that may be listening.

Definition at line 639 of file Operation.cpp.

Referenced by mlir::spirv::ElementwiseOpPattern< Op, SPIRVOp >::matchAndRewrite(), verifyExtOp(), verifyImageOperands(), and verifyTruncateOp().

◆ 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 645 of file Operation.cpp.

Referenced by verifyAccessChain(), 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 657 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 651 of file Operation.cpp.

◆ erase()

void mlir::OpState::erase ( )
inline

Remove this operation from its parent block and delete it.

Definition at line 114 of file OpDefinition.h.

References mlir::emitError(), mlir::emitRemark(), mlir::emitWarning(), and mlir::PostOrder.

◆ 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 182 of file OpDefinition.h.

◆ getContext()

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

Return the context this operation belongs to.

Definition at line 94 of file OpDefinition.h.

Referenced by mlir::AffineDmaStartOp::getAffineMapAttrForMemRef(), and mlir::AffineDmaWaitOp::getAffineMapAttrForMemRef().

◆ getLoc()

Location mlir::OpState::getLoc ( )
inline

◆ getOperation()

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

Return the operation that this refers to.

Definition at line 91 of file OpDefinition.h.

Referenced by generateCopy(), isFusionProfitable(), loadCSE(), and mlir::DataDescriptor::setSize().

◆ operator bool()

mlir::OpState::operator bool ( )
inlineexplicit

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

Definition at line 82 of file OpDefinition.h.

◆ operator Operation *()

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

This implicitly converts to Operation*.

Definition at line 85 of file OpDefinition.h.

◆ operator->()

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

Shortcut of -> to access a member of Operation.

Definition at line 88 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 609 of file Operation.cpp.

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

◆ print() [1/3]

void mlir::OpState::print ( raw_ostream &  os,
OpPrintingFlags  flags = llvm::None 
)
inline

◆ print() [2/3]

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

Definition at line 100 of file OpDefinition.h.

◆ print() [3/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 618 of file Operation.cpp.

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

◆ 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 629 of file Operation.cpp.

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

Referenced by mlir::Op< AffineDmaStartOp, OpTrait::MemRefsNormalizable, OpTrait::VariadicOperands, OpTrait::ZeroResults, OpTrait::OpInvariants, AffineMapAccessInterface::Trait >::attachInterface().

◆ use_empty()

bool mlir::OpState::use_empty ( )
inline

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

Definition at line 111 of file OpDefinition.h.

◆ 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 188 of file OpDefinition.h.

References mlir::success().

◆ verifyRegions()

LogicalResult mlir::OpState::verifyRegions ( )
inlineprotected

Definition at line 189 of file OpDefinition.h.

References print(), and mlir::success().

◆ walk() [1/2]

template<WalkOrder Order = WalkOrder::PostOrder, typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if< llvm::function_traits<std::decay_t<FnT> >::num_args == 1, RetT>::type 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.

Regions, blocks and operations at the same nesting level are visited in lexicographical order. 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 146 of file OpDefinition.h.

◆ walk() [2/2]

template<typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if< llvm::function_traits<std::decay_t<FnT> >::num_args == 2, RetT>::type 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 174 of file OpDefinition.h.


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