MLIR  19.0.0git
Classes | Namespaces | Macros | Functions
DialectConversion.cpp File Reference
#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/IRMapping.h"
#include "mlir/IR/Iterators.h"
#include "mlir/Interfaces/FunctionInterfaces.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"
#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
 

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

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...
 
template<typename RewriteTy , typename R >
static bool hasRewrite (R &&rewrites, Operation *op)
 Return "true" if there is an operation rewrite that matches the specified rewrite type and operation among the given rewrites. More...
 
template<typename RewriteTy , typename R >
static RewriteTy * findSingleRewrite (R &&rewrites, Block *block)
 Find the single rewrite object of the specified type and block among the given rewrites. 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 *, UnresolvedMaterializationRewrite * > &materializationOps, ConversionPatternRewriter &rewriter, ConversionPatternRewriterImpl &rewriterImpl, DenseMap< Value, SmallVector< Value >> &inverseMapping, SetVector< UnresolvedMaterializationRewrite * > &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 (UnresolvedMaterializationRewrite &mat, DenseMap< Operation *, UnresolvedMaterializationRewrite * > &materializationOps, ConversionPatternRewriter &rewriter, ConversionPatternRewriterImpl &rewriterImpl, DenseMap< Value, SmallVector< Value >> &inverseMapping)
 Legalize the given unresolved materialization. More...
 
static OperationfindLiveUserOfReplaced (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, 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...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "dialect-conversion"

Definition at line 30 of file DialectConversion.cpp.

Function Documentation

◆ composeLegalityCallbacks()

◆ computeNecessaryMaterializations()

static void computeNecessaryMaterializations ( DenseMap< Operation *, UnresolvedMaterializationRewrite * > &  materializationOps,
ConversionPatternRewriter rewriter,
ConversionPatternRewriterImpl rewriterImpl,
DenseMap< Value, SmallVector< Value >> &  inverseMapping,
SetVector< UnresolvedMaterializationRewrite * > &  necessaryMaterializations 
)
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 2673 of file DialectConversion.cpp.

References mlir::Value::getDefiningOp(), mlir::Value::getType(), mlir::Value::getUsers(), mlir::detail::ConversionPatternRewriterImpl::isOpIgnored(), mlir::detail::ConversionPatternRewriterImpl::mapping, rewrite(), mlir::detail::ConversionPatternRewriterImpl::rewrites, and mlir::Value::user_end().

◆ convertFuncOpTypes()

static LogicalResult convertFuncOpTypes ( FunctionOpInterface  funcOp,
const TypeConverter typeConverter,
ConversionPatternRewriter rewriter 
)
static

◆ findLiveUserOfReplaced()

static Operation* findLiveUserOfReplaced ( Value  initialValue,
ConversionPatternRewriterImpl rewriterImpl,
const DenseMap< Value, SmallVector< Value >> &  inverseMapping 
)
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 2947 of file DialectConversion.cpp.

References mlir::Value::getUsers(), and mlir::Value::user_end().

◆ findSingleRewrite()

template<typename RewriteTy , typename R >
static RewriteTy* findSingleRewrite ( R &&  rewrites,
Block block 
)
static

Find the single rewrite object of the specified type and block among the given rewrites.

In debug mode, asserts that there is mo more than one such object. Return "nullptr" if no object was found.

Definition at line 770 of file DialectConversion.cpp.

References rewrite().

◆ hasRewrite()

template<typename RewriteTy , typename R >
static bool hasRewrite ( R &&  rewrites,
Operation op 
)
static

Return "true" if there is an operation rewrite that matches the specified rewrite type and operation among the given rewrites.

Definition at line 759 of file DialectConversion.cpp.

◆ legalizeUnresolvedMaterialization()

static LogicalResult legalizeUnresolvedMaterialization ( UnresolvedMaterializationRewrite &  mat,
DenseMap< Operation *, UnresolvedMaterializationRewrite * > &  materializationOps,
ConversionPatternRewriter rewriter,
ConversionPatternRewriterImpl rewriterImpl,
DenseMap< Value, SmallVector< Value >> &  inverseMapping 
)
static

Legalize the given unresolved materialization.

Returns success if the materialization was legalized, failure otherise.

Definition at line 2795 of file DialectConversion.cpp.

References mlir::Value::getType(), mlir::detail::ConversionPatternRewriterImpl::isOpIgnored(), and mlir::detail::ConversionPatternRewriterImpl::mapping.

◆ logFailure()

template<typename... Args>
static void logFailure ( llvm::ScopedPrinter &  os,
StringRef  fmt,
Args &&...  args 
)
static

A utility function to log a failure result for the given reason.

Definition at line 47 of file DialectConversion.cpp.

◆ logSuccess()

template<typename... Args>
static void logSuccess ( llvm::ScopedPrinter &  os,
StringRef  fmt,
Args &&...  args 
)
static

A utility function to log a successful result for the given reason.

Definition at line 34 of file DialectConversion.cpp.

◆ pdllConvertValues()

static FailureOr<SmallVector<Value> > pdllConvertValues ( ConversionPatternRewriter rewriter,
ValueRange  values 
)
static

Remap the given value using the rewriter and the type converter in the provided config.

Definition at line 3474 of file DialectConversion.cpp.

References mlir::failed(), mlir::failure(), and mlir::ConversionPatternRewriter::getRemappedValues().

Referenced by mlir::registerConversionPDLFunctions().

◆ replaceMaterialization()

static void replaceMaterialization ( ConversionPatternRewriterImpl rewriterImpl,
ResultRange  matResults,
ValueRange  values,
DenseMap< Value, SmallVector< Value >> &  inverseMapping 
)
static

Replace the results of a materialization operation with the given values.

Definition at line 2647 of file DialectConversion.cpp.

References mlir::detail::ConversionPatternRewriterImpl::mapping, and mlir::ResultRange::replaceAllUsesWith().