MLIR  16.0.0git
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
mlir::LLVMTypeConverter Class Reference

Conversion from types to the LLVM IR dialect. More...

#include "mlir/Conversion/LLVMCommon/TypeConverter.h"

+ Inheritance diagram for mlir::LLVMTypeConverter:
+ Collaboration diagram for mlir::LLVMTypeConverter:

Public Member Functions

 LLVMTypeConverter (MLIRContext *ctx, const DataLayoutAnalysis *analysis=nullptr)
 Create an LLVMTypeConverter using the default LowerToLLVMOptions. More...
 
 LLVMTypeConverter (MLIRContext *ctx, const LowerToLLVMOptions &options, const DataLayoutAnalysis *analysis=nullptr)
 Create an LLVMTypeConverter using custom LowerToLLVMOptions. More...
 
Type convertFunctionSignature (FunctionType funcTy, bool isVariadic, SignatureConversion &result)
 Convert a function type. More...
 
Type packFunctionResults (TypeRange types)
 Convert a non-empty list of types to be returned from a function into a supported LLVM IR type. More...
 
Type convertCallingConventionType (Type type)
 Convert a type in the context of the default or bare pointer calling convention. More...
 
void promoteBarePtrsToDescriptors (ConversionPatternRewriter &rewriter, Location loc, ArrayRef< Type > stdTypes, SmallVectorImpl< Value > &values)
 Promote the bare pointers in 'values' that resulted from memrefs to descriptors. More...
 
MLIRContextgetContext ()
 Returns the MLIR context. More...
 
LLVM::LLVMDialect * getDialect ()
 Returns the LLVM dialect. More...
 
const LowerToLLVMOptionsgetOptions () const
 
void dangerousSetOptions (LowerToLLVMOptions newOptions)
 Set the lowering options to newOptions. More...
 
SmallVector< Value, 4 > promoteOperands (Location loc, ValueRange opOperands, ValueRange operands, OpBuilder &builder)
 Promote the LLVM representation of all operands including promoting MemRef descriptors to stack and use pointers to struct to avoid the complexity of the platform-specific C/C++ ABI lowering related to struct argument passing. More...
 
Value promoteOneMemRefDescriptor (Location loc, Value operand, OpBuilder &builder)
 Promote the LLVM struct representation of one MemRef descriptor to stack and use pointer to struct to avoid the complexity of the platform-specific C/C++ ABI lowering related to struct argument passing. More...
 
std::pair< Type, bool > convertFunctionTypeCWrapper (FunctionType type)
 Converts the function type to a C-compatible format, in particular using pointers to memref descriptors for arguments. More...
 
const llvm::DataLayout & getDataLayout ()
 Returns the data layout to use during and after conversion. More...
 
const DataLayoutAnalysisgetDataLayoutAnalysis () const
 Returns the data layout analysis to query during conversion. More...
 
Type getIndexType ()
 Gets the LLVM representation of the index type. More...
 
unsigned getIndexTypeBitwidth ()
 Gets the bitwidth of the index type when converted to LLVM. More...
 
unsigned getPointerBitwidth (unsigned addressSpace=0)
 Gets the pointer bitwidth. More...
 
unsigned getMemRefDescriptorSize (MemRefType type, const DataLayout &layout)
 Returns the size of the memref descriptor object in bytes. More...
 
unsigned getUnrankedMemRefDescriptorSize (UnrankedMemRefType type, const DataLayout &layout)
 Returns the size of the unranked memref descriptor object in bytes. More...
 
- Public Member Functions inherited from mlir::TypeConverter
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)
 

Static Public Member Functions

static bool canConvertToBarePtr (BaseMemRefType type)
 Check if a memref type can be converted to a bare pointer. More...
 

Protected Attributes

LLVM::LLVMDialect * llvmDialect
 Pointer to the LLVM dialect. More...
 

Friends

LogicalResult structFuncArgTypeConverter (LLVMTypeConverter &converter, Type type, SmallVectorImpl< Type > &result)
 Give structFuncArgTypeConverter access to memref-specific functions. More...
 

Detailed Description

Conversion from types to the LLVM IR dialect.

Definition at line 30 of file TypeConverter.h.

