MLIR 22.0.0git
mlir::ConvertToLLVMPattern Class Reference

Base class for operation conversions targeting the LLVM IR dialect. More...

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

Inheritance diagram for mlir::ConvertToLLVMPattern:

Public Member Functions

 ConvertToLLVMPattern (StringRef rootOpName, MLIRContext *context, const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)

Protected Member Functions

LLVM::LLVMDialect & getDialect () const
 Returns the LLVM dialect.
const LLVMTypeConvertergetTypeConverter () const
Type getIndexType () const
 Gets the MLIR type wrapping the LLVM integer type whose bit width is defined by the used type converter.
Type getIntPtrType (unsigned addressSpace=0) const
 Gets the MLIR type wrapping the LLVM integer type whose bit width corresponds to that of a LLVM pointer type.
Type getVoidType () const
 Gets the MLIR type wrapping the LLVM void type.
Type getVoidPtrType () const
 Get the MLIR type wrapping the LLVM i8* type.
Type getPtrType (unsigned addressSpace=0) const
 Get the MLIR type wrapping the LLVM ptr type.
Value getStridedElementPtr (ConversionPatternRewriter &rewriter, Location loc, MemRefType type, Value memRefDesc, ValueRange indices, LLVM::GEPNoWrapFlags noWrapFlags=LLVM::GEPNoWrapFlags::none) const
 Convenience wrapper for the corresponding helper utility.
bool isConvertibleAndHasIdentityMaps (MemRefType type) const
 Returns if the given memref type is convertible to LLVM and has an identity layout map.
Type getElementPtrType (MemRefType type) const
 Returns the type of a pointer to an element of the memref.
void getMemRefDescriptorSizes (Location loc, MemRefType memRefType, ValueRange dynamicSizes, ConversionPatternRewriter &rewriter, SmallVectorImpl< Value > &sizes, SmallVectorImpl< Value > &strides, Value &size, bool sizeInBytes=true) const
 Computes sizes, strides and buffer size of memRefType with identity layout.
Value getSizeInBytes (Location loc, Type type, ConversionPatternRewriter &rewriter) const
 Computes the size of type in bytes.
Value getNumElements (Location loc, MemRefType memRefType, ValueRange dynamicSizes, ConversionPatternRewriter &rewriter) const
 Computes total number of elements for the given MemRef and dynamicSizes.
MemRefDescriptor createMemRefDescriptor (Location loc, MemRefType memRefType, Value allocatedPtr, Value alignedPtr, ArrayRef< Value > sizes, ArrayRef< Value > strides, ConversionPatternRewriter &rewriter) const
 Creates and populates a canonical memref descriptor struct.
Value copyUnrankedDescriptor (OpBuilder &builder, Location loc, UnrankedMemRefType memRefType, Value operand, bool toDynamic) const
 Copies the given unranked memory descriptor to heap-allocated memory (if toDynamic is true) or to stack-allocated memory (otherwise) and returns the new descriptor.
LogicalResult copyUnrankedDescriptors (OpBuilder &builder, Location loc, TypeRange origTypes, SmallVectorImpl< Value > &operands, bool toDynamic) const
 Copies the memory descriptor for any operands that were unranked descriptors originally to heap-allocated memory (if toDynamic is true) or to stack-allocated memory (otherwise).

Static Protected Member Functions

static Value createIndexAttrConstant (OpBuilder &builder, Location loc, Type resultType, int64_t value)
 Create a constant Op producing a value of resultType from an index-typed integer attribute.

Detailed Description

Base class for operation conversions targeting the LLVM IR dialect.

It provides the conversion patterns with access to the LLVMTypeConverter and the LowerToLLVMOptions. The class captures the LLVMTypeConverter and the LowerToLLVMOptions by reference meaning the references have to remain alive during the entire pattern lifetime.

Definition at line 88 of file Pattern.h.

Constructor & Destructor Documentation

◆ ConvertToLLVMPattern()

ConvertToLLVMPattern::ConvertToLLVMPattern ( StringRef rootOpName,
MLIRContext * context,
const LLVMTypeConverter & typeConverter,
PatternBenefit benefit = 1 )

Member Function Documentation

◆ copyUnrankedDescriptor()

