MLIR  17.0.0git
Classes | Namespaces | Macros | Functions
DialectConversion.cpp File Reference
#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"
+ Include dependency graph for DialectConversion.cpp:

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 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, 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 27 of file DialectConversion.cpp.

Function Documentation

◆ buildUnresolvedArgumentMaterialization()

static Value buildUnresolvedArgumentMaterialization ( PatternRewriter rewriter,
Location  loc,
ValueRange  inputs,
Type  origOutputType,
Type  outputType,
TypeConverter converter,
SmallVectorImpl< UnresolvedMaterialization > &  unresolvedMaterializations 
)
static

◆ buildUnresolvedMaterialization()

static Value buildUnresolvedMaterialization ( UnresolvedMaterialization::Kind  kind,
Block insertBlock,
Block::iterator  insertPt,
Location  loc,
ValueRange  inputs,
Type  outputType,
Type  origOutputType,
TypeConverter converter,
SmallVectorImpl< UnresolvedMaterialization > &  unresolvedMaterializations 
)
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().

◆ buildUnresolvedTargetMaterialization()

static Value buildUnresolvedTargetMaterialization ( Location  loc,
Value  input,
Type  outputType,
TypeConverter converter,
SmallVectorImpl< UnresolvedMaterialization > &  unresolvedMaterializations 
)
static

◆ composeLegalityCallbacks()

◆ computeConversionSet()

static LogicalResult computeConversionSet ( iterator_range< Region::iterator region,
Location  regionLoc,
SmallVectorImpl< Operation * > &  toConvert,
ConversionTarget target = nullptr 
)
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().

◆ computeNecessaryMaterializations()

static void computeNecessaryMaterializations ( DenseMap< Operation *, UnresolvedMaterialization * > &  materializationOps,
ConversionPatternRewriter rewriter,
ConversionPatternRewriterImpl rewriterImpl,
DenseMap< Value, SmallVector< Value >> &  inverseMapping,
SetVector< UnresolvedMaterialization * > &  necessaryMaterializations 
)
static

◆ convertFuncOpTypes()

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

◆ detachNestedAndErase()

static void detachNestedAndErase ( Operation op)
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().

◆ 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 2852 of file DialectConversion.cpp.

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

◆ legalizeUnresolvedMaterialization()

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

◆ 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 93 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 80 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 3295 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 2549 of file DialectConversion.cpp.

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

Referenced by computeNecessaryMaterializations(), and legalizeUnresolvedMaterialization().