Constructor & Destructor Documentation

◆ LLVMTypeConverter() [1/2]

LLVMTypeConverter::LLVMTypeConverter ( MLIRContext ctx,
const DataLayoutAnalysis analysis = nullptr 
)

Create an LLVMTypeConverter using the default LowerToLLVMOptions.

Create an LLVMTypeConverter using default LowerToLLVMOptions.

Optionally takes a data layout analysis to use in conversions.

Definition at line 18 of file TypeConverter.cpp.

◆ LLVMTypeConverter() [2/2]

LLVMTypeConverter::LLVMTypeConverter ( MLIRContext ctx,
const LowerToLLVMOptions options,
const DataLayoutAnalysis analysis = nullptr 
)

Member Function Documentation

◆ canConvertToBarePtr()

bool LLVMTypeConverter::canConvertToBarePtr ( BaseMemRefType  type)
static

◆ convertCallingConventionType()

Type LLVMTypeConverter::convertCallingConventionType ( Type  type)

Convert a type in the context of the default or bare pointer calling convention.

Calling convention sensitive types, such as MemRefType and UnrankedMemRefType, are converted following the specific rules for the calling convention. Calling convention independent types are converted following the default LLVM type conversions.

Definition at line 431 of file TypeConverter.cpp.

References mlir::TypeConverter::convertType(), mlir::Type::dyn_cast(), and mlir::LowerToLLVMOptions::useBarePtrCallConv.

Referenced by mlir::barePtrFuncArgTypeConverter(), and packFunctionResults().

◆ convertFunctionSignature()

Type LLVMTypeConverter::convertFunctionSignature ( FunctionType  funcTy,
bool  isVariadic,
LLVMTypeConverter::SignatureConversion result 
)

◆ convertFunctionTypeCWrapper()

std::pair< Type, bool > LLVMTypeConverter::convertFunctionTypeCWrapper ( FunctionType  type)

Converts the function type to a C-compatible format, in particular using pointers to memref descriptors for arguments.

Also converts the return type to a pointer argument if it is a struct. Returns true if this was the case.

Definition at line 240 of file TypeConverter.cpp.

References mlir::TypeConverter::convertType(), mlir::Type::dyn_cast(), mlir::LLVM::LLVMArrayType::get(), mlir::LLVM::LLVMFunctionType::get(), mlir::LLVM::LLVMPointerType::get(), getContext(), getIndexType(), mlir::LLVM::isCompatibleType(), mlir::isStrided(), and packFunctionResults().

Referenced by wrapExternalFunction(), and wrapForExternalCallers().

◆ dangerousSetOptions()

void mlir::LLVMTypeConverter::dangerousSetOptions ( LowerToLLVMOptions  newOptions)
inline

Set the lowering options to newOptions.

Note: using this after some some conversions have been performed can lead to inconsistencies in the IR.

Definition at line 86 of file TypeConverter.h.

Referenced by isDefinedByCallTo().

◆ getContext()

MLIRContext & LLVMTypeConverter::getContext ( )

◆ getDataLayout()

const llvm::DataLayout& mlir::LLVMTypeConverter::getDataLayout ( )
inline

Returns the data layout to use during and after conversion.

Definition at line 111 of file TypeConverter.h.

References mlir::LowerToLLVMOptions::dataLayout.

Referenced by getMemRefAlignment().

◆ getDataLayoutAnalysis()

const DataLayoutAnalysis* mlir::LLVMTypeConverter::getDataLayoutAnalysis ( ) const
inline

Returns the data layout analysis to query during conversion.

Definition at line 114 of file TypeConverter.h.

◆ getDialect()

LLVM::LLVMDialect* mlir::LLVMTypeConverter::getDialect ( )
inline

◆ getIndexType()

Type LLVMTypeConverter::getIndexType ( )

◆ getIndexTypeBitwidth()

unsigned mlir::LLVMTypeConverter::getIndexTypeBitwidth ( )
inline

Gets the bitwidth of the index type when converted to LLVM.

Definition at line 123 of file TypeConverter.h.

References mlir::LowerToLLVMOptions::getIndexBitwidth().

Referenced by mlir::UnrankedMemRefDescriptor::computeSizes(), and getIndexType().

