MLIR  15.0.0git
Classes | Public Member Functions | List of all members
mlir::TypeConverter Class Reference

Type conversion class. More...

#include "mlir/Transforms/DialectConversion.h"

+ Inheritance diagram for mlir::TypeConverter:

Classes

class  SignatureConversion
 This class provides all of the information necessary to convert a type signature. More...
 

Public Member Functions

template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<0>>
void addConversion (FnT &&callback)
 Register a conversion function. More...
 
template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<1>>
void addArgumentMaterialization (FnT &&callback)
 Register a materialization function, which must be convertible to the following form: Optional<Value>(OpBuilder &, T, ValueRange, Location), where T is any subclass of Type. More...
 
template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<1>>
void addSourceMaterialization (FnT &&callback)
 This method registers a materialization that will be called when converting a legal type to an illegal source type. More...
 
template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<1>>
void addTargetMaterialization (FnT &&callback)
 This method registers a materialization that will be called when converting type from an illegal, or source, type to a legal type. More...
 
LogicalResult convertType (Type t, SmallVectorImpl< Type > &results)
 Convert the given type. More...
 
Type convertType (Type t)
 This hook simplifies defining 1-1 type conversions. More...
 
LogicalResult convertTypes (TypeRange types, SmallVectorImpl< Type > &results)
 Convert the given set of types, filling 'results' as necessary. More...
 
bool isLegal (Type type)
 Return true if the given type is legal for this type converter, i.e. More...
 
template<typename RangeT >
std::enable_if_t<!std::is_convertible< RangeT, Type >::value &&!std::is_convertible< RangeT, Operation * >::value, bool > isLegal (RangeT &&range)
 Return true if all of the given types are legal for this type converter. More...
 
bool isLegal (Operation *op)
 Return true if the given operation has legal operand and result types. More...
 
bool isLegal (Region *region)
 Return true if the types of block arguments within the region are legal. More...
 
bool isSignatureLegal (FunctionType ty)
 Return true if the inputs and outputs of the given function type are legal. More...
 
LogicalResult convertSignatureArg (unsigned inputNo, Type type, SignatureConversion &result)
 This method allows for converting a specific argument of a signature. More...
 
LogicalResult convertSignatureArgs (TypeRange types, SignatureConversion &result, unsigned origInputOffset=0)
 
Optional< SignatureConversionconvertBlockSignature (Block *block)
 This function converts the type signature of the given block, by invoking 'convertSignatureArg' for each argument. More...
 
Value materializeArgumentConversion (OpBuilder &builder, Location loc, Type resultType, ValueRange inputs)
 Materialize a conversion from a set of types into one result type by generating a cast sequence of some kind. More...
 
Value materializeSourceConversion (OpBuilder &builder, Location loc, Type resultType, ValueRange inputs)
 
Value materializeTargetConversion (OpBuilder &builder, Location loc, Type resultType, ValueRange inputs)
 

Detailed Description

Type conversion class.

Specific conversions and materializations can be registered using addConversion and addMaterialization, respectively.

Definition at line 36 of file DialectConversion.h.

Member Function Documentation

◆ addArgumentMaterialization()

template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<1>>
void mlir::TypeConverter::addArgumentMaterialization ( FnT &&  callback)
inline

Register a materialization function, which must be convertible to the following form: Optional<Value>(OpBuilder &, T, ValueRange, Location), where T is any subclass of Type.

This function is responsible for creating an operation, using the OpBuilder and Location provided, that "casts" a range of values into a single value of the given type T. It must return a Value of the converted type on success, an llvm::None if it failed but other materialization can be attempted, and nullptr on unrecoverable failure. It will only be called for (sub)types of T. Materialization functions must be provided when a type conversion may persist after the conversion has finished.

This method registers a materialization that will be called when converting an illegal block argument type, to a legal type.

Definition at line 135 of file DialectConversion.h.

Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), and mlir::LLVMTypeConverter::LLVMTypeConverter().

◆ addConversion()

template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<0>>
void mlir::TypeConverter::addConversion ( FnT &&  callback)
inline

Register a conversion function.

