MLIR
17.0.0git
|
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/FunctionInterfaces.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/Rewrite/PatternApplicator.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/ScopedPrinter.h"
Go to the source code of this file.
Classes | |
struct | mlir::detail::ConversionPatternRewriterImpl |
Namespaces | |
mlir | |
Include the generated interface declarations. | |
mlir::detail | |
Detect if any of the given parameter types has a sub-element handler. | |
Macros | |
#define | DEBUG_TYPE "dialect-conversion" |
Functions | |
static LogicalResult | computeConversionSet (iterator_range< Region::iterator > region, Location regionLoc, SmallVectorImpl< Operation * > &toConvert, ConversionTarget *target=nullptr) |
Recursively collect all of the operations to convert from within 'region'. More... | |
template<typename... Args> | |
static void | logSuccess (llvm::ScopedPrinter &os, StringRef fmt, Args &&...args) |
A utility function to log a successful result for the given reason. More... | |
template<typename... Args> | |
static void | logFailure (llvm::ScopedPrinter &os, StringRef fmt, Args &&...args) |
A utility function to log a failure result for the given reason. More... | |
static Value | buildUnresolvedMaterialization (UnresolvedMaterialization::Kind kind, Block *insertBlock, Block::iterator insertPt, Location loc, ValueRange inputs, Type outputType, Type origOutputType, TypeConverter *converter, SmallVectorImpl< UnresolvedMaterialization > &unresolvedMaterializations) |
Build an unresolved materialization operation given an output type and set of input operands. More... | |
static Value | buildUnresolvedArgumentMaterialization (PatternRewriter &rewriter, Location loc, ValueRange inputs, Type origOutputType, Type outputType, TypeConverter *converter, SmallVectorImpl< UnresolvedMaterialization > &unresolvedMaterializations) |
static Value | buildUnresolvedTargetMaterialization (Location loc, Value input, Type outputType, TypeConverter *converter, SmallVectorImpl< UnresolvedMaterialization > &unresolvedMaterializations) |
static void | detachNestedAndErase (Operation *op) |
Detach any operations nested in the given operation from their parent blocks, and erase the given operation. More... | |
static void | replaceMaterialization (ConversionPatternRewriterImpl &rewriterImpl, ResultRange matResults, ValueRange values, DenseMap< Value, SmallVector< Value >> &inverseMapping) |
Replace the results of a materialization operation with the given values. More... | |
static void | computeNecessaryMaterializations (DenseMap< Operation *, UnresolvedMaterialization * > &materializationOps, ConversionPatternRewriter &rewriter, ConversionPatternRewriterImpl &rewriterImpl, DenseMap< Value, SmallVector< Value >> &inverseMapping, SetVector< UnresolvedMaterialization * > &necessaryMaterializations) |
Compute all of the unresolved materializations that will persist beyond the conversion process, and require inserting a proper user materialization for. More... | |
static LogicalResult | legalizeUnresolvedMaterialization (UnresolvedMaterialization &mat, DenseMap< Operation *, UnresolvedMaterialization * > &materializationOps, ConversionPatternRewriter &rewriter, ConversionPatternRewriterImpl &rewriterImpl, DenseMap< Value, SmallVector< Value >> &inverseMapping) |
Legalize the given unresolved materialization. More... | |
static Operation * | findLiveUserOfReplaced (Value initialValue, ConversionPatternRewriterImpl &rewriterImpl, const DenseMap< Value, SmallVector< Value >> &inverseMapping) |
Finds a user of the given value, or of any other value that the given value replaced, that was not replaced in the conversion process. More... | |
static LogicalResult | convertFuncOpTypes (FunctionOpInterface funcOp, TypeConverter &typeConverter, ConversionPatternRewriter &rewriter) |
static ConversionTarget::DynamicLegalityCallbackFn | composeLegalityCallbacks (ConversionTarget::DynamicLegalityCallbackFn oldCallback, ConversionTarget::DynamicLegalityCallbackFn newCallback) |
static FailureOr< SmallVector< Value > > | pdllConvertValues (ConversionPatternRewriter &rewriter, ValueRange values) |
Remap the given value using the rewriter and the type converter in the provided config. More... | |
#define DEBUG_TYPE "dialect-conversion" |
Definition at line 27 of file DialectConversion.cpp.
|
static |
Definition at line 433 of file DialectConversion.cpp.
References buildUnresolvedMaterialization(), mlir::OpBuilder::getInsertionBlock(), and mlir::OpBuilder::getInsertionPoint().
|
static |
Build an unresolved materialization operation given an output type and set of input operands.
Definition at line 415 of file DialectConversion.cpp.
References mlir::OpBuilder::create(), and mlir::ValueRange::getType().
Referenced by buildUnresolvedArgumentMaterialization(), and buildUnresolvedTargetMaterialization().
|
static |
Definition at line 442 of file DialectConversion.cpp.
References mlir::Block::begin(), buildUnresolvedMaterialization(), mlir::Value::dyn_cast(), and mlir::Value::getParentBlock().
Referenced by mlir::detail::ConversionPatternRewriterImpl::remapValues().
|
static |
Definition at line 3198 of file DialectConversion.cpp.
Referenced by mlir::ConversionTarget::markOpRecursivelyLegal().
|
static |
Recursively collect all of the operations to convert from within 'region'.
If 'target' is nonnull, operations that are recursively legal have their regions pre-filtered to avoid considering them for legalization.
Definition at line 33 of file DialectConversion.cpp.
References mlir::emitError(), mlir::failed(), mlir::failure(), mlir::Block::getSuccessors(), and mlir::success().
Referenced by mlir::detail::ConversionPatternRewriterImpl::notifyRegionWasClonedBefore().
|
static |
Compute all of the unresolved materializations that will persist beyond the conversion process, and require inserting a proper user materialization for.
Definition at line 2575 of file DialectConversion.cpp.
References mlir::Value::getDefiningOp(), mlir::Value::getType(), mlir::OperandRange::getTypes(), mlir::Value::getUsers(), mlir::detail::ConversionPatternRewriterImpl::isOpIgnored(), mlir::detail::ConversionPatternRewriterImpl::mapping, replaceMaterialization(), mlir::detail::ConversionPatternRewriterImpl::unresolvedMaterializations, and mlir::Value::user_end().
|
static |
Definition at line 3060 of file DialectConversion.cpp.
References mlir::ConversionPatternRewriter::convertRegionTypes(), mlir::TypeConverter::convertSignatureArgs(), mlir::TypeConverter::convertTypes(), mlir::failed(), mlir::failure(), mlir::Builder::getContext(), mlir::success(), and mlir::RewriterBase::updateRootInPlace().
|
static |
Detach any operations nested in the given operation from their parent blocks, and erase the given operation.
This can be used when the nested operations are scheduled for erasure themselves, so deleting the regions of the given operation together with their content would result in double-free. This happens, for example, when rolling back op creation in the reverse order and if the nested ops were created before the parent op. This function does not need to collect nested ops recursively because it is expected to also be called for each nested op when it is about to be deleted.
Definition at line 1037 of file DialectConversion.cpp.
References mlir::Block::dropAllDefinedValueUses(), mlir::Operation::dropAllUses(), mlir::Operation::erase(), mlir::Region::getBlocks(), mlir::Block::getOperations(), and mlir::Operation::getRegions().
Referenced by mlir::detail::ConversionPatternRewriterImpl::discardRewrites(), and mlir::detail::ConversionPatternRewriterImpl::resetState().
|
static |
Finds a user of the given value, or of any other value that the given value replaced, that was not replaced in the conversion process.
Definition at line 2852 of file DialectConversion.cpp.
References mlir::Value::getUsers(), and mlir::Value::user_end().
|
static |
Legalize the given unresolved materialization.
Returns success if the materialization was legalized, failure otherise.
Definition at line 2693 of file DialectConversion.cpp.
References diag(), mlir::failed(), mlir::failure(), mlir::Value::getDefiningOp(), mlir::Operation::getLoc(), mlir::Value::getType(), mlir::OperandRange::getTypes(), mlir::detail::ConversionPatternRewriterImpl::ignoredOps, mlir::detail::ConversionPatternRewriterImpl::isOpIgnored(), mlir::detail::ConversionPatternRewriterImpl::mapping, mlir::TypeConverter::materializeArgumentConversion(), mlir::TypeConverter::materializeTargetConversion(), replaceMaterialization(), mlir::OpBuilder::setInsertionPoint(), mlir::OpBuilder::setInsertionPointAfterValue(), and mlir::success().
|
static |
A utility function to log a failure result for the given reason.
Definition at line 93 of file DialectConversion.cpp.
|
static |
A utility function to log a successful result for the given reason.
Definition at line 80 of file DialectConversion.cpp.
|
static |
Remap the given value using the rewriter and the type converter in the provided config.
Definition at line 3295 of file DialectConversion.cpp.
References mlir::failed(), mlir::failure(), and mlir::ConversionPatternRewriter::getRemappedValues().
Referenced by mlir::registerConversionPDLFunctions().
|
static |
Replace the results of a materialization operation with the given values.
Definition at line 2549 of file DialectConversion.cpp.
References mlir::detail::ConversionPatternRewriterImpl::mapping, and mlir::ResultRange::replaceAllUsesWith().
Referenced by computeNecessaryMaterializations(), and legalizeUnresolvedMaterialization().