MLIR
20.0.0git
|
Type conversion class. More...
#include "mlir/Transforms/DialectConversion.h"
Classes | |
class | AttributeConversionResult |
The general result of a type attribute conversion callback, allowing for early termination. More... | |
class | SignatureConversion |
This class provides all of the information necessary to convert a type signature. More... | |
Public Member Functions | |
virtual | ~TypeConverter ()=default |
TypeConverter ()=default | |
TypeConverter (const TypeConverter &other) | |
TypeConverter & | operator= (const TypeConverter &other) |
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) |
All of the following materializations require function objects that are convertible to the following form: std::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 replacement value back 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 an illegal (source) value to a legal (target) type. More... | |
template<typename FnT , typename T = typename llvm::function_traits<std::decay_t<FnT>>::template arg_t<0>, typename A = typename llvm::function_traits<std::decay_t<FnT>>::template arg_t<1>> | |
void | addTypeAttributeConversion (FnT &&callback) |
Register a conversion function for attributes within types. More... | |
LogicalResult | convertType (Type t, SmallVectorImpl< Type > &results) const |
Convert the given type. More... | |
Type | convertType (Type t) const |
This hook simplifies defining 1-1 type conversions. More... | |
template<typename TargetType > | |
TargetType | convertType (Type t) const |
Attempts a 1-1 type conversion, expecting the result type to be TargetType . More... | |
LogicalResult | convertTypes (TypeRange types, SmallVectorImpl< Type > &results) const |
Convert the given set of types, filling 'results' as necessary. More... | |
bool | isLegal (Type type) const |
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) const |
Return true if all of the given types are legal for this type converter. More... | |
bool | isLegal (Operation *op) const |
Return true if the given operation has legal operand and result types. More... | |
bool | isLegal (Region *region) const |
Return true if the types of block arguments within the region are legal. More... | |
bool | isSignatureLegal (FunctionType ty) const |
Return true if the inputs and outputs of the given function type are legal. More... | |
LogicalResult | convertSignatureArg (unsigned inputNo, Type type, SignatureConversion &result) const |
This method allows for converting a specific argument of a signature. More... | |
LogicalResult | convertSignatureArgs (TypeRange types, SignatureConversion &result, unsigned origInputOffset=0) const |
std::optional< SignatureConversion > | convertBlockSignature (Block *block) const |
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) const |
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) const |
Value | materializeTargetConversion (OpBuilder &builder, Location loc, Type resultType, ValueRange inputs) const |
std::optional< Attribute > | convertTypeAttribute (Type type, Attribute attr) const |
Convert an attribute present attr from within the type type using the registered conversion functions. More... | |
Type conversion class.
Specific conversions and materializations can be registered using addConversion and addMaterialization, respectively.
Definition at line 41 of file DialectConversion.h.
|
virtualdefault |
|
default |
|
inline |
Definition at line 46 of file DialectConversion.h.
|
inline |
All of the following materializations require function objects that are convertible to the following form: std::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 type T
on success, an std::nullopt
if it failed but other materialization can be attempted, and nullptr
on unrecoverable failure. 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 (potentially multiple) block arguments that were the result of a signature conversion of a single block argument, to a single SSA value with the old block argument type.
Definition at line 188 of file DialectConversion.h.
Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), mlir::LLVMTypeConverter::LLVMTypeConverter(), mlir::populateEmitCSizeTTypeConversions(), and mlir::vector::populateVectorLinearizeTypeConversionsAndLegality().
|
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
:
std::nullopt
to signify failure. If std::nullopt
is returned, the converter is allowed to try another conversion function to perform the conversion.failure
or std::nullopt
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 std::nullopt
is returned, the converter is allowed to try another conversion function to perform the conversion.Definition at line 167 of file DialectConversion.h.
Referenced by addOpaquePointerConversion(), mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), mlir::LLVMTypeConverter::LLVMTypeConverter(), mlir::spirv::MemorySpaceToStorageClassConverter::MemorySpaceToStorageClassConverter(), mlir::arith::NarrowTypeEmulationConverter::NarrowTypeEmulationConverter(), mlir::populateAMDGPUToROCDLConversionPatterns(), mlir::populateArmSMEToLLVMConversionPatterns(), mlir::populateAsyncStructuralTypeConversionsAndLegality(), mlir::populateEmitCSizeTTypeConversions(), mlir::arith::populateEmulateUnsupportedFloatsConversions(), mlir::math::populateLegalizeToF32TypeConverter(), mlir::memref::populateMemRefNarrowTypeEmulationConversions(), mlir::populateMemRefToEmitCTypeConversion(), mlir::memref::populateMemRefWideIntEmulationConversions(), mlir::populateMMAToSPIRVCoopMatrixTypeConversion(), mlir::populateOpenMPToLLVMConversionPatterns(), mlir::populateSPIRVToLLVMTypeConversion(), mlir::tosa::populateTosaTypeConversion(), mlir::vector::populateVectorLinearizeTypeConversionsAndLegality(), mlir::SPIRVTypeConverter::SPIRVTypeConverter(), and mlir::arith::WideIntEmulationConverter::WideIntEmulationConverter().
|
inline |
This method registers a materialization that will be called when converting a legal replacement value back to an illegal source type.
This is used when some uses of the original, illegal value must persist beyond the main conversion.
Definition at line 199 of file DialectConversion.h.
Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), mlir::LLVMTypeConverter::LLVMTypeConverter(), mlir::populateEmitCSizeTTypeConversions(), mlir::tosa::populateTosaTypeConversion(), mlir::vector::populateVectorLinearizeTypeConversionsAndLegality(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
inline |
This method registers a materialization that will be called when converting an illegal (source) value to a legal (target) type.
Definition at line 208 of file DialectConversion.h.
Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), mlir::LLVMTypeConverter::LLVMTypeConverter(), mlir::populateEmitCSizeTTypeConversions(), mlir::arith::populateEmulateUnsupportedFloatsConversions(), mlir::math::populateLegalizeToF32TypeConverter(), mlir::tosa::populateTosaTypeConversion(), mlir::vector::populateVectorLinearizeTypeConversionsAndLegality(), and mlir::SPIRVTypeConverter::SPIRVTypeConverter().
|
inline |
Register a conversion function for attributes within types.
Type converters may call this function in order to allow hoking into the translation of attributes that exist within types. For example, a type converter for the memref
type could use these conversions to convert memory spaces or layouts in an extensible way.
The conversion functions take a non-null Type or subclass of Type and a non-null Attribute (or subclass of Attribute), and returns a AttributeConversionResult
. This result can either contan an Attribute
, which may be nullptr
, representing the conversion's success, AttributeConversionResult::na()
(the default empty value), indicating that the conversion function did not apply and that further conversion functions should be checked, or AttributeConversionResult::abort()
indicating that the conversion process should be aborted.
Registered conversion functions are callled in the reverse of the order in which they were registered.
Definition at line 236 of file DialectConversion.h.
Referenced by mlir::LLVMTypeConverter::LLVMTypeConverter(), and mlir::populateGpuMemorySpaceAttributeConversions().
std::optional< TypeConverter::SignatureConversion > TypeConverter::convertBlockSignature | ( | Block * | block | ) | const |
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, std::nullopt otherwise.
Definition at line 2973 of file DialectConversion.cpp.
References convertSignatureArgs(), mlir::Block::getArgumentTypes(), and mlir::Block::getNumArguments().
Referenced by mlir::detail::ConversionPatternRewriterImpl::convertRegionTypes().
LogicalResult TypeConverter::convertSignatureArg | ( | unsigned | inputNo, |
Type | type, | ||
SignatureConversion & | result | ||
) | const |
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 2938 of file DialectConversion.cpp.
References mlir::TypeConverter::SignatureConversion::addInputs(), and convertType().
Referenced by convertSignatureArgs().
LogicalResult TypeConverter::convertSignatureArgs | ( | TypeRange | types, |
SignatureConversion & | result, | ||
unsigned | origInputOffset = 0 |
||
) | const |
Definition at line 2954 of file DialectConversion.cpp.
References convertSignatureArg().
Referenced by mlir::OneToNTypeConverter::computeTypeMapping(), convertBlockSignature(), and convertFuncOpTypes().
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 2901 of file DialectConversion.cpp.
References convertType().
|
inline |
Attempts a 1-1 type conversion, expecting the result type to be TargetType
.
Returns the converted type cast to TargetType
on success, and a null type on conversion or cast failure.
Definition at line 255 of file DialectConversion.h.
References convertType().
LogicalResult TypeConverter::convertType | ( | Type | t, |
SmallVectorImpl< Type > & | results | ||
) | const |
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 2856 of file DialectConversion.cpp.
References mlir::Type::getContext(), and mlir::MLIRContext::isMultithreadingEnabled().
Referenced by mlir::detail::ConversionPatternRewriterImpl::applySignatureConversion(), convertArrayType(), convertRuntimeArrayType(), convertSignatureArg(), convertType(), convertTypes(), mlir::ConvertToLLVMPattern::createMemRefDescriptor(), emitElementwiseComputation(), mlir::ConvertToLLVMPattern::getMemRefDescriptorSizes(), mlir::ConvertToLLVMPattern::getSizeInBytes(), mlir::ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(), isLegal(), lowerAsEntryFunction(), mlir::GPUFuncOpLowering::matchAndRewrite(), mlir::GPUPrintfOpToHIPLowering::matchAndRewrite(), mlir::GPUPrintfOpToLLVMCallLowering::matchAndRewrite(), mlir::GPUPrintfOpToVPrintfLowering::matchAndRewrite(), mlir::populateAsyncStructuralTypeConversionsAndLegality(), mlir::populateMemRefToEmitCTypeConversion(), mlir::memref::populateMemRefWideIntEmulationConversions(), mlir::tosa::populateTosaTypeConversion(), mlir::detail::ConversionPatternRewriterImpl::remapValues(), and wmmaPushInputOperand().
Convert an attribute present attr
from within the type type
using the registered conversion functions.
If no applicable conversion has been registered, return std::nullopt. Note that the empty attribute/nullptr
is a valid return value for this function.
Definition at line 3016 of file DialectConversion.cpp.
References mlir::TypeConverter::AttributeConversionResult::getResult(), mlir::TypeConverter::AttributeConversionResult::hasResult(), and mlir::TypeConverter::AttributeConversionResult::isAbort().
Referenced by mlir::LLVMTypeConverter::getMemRefAddressSpace().
LogicalResult TypeConverter::convertTypes | ( | TypeRange | types, |
SmallVectorImpl< Type > & | results | ||
) | const |
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 2912 of file DialectConversion.cpp.
References convertType().
Referenced by convertFuncOpTypes(), convertStructTypePacked(), convertStructTypeWithOffset(), mlir::LLVMTypeConverter::LLVMTypeConverter(), mlir::arith::NarrowTypeEmulationConverter::NarrowTypeEmulationConverter(), mlir::registerConversionPDLFunctions(), and mlir::arith::WideIntEmulationConverter::WideIntEmulationConverter().
bool TypeConverter::isLegal | ( | Operation * | op | ) | const |
Return true if the given operation has legal operand and result types.
Definition at line 2923 of file DialectConversion.cpp.
|
inline |
Return true if all of the given types are legal for this type converter.
Definition at line 274 of file DialectConversion.h.
References isLegal().
bool TypeConverter::isLegal | ( | Region * | region | ) | const |
Return true if the types of block arguments within the region are legal.
Definition at line 2927 of file DialectConversion.cpp.
References mlir::Block::getArgumentTypes(), and isLegal().
bool TypeConverter::isLegal | ( | Type | type | ) | const |
Return true if the given type is legal for this type converter, i.e.
the type converts to itself.
Definition at line 2920 of file DialectConversion.cpp.
References convertType().
Referenced by isLegal(), and isSignatureLegal().
bool TypeConverter::isSignatureLegal | ( | FunctionType | ty | ) | const |
Return true if the inputs and outputs of the given function type are legal.
Definition at line 2933 of file DialectConversion.cpp.
References isLegal().
|
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 305 of file DialectConversion.h.
|
inline |
Definition at line 311 of file DialectConversion.h.
|
inline |
Definition at line 316 of file DialectConversion.h.
|
inline |
Definition at line 52 of file DialectConversion.h.