A conversion function must be convertible to any of the following forms(where T is a class derived from Type:

  • Optional<Type>(T)
    • This form represents a 1-1 type conversion. It should return nullptr or llvm::None to signify failure. If llvm::None is returned, the converter is allowed to try another conversion function to perform the conversion.
  • Optional<LogicalResult>(T, SmallVectorImpl<Type> &)
    • This form represents a 1-N type conversion. It should return failure or llvm::None to signify a failed conversion. If the new set of types is empty, the type is removed and any usages of the existing value are expected to be removed during conversion. If llvm::None is returned, the converter is allowed to try another conversion function to perform the conversion.
  • Optional<LogicalResult>(T, SmallVectorImpl<Type> &, ArrayRef<Type>)
    • This form represents a 1-N type conversion supporting recursive types. The first two arguments and the return value are the same as for the regular 1-N form. The third argument is contains is the "call stack" of the recursive conversion: it contains the list of types currently being converted, with the current type being the last one. If it is present more than once in the list, the conversion concerns a recursive type. Note: When attempting to convert a type, e.g. via 'convertType', the mostly recently added conversions will be invoked first.

Definition at line 115 of file DialectConversion.h.

Referenced by addResumeFunction(), mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), mlir::LLVMTypeConverter::LLVMTypeConverter(), mlir::populateAsyncStructuralTypeConversionsAndLegality(), mlir::populateGpuToLLVMConversionPatterns(), mlir::populateSPIRVToLLVMTypeConversion(), mlir::SPIRVTypeConverter::SPIRVTypeConverter(), and unpackOperandVector().

◆ addSourceMaterialization()

template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<1>>
void mlir::TypeConverter::addSourceMaterialization ( FnT &&  callback)
inline

This method registers a materialization that will be called when converting a legal type to an illegal source type.

This is used when conversions to an illegal type must persist beyond the main conversion.

Definition at line 144 of file DialectConversion.h.

Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), mlir::LLVMTypeConverter::LLVMTypeConverter(), and lowerEntryPointABIAttr().

◆ addTargetMaterialization()

template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<1>>
void mlir::TypeConverter::addTargetMaterialization ( FnT &&  callback)
inline

This method registers a materialization that will be called when converting type from an illegal, or source, type to a legal type.

Definition at line 152 of file DialectConversion.h.

References convertType(), convertTypes(), isLegal(), and value.

Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), and mlir::LLVMTypeConverter::LLVMTypeConverter().

◆ convertBlockSignature()

auto TypeConverter::convertBlockSignature ( Block block)

This function converts the type signature of the given block, by invoking 'convertSignatureArg' for each argument.

This function should return a valid conversion for the signature on success, None otherwise.

Definition at line 3051 of file DialectConversion.cpp.

References mlir::ConversionPatternRewriter::convertRegionTypes(), mlir::failed(), mlir::failure(), mlir::Block::getArgumentTypes(), mlir::Builder::getContext(), mlir::Block::getNumArguments(), mlir::success(), and mlir::RewriterBase::updateRootInPlace().

Referenced by buildUnresolvedTargetMaterialization(), and isLegal().

◆ convertSignatureArg()

LogicalResult TypeConverter::convertSignatureArg ( unsigned  inputNo,
Type  type,
SignatureConversion result 
)

This method allows for converting a specific argument of a signature.

It takes as inputs the original argument input number, type. On success, it populates 'result' with any new mappings.

Definition at line 3018 of file DialectConversion.cpp.

References mlir::TypeConverter::SignatureConversion::addInputs(), mlir::failed(), mlir::failure(), and mlir::success().

Referenced by isLegal().

◆ convertSignatureArgs()

LogicalResult TypeConverter::convertSignatureArgs ( TypeRange  types,
SignatureConversion result,
unsigned  origInputOffset = 0 
)

Definition at line 3033 of file DialectConversion.cpp.

References mlir::failed(), mlir::failure(), and mlir::success().

Referenced by isLegal().

◆ convertType() [1/2]

LogicalResult TypeConverter::convertType ( Type  t,
SmallVectorImpl< Type > &  results 
)

Convert the given type.

This function should return failure if no valid conversion exists, success otherwise. If the new set of types is empty, the type is removed and any usages of the existing value are expected to be removed during conversion.

Definition at line 2947 of file DialectConversion.cpp.

References mlir::failure(), mlir::succeeded(), and mlir::success().

