|
MLIR 23.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/ErrorHandling.h"#include "llvm/Support/FormatVariadic.h"#include "llvm/Support/SaveAndRestore.h"#include "llvm/Support/ScopedPrinter.h"#include <optional>#include <utility>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 | |
| namespace | mlir |
| Include the generated interface declarations. | |
| namespace | 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. | |
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. | |
| 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. | |
| 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. | |
| 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. | |
| static Operation * | getCommonDefiningOp (const ValueVector &values) |
| Return the operation that defines all values in the vector. | |
| 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. | |
| static void | performReplaceValue (RewriterBase &rewriter, Value from, Value repl, function_ref< bool(OpOperand &)> functor=nullptr) |
| Replace all uses of from with repl. | |
| 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. | |
| template<typename T> | |
| static T | moveAndReset (T &obj) |
| Helper function that moves and returns the given object. | |
| static void | reportNewIrLegalizationFatalError (const Pattern &pattern, const SetVector< Operation * > &newOps, const SetVector< Operation * > &modifiedOps) |
| Report a fatal error indicating that newly produced or modified IR could not be legalized. | |
| 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). | |
| 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 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. | |
Variables | |
| static const StringRef | kPureTypeConversionMarker = "__pure_type_conversion__" |
| Marker attribute for pure type conversions. | |
| #define DEBUG_TYPE "dialect-conversion" |
Definition at line 34 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 119 of file DialectConversion.cpp.
|
static |
Definition at line 4165 of file DialectConversion.cpp.
References mlir::OperationConverter::applyConversion(), mlir::config, mlir::MLIRContext::executeAction(), mlir::patterns, success(), and target.
|
static |
Definition at line 3997 of file DialectConversion.cpp.
References result.
|
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 72 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 62 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 3833 of file DialectConversion.cpp.
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 4226 of file DialectConversion.cpp.
References mlir::Operation::getParentOp(), mlir::Operation::getParentWithTrait(), mlir::Operation::hasTrait(), mlir::Operation::isAncestor(), and mlir::Operation::isProperAncestor().
|
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 205 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 1845 of file DialectConversion.cpp.
References computeInsertPoint(), mlir::Value::getLoc(), mlir::Value::getType(), TypeRange, mlir::Value::use_empty(), and ValueRange.
Referenced by mlir::detail::ConversionPatternRewriterImpl::replaceOp(), and mlir::detail::ConversionPatternRewriterImpl::replaceValueUses().
|
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 218 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 3342 of file DialectConversion.cpp.
References diag(), mlir::OperandRange::getTypes(), mlir::RewriterBase::replaceOp(), mlir::OpBuilder::setInsertionPoint(), success(), and TypeRange.
Referenced by mlir::OperationConverter::applyConversion().
|
static |
A utility function to log a failure result for the given reason.
Definition at line 51 of file DialectConversion.cpp.
|
static |
A utility function to log a successful result for the given reason.
Definition at line 38 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 2639 of file DialectConversion.cpp.
References result.
|
static |
Replace all uses of from with repl.
Definition at line 1217 of file DialectConversion.cpp.
References mlir::Operation::getBlock(), mlir::Value::getDefiningOp(), mlir::detail::IROperandBase::getOwner(), mlir::Operation::isBeforeInBlock(), mlir::RewriterBase::replaceAllUsesWith(), mlir::RewriterBase::replaceUsesWithIf(), and result.
Referenced by mlir::detail::ConversionPatternRewriterImpl::replaceValueUses().
|
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 3118 of file DialectConversion.cpp.
References mlir::Value::getDefiningOp(), and 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 2708 of file DialectConversion.cpp.
References mlir::Pattern::getDebugName(), mlir::Operation::getName(), 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 201 of file DialectConversion.cpp.
Referenced by mlir::OperationConverter::applyConversion(), mlir::detail::ConversionPatternRewriterImpl::buildUnresolvedMaterialization(), and isPureTypeConversion().