MLIR  19.0.0git
Classes | Public Member Functions | Public Attributes | List of all members
mlir::detail::ConversionPatternRewriterImpl Struct Reference
+ Inheritance diagram for mlir::detail::ConversionPatternRewriterImpl:

Classes

struct  SingleEraseRewriter
 A rewriter that keeps track of erased ops and blocks. More...
 

Public Member Functions

 ConversionPatternRewriterImpl (MLIRContext *ctx, const ConversionConfig &config)
 
RewriterState getCurrentState ()
 Return the current state of the rewriter. More...
 
void applyRewrites ()
 Apply all requested operation rewrites. More...
 
void resetState (RewriterState state)
 Reset the state of the rewriter to a previously saved point. More...
 
template<typename RewriteTy , typename... Args>
void appendRewrite (Args &&...args)
 Append a rewrite. More...
 
void undoRewrites (unsigned numRewritesToKeep=0)
 Undo the rewrites (motions, splits) one by one in reverse order until "numRewritesToKeep" rewrites remains. More...
 
LogicalResult remapValues (StringRef valueDiagTag, std::optional< Location > inputLoc, PatternRewriter &rewriter, ValueRange values, SmallVectorImpl< Value > &remapped)
 Remap the given values to those with potentially different types. More...
 
bool isOpIgnored (Operation *op) const
 Return "true" if the given operation is ignored, and does not need to be converted. More...
 
bool wasOpReplaced (Operation *op) const
 Return "true" if the given operation was replaced or erased. More...
 
FailureOr< Block * > convertBlockSignature (ConversionPatternRewriter &rewriter, Block *block, const TypeConverter *converter, TypeConverter::SignatureConversion *conversion=nullptr)
 Attempt to convert the signature of the given block, if successful a new block is returned containing the new arguments. More...
 
LogicalResult convertNonEntryRegionTypes (ConversionPatternRewriter &rewriter, Region *region, const TypeConverter &converter, ArrayRef< TypeConverter::SignatureConversion > blockConversions={})
 Convert the types of non-entry block arguments within the given region. More...
 
BlockapplySignatureConversion (ConversionPatternRewriter &rewriter, Region *region, TypeConverter::SignatureConversion &conversion, const TypeConverter *converter)
 Apply a signature conversion on the given region, using converter for materializations if not null. More...
 
FailureOr< Block * > convertRegionTypes (ConversionPatternRewriter &rewriter, Region *region, const TypeConverter &converter, TypeConverter::SignatureConversion *entryConversion)
 Convert the types of block arguments within the given region. More...
 
BlockapplySignatureConversion (ConversionPatternRewriter &rewriter, Block *block, const TypeConverter *converter, TypeConverter::SignatureConversion &signatureConversion)
 Apply the given signature conversion on the given block. More...
 
Value buildUnresolvedMaterialization (MaterializationKind kind, Block *insertBlock, Block::iterator insertPt, Location loc, ValueRange inputs, Type outputType, Type origOutputType, const TypeConverter *converter)
 Build an unresolved materialization operation given an output type and set of input operands. More...
 
Value buildUnresolvedArgumentMaterialization (Block *block, Location loc, ValueRange inputs, Type origOutputType, Type outputType, const TypeConverter *converter)
 
Value buildUnresolvedTargetMaterialization (Location loc, Value input, Type outputType, const TypeConverter *converter)
 
void notifyOperationInserted (Operation *op, OpBuilder::InsertPoint previous) override
 Notify the listener that the specified operation was inserted. More...
 
void notifyOpReplaced (Operation *op, ValueRange newValues)
 Notifies that an op is about to be replaced with the given values. More...
 
void notifyBlockIsBeingErased (Block *block)
 Notifies that a block is about to be erased. More...
 
void notifyBlockInserted (Block *block, Region *previous, Region::iterator previousIt) override
 Notifies that a block was inserted. More...
 