Referenced by addResumeFunction(), addTargetMaterialization(), adjustAccessChainForBitwidth(), broadcast(), buildUnresolvedTargetMaterialization(), mlir::LLVMTypeConverter::canConvertToBarePtr(), convertArrayType(), mlir::LLVMTypeConverter::convertCallingConventionType(), mlir::LLVMTypeConverter::convertFunctionTypeCWrapper(), convertPointerType(), convertRuntimeArrayType(), convertStructTypePacked(), convertStructTypeWithOffset(), mlir::ConvertToLLVMPattern::copyUnrankedDescriptors(), mlir::ConvertToLLVMPattern::createMemRefDescriptor(), mlir::LLVM::detail::extractNDVectorTypeInfo(), extractOne(), mlir::MemRefDescriptor::fromStaticShape(), mlir::ConvertToLLVMPattern::getElementPtrType(), mlir::bufferization::getGlobalFor(), getMemRefAlignment(), mlir::LLVMTypeConverter::getPointerBitwidth(), getPtrToElementType(), mlir::ConvertToLLVMPattern::getSizeInBytes(), mlir::LLVMTypeConverter::getUnrankedMemRefDescriptorSize(), insertOne(), mlir::ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(), mlir::LLVMTypeConverter::LLVMTypeConverter(), lowerAsEntryFunction(), mlir::GPUFuncOpLowering::matchAndRewrite(), mlir::spirv::ElementwiseOpPattern< Op, SPIRVOp >::matchAndRewrite(), mlir::GPUPrintfOpToHIPLowering::matchAndRewrite(), mlir::GPUPrintfOpToLLVMCallLowering::matchAndRewrite(), mlir::LLVM::detail::oneToOneRewrite(), mlir::MemRefDescriptor::pack(), mlir::UnrankedMemRefDescriptor::pack(), mlir::populateAsyncStructuralTypeConversionsAndLegality(), replaceWithLoadOrStore(), mlir::DataDescriptor::setSize(), mlir::UnrankedMemRefDescriptor::sizeBasePtr(), mlir::structFuncArgTypeConverter(), unpackOperandVector(), and wrapExternalFunction().

◆ convertType() [2/2]

Type TypeConverter::convertType ( Type  t)

This hook simplifies defining 1-1 type conversions.

This function returns the type to convert to on success, and a null type on failure.

Definition at line 2985 of file DialectConversion.cpp.

References mlir::failed().

◆ convertTypes()

LogicalResult TypeConverter::convertTypes ( TypeRange  types,
SmallVectorImpl< Type > &  results 
)

Convert the given set of types, filling 'results' as necessary.

This returns failure if the conversion of any of the types fails, success otherwise.

Definition at line 2995 of file DialectConversion.cpp.

References mlir::failed(), mlir::failure(), and mlir::success().

Referenced by addTargetMaterialization(), and mlir::LLVMTypeConverter::LLVMTypeConverter().

◆ isLegal() [1/4]

bool TypeConverter::isLegal ( Type  type)

◆ isLegal() [2/4]

template<typename RangeT >
std::enable_if_t<!std::is_convertible<RangeT, Type>::value && !std::is_convertible<RangeT, Operation *>::value, bool> mlir::TypeConverter::isLegal ( RangeT &&  range)
inline

Return true if all of the given types are legal for this type converter.

Definition at line 180 of file DialectConversion.h.

References convertBlockSignature(), convertSignatureArg(), convertSignatureArgs(), mlir::TypeConverter::SignatureConversion::InputMapping::inputNo, isLegal(), and isSignatureLegal().

◆ isLegal() [3/4]

bool TypeConverter::isLegal ( Operation op)

Return true if the given operation has legal operand and result types.

Definition at line 3004 of file DialectConversion.cpp.

References mlir::Operation::getOperandTypes(), and mlir::Operation::getResultTypes().

◆ isLegal() [4/4]

bool TypeConverter::isLegal ( Region region)

Return true if the types of block arguments within the region are legal.

Definition at line 3008 of file DialectConversion.cpp.

References mlir::Block::getArgumentTypes().

◆ isSignatureLegal()

bool TypeConverter::isSignatureLegal ( FunctionType  ty)

Return true if the inputs and outputs of the given function type are legal.

Definition at line 3014 of file DialectConversion.cpp.

Referenced by isLegal().

◆ materializeArgumentConversion()

Value mlir::TypeConverter::materializeArgumentConversion ( OpBuilder builder,
Location  loc,
Type  resultType,
ValueRange  inputs 
)
inline

Materialize a conversion from a set of types into one result type by generating a cast sequence of some kind.

See the respective add*Materialization for more information on the context for these methods.

Definition at line 211 of file DialectConversion.h.

Referenced by legalizeUnresolvedMaterialization().

◆ materializeSourceConversion()

Value mlir::TypeConverter::materializeSourceConversion ( OpBuilder builder,
Location  loc,
Type  resultType,
ValueRange  inputs 
)
inline

Definition at line 216 of file DialectConversion.h.

Referenced by findLiveUserOfReplaced().

◆ materializeTargetConversion()

Value mlir::TypeConverter::materializeTargetConversion ( OpBuilder builder,
Location  loc,
Type  resultType,
ValueRange  inputs 
)
inline

Definition at line 221 of file DialectConversion.h.

References mlir::Type::dyn_cast(), mlir::success(), and value.

Referenced by legalizeUnresolvedMaterialization().


The documentation for this class was generated from the following files: