MLIR 22.0.0git
MemRefBuilder.cpp
Go to the documentation of this file.
1//===- MemRefBuilder.cpp - Helper for LLVM MemRef equivalents -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "MemRefDescriptor.h"
14#include "mlir/IR/Builders.h"
15#include "llvm/Support/MathExtras.h"
16
17using namespace mlir;
18
19//===----------------------------------------------------------------------===//
20// MemRefDescriptor implementation
21//===----------------------------------------------------------------------===//
22
23/// Construct a helper for the given descriptor value.
25 : StructBuilder(descriptor) {
26 assert(value != nullptr && "value cannot be null");
27 indexType = cast<LLVM::LLVMStructType>(value.getType())
29}
30
31/// Builds IR creating an `undef` value of the descriptor type.
33 Type descriptorType) {
34
35 Value descriptor = LLVM::PoisonOp::create(builder, loc, descriptorType);
36 return MemRefDescriptor(descriptor);
37}
38
39/// Builds IR creating a MemRef descriptor that represents `type` and
40/// populates it with static shape and stride information extracted from the
41/// type.
44 const LLVMTypeConverter &typeConverter,
45 MemRefType type, Value memory) {
46 return fromStaticShape(builder, loc, typeConverter, type, memory, memory);
47}
48
50 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
51 MemRefType type, Value memory, Value alignedMemory) {
52 assert(type.hasStaticShape() && "unexpected dynamic shape");
53
54 // Extract all strides and offsets and verify they are static.
55 auto [strides, offset] = type.getStridesAndOffset();
56 assert(ShapedType::isStatic(offset) && "expected static offset");
57 assert(!llvm::any_of(strides, ShapedType::isDynamic) &&
58 "expected static strides");
59
60 auto convertedType = typeConverter.convertType(type);
61 assert(convertedType && "unexpected failure in memref type conversion");
62
63 auto descr = MemRefDescriptor::poison(builder, loc, convertedType);
64 descr.setAllocatedPtr(builder, loc, memory);
65 descr.setAlignedPtr(builder, loc, alignedMemory);
66 descr.setConstantOffset(builder, loc, offset);
67
68 // Fill in sizes and strides
69 for (unsigned i = 0, e = type.getRank(); i != e; ++i) {
70 descr.setConstantSize(builder, loc, i, type.getDimSize(i));
71 descr.setConstantStride(builder, loc, i, strides[i]);
72 }
73 return descr;
74}
75
76/// Builds IR extracting the allocated pointer from the descriptor.
80
81/// Builds IR inserting the allocated pointer into the descriptor.
86
87/// Builds IR extracting the aligned pointer from the descriptor.
91
92/// Builds IR inserting the aligned pointer into the descriptor.
97
98// Creates a constant Op producing a value of `resultType` from an index-typed
99// integer attribute.
101 Type resultType, int64_t value) {
102 return LLVM::ConstantOp::create(builder, loc, resultType,
103 builder.getIndexAttr(value));
104}
105
106/// Builds IR extracting the offset from the descriptor.
108 return LLVM::ExtractValueOp::create(builder, loc, value,
110}
111
112/// Builds IR inserting the offset into the descriptor.
114 Value offset) {
115 value = LLVM::InsertValueOp::create(builder, loc, value, offset,
117}
118
119/// Builds IR inserting the offset into the descriptor.
121 uint64_t offset) {
122 setOffset(builder, loc,
123 createIndexAttrConstant(builder, loc, indexType, offset));
124}
125
126/// Builds IR extracting the pos-th size from the descriptor.
127Value MemRefDescriptor::size(OpBuilder &builder, Location loc, unsigned pos) {
128 return LLVM::ExtractValueOp::create(
129 builder, loc, value,
131}
132
134 int64_t rank) {
135 auto arrayTy = LLVM::LLVMArrayType::get(indexType, rank);
136
137 auto ptrTy = LLVM::LLVMPointerType::get(builder.getContext());
138
139 // Copy size values to stack-allocated memory.
140 auto one = createIndexAttrConstant(builder, loc, indexType, 1);
141 auto sizes = LLVM::ExtractValueOp::create(
142 builder, loc, value,
144 auto sizesPtr = LLVM::AllocaOp::create(builder, loc, ptrTy, arrayTy, one,
145 /*alignment=*/0);
146 LLVM::StoreOp::create(builder, loc, sizes, sizesPtr);
147
148 // Load an return size value of interest.
149 auto resultPtr = LLVM::GEPOp::create(builder, loc, ptrTy, arrayTy, sizesPtr,
150 ArrayRef<LLVM::GEPArg>{0, pos});
151 return LLVM::LoadOp::create(builder, loc, indexType, resultPtr);
152}
153
154/// Builds IR inserting the pos-th size into the descriptor
155void MemRefDescriptor::setSize(OpBuilder &builder, Location loc, unsigned pos,
156 Value size) {
157 value = LLVM::InsertValueOp::create(
158 builder, loc, value, size,
160}
161
163 unsigned pos, uint64_t size) {
164 setSize(builder, loc, pos,
165 createIndexAttrConstant(builder, loc, indexType, size));
166}
167
168/// Builds IR extracting the pos-th stride from the descriptor.
169Value MemRefDescriptor::stride(OpBuilder &builder, Location loc, unsigned pos) {
170 return LLVM::ExtractValueOp::create(
171 builder, loc, value,
173}
174
175/// Builds IR inserting the pos-th stride into the descriptor
176void MemRefDescriptor::setStride(OpBuilder &builder, Location loc, unsigned pos,
177 Value stride) {
178 value = LLVM::InsertValueOp::create(
179 builder, loc, value, stride,
181}
182
184 unsigned pos, uint64_t stride) {
185 setStride(builder, loc, pos,
186 createIndexAttrConstant(builder, loc, indexType, stride));
187}
188
189LLVM::LLVMPointerType MemRefDescriptor::getElementPtrType() {
190 return cast<LLVM::LLVMPointerType>(
191 cast<LLVM::LLVMStructType>(value.getType())
193}
194
196 const LLVMTypeConverter &converter,
197 MemRefType type) {
198 // When we convert to LLVM, the input memref must have been normalized
199 // beforehand. Hence, this call is guaranteed to work.
200 auto [strides, offsetCst] = type.getStridesAndOffset();
201
202 Value ptr = alignedPtr(builder, loc);
203 // For zero offsets, we already have the base pointer.
204 if (offsetCst == 0)
205 return ptr;
206
207 // Otherwise add the offset to the aligned base.
208 Type indexType = converter.getIndexType();
209 Value offsetVal =
210 ShapedType::isDynamic(offsetCst)
211 ? offset(builder, loc)
212 : createIndexAttrConstant(builder, loc, indexType, offsetCst);
213 Type elementType = converter.convertType(type.getElementType());
214 ptr = LLVM::GEPOp::create(builder, loc, ptr.getType(), elementType, ptr,
215 offsetVal);
216 return ptr;
217}
218
219/// Creates a MemRef descriptor structure from a list of individual values
220/// composing that descriptor, in the following order:
221/// - allocated pointer;
222/// - aligned pointer;
223/// - offset;
224/// - <rank> sizes;
225/// - <rank> strides;
226/// where <rank> is the MemRef rank as provided in `type`.
228 const LLVMTypeConverter &converter,
229 MemRefType type, ValueRange values) {
230 Type llvmType = converter.convertType(type);
231 auto d = MemRefDescriptor::poison(builder, loc, llvmType);
232
233 d.setAllocatedPtr(builder, loc, values[kAllocatedPtrPosInMemRefDescriptor]);
234 d.setAlignedPtr(builder, loc, values[kAlignedPtrPosInMemRefDescriptor]);
235 d.setOffset(builder, loc, values[kOffsetPosInMemRefDescriptor]);
236
237 int64_t rank = type.getRank();
238 for (unsigned i = 0; i < rank; ++i) {
239 d.setSize(builder, loc, i, values[kSizePosInMemRefDescriptor + i]);
240 d.setStride(builder, loc, i, values[kSizePosInMemRefDescriptor + rank + i]);
241 }
242
243 return d;
244}
245
246/// Builds IR extracting individual elements of a MemRef descriptor structure
247/// and returning them as `results` list.
249 MemRefType type,
250 SmallVectorImpl<Value> &results) {
251 int64_t rank = type.getRank();
252 results.reserve(results.size() + getNumUnpackedValues(type));
253
254 MemRefDescriptor d(packed);
255 results.push_back(d.allocatedPtr(builder, loc));
256 results.push_back(d.alignedPtr(builder, loc));
257 results.push_back(d.offset(builder, loc));
258 for (int64_t i = 0; i < rank; ++i)
259 results.push_back(d.size(builder, loc, i));
260 for (int64_t i = 0; i < rank; ++i)
261 results.push_back(d.stride(builder, loc, i));
262}
263
264/// Returns the number of non-aggregate values that would be produced by
265/// `unpack`.
266unsigned MemRefDescriptor::getNumUnpackedValues(MemRefType type) {
267 // Two pointers, offset, <rank> sizes, <rank> strides.
268 return 3 + 2 * type.getRank();
269}
270
271//===----------------------------------------------------------------------===//
272// MemRefDescriptorView implementation.
273//===----------------------------------------------------------------------===//
274
276 : rank((range.size() - kSizePosInMemRefDescriptor) / 2), elements(range) {}
277
281
285
289
291 return elements[kSizePosInMemRefDescriptor + pos];
292}
293
295 return elements[kSizePosInMemRefDescriptor + rank + pos];
296}
297
298//===----------------------------------------------------------------------===//
299// UnrankedMemRefDescriptor implementation
300//===----------------------------------------------------------------------===//
301
302/// Construct a helper for the given descriptor value.
305
306/// Builds IR creating an `undef` value of the descriptor type.
308 Location loc,
309 Type descriptorType) {
310 Value descriptor = LLVM::PoisonOp::create(builder, loc, descriptorType);
311 return UnrankedMemRefDescriptor(descriptor);
312}
328
329/// Builds IR populating an unranked MemRef descriptor structure from a list
330/// of individual constituent values in the following order:
331/// - rank of the memref;
332/// - pointer to the memref descriptor.
334 const LLVMTypeConverter &converter,
336 ValueRange values) {
337 Type llvmType = converter.convertType(type);
338 auto d = UnrankedMemRefDescriptor::poison(builder, loc, llvmType);
339
340 d.setRank(builder, loc, values[kRankInUnrankedMemRefDescriptor]);
341 d.setMemRefDescPtr(builder, loc, values[kPtrInUnrankedMemRefDescriptor]);
342 return d;
343}
344
345/// Builds IR extracting individual elements that compose an unranked memref
346/// descriptor and returns them as `results` list.
348 Value packed,
349 SmallVectorImpl<Value> &results) {
350 UnrankedMemRefDescriptor d(packed);
351 results.reserve(results.size() + 2);
352 results.push_back(d.rank(builder, loc));
353 results.push_back(d.memRefDescPtr(builder, loc));
354}
355
357 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
358 UnrankedMemRefDescriptor desc, unsigned addressSpace) {
359 // Cache the index type.
360 Type indexType = typeConverter.getIndexType();
361
362 // Initialize shared constants.
363 Value one = createIndexAttrConstant(builder, loc, indexType, 1);
364 Value two = createIndexAttrConstant(builder, loc, indexType, 2);
365 Value indexSize = createIndexAttrConstant(
366 builder, loc, indexType,
367 llvm::divideCeil(typeConverter.getIndexTypeBitwidth(), 8));
368
369 // Emit IR computing the memory necessary to store the descriptor. This
370 // assumes the descriptor to be
371 // { type*, type*, index, index[rank], index[rank] }
372 // and densely packed, so the total size is
373 // 2 * sizeof(pointer) + (1 + 2 * rank) * sizeof(index).
374 // TODO: consider including the actual size (including eventual padding due
375 // to data layout) into the unranked descriptor.
376 Value pointerSize = createIndexAttrConstant(
377 builder, loc, indexType,
378 llvm::divideCeil(typeConverter.getPointerBitwidth(addressSpace), 8));
379 Value doublePointerSize =
380 LLVM::MulOp::create(builder, loc, indexType, two, pointerSize);
381
382 // (1 + 2 * rank) * sizeof(index)
383 Value rank = desc.rank(builder, loc);
384 Value doubleRank = LLVM::MulOp::create(builder, loc, indexType, two, rank);
385 Value doubleRankIncremented =
386 LLVM::AddOp::create(builder, loc, indexType, doubleRank, one);
387 Value rankIndexSize = LLVM::MulOp::create(builder, loc, indexType,
388 doubleRankIncremented, indexSize);
389
390 // Total allocation size.
391 Value allocationSize = LLVM::AddOp::create(builder, loc, indexType,
392 doublePointerSize, rankIndexSize);
393 return allocationSize;
394}
395
397 OpBuilder &builder, Location loc, Value memRefDescPtr,
398 LLVM::LLVMPointerType elemPtrType) {
399 return LLVM::LoadOp::create(builder, loc, elemPtrType, memRefDescPtr);
400}
401
403 OpBuilder &builder, Location loc, Value memRefDescPtr,
404 LLVM::LLVMPointerType elemPtrType, Value allocatedPtr) {
405 LLVM::StoreOp::create(builder, loc, allocatedPtr, memRefDescPtr);
406}
407
408static std::pair<Value, Type>
409castToElemPtrPtr(OpBuilder &builder, Location loc, Value memRefDescPtr,
410 LLVM::LLVMPointerType elemPtrType) {
411 auto elemPtrPtrType = LLVM::LLVMPointerType::get(builder.getContext());
412 return {memRefDescPtr, elemPtrPtrType};
413}
414
416 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
417 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType) {
418 auto [elementPtrPtr, elemPtrPtrType] =
419 castToElemPtrPtr(builder, loc, memRefDescPtr, elemPtrType);
420
421 Value alignedGep =
422 LLVM::GEPOp::create(builder, loc, elemPtrPtrType, elemPtrType,
423 elementPtrPtr, ArrayRef<LLVM::GEPArg>{1});
424 return LLVM::LoadOp::create(builder, loc, elemPtrType, alignedGep);
425}
426
428 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
429 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType, Value alignedPtr) {
430 auto [elementPtrPtr, elemPtrPtrType] =
431 castToElemPtrPtr(builder, loc, memRefDescPtr, elemPtrType);
432
433 Value alignedGep =
434 LLVM::GEPOp::create(builder, loc, elemPtrPtrType, elemPtrType,
435 elementPtrPtr, ArrayRef<LLVM::GEPArg>{1});
436 LLVM::StoreOp::create(builder, loc, alignedPtr, alignedGep);
437}
438
440 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
441 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType) {
442 auto [elementPtrPtr, elemPtrPtrType] =
443 castToElemPtrPtr(builder, loc, memRefDescPtr, elemPtrType);
444
445 return LLVM::GEPOp::create(builder, loc, elemPtrPtrType, elemPtrType,
446 elementPtrPtr, ArrayRef<LLVM::GEPArg>{2});
447}
448
450 const LLVMTypeConverter &typeConverter,
452 LLVM::LLVMPointerType elemPtrType) {
453 Value offsetPtr =
454 offsetBasePtr(builder, loc, typeConverter, memRefDescPtr, elemPtrType);
455 return LLVM::LoadOp::create(builder, loc, typeConverter.getIndexType(),
456 offsetPtr);
457}
458
460 const LLVMTypeConverter &typeConverter,
462 LLVM::LLVMPointerType elemPtrType,
463 Value offset) {
464 Value offsetPtr =
465 offsetBasePtr(builder, loc, typeConverter, memRefDescPtr, elemPtrType);
466 LLVM::StoreOp::create(builder, loc, offset, offsetPtr);
467}
468
470 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
471 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType) {
472 Type indexTy = typeConverter.getIndexType();
473 Type structTy = LLVM::LLVMStructType::getLiteral(
474 indexTy.getContext(), {elemPtrType, elemPtrType, indexTy, indexTy});
475 auto resultType = LLVM::LLVMPointerType::get(builder.getContext());
476 return LLVM::GEPOp::create(builder, loc, resultType, structTy, memRefDescPtr,
478}
479
481 const LLVMTypeConverter &typeConverter,
483
484 Type indexTy = typeConverter.getIndexType();
485 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
486
487 Value sizeStoreGep =
488 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, sizeBasePtr, index);
489 return LLVM::LoadOp::create(builder, loc, indexTy, sizeStoreGep);
490}
491
493 const LLVMTypeConverter &typeConverter,
495 Value size) {
496 Type indexTy = typeConverter.getIndexType();
497 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
498
499 Value sizeStoreGep =
500 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, sizeBasePtr, index);
501 LLVM::StoreOp::create(builder, loc, size, sizeStoreGep);
502}
503
505 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
507 Type indexTy = typeConverter.getIndexType();
508 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
509
510 return LLVM::GEPOp::create(builder, loc, ptrType, indexTy, sizeBasePtr, rank);
511}
512
514 const LLVMTypeConverter &typeConverter,
516 Value stride) {
517 Type indexTy = typeConverter.getIndexType();
518 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
519
520 Value strideStoreGep =
521 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, strideBasePtr, index);
522 return LLVM::LoadOp::create(builder, loc, indexTy, strideStoreGep);
523}
524
526 const LLVMTypeConverter &typeConverter,
528 Value stride) {
529 Type indexTy = typeConverter.getIndexType();
530 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
531
532 Value strideStoreGep =
533 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, strideBasePtr, index);
534 LLVM::StoreOp::create(builder, loc, stride, strideStoreGep);
535}
static std::pair< Value, Type > castToElemPtrPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
static Value createIndexAttrConstant(OpBuilder &builder, Location loc, Type resultType, int64_t value)
static constexpr unsigned kSizePosInMemRefDescriptor
static constexpr unsigned kStridePosInMemRefDescriptor
static constexpr unsigned kOffsetPosInMemRefDescriptor
static constexpr unsigned kAllocatedPtrPosInMemRefDescriptor
static constexpr unsigned kPtrInUnrankedMemRefDescriptor
static constexpr unsigned kAlignedPtrPosInMemRefDescriptor
static constexpr unsigned kRankInUnrankedMemRefDescriptor
IntegerAttr getIndexAttr(int64_t value)
Definition Builders.cpp:108
MLIRContext * getContext() const
Definition Builders.h:56
Conversion from types to the LLVM IR dialect.
unsigned getPointerBitwidth(unsigned addressSpace=0) const
Gets the pointer bitwidth.
unsigned getIndexTypeBitwidth() const
Gets the bitwidth of the index type when converted to LLVM.
Type getIndexType() const
Gets the LLVM representation of the index type.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
Value size(unsigned pos)
Returns the pos-th size Value.
Value alignedPtr()
Returns the aligned pointer Value.
Value stride(unsigned pos)
Returns the pos-th stride Value.
Value allocatedPtr()
Returns the allocated pointer Value.
MemRefDescriptorView(ValueRange range)
Constructs the view from a range of values.
Value offset()
Returns the offset Value.
Helper class to produce LLVM dialect operations extracting or inserting elements of a MemRef descript...
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....
Value alignedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the aligned pointer from the descriptor.
void setOffset(OpBuilder &builder, Location loc, Value offset)
Builds IR inserting the offset into the descriptor.
LLVM::LLVMPointerType getElementPtrType()
Returns the (LLVM) pointer type this descriptor contains.
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 st...
Value stride(OpBuilder &builder, Location loc, unsigned pos)
Builds IR extracting the pos-th size from the descriptor.
void setConstantSize(OpBuilder &builder, Location loc, unsigned pos, uint64_t size)
MemRefDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
static MemRefDescriptor poison(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating a poison value of the descriptor type.
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 resul...
static unsigned getNumUnpackedValues(MemRefType type)
Returns the number of non-aggregate values that would be produced by unpack.
void setSize(OpBuilder &builder, Location loc, unsigned pos, Value size)
Builds IR inserting the pos-th size into the descriptor.
void setAllocatedPtr(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the allocated pointer into the descriptor.
void setStride(OpBuilder &builder, Location loc, unsigned pos, Value stride)
Builds IR inserting the pos-th stride into the descriptor.
Value allocatedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the allocated pointer from the descriptor.
Value offset(OpBuilder &builder, Location loc)
Builds IR extracting the offset from the descriptor.
void setConstantStride(OpBuilder &builder, Location loc, unsigned pos, uint64_t stride)
void setAlignedPtr(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the aligned pointer into the descriptor.
Value size(OpBuilder &builder, Location loc, unsigned pos)
Builds IR extracting the pos-th size from the descriptor.
void setConstantOffset(OpBuilder &builder, Location loc, uint64_t offset)
Builds IR inserting the offset into the descriptor.
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 de...
This class helps build Operations.
Definition Builders.h:207
void setPtr(OpBuilder &builder, Location loc, unsigned pos, Value ptr)
Builds IR to set a value in the struct at position pos.
StructBuilder(Value v)
Construct a helper for the given value.
Value extractPtr(OpBuilder &builder, Location loc, unsigned pos) const
Builds IR to extract a value from the struct at position pos.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition Types.cpp:35
static void setOffset(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType, Value offset)
Builds IR inserting the offset into the descriptor.
static Value allocatedPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
TODO: The following accessors don't take alignment rules between elements of the descriptor struct in...
static Value computeSize(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, UnrankedMemRefDescriptor desc, unsigned addressSpace)
Builds and returns IR computing the size in bytes (suitable for opaque allocation).
void setRank(OpBuilder &builder, Location loc, Value value)
Builds IR setting the rank in the descriptor.
Value memRefDescPtr(OpBuilder &builder, Location loc) const
Builds IR extracting ranked memref descriptor ptr.
static void setAllocatedPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType, Value allocatedPtr)
Builds IR inserting the allocated pointer into the descriptor.
static void setSize(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value index, Value size)
Builds IR inserting the size[index] into the descriptor.
static Value pack(OpBuilder &builder, Location loc, const LLVMTypeConverter &converter, UnrankedMemRefType type, ValueRange values)
Builds IR populating an unranked MemRef descriptor structure from a list of individual constituent va...
static Value stride(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value strideBasePtr, Value index, Value stride)
Builds IR extracting the stride[index] from the descriptor.
static Value size(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value index)
Builds IR extracting the size[index] from the descriptor.
UnrankedMemRefDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
static UnrankedMemRefDescriptor poison(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating an undef value of the descriptor type.
static void setAlignedPtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType, Value alignedPtr)
Builds IR inserting the aligned pointer into the descriptor.
Value rank(OpBuilder &builder, Location loc) const
Builds IR extracting the rank from the descriptor.
static Value offsetBasePtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
Builds IR for getting the pointer to the offset's location.
static void unpack(OpBuilder &builder, Location loc, Value packed, SmallVectorImpl< Value > &results)
Builds IR extracting individual elements that compose an unranked memref descriptor and returns them ...
static Value offset(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
Builds IR extracting the offset from the descriptor.
static Value strideBasePtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value rank)
Builds IR extracting the pointer to the first element of the stride array.
void setMemRefDescPtr(OpBuilder &builder, Location loc, Value value)
Builds IR setting ranked memref descriptor ptr.
static void setStride(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value strideBasePtr, Value index, Value stride)
Builds IR inserting the stride[index] into the descriptor.
static Value sizeBasePtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
Builds IR extracting the pointer to the first element of the size array.
static Value alignedPtr(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
Builds IR extracting the aligned pointer from the descriptor.
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Include the generated interface declarations.