MLIR
20.0.0git
|
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, SmallVector< SmallVector< 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 * > | convertRegionTypes (ConversionPatternRewriter &rewriter, Region *region, const TypeConverter &converter, TypeConverter::SignatureConversion *entryConversion) |
Convert the types of block arguments within the given region. More... | |
Block * | applySignatureConversion (ConversionPatternRewriter &rewriter, Block *block, const TypeConverter *converter, TypeConverter::SignatureConversion &signatureConversion) |
Apply the given signature conversion on the given block. More... | |
ValueRange | buildUnresolvedMaterialization (MaterializationKind kind, OpBuilder::InsertPoint ip, Location loc, Value valueToMap, ValueRange inputs, TypeRange outputTypes, Type originalType, const TypeConverter *converter, UnrealizedConversionCastOp *castOp=nullptr) |
Build an unresolved materialization operation given a range of output types and a list of input operands. More... | |
Value | buildUnresolvedMaterialization (MaterializationKind kind, OpBuilder::InsertPoint ip, Location loc, Value valueToMap, ValueRange inputs, Type outputType, Type originalType, const TypeConverter *converter, UnrealizedConversionCastOp *castOp=nullptr) |
void | insertNTo1Materialization (OpBuilder::InsertPoint ip, Location loc, ValueRange replacements, Value originalValue, const TypeConverter *converter) |
Build an N:1 materialization for the given original value that was replaced with the given replacement values. More... | |
Value | findOrBuildReplacementValue (Value value, const TypeConverter *converter) |
Find a replacement value for the given SSA value in the conversion value mapping. More... | |
SmallVector< Value > | unpackNTo1Materialization (Value value) |
Unpack an N:1 materialization and return the inputs of the materialization. More... | |
void | notifyOperationInserted (Operation *op, OpBuilder::InsertPoint previous) override |
Notify the listener that the specified operation was inserted. More... | |
void | notifyOpReplaced (Operation *op, ArrayRef< 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 | |
MLIRContext * | context |
MLIR context. More... | |
SingleEraseRewriter | eraseRewriter |
A rewriter that keeps track of ops/block that were already erased and skips duplicate op/block erasures. 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... | |
DenseMap< UnrealizedConversionCastOp, UnresolvedMaterializationRewrite * > | unresolvedMaterializations |
A mapping of all unresolved materializations (UnrealizedConversionCastOp) to the corresponding rewrite objects. More... | |
DenseSet< UnrealizedConversionCastOp > | nTo1TempMaterializations |
A set of all N:1 materializations that were added to work around incomplete 1:N support in the dialect conversion driver. More... | |
const TypeConverter * | currentTypeConverter = 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 ConversionConfig & | config |
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) | |
Definition at line 744 of file DialectConversion.cpp.
|
inlineexplicit |
Definition at line 745 of file DialectConversion.cpp.
|
inline |
Append a rewrite.
Rewrites are committed upon success and rolled back upon failure.
Definition at line 766 of file DialectConversion.cpp.
void ConversionPatternRewriterImpl::applyRewrites | ( | ) |
Apply all requested operation rewrites.
This method is invoked when the conversion process succeeds.
Definition at line 1121 of file DialectConversion.cpp.
References config, context, eraseRewriter, mlir::ConversionConfig::listener, rewrite(), and rewrites.
Referenced by mlir::OperationConverter::convertOperations().
Block * ConversionPatternRewriterImpl::applySignatureConversion | ( | ConversionPatternRewriter & | rewriter, |
Block * | block, | ||
const TypeConverter * | converter, | ||
TypeConverter::SignatureConversion & | signatureConversion | ||
) |
Apply the given signature conversion on the given block.
The new block containing the updated signature is returned. If no conversions were necessary, e.g. if the block has no arguments, block
is returned. converter
is used to generate any necessary cast operations that translate between the origin argument types and those specified in the signature conversion.
Definition at line 1290 of file DialectConversion.cpp.
References mlir::Block::begin(), buildUnresolvedMaterialization(), config, mlir::OpBuilder::createBlock(), mlir::Block::empty(), mlir::Block::end(), mlir::ConversionPatternRewriter::eraseBlock(), mlir::Block::front(), mlir::Block::getArgument(), mlir::Block::getArguments(), mlir::Block::getArgumentTypes(), mlir::TypeConverter::SignatureConversion::getConvertedTypes(), mlir::TypeConverter::SignatureConversion::getInputMapping(), mlir::BlockArgument::getLoc(), mlir::Block::getNumArguments(), mlir::Block::getOperations(), mlir::Block::getParent(), mlir::Value::getType(), mlir::Builder::getUnknownLoc(), insertNTo1Materialization(), mlir::ConversionConfig::listener, mapping, mlir::RewriterBase::moveOpBefore(), mlir::IRObjectWithUseList< OperandType >::replaceAllUsesWith(), and rewrites.
Referenced by convertRegionTypes().
|
inline |
Definition at line 831 of file DialectConversion.cpp.
ValueRange ConversionPatternRewriterImpl::buildUnresolvedMaterialization | ( | MaterializationKind | kind, |
OpBuilder::InsertPoint | ip, | ||
Location | loc, | ||
Value | valueToMap, | ||
ValueRange | inputs, | ||
TypeRange | outputTypes, | ||
Type | originalType, | ||
const TypeConverter * | converter, | ||
UnrealizedConversionCastOp * | castOp = nullptr |
||
) |
Build an unresolved materialization operation given a range of output types and a list of input operands.
Build an unresolved materialization operation given an output type and set of input operands.
Returns the inputs if they their types match the output types.
If a cast op was built, it can optionally be returned with the castOp
output argument.
If valueToMap
is set to a non-null Value, then that value is mapped to the results of the unresolved materialization in the conversion value mapping.
Definition at line 1403 of file DialectConversion.cpp.
References mlir::OpBuilder::create(), mlir::OpBuilder::InsertPoint::getBlock(), mlir::OpBuilder::InsertPoint::getPoint(), mapping, and mlir::OpBuilder::setInsertionPoint().
Referenced by applySignatureConversion(), findOrBuildReplacementValue(), insertNTo1Materialization(), notifyOpReplaced(), and remapValues().
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 1257 of file DialectConversion.cpp.
References applySignatureConversion(), mlir::TypeConverter::convertBlockSignature(), mlir::Region::empty(), mlir::Region::front(), and regionToConverter.
Value ConversionPatternRewriterImpl::findOrBuildReplacementValue | ( | Value | value, |
const TypeConverter * | converter | ||
) |
Find a replacement value for the given SSA value in the conversion value mapping.
The replacement value must have the same type as the given SSA value. If there is no replacement value with the correct type, find the latest replacement value (regardless of the type) and build a source materialization.
Definition at line 1451 of file DialectConversion.cpp.
References buildUnresolvedMaterialization(), computeInsertPoint(), mlir::Value::getLoc(), mlir::Value::getType(), mlir::Value::getUsers(), and mapping.
RewriterState ConversionPatternRewriterImpl::getCurrentState | ( | ) |
Return the current state of the rewriter.
Definition at line 1137 of file DialectConversion.cpp.
References ignoredOps, replacedOps, and rewrites.
void ConversionPatternRewriterImpl::insertNTo1Materialization | ( | OpBuilder::InsertPoint | ip, |
Location | loc, | ||
ValueRange | replacements, | ||
Value | originalValue, | ||
const TypeConverter * | converter | ||
) |
Build an N:1 materialization for the given original value that was replaced with the given replacement values.
This is a workaround around incomplete 1:N support in the dialect conversion driver. The conversion mapping can store only 1:1 replacements and the conversion patterns only support single Value replacements in the adaptor, so N values must be converted back to a single value. This function will be deleted when full 1:N support has been added.
This function inserts an argument materialization back to the original type.
Definition at line 1437 of file DialectConversion.cpp.
References buildUnresolvedMaterialization(), mlir::Value::getType(), and nTo1TempMaterializations.
Referenced by applySignatureConversion(), and notifyOpReplaced().
bool ConversionPatternRewriterImpl::isOpIgnored | ( | Operation * | op | ) | const |
Return "true" if the given operation is ignored, and does not need to be converted.
Definition at line 1244 of file DialectConversion.cpp.
References ignoredOps, and replacedOps.
void ConversionPatternRewriterImpl::notifyBlockBeingInlined | ( | Block * | block, |
Block * | srcBlock, | ||
Block::iterator | before | ||
) |
Notifies that a block is being inlined into another block.
Definition at line 1621 of file DialectConversion.cpp.
|
overridevirtual |
Notifies that a block was inserted.
Reimplemented from mlir::OpBuilder::Listener.
Definition at line 1596 of file DialectConversion.cpp.
References mlir::Region::end(), mlir::Operation::getName(), mlir::Block::getParentOp(), logger, and wasOpReplaced().
void ConversionPatternRewriterImpl::notifyBlockIsBeingErased | ( | Block * | block | ) |
Notifies that a block is about to be erased.
Definition at line 1592 of file DialectConversion.cpp.
|
overridevirtual |
Notifies that a pattern match failed for the given reason.
Reimplemented from mlir::RewriterBase::Listener.
Definition at line 1626 of file DialectConversion.cpp.
References config, diag(), logger, mlir::ConversionConfig::notifyCallback, and mlir::Remark.
Referenced by remapValues().
|
overridevirtual |
Notify the listener that the specified operation was inserted.
previous
is the previous location of the op.previous
is empty.Note: Creating an (unlinked) op does not trigger this notification.
Reimplemented from mlir::OpBuilder::Listener.
Definition at line 1512 of file DialectConversion.cpp.
References mlir::Block::end(), mlir::OpBuilder::InsertPoint::getBlock(), mlir::Operation::getName(), mlir::Operation::getParentOp(), mlir::OpBuilder::InsertPoint::getPoint(), mlir::OpBuilder::InsertPoint::isSet(), logger, and wasOpReplaced().
void ConversionPatternRewriterImpl::notifyOpReplaced | ( | Operation * | op, |
ArrayRef< ValueRange > | newValues | ||
) |
Notifies that an op is about to be replaced with the given values.
Definition at line 1532 of file DialectConversion.cpp.
References buildUnresolvedMaterialization(), computeInsertPoint(), currentTypeConverter, mlir::Value::getLoc(), mlir::Operation::getNumResults(), mlir::Operation::getResults(), mlir::Value::getType(), ignoredOps, insertNTo1Materialization(), mapping, replacedOps, unresolvedMaterializations, and mlir::Operation::walk().
LogicalResult ConversionPatternRewriterImpl::remapValues | ( | StringRef | valueDiagTag, |
std::optional< Location > | inputLoc, | ||
PatternRewriter & | rewriter, | ||
ValueRange | values, | ||
SmallVector< SmallVector< 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 1160 of file DialectConversion.cpp.
References buildUnresolvedMaterialization(), computeInsertPoint(), mlir::TypeConverter::convertType(), currentTypeConverter, diag(), mlir::detail::enumerate(), mlir::Value::getLoc(), mlir::Value::getType(), mapping, notifyMatchFailure(), and unpackNTo1Materialization().
Referenced by mlir::ConversionPattern::matchAndRewrite().
void ConversionPatternRewriterImpl::resetState | ( | RewriterState | state | ) |
Reset the state of the rewriter to a previously saved point.
Definition at line 1141 of file DialectConversion.cpp.
void ConversionPatternRewriterImpl::undoRewrites | ( | unsigned | numRewritesToKeep = 0 | ) |
Undo the rewrites (motions, splits) one by one in reverse order until "numRewritesToKeep" rewrites remains.
Definition at line 1153 of file DialectConversion.cpp.
References rewrite(), and rewrites.
Referenced by mlir::OperationConverter::convertOperations().
SmallVector< Value > ConversionPatternRewriterImpl::unpackNTo1Materialization | ( | Value | value | ) |
Unpack an N:1 materialization and return the inputs of the materialization.
This function unpacks only those materializations that were built with insertNTo1Materialization
.
This is a workaround around incomplete 1:N support in the dialect conversion driver. It allows us to write 1:N conversion patterns while 1:N support is still missing in the conversion value mapping. This function will be deleted when full 1:N support has been added.
Definition at line 1488 of file DialectConversion.cpp.
References mlir::Value::getDefiningOp(), and nTo1TempMaterializations.
Referenced by remapValues().
bool ConversionPatternRewriterImpl::wasOpReplaced | ( | Operation * | op | ) | const |
Return "true" if the given operation was replaced or erased.
Definition at line 1249 of file DialectConversion.cpp.
References replacedOps.
Referenced by notifyBlockInserted(), and notifyOperationInserted().
const ConversionConfig& mlir::detail::ConversionPatternRewriterImpl::config |
Dialect conversion configuration.
Definition at line 990 of file DialectConversion.cpp.
Referenced by applyRewrites(), applySignatureConversion(), and notifyMatchFailure().
MLIRContext* mlir::detail::ConversionPatternRewriterImpl::context |
MLIR context.
Definition at line 947 of file DialectConversion.cpp.
Referenced by applyRewrites(), and mlir::OperationConverter::convertOperations().
const TypeConverter* mlir::detail::ConversionPatternRewriterImpl::currentTypeConverter = nullptr |
The current type converter, or nullptr if no type converter is currently active.
Definition at line 983 of file DialectConversion.cpp.
Referenced by mlir::ConversionPattern::matchAndRewrite(), notifyOpReplaced(), mlir::PDLConversionConfig::notifyRewriteBegin(), mlir::PDLConversionConfig::notifyRewriteEnd(), mlir::registerConversionPDLFunctions(), and remapValues().
SingleEraseRewriter mlir::detail::ConversionPatternRewriterImpl::eraseRewriter |
A rewriter that keeps track of ops/block that were already erased and skips duplicate op/block erasures.
This rewriter is used during the "cleanup" phase.
Definition at line 952 of file DialectConversion.cpp.
Referenced by applyRewrites(), and mlir::OperationConverter::convertOperations().
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 964 of file DialectConversion.cpp.
Referenced by getCurrentState(), isOpIgnored(), and notifyOpReplaced().
llvm::ScopedPrinter mlir::detail::ConversionPatternRewriterImpl::logger {llvm::dbgs()} |
A logger used to emit diagnostics during the conversion process.
Definition at line 999 of file DialectConversion.cpp.
Referenced by notifyBlockInserted(), notifyMatchFailure(), and notifyOperationInserted().
ConversionValueMapping mlir::detail::ConversionPatternRewriterImpl::mapping |
Definition at line 956 of file DialectConversion.cpp.
Referenced by applySignatureConversion(), buildUnresolvedMaterialization(), findOrBuildReplacementValue(), notifyOpReplaced(), and remapValues().
DenseSet<UnrealizedConversionCastOp> mlir::detail::ConversionPatternRewriterImpl::nTo1TempMaterializations |
A set of all N:1 materializations that were added to work around incomplete 1:N support in the dialect conversion driver.
Definition at line 979 of file DialectConversion.cpp.
Referenced by insertNTo1Materialization(), and unpackNTo1Materialization().
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 996 of file DialectConversion.cpp.
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 987 of file DialectConversion.cpp.
Referenced by convertRegionTypes().
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 970 of file DialectConversion.cpp.
Referenced by getCurrentState(), isOpIgnored(), notifyOpReplaced(), and wasOpReplaced().
SmallVector<std::unique_ptr<IRRewrite> > mlir::detail::ConversionPatternRewriterImpl::rewrites |
Ordered list of block operations (creations, splits, motions).
Definition at line 959 of file DialectConversion.cpp.
Referenced by applyRewrites(), applySignatureConversion(), getCurrentState(), and undoRewrites().
DenseMap<UnrealizedConversionCastOp, UnresolvedMaterializationRewrite *> mlir::detail::ConversionPatternRewriterImpl::unresolvedMaterializations |
A mapping of all unresolved materializations (UnrealizedConversionCastOp) to the corresponding rewrite objects.
Definition at line 975 of file DialectConversion.cpp.
Referenced by mlir::OperationConverter::convertOperations(), and notifyOpReplaced().