MLIR  19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
mlir::MemRefDescriptor Class Reference

Helper class to produce LLVM dialect operations extracting or inserting elements of a MemRef descriptor. More...

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

+ Inheritance diagram for mlir::MemRefDescriptor:

Public Member Functions

 MemRefDescriptor (Value descriptor)
 Construct a helper for the given descriptor value. More...
 
Value allocatedPtr (OpBuilder &builder, Location loc)
 Builds IR extracting the allocated pointer from the descriptor. More...
 
void setAllocatedPtr (OpBuilder &builder, Location loc, Value ptr)
 Builds IR inserting the allocated pointer into the descriptor. More...
 
Value alignedPtr (OpBuilder &builder, Location loc)
 Builds IR extracting the aligned pointer from the descriptor. More...
 
void setAlignedPtr (OpBuilder &builder, Location loc, Value ptr)
 Builds IR inserting the aligned pointer into the descriptor. More...
 
Value offset (OpBuilder &builder, Location loc)
 Builds IR extracting the offset from the descriptor. More...
 
void setOffset (OpBuilder &builder, Location loc, Value offset)
 Builds IR inserting the offset into the descriptor. More...
 
void setConstantOffset (OpBuilder &builder, Location loc, uint64_t offset)
 Builds IR inserting the offset into the descriptor. More...
 
Value size (OpBuilder &builder, Location loc, unsigned pos)
 Builds IR extracting the pos-th size from the descriptor. More...
 
Value size (OpBuilder &builder, Location loc, Value pos, int64_t rank)
 
void setSize (OpBuilder &builder, Location loc, unsigned pos, Value size)
 Builds IR inserting the pos-th size into the descriptor. More...
 
void setConstantSize (OpBuilder &builder, Location loc, unsigned pos, uint64_t size)
 
Value stride (OpBuilder &builder, Location loc, unsigned pos)
 Builds IR extracting the pos-th size from the descriptor. More...
 
void setStride (OpBuilder &builder, Location loc, unsigned pos, Value stride)
 Builds IR inserting the pos-th stride into the descriptor. More...
 
void setConstantStride (OpBuilder &builder, Location loc, unsigned pos, uint64_t stride)
 
Type getIndexType ()
 Returns the type of array element in this descriptor. More...
 
LLVM::LLVMPointerType getElementPtrType ()
 Returns the (LLVM) pointer type this descriptor contains. More...
 
Value bufferPtr (OpBuilder &builder, Location loc, const LLVMTypeConverter &converter, MemRefType type)
 Builds IR for getting the start address of the buffer represented by this memref: memref.alignedPtr + memref.offset * sizeof(type.getElementType()). More...
 
- Public Member Functions inherited from mlir::StructBuilder
 StructBuilder (Value v)
 Construct a helper for the given value. More...
 
 operator Value ()
 

Static Public Member Functions

static MemRefDescriptor undef (OpBuilder &builder, Location loc, Type descriptorType)
 Builds IR creating an undef value of the descriptor type. More...
 
static MemRefDescriptor fromStaticShape (OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, MemRefType type, Value memory)
 Builds IR creating a MemRef descriptor that represents type and populates it with static shape and stride information extracted from the type. More...
 
static MemRefDescriptor fromStaticShape (OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, MemRefType type, Value memory, Value alignedMemory)
 
static Value pack (OpBuilder &builder, Location loc, const LLVMTypeConverter &converter, MemRefType type, ValueRange values)
 Builds IR populating a MemRef descriptor structure from a list of individual values composing that descriptor, in the following order: More...
 
static void unpack (OpBuilder &builder, Location loc, Value packed, MemRefType type, SmallVectorImpl< Value > &results)
 Builds IR extracting individual elements of a MemRef descriptor structure and returning them as results list. More...
 
static unsigned getNumUnpackedValues (MemRefType type)
 Returns the number of non-aggregate values that would be produced by unpack. More...
 
- Static Public Member Functions inherited from mlir::StructBuilder
static StructBuilder undef (OpBuilder &builder, Location loc, Type descriptorType)
 Builds IR creating an undef value of the descriptor type. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mlir::StructBuilder
Value extractPtr (OpBuilder &builder, Location loc, unsigned pos) const
 Builds IR to extract a value from the struct at position pos. More...
 
void setPtr (OpBuilder &builder, Location loc, unsigned pos, Value ptr)
 Builds IR to set a value in the struct at position pos. More...
 
- Protected Attributes inherited from mlir::StructBuilder
Value value
 
Type structType
 

Detailed Description

Helper class to produce LLVM dialect operations extracting or inserting elements of a MemRef descriptor.

Wraps a Value pointing to the descriptor. The Value may be null, in which case none of the operations are valid.

Definition at line 33 of file MemRefBuilder.h.

Constructor & Destructor Documentation