Value ConvertToLLVMPattern::copyUnrankedDescriptor ( OpBuilder & builder,
Location loc,
UnrankedMemRefType memRefType,
Value operand,
bool toDynamic ) const
protected

Copies the given unranked memory descriptor to heap-allocated memory (if toDynamic is true) or to stack-allocated memory (otherwise) and returns the new descriptor.

Also frees the previously used memory (that is assumed to be heap-allocated) if toDynamic is false. Returns a "null" SSA value on failure.

Definition at line 219 of file Pattern.cpp.

References mlir::UnrankedMemRefDescriptor::computeSize(), getContext(), mlir::LLVMTypeConverter::getIndexType(), mlir::LLVMTypeConverter::getMemRefAddressSpace(), getPtrType(), getTypeConverter(), mlir::LLVM::lookupOrCreateFreeFn(), mlir::LLVM::lookupOrCreateMallocFn(), mlir::UnrankedMemRefDescriptor::memRefDescPtr(), mlir::UnrankedMemRefDescriptor::poison(), and mlir::UnrankedMemRefDescriptor::rank().

Referenced by copyUnrankedDescriptors().

◆ copyUnrankedDescriptors()

LogicalResult ConvertToLLVMPattern::copyUnrankedDescriptors ( OpBuilder & builder,
Location loc,
TypeRange origTypes,
SmallVectorImpl< Value > & operands,
bool toDynamic ) const
protected

Copies the memory descriptor for any operands that were unranked descriptors originally to heap-allocated memory (if toDynamic is true) or to stack-allocated memory (otherwise).

The vector of descriptors is updated in place. Also frees the previously used memory (that is assumed to be heap-allocated) if toDynamic is false.

Definition at line 278 of file Pattern.cpp.

References copyUnrankedDescriptor(), and success().

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

◆ createIndexAttrConstant()

Value ConvertToLLVMPattern::createIndexAttrConstant ( OpBuilder & builder,
Location loc,
Type resultType,
int64_t value )
staticprotected

Create a constant Op producing a value of resultType from an index-typed integer attribute.

Definition at line 56 of file Pattern.cpp.

References mlir::Builder::getIndexAttr().

Referenced by createMemRefDescriptor(), getMemRefDescriptorSizes(), and getNumElements().

◆ createMemRefDescriptor()

MemRefDescriptor ConvertToLLVMPattern::createMemRefDescriptor ( Location loc,
MemRefType memRefType,
Value allocatedPtr,
Value alignedPtr,
ArrayRef< Value > sizes,
ArrayRef< Value > strides,
ConversionPatternRewriter & rewriter ) const
protected

Creates and populates a canonical memref descriptor struct.

Creates and populates the memref descriptor struct given all its fields.

Definition at line 190 of file Pattern.cpp.

References createIndexAttrConstant(), getIndexType(), and mlir::MemRefDescriptor::poison().

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

◆ getDialect()

LLVM::LLVMDialect & ConvertToLLVMPattern::getDialect ( ) const
protected

Returns the LLVM dialect.

Definition at line 32 of file Pattern.cpp.

References mlir::LLVMTypeConverter::getDialect(), and getTypeConverter().

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

◆ getElementPtrType()

Type ConvertToLLVMPattern::getElementPtrType ( MemRefType type) const
protected

Returns the type of a pointer to an element of the memref.

Definition at line 81 of file Pattern.cpp.

References mlir::LLVMTypeConverter::getMemRefAddressSpace(), and getTypeConverter().

◆ getIndexType()

Type ConvertToLLVMPattern::getIndexType ( ) const
protected

Gets the MLIR type wrapping the LLVM integer type whose bit width is defined by the used type converter.

Definition at line 36 of file Pattern.cpp.

References mlir::LLVMTypeConverter::getIndexType(), and getTypeConverter().

Referenced by createMemRefDescriptor(), getMemRefDescriptorSizes(), getNumElements(), and getSizeInBytes().

◆ getIntPtrType()

Type ConvertToLLVMPattern::getIntPtrType ( unsigned addressSpace = 0) const
protected

Gets the MLIR type wrapping the LLVM integer type whose bit width corresponds to that of a LLVM pointer type.