◆ getMemRefDescriptorSize()

unsigned LLVMTypeConverter::getMemRefDescriptorSize ( MemRefType  type,
const DataLayout layout 
)

◆ getOptions()

const LowerToLLVMOptions& mlir::LLVMTypeConverter::getOptions ( ) const
inline

◆ getPointerBitwidth()

unsigned LLVMTypeConverter::getPointerBitwidth ( unsigned  addressSpace = 0)

◆ getUnrankedMemRefDescriptorSize()

unsigned LLVMTypeConverter::getUnrankedMemRefDescriptorSize ( UnrankedMemRefType  type,
const DataLayout layout 
)

◆ packFunctionResults()

Type LLVMTypeConverter::packFunctionResults ( TypeRange  types)

Convert a non-empty list of types to be returned from a function into a supported LLVM IR type.

In particular, if more than one value is returned, create an LLVM IR structure type with elements that correspond to each of the MLIR types converted with convertType.

Definition at line 457 of file TypeConverter.cpp.

References convertCallingConventionType(), getContext(), mlir::LLVM::LLVMStructType::getLiteral(), and mlir::LLVM::isCompatibleType().

Referenced by convertFunctionSignature(), convertFunctionTypeCWrapper(), and mlir::LLVM::detail::oneToOneRewrite().

◆ promoteBarePtrsToDescriptors()

void LLVMTypeConverter::promoteBarePtrsToDescriptors ( ConversionPatternRewriter rewriter,
Location  loc,
ArrayRef< Type stdTypes,
SmallVectorImpl< Value > &  values 
)

Promote the bare pointers in 'values' that resulted from memrefs to descriptors.

'stdTypes' holds the types of 'values' before the conversion to the LLVM-IR dialect (i.e., MemRefType, or any other builtin type).

'stdTypes' holds they types of 'values' before the conversion to the LLVM-IR dialect (i.e., MemRefType, or any other builtin type).

Definition at line 442 of file TypeConverter.cpp.

References mlir::MemRefDescriptor::fromStaticShape().

◆ promoteOneMemRefDescriptor()

Value LLVMTypeConverter::promoteOneMemRefDescriptor ( Location  loc,
Value  operand,
OpBuilder builder 
)

Promote the LLVM struct representation of one MemRef descriptor to stack and use pointer to struct to avoid the complexity of the platform-specific C/C++ ABI lowering related to struct argument passing.

Definition at line 475 of file TypeConverter.cpp.

References mlir::OpBuilder::create(), mlir::LLVM::LLVMPointerType::get(), mlir::Builder::getI64Type(), mlir::Builder::getIndexAttr(), and mlir::Value::getType().

◆ promoteOperands()

SmallVector< Value, 4 > LLVMTypeConverter::promoteOperands ( Location  loc,
ValueRange  opOperands,
ValueRange  operands,
OpBuilder builder 
)

Promote the LLVM representation of all operands including promoting MemRef descriptors to stack and use pointers to struct to avoid the complexity of the platform-specific C/C++ ABI lowering related to struct argument passing.

Definition at line 489 of file TypeConverter.cpp.

References mlir::MemRefDescriptor::alignedPtr(), mlir::MemRefDescriptor::unpack(), mlir::UnrankedMemRefDescriptor::unpack(), and mlir::LowerToLLVMOptions::useBarePtrCallConv.

Referenced by isDefinedByCallTo().

Friends And Related Function Documentation

◆ structFuncArgTypeConverter

LogicalResult structFuncArgTypeConverter ( LLVMTypeConverter converter,
Type  type,
SmallVectorImpl< Type > &  result 
)
friend

Give structFuncArgTypeConverter access to memref-specific functions.

It converts a MemRef function argument to a list of non-aggregate types containing descriptor information, and an UnrankedmemRef function argument to a list containing the rank and a pointer to a descriptor struct.

Referenced by convertFunctionSignature().

Member Data Documentation

◆ llvmDialect

LLVM::LLVMDialect* mlir::LLVMTypeConverter::llvmDialect
protected

Pointer to the LLVM dialect.

Definition at line 140 of file TypeConverter.h.

Referenced by LLVMTypeConverter().


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