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