Definition at line 40 of file Pattern.cpp.

References getContext(), and getTypeConverter().

◆ getMemRefDescriptorSizes()

void ConvertToLLVMPattern::getMemRefDescriptorSizes ( Location loc,
MemRefType memRefType,
ValueRange dynamicSizes,
ConversionPatternRewriter & rewriter,
SmallVectorImpl< Value > & sizes,
SmallVectorImpl< Value > & strides,
Value & size,
bool sizeInBytes = true ) const
protected

Computes sizes, strides and buffer size of memRefType with identity layout.

Emits constant ops for the static sizes of memRefType, and uses dynamicSizes for the others. Emits instructions to compute strides and buffer size from these sizes.

For example, memref<4x?xf32> with sizeInBytes = true emits: sizes[0] = llvm.mlir.constant(4 : index) : i64 sizes[1] = dynamicSizes[0] strides[1] = llvm.mlir.constant(1 : index) : i64 strides[0] = sizes[0] size = llvm.mul sizes[0], sizes[1] : i64 nullptr = llvm.mlir.zero : !llvm.ptr gep = llvm.getelementptr nullptr[size] : (!llvm.ptr, i64) -> !llvm.ptr, f32 sizeBytes = llvm.ptrtoint gep : !llvm.ptr to i64

If sizeInBytes = false, memref<4x?xf32> emits: sizes[0] = llvm.mlir.constant(4 : index) : i64 sizes[1] = dynamicSizes[0] strides[1] = llvm.mlir.constant(1 : index) : i64 strides[0] = sizes[0] size = llvm.mul sizes[0], sizes[1] : i64

Definition at line 88 of file Pattern.cpp.

References createIndexAttrConstant(), getIndexType(), and isConvertibleAndHasIdentityMaps().

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

◆ getNumElements()

Value ConvertToLLVMPattern::getNumElements ( Location loc,
MemRefType memRefType,
ValueRange dynamicSizes,
ConversionPatternRewriter & rewriter ) const
protected

Computes total number of elements for the given MemRef and dynamicSizes.

Definition at line 158 of file Pattern.cpp.

References createIndexAttrConstant(), and getIndexType().

◆ getPtrType()

Type ConvertToLLVMPattern::getPtrType ( unsigned addressSpace = 0) const
protected

Get the MLIR type wrapping the LLVM ptr type.

Definition at line 49 of file Pattern.cpp.

References getContext(), and getTypeConverter().

Referenced by copyUnrankedDescriptor(), and getVoidPtrType().

◆ getSizeInBytes()

Value ConvertToLLVMPattern::getSizeInBytes ( Location loc,
Type type,
ConversionPatternRewriter & rewriter ) const
protected

Computes the size of type in bytes.

Definition at line 143 of file Pattern.cpp.

References getIndexType().

◆ getStridedElementPtr()

Value ConvertToLLVMPattern::getStridedElementPtr ( ConversionPatternRewriter & rewriter,
Location loc,
MemRefType type,
Value memRefDesc,
ValueRange indices,
LLVM::GEPNoWrapFlags noWrapFlags = LLVM::GEPNoWrapFlags::none ) const
protected

Convenience wrapper for the corresponding helper utility.

This is a strided getElementPtr variant with linearized subscripts.

Definition at line 64 of file Pattern.cpp.

References mlir::LLVM::getStridedElementPtr(), getTypeConverter(), and indices.

◆ getTypeConverter()

◆ getVoidPtrType()

Type ConvertToLLVMPattern::getVoidPtrType ( ) const
protected

Get the MLIR type wrapping the LLVM i8* type.

Definition at line 54 of file Pattern.cpp.

References getPtrType().

◆ getVoidType()

Type ConvertToLLVMPattern::getVoidType ( ) const
protected

Gets the MLIR type wrapping the LLVM void type.

Definition at line 45 of file Pattern.cpp.

References getContext(), and getTypeConverter().

◆ isConvertibleAndHasIdentityMaps()

bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps ( MemRefType type) const
protected

Returns if the given memref type is convertible to LLVM and has an identity layout map.

Definition at line 74 of file Pattern.cpp.

Referenced by getMemRefDescriptorSizes().


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