void notifyBlockBeingInlined (Block *block, Block *srcBlock, Block::iterator before)
 Notifies that a block is being inlined into another block. More...
 
void notifyMatchFailure (Location loc, function_ref< void(Diagnostic &)> reasonCallback) override
 Notifies that a pattern match failed for the given reason. More...
 
- Public Member Functions inherited from mlir::RewriterBase::Listener
 Listener ()
 
virtual void notifyBlockErased (Block *block)
 Notify the listener that the specified block is about to be erased. More...
 
virtual void notifyOperationModified (Operation *op)
 Notify the listener that the specified operation was modified in-place. More...
 
virtual void notifyOperationReplaced (Operation *op, Operation *replacement)
 Notify the listener that all uses of the specified operation's results are about to be replaced with the results of another operation. More...
 
virtual void notifyOperationReplaced (Operation *op, ValueRange replacement)
 Notify the listener that all uses of the specified operation's results are about to be replaced with the a range of values, potentially produced by other operations. More...
 
virtual void notifyOperationErased (Operation *op)
 Notify the listener that the specified operation is about to be erased. More...
 
virtual void notifyPatternBegin (const Pattern &pattern, Operation *op)
 Notify the listener that the specified pattern is about to be applied at the specified root operation. More...
 
virtual void notifyPatternEnd (const Pattern &pattern, LogicalResult status)
 Notify the listener that a pattern application finished with the specified status. More...
 
- Public Member Functions inherited from mlir::OpBuilder::Listener
 Listener ()
 
virtual ~Listener ()=default
 
- Public Member Functions inherited from mlir::OpBuilder::ListenerBase
Kind getKind () const
 

Public Attributes

MLIRContextcontext
 MLIR context. More...
 
ConversionValueMapping mapping
 
SmallVector< std::unique_ptr< IRRewrite > > rewrites
 Ordered list of block operations (creations, splits, motions). More...
 
SetVector< Operation * > ignoredOps
 A set of operations that should no longer be considered for legalization. More...
 
SetVector< Operation * > replacedOps
 A set of operations that were replaced/erased. More...
 
const TypeConvertercurrentTypeConverter = nullptr
 The current type converter, or nullptr if no type converter is currently active. More...
 
DenseMap< Region *, const TypeConverter * > regionToConverter
 A mapping of regions to type converters that should be used when converting the arguments of blocks within that region. More...
 
const ConversionConfigconfig
 Dialect conversion configuration. More...
 
SmallPtrSet< Operation *, 1 > pendingRootUpdates
 A set of operations that have pending updates. More...
 
llvm::ScopedPrinter logger {llvm::dbgs()}
 A logger used to emit diagnostics during the conversion process. More...
 

Additional Inherited Members

- Public Types inherited from mlir::OpBuilder::ListenerBase
enum class  Kind { OpBuilderListener = 0 , RewriterBaseListener = 1 }
 The kind of listener. More...
 
- Static Public Member Functions inherited from mlir::RewriterBase::Listener
static bool classof (const OpBuilder::Listener *base)
 
- Protected Member Functions inherited from mlir::OpBuilder::Listener
 Listener (Kind kind)
 
- Protected Member Functions inherited from mlir::OpBuilder::ListenerBase
 ListenerBase (Kind kind)
 

Detailed Description

Definition at line 791 of file DialectConversion.cpp.

Constructor & Destructor Documentation

◆ ConversionPatternRewriterImpl()

mlir::detail::ConversionPatternRewriterImpl::ConversionPatternRewriterImpl ( MLIRContext ctx,
const ConversionConfig config 
)
inlineexplicit

Definition at line 792 of file DialectConversion.cpp.

Member Function Documentation

◆ appendRewrite()

template<typename RewriteTy , typename... Args>
void mlir::detail::ConversionPatternRewriterImpl::appendRewrite ( Args &&...  args)
inline

Append a rewrite.

Rewrites are committed upon success and rolled back upon failure.

