9 #ifndef MLIR_CONVERSION_MEMREFTOLLVM_ALLOCLIKECONVERSION_H
10 #define MLIR_CONVERSION_MEMREFTOLLVM_ALLOCLIKECONVERSION_H
38 template <
typename OpType>
41 MemRefType memRefType = op.
getType();
43 if (
auto alignmentAttr = op.getAlignment()) {
45 }
else if (!memRefType.getElementType().isSignlessIntOrIndexOrFloat()) {
50 alignment =
getSizeInBytes(loc, memRefType.getElementType(), rewriter);
60 template <
typename OpType>
64 if (std::optional<uint64_t> alignment = op.getAlignment())
70 unsigned eltSizeBytes =
71 getMemRefEltSizeInBytes(op.getType(), op, defaultLayout);
72 return std::max(kMinAlignedAllocAlignment,
73 llvm::PowerOf2Ceil(eltSizeBytes));
78 std::tuple<Value, Value>
81 Value alignment)
const;
87 int64_t alignment)
const;
91 unsigned getMemRefEltSizeInBytes(MemRefType memRefType,
Operation *op,
96 bool isMemRefSizeMultipleOf(MemRefType type, uint64_t factor,
Operation *op,
100 static constexpr uint64_t kMinAlignedAllocAlignment = 16UL;
112 virtual std::tuple<Value, Value>
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
This class implements a pattern rewriter for use with ConversionPatterns.
Base class for operation conversions targeting the LLVM IR dialect.
Type getIndexType() const
Gets the MLIR type wrapping the LLVM integer type whose bit width is defined by the used type convert...
Value getSizeInBytes(Location loc, Type type, ConversionPatternRewriter &rewriter) const
Computes the size of type in bytes.
Value createIndexConstant(ConversionPatternRewriter &builder, Location loc, uint64_t value) const
Create an LLVM dialect operation defining the given index constant.
Type getVoidPtrType() const
Get the MLIR type wrapping the LLVM i8* type.
The main mechanism for performing data layout queries.
Conversion from types to the LLVM IR dialect.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation is the basic unit of execution within MLIR.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
MLIRContext * getContext() const
Return the MLIRContext used to create this pattern.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Include the generated interface declarations.
Lowering for AllocOp and AllocaOp.
virtual std::tuple< Value, Value > allocateBuffer(ConversionPatternRewriter &rewriter, Location loc, Value sizeBytes, Operation *op) const =0
Allocates the underlying buffer.
AllocLikeOpLLVMLowering(StringRef opName, LLVMTypeConverter &converter)
Lowering for memory allocation ops.
static Value createAligned(ConversionPatternRewriter &rewriter, Location loc, Value input, Value alignment)
Computes the aligned value for 'input' as follows: bumped = input + alignement - 1 aligned = bumped -...
int64_t alignedAllocationGetAlignment(ConversionPatternRewriter &rewriter, Location loc, OpType op, const DataLayout *defaultLayout) const
Computes the alignment for aligned_alloc used to allocate the buffer for the memory allocation op.
Value getAlignment(ConversionPatternRewriter &rewriter, Location loc, OpType op) const
Computes the alignment for the given memory allocation op.
Value allocateBufferAutoAlign(ConversionPatternRewriter &rewriter, Location loc, Value sizeBytes, Operation *op, const DataLayout *defaultLayout, int64_t alignment) const
Allocates a memory buffer using an aligned allocation method.
static MemRefType getMemRefResultType(Operation *op)
std::tuple< Value, Value > allocateBufferManuallyAlign(ConversionPatternRewriter &rewriter, Location loc, Value sizeBytes, Operation *op, Value alignment) const
Allocates a memory buffer using an allocation method that doesn't guarantee alignment.
Value createIndexConstant(ConversionPatternRewriter &builder, Location loc, uint64_t value) const
Create an LLVM dialect operation defining the given index constant.
AllocationOpLLVMLowering(StringRef opName, LLVMTypeConverter &converter)
This class represents an efficient way to signal success or failure.