MLIR  18.0.0git
Public Member Functions | Public Attributes | List of all members
mlir::detail::ConversionPatternRewriterImpl Struct Reference

Public Member Functions

 ConversionPatternRewriterImpl (PatternRewriter &rewriter)
 
void discardRewrites ()
 Cleanup and destroy any generated rewrite operations. More...
 
void applyRewrites ()
 Apply all requested operation rewrites. More...
 
RewriterState getCurrentState ()
 Return the current state of the rewriter. More...
 
void resetState (RewriterState state)
 Reset the state of the rewriter to a previously saved point. More...
 
void eraseDanglingBlocks ()
 Erase any blocks that were unlinked from their regions and stored in block actions. More...
 
void undoBlockActions (unsigned numActionsToKeep=0)
 Undo the block actions (motions, splits) one by one in reverse order until "numActionsToKeep" actions 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
 Returns true if the given operation is ignored, and does not need to be converted. More...
 
void markNestedOpsIgnored (Operation *op)
 Recursively marks the nested operations under 'op' as ignored. More...
 
FailureOr< Block * > convertBlockSignature (Block *block, const TypeConverter *converter, TypeConverter::SignatureConversion *conversion=nullptr)
 Convert the signature of the given block. More...
 
BlockapplySignatureConversion (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 (Region *region, const TypeConverter &converter, TypeConverter::SignatureConversion *entryConversion)
 Convert the types of block arguments within the given region. More...
 
LogicalResult convertNonEntryRegionTypes (Region *region, const TypeConverter &converter, ArrayRef< TypeConverter::SignatureConversion > blockConversions={})
 Convert the types of non-entry block arguments within the given region. More...
 
void notifyOpReplaced (Operation *op, ValueRange newValues)
 PatternRewriter hook for replacing the results of an operation. More...
 
void notifyBlockIsBeingErased (Block *block)
 Notifies that a block is about to be erased. More...
 
void notifyCreatedBlock (Block *block)
 Notifies that a block was created. More...
 
void notifySplitBlock (Block *block, Block *continuation)
 Notifies that a block was split. More...
 
void notifyBlockBeingInlined (Block *block, Block *srcBlock, Block::iterator before)
 Notifies that a block is being inlined into another block. More...
 
void notifyRegionIsBeingInlinedBefore (Region &region, Region &parent, Region::iterator before)
 Notifies that the blocks of a region are about to be moved. More...
 
LogicalResult notifyMatchFailure (Location loc, function_ref< void(Diagnostic &)> reasonCallback)
 Notifies that a pattern match failed for the given reason. More...
 

Public Attributes

ConversionValueMapping mapping
 
ArgConverter argConverter
 Utility used to convert block arguments. More...
 
SmallVector< Operation * > createdOps
 Ordered vector of all of the newly created operations during conversion. More...
 
SmallVector< UnresolvedMaterialization > unresolvedMaterializations
 Ordered vector of all unresolved type conversion materializations during conversion. More...
 
llvm::MapVector< Operation *, OpReplacement > replacements
 Ordered map of requested operation replacements. More...
 
SmallVector< BlockArgument, 4 > argReplacements
 Ordered vector of any requested block argument replacements. More...
 
SmallVector< BlockAction, 4 > blockActions
 Ordered list of block operations (creations, splits, motions). More...
 
SetVector< Operation * > ignoredOps
 A set of operations that should no longer be considered for legalization, but were not directly replace/erased/etc. More...
 
SmallVector< OperationTransactionState, 4 > rootUpdates
 A transaction state for each of operations that were updated in-place. More...
 
SmallVector< unsigned, 4 > operationsWithChangedResults
 A vector of indices into replacements of operations that were replaced with values with different result types than the original operation, e.g. More...
 
const TypeConvertercurrentTypeConverter = nullptr
 The current type converter, or nullptr if no type converter is currently active. More...
 
function_ref< void(Diagnostic &)> notifyCallback
 This allows the user to collect the match failure message. 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...
 

Detailed Description

Definition at line 827 of file DialectConversion.cpp.

Constructor & Destructor Documentation

◆ ConversionPatternRewriterImpl()

mlir::detail::ConversionPatternRewriterImpl::ConversionPatternRewriterImpl ( PatternRewriter rewriter)
inlineexplicit

Definition at line 828 of file DialectConversion.cpp.

Member Function Documentation

◆ applyRewrites()

void ConversionPatternRewriterImpl::applyRewrites ( )

◆ applySignatureConversion()

Block * ConversionPatternRewriterImpl::applySignatureConversion ( 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().

◆ convertBlockSignature()

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

Convert the signature of the given block.

Definition at line 1298 of file DialectConversion.cpp.

References argConverter, argReplacements, blockActions, mlir::failed(), mlir::failure(), and mapping.

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

◆ convertNonEntryRegionTypes()

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

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

Definition at line 1338 of file DialectConversion.cpp.

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

Referenced by convertRegionTypes().

◆ convertRegionTypes()

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

Convert the types of block arguments within the given region.

Definition at line 1323 of file DialectConversion.cpp.

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

◆ discardRewrites()

void ConversionPatternRewriterImpl::discardRewrites ( )

Cleanup and destroy any generated rewrite operations.

This method is invoked when the conversion process fails.

Definition at line 1016 of file DialectConversion.cpp.

◆ eraseDanglingBlocks()

void ConversionPatternRewriterImpl::eraseDanglingBlocks ( )

Erase any blocks that were unlinked from their regions and stored in block actions.

Definition at line 1150 of file DialectConversion.cpp.

References blockActions.

Referenced by applyRewrites().

◆ getCurrentState()

RewriterState ConversionPatternRewriterImpl::getCurrentState ( )

Return the current state of the rewriter.

Definition at line 1091 of file DialectConversion.cpp.

References argReplacements, blockActions, createdOps, ignoredOps, replacements, rootUpdates, and unresolvedMaterializations.

◆ isOpIgnored()

bool ConversionPatternRewriterImpl::isOpIgnored ( Operation op) const

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

Definition at line 1277 of file DialectConversion.cpp.

Referenced by computeNecessaryMaterializations(), and legalizeUnresolvedMaterialization().

◆ markNestedOpsIgnored()

void ConversionPatternRewriterImpl::markNestedOpsIgnored ( Operation op)

Recursively marks the nested operations under 'op' as ignored.

This removes them from being considered for legalization.

Definition at line 1282 of file DialectConversion.cpp.

◆ notifyBlockBeingInlined()

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

Notifies that a block is being inlined into another block.

Definition at line 1413 of file DialectConversion.cpp.

References blockActions.

◆ notifyBlockIsBeingErased()

void ConversionPatternRewriterImpl::notifyBlockIsBeingErased ( Block block)

Notifies that a block is about to be erased.

Definition at line 1398 of file DialectConversion.cpp.

References blockActions, and mlir::Block::getParent().

◆ notifyCreatedBlock()

void ConversionPatternRewriterImpl::notifyCreatedBlock ( Block block)

Notifies that a block was created.

Definition at line 1404 of file DialectConversion.cpp.

References blockActions.

◆ notifyMatchFailure()

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

Notifies that a pattern match failed for the given reason.

Definition at line 1431 of file DialectConversion.cpp.

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

Referenced by remapValues().

◆ notifyOpReplaced()

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

PatternRewriter hook for replacing the results of an operation.

Definition at line 1369 of file DialectConversion.cpp.

◆ notifyRegionIsBeingInlinedBefore()

void ConversionPatternRewriterImpl::notifyRegionIsBeingInlinedBefore ( Region region,
Region parent,
Region::iterator  before 
)

Notifies that the blocks of a region are about to be moved.

Definition at line 1418 of file DialectConversion.cpp.

References mlir::Region::back(), blockActions, and mlir::Region::empty().

◆ notifySplitBlock()

void ConversionPatternRewriterImpl::notifySplitBlock ( Block block,
Block continuation 
)

Notifies that a block was split.

Definition at line 1408 of file DialectConversion.cpp.

References blockActions.

◆ 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 1223 of file DialectConversion.cpp.

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

◆ resetState()

void ConversionPatternRewriterImpl::resetState ( RewriterState  state)

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

Definition at line 1098 of file DialectConversion.cpp.

◆ undoBlockActions()

void ConversionPatternRewriterImpl::undoBlockActions ( unsigned  numActionsToKeep = 0)

Undo the block actions (motions, splits) one by one in reverse order until "numActionsToKeep" actions remains.

Definition at line 1156 of file DialectConversion.cpp.

References argConverter, mlir::Block::begin(), blockActions, mlir::Region::end(), mlir::Region::getBlocks(), and mlir::Block::getOperations().

Member Data Documentation

◆ argConverter

ArgConverter mlir::detail::ConversionPatternRewriterImpl::argConverter

Utility used to convert block arguments.

Definition at line 939 of file DialectConversion.cpp.

Referenced by applyRewrites(), convertBlockSignature(), convertNonEntryRegionTypes(), convertRegionTypes(), and undoBlockActions().

◆ argReplacements

SmallVector<BlockArgument, 4> mlir::detail::ConversionPatternRewriterImpl::argReplacements

Ordered vector of any requested block argument replacements.

Definition at line 952 of file DialectConversion.cpp.

Referenced by applyRewrites(), convertBlockSignature(), and getCurrentState().

◆ blockActions

SmallVector<BlockAction, 4> mlir::detail::ConversionPatternRewriterImpl::blockActions

◆ createdOps

SmallVector<Operation *> mlir::detail::ConversionPatternRewriterImpl::createdOps

Ordered vector of all of the newly created operations during conversion.

Definition at line 942 of file DialectConversion.cpp.

Referenced by getCurrentState().

◆ currentTypeConverter

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

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

Definition at line 978 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, but were not directly replace/erased/etc.

by a pattern. These are generally child operations of other operations who were replaced/erased/etc. This is not meant to be an exhaustive list of all operations, but the minimal set that can be used to detect if a given operation should be ignored. For example, we may add the operations that define non-empty regions to the set, but not any of the others. This simplifies the amount of memory needed as we can query if the parent operation was ignored.

Definition at line 966 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 990 of file DialectConversion.cpp.

Referenced by notifyMatchFailure().

◆ mapping

ConversionValueMapping mlir::detail::ConversionPatternRewriterImpl::mapping

◆ notifyCallback

function_ref<void(Diagnostic &)> mlir::detail::ConversionPatternRewriterImpl::notifyCallback

This allows the user to collect the match failure message.

Definition at line 981 of file DialectConversion.cpp.

Referenced by notifyMatchFailure().

◆ operationsWithChangedResults

SmallVector<unsigned, 4> mlir::detail::ConversionPatternRewriterImpl::operationsWithChangedResults

A vector of indices into replacements of operations that were replaced with values with different result types than the original operation, e.g.

1->N conversion of some kind.

Definition at line 974 of file DialectConversion.cpp.

◆ 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 987 of file DialectConversion.cpp.

◆ replacements

llvm::MapVector<Operation *, OpReplacement> mlir::detail::ConversionPatternRewriterImpl::replacements

Ordered map of requested operation replacements.

Definition at line 949 of file DialectConversion.cpp.

Referenced by applyRewrites(), and getCurrentState().

◆ rootUpdates

SmallVector<OperationTransactionState, 4> mlir::detail::ConversionPatternRewriterImpl::rootUpdates

A transaction state for each of operations that were updated in-place.

Definition at line 969 of file DialectConversion.cpp.

Referenced by getCurrentState().

◆ unresolvedMaterializations

SmallVector<UnresolvedMaterialization> mlir::detail::ConversionPatternRewriterImpl::unresolvedMaterializations

Ordered vector of all unresolved type conversion materializations during conversion.

Definition at line 946 of file DialectConversion.cpp.

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


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