Definition at line 813 of file DialectConversion.cpp.

◆ applyRewrites()

void ConversionPatternRewriterImpl::applyRewrites ( )

Apply all requested operation rewrites.

This method is invoked when the conversion process succeeds.

Definition at line 1192 of file DialectConversion.cpp.

References config, context, mlir::ConversionConfig::listener, rewrite(), and rewrites.

◆ applySignatureConversion() [1/2]

Block * ConversionPatternRewriterImpl::applySignatureConversion ( ConversionPatternRewriter rewriter,
Block block,
const TypeConverter converter,
TypeConverter::SignatureConversion signatureConversion 
)

◆ applySignatureConversion() [2/2]

Block * ConversionPatternRewriterImpl::applySignatureConversion ( ConversionPatternRewriter rewriter,
Region region,
TypeConverter::SignatureConversion conversion,
const TypeConverter converter 
)

Apply a signature conversion on the given region, using converter for materializations if not null.

Definition at line 1315 of file DialectConversion.cpp.

References convertBlockSignature(), mlir::Region::empty(), and mlir::Region::front().

Referenced by convertBlockSignature().

◆ buildUnresolvedArgumentMaterialization()

Value ConversionPatternRewriterImpl::buildUnresolvedArgumentMaterialization ( Block block,
Location  loc,
ValueRange  inputs,
Type  origOutputType,
Type  outputType,
const TypeConverter converter 
)

◆ buildUnresolvedMaterialization()

Value ConversionPatternRewriterImpl::buildUnresolvedMaterialization ( MaterializationKind  kind,
Block insertBlock,
Block::iterator  insertPt,
Location  loc,
ValueRange  inputs,
Type  outputType,
Type  origOutputType,
const TypeConverter converter 
)

Build an unresolved materialization operation given an output type and set of input operands.

Definition at line 1492 of file DialectConversion.cpp.

Referenced by buildUnresolvedArgumentMaterialization(), and buildUnresolvedTargetMaterialization().

◆ buildUnresolvedTargetMaterialization()

Value ConversionPatternRewriterImpl::buildUnresolvedTargetMaterialization ( Location  loc,
Value  input,
Type  outputType,
const TypeConverter converter 
)

◆ convertBlockSignature()

FailureOr< Block * > ConversionPatternRewriterImpl::convertBlockSignature ( ConversionPatternRewriter rewriter,
Block block,
const TypeConverter converter,
TypeConverter::SignatureConversion conversion = nullptr 
)

Attempt to convert the signature of the given block, if successful a new block is returned containing the new arguments.

Returns block if it did not require conversion.

Definition at line 1297 of file DialectConversion.cpp.

References applySignatureConversion(), mlir::TypeConverter::convertBlockSignature(), and mlir::failure().

Referenced by applySignatureConversion(), convertNonEntryRegionTypes(), and convertRegionTypes().

◆ convertNonEntryRegionTypes()

LogicalResult ConversionPatternRewriterImpl::convertNonEntryRegionTypes ( ConversionPatternRewriter rewriter,
Region region,
const TypeConverter converter,
ArrayRef< TypeConverter::SignatureConversion blockConversions = {} 
)

Convert the types of non-entry block arguments within the given region.

Definition at line 1341 of file DialectConversion.cpp.

References convertBlockSignature(), mlir::Region::empty(), mlir::failed(), mlir::failure(), mlir::Region::getBlocks(), regionToConverter, and mlir::success().

Referenced by convertRegionTypes().

◆ convertRegionTypes()

FailureOr< Block * > ConversionPatternRewriterImpl::convertRegionTypes ( ConversionPatternRewriter rewriter,
Region region,
const TypeConverter converter,
TypeConverter::SignatureConversion entryConversion 
)

Convert the types of block arguments within the given region.

Definition at line 1325 of file DialectConversion.cpp.

