MLIR 24.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"
15#include "mlir/IR/Builders.h"
16#include "llvm/Support/MathExtras.h"
17
18using namespace mlir;
19
20//===----------------------------------------------------------------------===//
21// MemRefDescriptor implementation
22//===----------------------------------------------------------------------===//
23
24/// Construct a helper for the given descriptor value.
26 : StructBuilder(descriptor) {
27 assert(value != nullptr && "value cannot be null");
28 indexType = cast<LLVM::LLVMStructType>(value.getType())
30}
31
32/// Builds IR creating an `undef` value of the descriptor type.
34 Type descriptorType) {
35
36 Value descriptor = LLVM::PoisonOp::create(builder, loc, descriptorType);
37 return MemRefDescriptor(descriptor);
38}
39
40/// Builds IR creating a MemRef descriptor that represents `type` and
41/// populates it with static shape and stride information extracted from the
42/// type.
45 const LLVMTypeConverter &typeConverter,
46 MemRefType type, Value memory) {
47 return fromStaticShape(builder, loc, typeConverter, type, memory, memory);
48}
49
51 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
52 MemRefType type, Value memory, Value alignedMemory) {
53 assert(type.hasStaticShape() && "unexpected dynamic shape");
54
55 // Extract all strides and offsets and verify they are static.
56 auto [strides, offset] = type.getStridesAndOffset();
57 assert(ShapedType::isStatic(offset) && "expected static offset");
58 assert(!llvm::any_of(strides, ShapedType::isDynamic) &&
59 "expected static strides");
60
61 auto convertedType = typeConverter.convertType(type);
62 assert(convertedType && "unexpected failure in memref type conversion");
63
64 auto descr = MemRefDescriptor::poison(builder, loc, convertedType);
65 descr.setAllocatedPtr(builder, loc, memory);
66 descr.setAlignedPtr(builder, loc, alignedMemory);
67 descr.setConstantOffset(builder, loc, offset);
68
69 // Fill in sizes and strides
70 for (unsigned i = 0, e = type.getRank(); i != e; ++i) {
71 descr.setConstantSize(builder, loc, i, type.getDimSize(i));
72 descr.setConstantStride(builder, loc, i, strides[i]);
73 }
74 return descr;
75}
76
77/// Builds IR extracting the allocated pointer from the descriptor.
81
82/// Builds IR inserting the allocated pointer into the descriptor.
87
88/// Builds IR extracting the aligned pointer from the descriptor.
92
93/// Builds IR inserting the aligned pointer into the descriptor.
98
99/// Builds IR extracting the offset from the descriptor.
101 return LLVM::ExtractValueOp::create(builder, loc, value,
103}
104
105/// Builds IR inserting the offset into the descriptor.
107 Value offset) {
108 value = LLVM::InsertValueOp::create(builder, loc, value, offset,
110}
111
112/// Builds IR inserting the offset into the descriptor.
114 uint64_t offset) {
115 setOffset(builder, loc,
116 LLVM::createIndexAttrConstant(builder, loc, indexType, offset));
117}
118
119/// Builds IR extracting the pos-th size from the descriptor.
120Value MemRefDescriptor::size(OpBuilder &builder, Location loc, unsigned pos) {
121 return LLVM::ExtractValueOp::create(
122 builder, loc, value,
124}
125
127 int64_t rank) {
128 auto arrayTy = LLVM::LLVMArrayType::get(indexType, rank);
129
130 auto ptrTy = LLVM::LLVMPointerType::get(builder.getContext());
131
132 // Copy size values to stack-allocated memory.
133 auto one = LLVM::createIndexAttrConstant(builder, loc, indexType, 1);
134 auto sizes = LLVM::ExtractValueOp::create(
135 builder, loc, value,
137 auto sizesPtr = LLVM::AllocaOp::create(builder, loc, ptrTy, arrayTy, one,
138 /*alignment=*/0);
139 LLVM::StoreOp::create(builder, loc, sizes, sizesPtr);
140
141 // Load an return size value of interest.
142 auto resultPtr = LLVM::GEPOp::create(builder, loc, ptrTy, arrayTy, sizesPtr,
143 ArrayRef<LLVM::GEPArg>{0, pos});
144 return LLVM::LoadOp::create(builder, loc, indexType, resultPtr);
145}
146
147/// Builds IR inserting the pos-th size into the descriptor
148void MemRefDescriptor::setSize(OpBuilder &builder, Location loc, unsigned pos,
149 Value size) {
150 value = LLVM::InsertValueOp::create(
151 builder, loc, value, size,
153}
154
156 unsigned pos, uint64_t size) {
157 setSize(builder, loc, pos,
158 LLVM::createIndexAttrConstant(builder, loc, indexType, size));
159}
160
161/// Builds IR extracting the pos-th stride from the descriptor.
162Value MemRefDescriptor::stride(OpBuilder &builder, Location loc, unsigned pos) {
163 return LLVM::ExtractValueOp::create(
164 builder, loc, value,
166}
167
168/// Builds IR inserting the pos-th stride into the descriptor
169void MemRefDescriptor::setStride(OpBuilder &builder, Location loc, unsigned pos,
170 Value stride) {
171 value = LLVM::InsertValueOp::create(
172 builder, loc, value, stride,
174}
175
177 unsigned pos, uint64_t stride) {
178 setStride(builder, loc, pos,
179 LLVM::createIndexAttrConstant(builder, loc, indexType, stride));
180}
181
182LLVM::LLVMPointerType MemRefDescriptor::getElementPtrType() {
183 return cast<LLVM::LLVMPointerType>(
184 cast<LLVM::LLVMStructType>(value.getType())
186}
187
189 const LLVMTypeConverter &converter,
190 MemRefType type) {
191 // When we convert to LLVM, the input memref must have been normalized
192 // beforehand. Hence, this call is guaranteed to work.
193 auto [strides, offsetCst] = type.getStridesAndOffset();
194
195 Value ptr = alignedPtr(builder, loc);
196 // For zero offsets, we already have the base pointer.
197 if (offsetCst == 0)
198 return ptr;
199
200 // Otherwise add the offset to the aligned base.
201 Type indexType = converter.getIndexType();
202 Value offsetVal =
203 ShapedType::isDynamic(offsetCst)
204 ? offset(builder, loc)
205 : LLVM::createIndexAttrConstant(builder, loc, indexType, offsetCst);
206 Type elementType = converter.convertType(type.getElementType());
207 ptr = LLVM::GEPOp::create(builder, loc, ptr.getType(), elementType, ptr,
208 offsetVal);
209 return ptr;
210}
211
212/// Creates a MemRef descriptor structure from a list of individual values
213/// composing that descriptor, in the following order:
214/// - allocated pointer;
215/// - aligned pointer;
216/// - offset;
217/// - <rank> sizes;
218/// - <rank> strides;
219/// where <rank> is the MemRef rank as provided in `type`.
221 const LLVMTypeConverter &converter,
222 MemRefType type, ValueRange values) {
223 Type llvmType = converter.convertType(type);
224 auto d = MemRefDescriptor::poison(builder, loc, llvmType);
225
226 d.setAllocatedPtr(builder, loc, values[kAllocatedPtrPosInMemRefDescriptor]);
227 d.setAlignedPtr(builder, loc, values[kAlignedPtrPosInMemRefDescriptor]);
228 d.setOffset(builder, loc, values[kOffsetPosInMemRefDescriptor]);
229
230 int64_t rank = type.getRank();
231 for (unsigned i = 0; i < rank; ++i) {
232 d.setSize(builder, loc, i, values[kSizePosInMemRefDescriptor + i]);
233 d.setStride(builder, loc, i, values[kSizePosInMemRefDescriptor + rank + i]);
234 }
235
236 return d;
237}
238
239/// Builds IR extracting individual elements of a MemRef descriptor structure
240/// and returning them as `results` list.
242 MemRefType type,
243 SmallVectorImpl<Value> &results) {
244 int64_t rank = type.getRank();
245 results.reserve(results.size() + getNumUnpackedValues(type));
246
247 MemRefDescriptor d(packed);
248 results.push_back(d.allocatedPtr(builder, loc));
249 results.push_back(d.alignedPtr(builder, loc));
250 results.push_back(d.offset(builder, loc));
251 for (int64_t i = 0; i < rank; ++i)
252 results.push_back(d.size(builder, loc, i));
253 for (int64_t i = 0; i < rank; ++i)
254 results.push_back(d.stride(builder, loc, i));
255}
256
257/// Returns the number of non-aggregate values that would be produced by
258/// `unpack`.
259unsigned MemRefDescriptor::getNumUnpackedValues(MemRefType type) {
260 // Two pointers, offset, <rank> sizes, <rank> strides.
261 return 3 + 2 * type.getRank();
262}
263
264//===----------------------------------------------------------------------===//
265// MemRefDescriptorView implementation.
266//===----------------------------------------------------------------------===//
267
269 : rank((range.size() - kSizePosInMemRefDescriptor) / 2), elements(range) {}
270
274
278
282
284 return elements[kSizePosInMemRefDescriptor + pos];
285}
286
288 return elements[kSizePosInMemRefDescriptor + rank + pos];
289}
290
291//===----------------------------------------------------------------------===//
292// UnrankedMemRefDescriptor implementation
293//===----------------------------------------------------------------------===//
294
295/// Construct a helper for the given descriptor value.
298
299/// Builds IR creating an `undef` value of the descriptor type.
301 Location loc,
302 Type descriptorType) {
303 Value descriptor = LLVM::PoisonOp::create(builder, loc, descriptorType);
304 return UnrankedMemRefDescriptor(descriptor);
305}
321
322/// Builds IR populating an unranked MemRef descriptor structure from a list
323/// of individual constituent values in the following order:
324/// - rank of the memref;
325/// - pointer to the memref descriptor.
327 const LLVMTypeConverter &converter,
329 ValueRange values) {
330 Type llvmType = converter.convertType(type);
331 auto d = UnrankedMemRefDescriptor::poison(builder, loc, llvmType);
332
333 d.setRank(builder, loc, values[kRankInUnrankedMemRefDescriptor]);
334 d.setMemRefDescPtr(builder, loc, values[kPtrInUnrankedMemRefDescriptor]);
335 return d;
336}
337
338/// Builds IR extracting individual elements that compose an unranked memref
339/// descriptor and returns them as `results` list.
341 Value packed,
342 SmallVectorImpl<Value> &results) {
343 UnrankedMemRefDescriptor d(packed);
344 results.reserve(results.size() + 2);
345 results.push_back(d.rank(builder, loc));
346 results.push_back(d.memRefDescPtr(builder, loc));
347}
348
350 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
351 UnrankedMemRefDescriptor desc, unsigned addressSpace) {
352 // Cache the index type.
353 Type indexType = typeConverter.getIndexType();
354
355 // Initialize shared constants.
356 Value one = LLVM::createIndexAttrConstant(builder, loc, indexType, 1);
357 Value two = LLVM::createIndexAttrConstant(builder, loc, indexType, 2);
359 builder, loc, indexType,
360 llvm::divideCeil(typeConverter.getIndexTypeBitwidth(), 8));
361
362 // Emit IR computing the memory necessary to store the descriptor. This
363 // assumes the descriptor to be
364 // { type*, type*, index, index[rank], index[rank] }
365 // and densely packed, so the total size is
366 // 2 * sizeof(pointer) + (1 + 2 * rank) * sizeof(index).
367 // TODO: consider including the actual size (including eventual padding due
368 // to data layout) into the unranked descriptor.
370 builder, loc, indexType,
371 llvm::divideCeil(typeConverter.getPointerBitwidth(addressSpace), 8));
372 Value doublePointerSize =
373 LLVM::MulOp::create(builder, loc, indexType, two, pointerSize);
374
375 // (1 + 2 * rank) * sizeof(index)
376 Value rank = desc.rank(builder, loc);
377 Value doubleRank = LLVM::MulOp::create(builder, loc, indexType, two, rank);
378 Value doubleRankIncremented =
379 LLVM::AddOp::create(builder, loc, indexType, doubleRank, one);
380 Value rankIndexSize = LLVM::MulOp::create(builder, loc, indexType,
381 doubleRankIncremented, indexSize);
382
383 // Total allocation size.
384 Value allocationSize = LLVM::AddOp::create(builder, loc, indexType,
385 doublePointerSize, rankIndexSize);
386 return allocationSize;
387}
388
390 OpBuilder &builder, Location loc, Value memRefDescPtr,
391 LLVM::LLVMPointerType elemPtrType) {
392 return LLVM::LoadOp::create(builder, loc, elemPtrType, memRefDescPtr);
393}
394
396 OpBuilder &builder, Location loc, Value memRefDescPtr,
397 LLVM::LLVMPointerType elemPtrType, Value allocatedPtr) {
398 LLVM::StoreOp::create(builder, loc, allocatedPtr, memRefDescPtr);
399}
400
401static std::pair<Value, Type>
402castToElemPtrPtr(OpBuilder &builder, Location loc, Value memRefDescPtr,
403 LLVM::LLVMPointerType elemPtrType) {
404 auto elemPtrPtrType = LLVM::LLVMPointerType::get(builder.getContext());
405 return {memRefDescPtr, elemPtrPtrType};
406}
407
409 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
410 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType) {
411 auto [elementPtrPtr, elemPtrPtrType] =
412 castToElemPtrPtr(builder, loc, memRefDescPtr, elemPtrType);
413
414 Value alignedGep =
415 LLVM::GEPOp::create(builder, loc, elemPtrPtrType, elemPtrType,
416 elementPtrPtr, ArrayRef<LLVM::GEPArg>{1});
417 return LLVM::LoadOp::create(builder, loc, elemPtrType, alignedGep);
418}
419
421 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
422 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType, Value alignedPtr) {
423 auto [elementPtrPtr, elemPtrPtrType] =
424 castToElemPtrPtr(builder, loc, memRefDescPtr, elemPtrType);
425
426 Value alignedGep =
427 LLVM::GEPOp::create(builder, loc, elemPtrPtrType, elemPtrType,
428 elementPtrPtr, ArrayRef<LLVM::GEPArg>{1});
429 LLVM::StoreOp::create(builder, loc, alignedPtr, alignedGep);
430}
431
433 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
434 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType) {
435 auto [elementPtrPtr, elemPtrPtrType] =
436 castToElemPtrPtr(builder, loc, memRefDescPtr, elemPtrType);
437
438 return LLVM::GEPOp::create(builder, loc, elemPtrPtrType, elemPtrType,
439 elementPtrPtr, ArrayRef<LLVM::GEPArg>{2});
440}
441
443 const LLVMTypeConverter &typeConverter,
445 LLVM::LLVMPointerType elemPtrType) {
446 Value offsetPtr =
447 offsetBasePtr(builder, loc, typeConverter, memRefDescPtr, elemPtrType);
448 return LLVM::LoadOp::create(builder, loc, typeConverter.getIndexType(),
449 offsetPtr);
450}
451
453 const LLVMTypeConverter &typeConverter,
455 LLVM::LLVMPointerType elemPtrType,
456 Value offset) {
457 Value offsetPtr =
458 offsetBasePtr(builder, loc, typeConverter, memRefDescPtr, elemPtrType);
459 LLVM::StoreOp::create(builder, loc, offset, offsetPtr);
460}
461
463 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
464 Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType) {
465 Type indexTy = typeConverter.getIndexType();
466 Type structTy = LLVM::LLVMStructType::getLiteral(
467 indexTy.getContext(), {elemPtrType, elemPtrType, indexTy, indexTy});
468 auto resultType = LLVM::LLVMPointerType::get(builder.getContext());
469 return LLVM::GEPOp::create(builder, loc, resultType, structTy, memRefDescPtr,
471}
472
474 const LLVMTypeConverter &typeConverter,
476
477 Type indexTy = typeConverter.getIndexType();
478 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
479
480 Value sizeStoreGep =
481 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, sizeBasePtr, index);
482 return LLVM::LoadOp::create(builder, loc, indexTy, sizeStoreGep);
483}
484
486 const LLVMTypeConverter &typeConverter,
488 Value size) {
489 Type indexTy = typeConverter.getIndexType();
490 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
491
492 Value sizeStoreGep =
493 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, sizeBasePtr, index);
494 LLVM::StoreOp::create(builder, loc, size, sizeStoreGep);
495}
496
498 OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter,
500 Type indexTy = typeConverter.getIndexType();
501 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
502
503 return LLVM::GEPOp::create(builder, loc, ptrType, indexTy, sizeBasePtr, rank);
504}
505
507 const LLVMTypeConverter &typeConverter,
509 Value stride) {
510 Type indexTy = typeConverter.getIndexType();
511 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
512
513 Value strideStoreGep =
514 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, strideBasePtr, index);
515 return LLVM::LoadOp::create(builder, loc, indexTy, strideStoreGep);
516}
517
519 const LLVMTypeConverter &typeConverter,
521 Value stride) {
522 Type indexTy = typeConverter.getIndexType();
523 auto ptrType = LLVM::LLVMPointerType::get(builder.getContext());
524
525 Value strideStoreGep =
526 LLVM::GEPOp::create(builder, loc, ptrType, indexTy, strideBasePtr, index);
527 LLVM::StoreOp::create(builder, loc, stride, strideStoreGep);
528}
static std::pair< Value, Type > castToElemPtrPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrType)
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
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:210
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:389
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Value createIndexAttrConstant(OpBuilder &builder, Location loc, Type resultType, int64_t value)
Creates an llvm.mlir.constant producing value as resultType, which is expected to be the converted in...
Definition Pattern.cpp:58
Include the generated interface declarations.