MLIR
22.0.0git
|
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Config/mlir-config.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Iterators.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Rewrite/PatternApplicator.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/ScopedPrinter.h"
#include <optional>
Go to the source code of this file.
Classes | |
struct | mlir::detail::ConversionPatternRewriterImpl |
struct | mlir::detail::ConversionPatternRewriterImpl::SingleEraseRewriter |
A rewriter that keeps track of erased ops and blocks. More... | |
struct | mlir::OperationConverter |
class | ApplyConversionAction |
This is the type of Action that is dispatched when a conversion is applied. More... | |
Namespaces | |
mlir | |
Include the generated interface declarations. | |
mlir::detail | |
AttrTypeReplacer. | |
Macros | |
#define | DEBUG_TYPE "dialect-conversion" |
Typedefs | |
using | ValueVector = SmallVector< Value, 1 > |
A vector of SSA values, optimized for the most common case of a single value. More... | |
Functions | |
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 OpBuilder::InsertPoint | computeInsertPoint (Value value) |
Helper function that computes an insertion point where the given value is defined and can be used without a dominance violation. More... | |
static OpBuilder::InsertPoint | computeInsertPoint (ArrayRef< Value > vals) |
Helper function that computes an insertion point where the given values are defined and can be used without a dominance violation. More... | |
static Operation * | getCommonDefiningOp (const ValueVector &values) |
Return the operation that defines all values in the vector. More... | |
static bool | isPureTypeConversion (const ValueVector &values) |
A vector of values is a pure type conversion if all values are defined by the same operation and the operation has the kPureTypeConversionMarker attribute. More... | |
static void | performReplaceValue (RewriterBase &rewriter, Value from, Value repl) |
Replace all uses of from with repl . More... | |
static SmallVector< Value > | getReplacementValues (ConversionPatternRewriterImpl &impl, ValueRange fromRange, const SmallVector< SmallVector< Value >> &toRange, const TypeConverter *converter) |
Given that fromRange is about to be replaced with toRange , compute replacement values with the types of fromRange . More... | |
template<typename T > | |
static T | moveAndReset (T &obj) |
Helper function that moves and returns the given object. More... | |
static void | reportNewIrLegalizationFatalError (const Pattern &pattern, const SetVector< Operation * > &newOps, const SetVector< Operation * > &modifiedOps, const SetVector< Block * > &insertedBlocks) |
Report a fatal error indicating that newly produced or modified IR could not be legalized. More... | |
template<typename RangeT > | |
static void | reconcileUnrealizedCastsImpl (RangeT castOps, function_ref< bool(UnrealizedConversionCastOp)> isCastOpOfInterestFn, SmallVectorImpl< UnrealizedConversionCastOp > *remainingCastOps) |
Try to reconcile all given UnrealizedConversionCastOps and store the left-over ops in remainingCastOps (if provided). More... | |
static void | mlir::reconcileUnrealizedCasts (const DenseMap< UnrealizedConversionCastOp, UnresolvedMaterializationInfo > &castOps, SmallVectorImpl< UnrealizedConversionCastOp > *remainingCastOps) |
static LogicalResult | legalizeUnresolvedMaterialization (RewriterBase &rewriter, UnrealizedConversionCastOp op, const UnresolvedMaterializationInfo &info) |
static LogicalResult | convertFuncOpTypes (FunctionOpInterface funcOp, const 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... | |
static LogicalResult | applyConversion (ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config, OpConversionMode mode) |
static Operation * | findCommonAncestor (ArrayRef< Operation * > ops) |
Find a common IsolatedFromAbove ancestor of the given ops. More... | |
Variables | |
static const StringRef | kPureTypeConversionMarker = "__pure_type_conversion__" |
Marker attribute for pure type conversions. More... | |
#define DEBUG_TYPE "dialect-conversion" |
Definition at line 32 of file DialectConversion.cpp.
using ValueVector = SmallVector<Value, 1> |
A vector of SSA values, optimized for the most common case of a single value.
Definition at line 101 of file DialectConversion.cpp.
|
static |
Definition at line 4093 of file DialectConversion.cpp.
References mlir::config, mlir::OperationConverter::convertOperations(), mlir::MLIRContext::executeAction(), and mlir::patterns.
Referenced by mlir::applyAnalysisConversion(), mlir::applyFullConversion(), and mlir::applyPartialConversion().
|
static |
Definition at line 3925 of file DialectConversion.cpp.
Referenced by mlir::ConversionTarget::markOpRecursivelyLegal().
|
static |
Helper function that computes an insertion point where the given values are defined and can be used without a dominance violation.
Definition at line 70 of file DialectConversion.cpp.
References computeInsertPoint(), mlir::DominanceInfo::dominates(), mlir::OpBuilder::InsertPoint::getBlock(), and mlir::OpBuilder::InsertPoint::getPoint().
|
static |
Helper function that computes an insertion point where the given value is defined and can be used without a dominance violation.
Definition at line 60 of file DialectConversion.cpp.
References mlir::Block::begin(), and mlir::Value::getParentBlock().
Referenced by computeInsertPoint(), mlir::detail::ConversionPatternRewriterImpl::findOrBuildReplacementValue(), getReplacementValues(), and mlir::detail::ConversionPatternRewriterImpl::remapValues().
|
static |
Definition at line 3762 of file DialectConversion.cpp.
References mlir::ConversionPatternRewriter::convertRegionTypes(), mlir::TypeConverter::convertSignatureArgs(), mlir::TypeConverter::convertTypes(), mlir::remark::failed(), mlir::get(), mlir::Builder::getContext(), mlir::TypeConverter::SignatureConversion::getConvertedTypes(), and mlir::RewriterBase::modifyOpInPlace().
Find a common IsolatedFromAbove ancestor of the given ops.
If at least one op is a top-level module op (which is expected to be isolated from above), return that op.
Definition at line 4154 of file DialectConversion.cpp.
References mlir::Operation::getParentOp(), mlir::Operation::getParentWithTrait(), mlir::Operation::hasTrait(), mlir::Operation::isAncestor(), and mlir::Operation::isProperAncestor().
Referenced by mlir::applyAnalysisConversion().
|
static |
Return the operation that defines all values in the vector.
Return nullptr if the values are not defined by the same operation.
Definition at line 187 of file DialectConversion.cpp.
Referenced by mlir::transform::TrackingListener::findReplacementOp(), isPureTypeConversion(), and mlir::detail::ConversionPatternRewriterImpl::lookupOrDefault().
|
static |
Given that fromRange
is about to be replaced with toRange
, compute replacement values with the types of fromRange
.
Definition at line 1809 of file DialectConversion.cpp.
References computeInsertPoint(), mlir::Value::getLoc(), mlir::Value::getType(), and mlir::Value::use_empty().
Referenced by mlir::detail::ConversionPatternRewriterImpl::replaceAllUsesWith(), and mlir::detail::ConversionPatternRewriterImpl::replaceOp().
|
static |
A vector of values is a pure type conversion if all values are defined by the same operation and the operation has the kPureTypeConversionMarker
attribute.
Definition at line 200 of file DialectConversion.cpp.
References getCommonDefiningOp(), mlir::Operation::hasAttr(), and kPureTypeConversionMarker.
Referenced by mlir::detail::ConversionPatternRewriterImpl::buildUnresolvedMaterialization(), and mlir::detail::ConversionPatternRewriterImpl::lookupOrDefault().
|
static |
Definition at line 3316 of file DialectConversion.cpp.
References diag(), mlir::OperandRange::getTypes(), mlir::RewriterBase::replaceOp(), and mlir::OpBuilder::setInsertionPoint().
Referenced by mlir::OperationConverter::convertOperations().
|
static |
A utility function to log a failure result for the given reason.
Definition at line 49 of file DialectConversion.cpp.
|
static |
A utility function to log a successful result for the given reason.
Definition at line 36 of file DialectConversion.cpp.
|
static |
Helper function that moves and returns the given object.
Also resets the original object, so that it is in a valid, empty state again.
Definition at line 2563 of file DialectConversion.cpp.
|
static |
Remap the given value using the rewriter and the type converter in the provided config.
Definition at line 4023 of file DialectConversion.cpp.
References mlir::remark::failed(), and mlir::ConversionPatternRewriter::getRemappedValues().
Referenced by mlir::registerConversionPDLFunctions().
|
static |
Replace all uses of from
with repl
.
Definition at line 1189 of file DialectConversion.cpp.
References mlir::Operation::getBlock(), mlir::Value::getDefiningOp(), mlir::detail::IROperandBase::getOwner(), mlir::Operation::isBeforeInBlock(), mlir::RewriterBase::replaceAllUsesWith(), and mlir::RewriterBase::replaceUsesWithIf().
Referenced by mlir::detail::ConversionPatternRewriterImpl::replaceAllUsesWith().
|
static |
Try to reconcile all given UnrealizedConversionCastOps and store the left-over ops in remainingCastOps
(if provided).
See documentation in DialectConversion.h for more details. The isCastOpOfInterestFn
is used to filter the cast ops to proceed: the algorithm may visit an operand (or user) which is a cast op, but will not try to reconcile it if not in the filtered set.
Definition at line 3100 of file DialectConversion.cpp.
References mlir::Operation::getOperands().
Referenced by mlir::reconcileUnrealizedCasts().
|
static |
Report a fatal error indicating that newly produced or modified IR could not be legalized.
Definition at line 2633 of file DialectConversion.cpp.
References mlir::Pattern::getDebugName(), mlir::Operation::getName(), mlir::Block::getParentOp(), and mlir::OperationName::getStringRef().
|
static |
Marker attribute for pure type conversions.
I.e., mappings whose only purpose is to resolve a type mismatch. (In contrast, mappings that point to the replacement values of a "replaceOp" call, etc., are not pure type conversions.)
Definition at line 183 of file DialectConversion.cpp.
Referenced by mlir::detail::ConversionPatternRewriterImpl::buildUnresolvedMaterialization(), mlir::OperationConverter::convertOperations(), and isPureTypeConversion().