References convertBlockSignature(), convertNonEntryRegionTypes(), mlir::Region::empty(), mlir::failed(), mlir::failure(), mlir::Region::front(), and regionToConverter.

◆ getCurrentState()

RewriterState ConversionPatternRewriterImpl::getCurrentState ( )

Return the current state of the rewriter.

Definition at line 1207 of file DialectConversion.cpp.

References ignoredOps, replacedOps, and rewrites.

◆ isOpIgnored()

bool ConversionPatternRewriterImpl::isOpIgnored ( Operation op) const

Return "true" if the given operation is ignored, and does not need to be converted.

Definition at line 1284 of file DialectConversion.cpp.

Referenced by computeNecessaryMaterializations(), and legalizeUnresolvedMaterialization().

◆ notifyBlockBeingInlined()

void ConversionPatternRewriterImpl::notifyBlockBeingInlined ( Block block,
Block srcBlock,
Block::iterator  before 
)

Notifies that a block is being inlined into another block.

Definition at line 1609 of file DialectConversion.cpp.

◆ notifyBlockInserted()

void ConversionPatternRewriterImpl::notifyBlockInserted ( Block block,
Region previous,
Region::iterator  previousIt 
)
overridevirtual

Notifies that a block was inserted.

Reimplemented from mlir::OpBuilder::Listener.

Definition at line 1584 of file DialectConversion.cpp.

References mlir::Region::end(), mlir::Operation::getName(), mlir::Block::getParentOp(), logger, and wasOpReplaced().

◆ notifyBlockIsBeingErased()

void ConversionPatternRewriterImpl::notifyBlockIsBeingErased ( Block block)

Notifies that a block is about to be erased.

Definition at line 1578 of file DialectConversion.cpp.

References mlir::Block::getParent().

◆ notifyMatchFailure()

void ConversionPatternRewriterImpl::notifyMatchFailure ( Location  loc,
function_ref< void(Diagnostic &)>  reasonCallback 
)
overridevirtual

Notifies that a pattern match failed for the given reason.

Reimplemented from mlir::RewriterBase::Listener.

Definition at line 1614 of file DialectConversion.cpp.

References config, diag(), logger, mlir::ConversionConfig::notifyCallback, and mlir::Remark.

Referenced by remapValues().

◆ notifyOperationInserted()

void ConversionPatternRewriterImpl::notifyOperationInserted ( Operation op,
OpBuilder::InsertPoint  previous 
)
overridevirtual

Notify the listener that the specified operation was inserted.

  • If the operation was moved, then previous is the previous location of the op.
  • If the operation was unlinked before it was inserted, then previous is empty.

Note: Creating an (unlinked) op does not trigger this notification.

Reimplemented from mlir::OpBuilder::Listener.

Definition at line 1532 of file DialectConversion.cpp.

◆ notifyOpReplaced()

void ConversionPatternRewriterImpl::notifyOpReplaced ( Operation op,
ValueRange  newValues 
)

Notifies that an op is about to be replaced with the given values.

Definition at line 1552 of file DialectConversion.cpp.

◆ remapValues()

LogicalResult ConversionPatternRewriterImpl::remapValues ( StringRef  valueDiagTag,
std::optional< Location inputLoc,
PatternRewriter rewriter,
ValueRange  values,
SmallVectorImpl< Value > &  remapped 
)

Remap the given values to those with potentially different types.

Returns success if the values could be remapped, failure otherwise. valueDiagTag is the tag used when describing a value within a diagnostic, e.g. "operand".

Definition at line 1230 of file DialectConversion.cpp.

References buildUnresolvedTargetMaterialization(), mlir::TypeConverter::convertType(), currentTypeConverter, diag(), mlir::detail::enumerate(), mlir::failed(), mlir::failure(), mlir::Value::getLoc(), mlir::Value::getType(), mapping, notifyMatchFailure(), and mlir::success().

◆ resetState()

void ConversionPatternRewriterImpl::resetState ( RewriterState  state)