◆ MemRefDescriptor()

MemRefDescriptor::MemRefDescriptor ( Value  descriptor)
explicit

Construct a helper for the given descriptor value.

Definition at line 24 of file MemRefBuilder.cpp.

References mlir::Value::getType(), kOffsetPosInMemRefDescriptor, and mlir::StructBuilder::value.

Referenced by undef().

Member Function Documentation

◆ alignedPtr()

Value MemRefDescriptor::alignedPtr ( OpBuilder builder,
Location  loc 
)

Builds IR extracting the aligned pointer from the descriptor.

Definition at line 88 of file MemRefBuilder.cpp.

References mlir::StructBuilder::extractPtr(), and kAlignedPtrPosInMemRefDescriptor.

Referenced by bufferPtr(), mlir::LLVMTypeConverter::promoteOperands(), and unpack().

◆ allocatedPtr()

Value MemRefDescriptor::allocatedPtr ( OpBuilder builder,
Location  loc 
)

Builds IR extracting the allocated pointer from the descriptor.

Definition at line 77 of file MemRefBuilder.cpp.

References mlir::StructBuilder::extractPtr(), and kAllocatedPtrPosInMemRefDescriptor.

Referenced by unpack().

◆ bufferPtr()

Value MemRefDescriptor::bufferPtr ( OpBuilder builder,
Location  loc,
const LLVMTypeConverter converter,
MemRefType  type 
)

Builds IR for getting the start address of the buffer represented by this memref: memref.alignedPtr + memref.offset * sizeof(type.getElementType()).

Note
there is no setter for this one since it is derived from alignedPtr and offset.

Definition at line 191 of file MemRefBuilder.cpp.

References alignedPtr(), mlir::LLVMTypeConverter::convertType(), mlir::OpBuilder::create(), createIndexAttrConstant(), mlir::LLVMTypeConverter::getIndexType(), mlir::getStridesAndOffset(), mlir::Value::getType(), and offset().

◆ fromStaticShape() [1/2]

MemRefDescriptor MemRefDescriptor::fromStaticShape ( OpBuilder builder,
Location  loc,
const LLVMTypeConverter typeConverter,
MemRefType  type,
Value  memory 
)
static

Builds IR creating a MemRef descriptor that represents type and populates it with static shape and stride information extracted from the type.

Definition at line 43 of file MemRefBuilder.cpp.

Referenced by mlir::GPUFuncOpLowering::matchAndRewrite(), modifyFuncOpToUseBarePtrCallingConv(), and mlir::LLVMTypeConverter::promoteBarePtrsToDescriptors().

◆ fromStaticShape() [2/2]

MemRefDescriptor MemRefDescriptor::fromStaticShape ( OpBuilder builder,
Location  loc,
const LLVMTypeConverter typeConverter,
MemRefType  type,
Value  memory,
Value  alignedMemory 
)
static

◆ getElementPtrType()

LLVM::LLVMPointerType MemRefDescriptor::getElementPtrType ( )

Returns the (LLVM) pointer type this descriptor contains.

Definition at line 185 of file MemRefBuilder.cpp.

References mlir::Value::getType(), kAlignedPtrPosInMemRefDescriptor, and mlir::StructBuilder::value.

Referenced by getIndexedPtrs().

◆ getIndexType()

Type mlir::MemRefDescriptor::getIndexType ( )
inline

Returns the type of array element in this descriptor.

Definition at line 88 of file MemRefBuilder.h.

◆ getNumUnpackedValues()

unsigned MemRefDescriptor::getNumUnpackedValues ( MemRefType  type)
static

Returns the number of non-aggregate values that would be produced by unpack.

Definition at line 262 of file MemRefBuilder.cpp.

Referenced by unpack(), and wrapExternalFunction().

◆ offset()

Value MemRefDescriptor::offset ( OpBuilder builder,
Location  loc 
)

Builds IR extracting the offset from the descriptor.

Definition at line 107 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), kOffsetPosInMemRefDescriptor, and mlir::StructBuilder::value.

Referenced by bufferPtr(), fromStaticShape(), setConstantOffset(), setOffset(), and unpack().

◆ pack()

Value MemRefDescriptor::pack ( OpBuilder builder,
Location  loc,
const LLVMTypeConverter converter,
MemRefType  type,
ValueRange  values 
)
static

Builds IR populating a MemRef descriptor structure from a list of individual values composing that descriptor, in the following order:

Creates a MemRef descriptor structure from a list of individual values composing that descriptor, in the following order:

  • allocated pointer;
  • aligned pointer;
  • offset;
  • <rank> sizes;
  • <rank> shapes; where <rank> is the MemRef rank as provided in type.

Definition at line 223 of file MemRefBuilder.cpp.

