MLIR  15.0.0git
Classes | Namespaces | Macros | Enumerations | Functions
DialectConversion.cpp File Reference
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/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 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
 

Macros

#define DEBUG_TYPE   "dialect-conversion"
 

Enumerations

enum  BlockActionKind
 The kind of the block action performed during the rewrite. More...
 
enum  OpConversionMode
 

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 ConversionTarget::DynamicLegalityCallbackFn composeLegalityCallbacks (ConversionTarget::DynamicLegalityCallbackFn oldCallback, ConversionTarget::DynamicLegalityCallbackFn newCallback)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "dialect-conversion"

Definition at line 27 of file DialectConversion.cpp.

Enumeration Type Documentation

◆ BlockActionKind

enum BlockActionKind
strong

The kind of the block action performed during the rewrite.

Actions can be undone if the conversion fails.

Definition at line 287 of file DialectConversion.cpp.

◆ OpConversionMode

Definition at line 2329 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 414 of file DialectConversion.cpp.

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

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

References mlir::Block::dropAllDefinedValueUses(), mlir::Operation::dropAllUses(), mlir::Operation::erase(), 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

◆ 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

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

Referenced by mlir::ConversionPattern::matchAndRewrite().

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

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

Referenced by computeNecessaryMaterializations(), and legalizeUnresolvedMaterialization().