Reset the state of the rewriter to a previously saved point.

Definition at line 1211 of file DialectConversion.cpp.

◆ undoRewrites()

void ConversionPatternRewriterImpl::undoRewrites ( unsigned  numRewritesToKeep = 0)

Undo the rewrites (motions, splits) one by one in reverse order until "numRewritesToKeep" rewrites remains.

Definition at line 1223 of file DialectConversion.cpp.

References rewrite(), and rewrites.

◆ wasOpReplaced()

bool ConversionPatternRewriterImpl::wasOpReplaced ( Operation op) const

Return "true" if the given operation was replaced or erased.

Definition at line 1289 of file DialectConversion.cpp.

Referenced by notifyBlockInserted().

Member Data Documentation

◆ config

const ConversionConfig& mlir::detail::ConversionPatternRewriterImpl::config

Dialect conversion configuration.

Definition at line 1000 of file DialectConversion.cpp.

Referenced by applyRewrites(), applySignatureConversion(), and notifyMatchFailure().

◆ context

MLIRContext* mlir::detail::ConversionPatternRewriterImpl::context

MLIR context.

Definition at line 971 of file DialectConversion.cpp.

Referenced by applyRewrites().

◆ currentTypeConverter

const TypeConverter* mlir::detail::ConversionPatternRewriterImpl::currentTypeConverter = nullptr

The current type converter, or nullptr if no type converter is currently active.

Definition at line 993 of file DialectConversion.cpp.

Referenced by mlir::PDLConversionConfig::notifyRewriteBegin(), mlir::PDLConversionConfig::notifyRewriteEnd(), mlir::registerConversionPDLFunctions(), and remapValues().

◆ ignoredOps

SetVector<Operation *> mlir::detail::ConversionPatternRewriterImpl::ignoredOps

A set of operations that should no longer be considered for legalization.

E.g., ops that are recursively legal. Ops that were replaced/erased are tracked separately.

Definition at line 983 of file DialectConversion.cpp.

Referenced by getCurrentState().

◆ logger

llvm::ScopedPrinter mlir::detail::ConversionPatternRewriterImpl::logger {llvm::dbgs()}

A logger used to emit diagnostics during the conversion process.

Definition at line 1009 of file DialectConversion.cpp.

Referenced by notifyBlockInserted(), and notifyMatchFailure().

◆ mapping

ConversionValueMapping mlir::detail::ConversionPatternRewriterImpl::mapping

◆ pendingRootUpdates

SmallPtrSet<Operation *, 1> mlir::detail::ConversionPatternRewriterImpl::pendingRootUpdates

A set of operations that have pending updates.

This tracking isn't strictly necessary, and is thus only active during debug builds for extra verification.

Definition at line 1006 of file DialectConversion.cpp.

◆ regionToConverter

DenseMap<Region *, const TypeConverter *> mlir::detail::ConversionPatternRewriterImpl::regionToConverter

A mapping of regions to type converters that should be used when converting the arguments of blocks within that region.

Definition at line 997 of file DialectConversion.cpp.

Referenced by convertNonEntryRegionTypes(), and convertRegionTypes().

◆ replacedOps

SetVector<Operation *> mlir::detail::ConversionPatternRewriterImpl::replacedOps

A set of operations that were replaced/erased.

Such ops are not erased immediately but only when the dialect conversion succeeds. In the mean time, they should no longer be considered for legalization and any attempt to modify/access them is invalid rewriter API usage.

Definition at line 989 of file DialectConversion.cpp.

Referenced by getCurrentState().

◆ rewrites

SmallVector<std::unique_ptr<IRRewrite> > mlir::detail::ConversionPatternRewriterImpl::rewrites

Ordered list of block operations (creations, splits, motions).

Definition at line 978 of file DialectConversion.cpp.

Referenced by applyRewrites(), computeNecessaryMaterializations(), getCurrentState(), and undoRewrites().


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