MLIR  19.0.0git
Public Types | Public Member Functions | List of all members
mlir::OneToNTypeConverter Class Reference

Extends TypeConverter with 1:N target materializations. More...

#include "mlir/Transforms/OneToNTypeConversion.h"

+ Inheritance diagram for mlir::OneToNTypeConverter:

Public Types

using OneToNMaterializationCallbackFn = std::function< std::optional< SmallVector< Value > >(OpBuilder &, TypeRange, Value, Location)>
 Callback that expresses user-provided materialization logic from the given value to N values of the given types. More...
 

Public Member Functions

LogicalResult computeTypeMapping (TypeRange types, SignatureConversion &result)
 Creates the mapping of the given range of original types to target types of the conversion and stores that mapping in the given (signature) conversion. More...
 
std::optional< SmallVector< Value > > materializeTargetConversion (OpBuilder &builder, Location loc, TypeRange resultTypes, Value input) const
 Applies one of the user-provided 1:N target materializations. More...
 
void addTargetMaterialization (OneToNMaterializationCallbackFn &&callback)
 Adds a 1:N target materialization to the converter. More...
 
- Public Member Functions inherited from mlir::TypeConverter
virtual ~TypeConverter ()=default
 
 TypeConverter ()=default
 
 TypeConverter (const TypeConverter &other)
 
TypeConverteroperator= (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< SignatureConversionconvertBlockSignature (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< AttributeconvertTypeAttribute (Type type, Attribute attr) const
 Convert an attribute present attr from within the type type using the registered conversion functions. More...
 

Detailed Description

Extends TypeConverter with 1:N target materializations.

Such materializations have to provide the "reverse" of 1:N type conversions, i.e., they need to materialize N values with target types into one value with a source type (which isn't possible in the base class currently).

Definition at line 40 of file OneToNTypeConversion.h.

Member Typedef Documentation

◆ OneToNMaterializationCallbackFn

Callback that expresses user-provided materialization logic from the given value to N values of the given types.

This is useful for expressing target materializations for 1:N type conversions, which materialize one value in a source type as N values in target types.

Definition at line 46 of file OneToNTypeConversion.h.

Member Function Documentation

◆ addTargetMaterialization()

void mlir::OneToNTypeConverter::addTargetMaterialization ( OneToNMaterializationCallbackFn &&  callback)
inline

Adds a 1:N target materialization to the converter.

Such materializations build IR that converts N values with target types into 1 value of the source type.

Definition at line 71 of file OneToNTypeConversion.h.

◆ computeTypeMapping()

LogicalResult mlir::OneToNTypeConverter::computeTypeMapping ( TypeRange  types,
SignatureConversion result 
)
inline

Creates the mapping of the given range of original types to target types of the conversion and stores that mapping in the given (signature) conversion.

This function simply calls TypeConverter::convertSignatureArgs and exists here with a different name to reflect the broader semantic.

Definition at line 55 of file OneToNTypeConversion.h.

References mlir::TypeConverter::convertSignatureArgs().

◆ materializeTargetConversion()

std::optional< SmallVector< Value > > OneToNTypeConverter::materializeTargetConversion ( OpBuilder builder,
Location  loc,
TypeRange  resultTypes,
Value  input 
) const

Applies one of the user-provided 1:N target materializations.

If several exists, they are tried out in the reverse order in which they have been added until the first one succeeds. If none succeeds, the functions returns std::nullopt.

Definition at line 21 of file OneToNTypeConversion.cpp.


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