9 #ifndef MLIR_CONVERSION_MEMREFTOLLVM_ALLOCLIKECONVERSION_H
10 #define MLIR_CONVERSION_MEMREFTOLLVM_ALLOCLIKECONVERSION_H
40 template <
typename OpType>
43 MemRefType memRefType = op.
getType();
45 if (
auto alignmentAttr = op.getAlignment()) {
49 }
else if (!memRefType.getElementType().isSignlessIntOrIndexOrFloat()) {
54 alignment =
getSizeInBytes(loc, memRefType.getElementType(), rewriter);
64 template <
typename OpType>
68 if (std::optional<uint64_t> alignment = op.getAlignment())
74 unsigned eltSizeBytes =
75 getMemRefEltSizeInBytes(op.getType(), op, defaultLayout);
76 return std::max(kMinAlignedAllocAlignment,
77 llvm::PowerOf2Ceil(eltSizeBytes));
82 std::tuple<Value, Value>
85 Value alignment)
const;
91 int64_t alignment)
const;
95 unsigned getMemRefEltSizeInBytes(MemRefType memRefType,
Operation *op,
100 bool isMemRefSizeMultipleOf(MemRefType type, uint64_t factor,
Operation *op,
104 static constexpr uint64_t kMinAlignedAllocAlignment = 16UL;
117 virtual std::tuple<Value, Value>
148 bool requiresNumElements =
false;
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.
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.
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.
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
MLIRContext * getContext() const
Return the MLIRContext used to create this pattern.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
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.
AllocLikeOpLLVMLowering(StringRef opName, const LLVMTypeConverter &converter, PatternBenefit benefit=1)
void setRequiresNumElements()
Sets the flag 'requiresNumElements', specifying the Op requires the number of elements instead of the...
virtual std::tuple< Value, Value > allocateBuffer(ConversionPatternRewriter &rewriter, Location loc, Value size, Operation *op) const =0
Allocates the underlying buffer.
Lowering for memory allocation ops.
Type getIndexType() const
Gets the MLIR type wrapping the LLVM integer type whose bit width is defined by the used type convert...
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.
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.
AllocationOpLLVMLowering(StringRef opName, const LLVMTypeConverter &converter, PatternBenefit benefit=1)