References mlir::LLVMTypeConverter::convertType(), kAlignedPtrPosInMemRefDescriptor, kAllocatedPtrPosInMemRefDescriptor, kOffsetPosInMemRefDescriptor, kSizePosInMemRefDescriptor, and undef().

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

◆ setAlignedPtr()

void MemRefDescriptor::setAlignedPtr ( OpBuilder builder,
Location  loc,
Value  ptr 
)

Builds IR inserting the aligned pointer into the descriptor.

Definition at line 93 of file MemRefBuilder.cpp.

References kAlignedPtrPosInMemRefDescriptor, and mlir::StructBuilder::setPtr().

◆ setAllocatedPtr()

void MemRefDescriptor::setAllocatedPtr ( OpBuilder builder,
Location  loc,
Value  ptr 
)

Builds IR inserting the allocated pointer into the descriptor.

Definition at line 82 of file MemRefBuilder.cpp.

References kAllocatedPtrPosInMemRefDescriptor, and mlir::StructBuilder::setPtr().

◆ setConstantOffset()

void MemRefDescriptor::setConstantOffset ( OpBuilder builder,
Location  loc,
uint64_t  offset 
)

Builds IR inserting the offset into the descriptor.

Definition at line 120 of file MemRefBuilder.cpp.

References createIndexAttrConstant(), offset(), and setOffset().

◆ setConstantSize()

void MemRefDescriptor::setConstantSize ( OpBuilder builder,
Location  loc,
unsigned  pos,
uint64_t  size 
)

Definition at line 159 of file MemRefBuilder.cpp.

References createIndexAttrConstant(), setSize(), and size().

◆ setConstantStride()

void MemRefDescriptor::setConstantStride ( OpBuilder builder,
Location  loc,
unsigned  pos,
uint64_t  stride 
)

Definition at line 179 of file MemRefBuilder.cpp.

References createIndexAttrConstant(), setStride(), and stride().

◆ setOffset()

void MemRefDescriptor::setOffset ( OpBuilder builder,
Location  loc,
Value  offset 
)

Builds IR inserting the offset into the descriptor.

Definition at line 113 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), kOffsetPosInMemRefDescriptor, offset(), and mlir::StructBuilder::value.

Referenced by setConstantOffset().

◆ setSize()

void MemRefDescriptor::setSize ( OpBuilder builder,
Location  loc,
unsigned  pos,
Value  size 
)

Builds IR inserting the pos-th size into the descriptor.

Definition at line 153 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), kSizePosInMemRefDescriptor, size(), and mlir::StructBuilder::value.

Referenced by setConstantSize().

◆ setStride()

void MemRefDescriptor::setStride ( OpBuilder builder,
Location  loc,
unsigned  pos,
Value  stride 
)

Builds IR inserting the pos-th stride into the descriptor.

Definition at line 172 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), kStridePosInMemRefDescriptor, stride(), and mlir::StructBuilder::value.

Referenced by setConstantStride().

◆ size() [1/2]

Value MemRefDescriptor::size ( OpBuilder builder,
Location  loc,
unsigned  pos 
)

Builds IR extracting the pos-th size from the descriptor.

Definition at line 127 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), kSizePosInMemRefDescriptor, and mlir::StructBuilder::value.

Referenced by setConstantSize(), setSize(), and unpack().

◆ size() [2/2]

Value MemRefDescriptor::size ( OpBuilder builder,
Location  loc,
Value  pos,
int64_t  rank 
)

◆ stride()

Value MemRefDescriptor::stride ( OpBuilder builder,
Location  loc,
unsigned  pos 
)

Builds IR extracting the pos-th size from the descriptor.

Builds IR extracting the pos-th stride from the descriptor.

Definition at line 166 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), kStridePosInMemRefDescriptor, and mlir::StructBuilder::value.

Referenced by setConstantStride(), setStride(), and unpack().

◆ undef()

MemRefDescriptor MemRefDescriptor::undef ( OpBuilder builder,
Location  loc,
Type  descriptorType 
)
static

Builds IR creating an undef value of the descriptor type.

Definition at line 32 of file MemRefBuilder.cpp.

References mlir::OpBuilder::create(), and MemRefDescriptor().

Referenced by mlir::ConvertToLLVMPattern::createMemRefDescriptor(), fromStaticShape(), and pack().

◆ unpack()

void MemRefDescriptor::unpack ( OpBuilder builder,
Location  loc,
Value  packed,
MemRefType  type,
SmallVectorImpl< Value > &  results 
)
static

Builds IR extracting individual elements of a MemRef descriptor structure and returning them as results list.

Definition at line 244 of file MemRefBuilder.cpp.

References alignedPtr(), allocatedPtr(), getNumUnpackedValues(), offset(), size(), and stride().

Referenced by mlir::LLVMTypeConverter::promoteOperands(), and wrapForExternalCallers().


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