MLIR  15.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"
13 #include "mlir/IR/Builders.h"
15 
16 using namespace mlir;
17 
18 //===----------------------------------------------------------------------===//
19 // MemRefDescriptor implementation
20 //===----------------------------------------------------------------------===//
21 
22 /// Construct a helper for the given descriptor value.
24  : StructBuilder(descriptor) {
25  assert(value != nullptr && "value cannot be null");
26  indexType = value.getType()
28  .getBody()[kOffsetPosInMemRefDescriptor];
29 }
30 
31 /// Builds IR creating an `undef` value of the descriptor type.
33  Type descriptorType) {
34 
35  Value descriptor = builder.create<LLVM::UndefOp>(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  LLVMTypeConverter &typeConverter,
45  MemRefType type, Value memory) {
46  assert(type.hasStaticShape() && "unexpected dynamic shape");
47 
48  // Extract all strides and offsets and verify they are static.
49  int64_t offset;
51  auto result = getStridesAndOffset(type, strides, offset);
52  (void)result;
53  assert(succeeded(result) && "unexpected failure in stride computation");
54  assert(!ShapedType::isDynamicStrideOrOffset(offset) &&
55  "expected static offset");
56  assert(!llvm::any_of(strides, [](int64_t stride) {
57  return ShapedType::isDynamicStrideOrOffset(stride);
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::undef(builder, loc, convertedType);
64  descr.setAllocatedPtr(builder, loc, memory);
65  descr.setAlignedPtr(builder, loc, memory);
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.
78  return extractPtr(builder, loc, kAllocatedPtrPosInMemRefDescriptor);
79 }
80 
81 /// Builds IR inserting the allocated pointer into the descriptor.
83  Value ptr) {
84  setPtr(builder, loc, kAllocatedPtrPosInMemRefDescriptor, ptr);
85 }
86 
87 /// Builds IR extracting the aligned pointer from the descriptor.
89  return extractPtr(builder, loc, kAlignedPtrPosInMemRefDescriptor);
90 }
91 
92 /// Builds IR inserting the aligned pointer into the descriptor.
94  Value ptr) {
95  setPtr(builder, loc, kAlignedPtrPosInMemRefDescriptor, ptr);
96 }
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 builder.create<LLVM::ConstantOp>(
103  loc, resultType, builder.getIntegerAttr(builder.getIndexType(), value));
104 }
105 
106 /// Builds IR extracting the offset from the descriptor.
108  return builder.create<LLVM::ExtractValueOp>(
109  loc, indexType, value,
111 }
112 
113 /// Builds IR inserting the offset into the descriptor.
115  Value offset) {
116  value = builder.create<LLVM::InsertValueOp>(
117  loc, structType, value, offset,
119 }
120 
121 /// Builds IR inserting the offset into the descriptor.
123  uint64_t offset) {
124  setOffset(builder, loc,
125  createIndexAttrConstant(builder, loc, indexType, offset));
126 }
127 
128 /// Builds IR extracting the pos-th size from the descriptor.
129 Value MemRefDescriptor::size(OpBuilder &builder, Location loc, unsigned pos) {
130  return builder.create<LLVM::ExtractValueOp>(
131  loc, indexType, value,
133 }
134 
136  int64_t rank) {
137  auto indexPtrTy = LLVM::LLVMPointerType::get(indexType);
138  auto arrayTy = LLVM::LLVMArrayType::get(indexType, rank);
139  auto arrayPtrTy = LLVM::LLVMPointerType::get(arrayTy);
140 
141  // Copy size values to stack-allocated memory.
142  auto zero = createIndexAttrConstant(builder, loc, indexType, 0);
143  auto one = createIndexAttrConstant(builder, loc, indexType, 1);
144  auto sizes = builder.create<LLVM::ExtractValueOp>(
145  loc, arrayTy, value,
147  auto sizesPtr =
148  builder.create<LLVM::AllocaOp>(loc, arrayPtrTy, one, /*alignment=*/0);
149  builder.create<LLVM::StoreOp>(loc, sizes, sizesPtr);
150 
151  // Load an return size value of interest.
152  auto resultPtr = builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizesPtr,
153  ValueRange({zero, pos}));
154  return builder.create<LLVM::LoadOp>(loc, resultPtr);
155 }
156 
157 /// Builds IR inserting the pos-th size into the descriptor
158 void MemRefDescriptor::setSize(OpBuilder &builder, Location loc, unsigned pos,
159  Value size) {
160  value = builder.create<LLVM::InsertValueOp>(
161  loc, structType, value, size,
163 }
164 
166  unsigned pos, uint64_t size) {
167  setSize(builder, loc, pos,
168  createIndexAttrConstant(builder, loc, indexType, size));
169 }
170 
171 /// Builds IR extracting the pos-th stride from the descriptor.
172 Value MemRefDescriptor::stride(OpBuilder &builder, Location loc, unsigned pos) {
173  return builder.create<LLVM::ExtractValueOp>(
174  loc, indexType, value,
176 }
177 
178 /// Builds IR inserting the pos-th stride into the descriptor
179 void MemRefDescriptor::setStride(OpBuilder &builder, Location loc, unsigned pos,
180  Value stride) {
181  value = builder.create<LLVM::InsertValueOp>(
182  loc, structType, value, stride,
184 }
185 
187  unsigned pos, uint64_t stride) {
188  setStride(builder, loc, pos,
189  createIndexAttrConstant(builder, loc, indexType, stride));
190 }
191 
193  return value.getType()
196  .cast<LLVM::LLVMPointerType>();
197 }
198 
199 /// Creates a MemRef descriptor structure from a list of individual values
200 /// composing that descriptor, in the following order:
201 /// - allocated pointer;
202 /// - aligned pointer;
203 /// - offset;
204 /// - <rank> sizes;
205 /// - <rank> shapes;
206 /// where <rank> is the MemRef rank as provided in `type`.
208  LLVMTypeConverter &converter, MemRefType type,
209  ValueRange values) {
210  Type llvmType = converter.convertType(type);
211  auto d = MemRefDescriptor::undef(builder, loc, llvmType);
212 
213  d.setAllocatedPtr(builder, loc, values[kAllocatedPtrPosInMemRefDescriptor]);
214  d.setAlignedPtr(builder, loc, values[kAlignedPtrPosInMemRefDescriptor]);
215  d.setOffset(builder, loc, values[kOffsetPosInMemRefDescriptor]);
216 
217  int64_t rank = type.getRank();
218  for (unsigned i = 0; i < rank; ++i) {
219  d.setSize(builder, loc, i, values[kSizePosInMemRefDescriptor + i]);
220  d.setStride(builder, loc, i, values[kSizePosInMemRefDescriptor + rank + i]);
221  }
222 
223  return d;
224 }
225 
226 /// Builds IR extracting individual elements of a MemRef descriptor structure
227 /// and returning them as `results` list.
229  MemRefType type,
230  SmallVectorImpl<Value> &results) {
231  int64_t rank = type.getRank();
232  results.reserve(results.size() + getNumUnpackedValues(type));
233 
234  MemRefDescriptor d(packed);
235  results.push_back(d.allocatedPtr(builder, loc));
236  results.push_back(d.alignedPtr(builder, loc));
237  results.push_back(d.offset(builder, loc));
238  for (int64_t i = 0; i < rank; ++i)
239  results.push_back(d.size(builder, loc, i));
240  for (int64_t i = 0; i < rank; ++i)
241  results.push_back(d.stride(builder, loc, i));
242 }
243 
244 /// Returns the number of non-aggregate values that would be produced by
245 /// `unpack`.
246 unsigned MemRefDescriptor::getNumUnpackedValues(MemRefType type) {
247  // Two pointers, offset, <rank> sizes, <rank> shapes.
248  return 3 + 2 * type.getRank();
249 }
250 
251 //===----------------------------------------------------------------------===//
252 // MemRefDescriptorView implementation.
253 //===----------------------------------------------------------------------===//
254 
256  : rank((range.size() - kSizePosInMemRefDescriptor) / 2), elements(range) {}
257 
259  return elements[kAllocatedPtrPosInMemRefDescriptor];
260 }
261 
263  return elements[kAlignedPtrPosInMemRefDescriptor];
264 }
265 
267  return elements[kOffsetPosInMemRefDescriptor];
268 }
269 
271  return elements[kSizePosInMemRefDescriptor + pos];
272 }
273 
275  return elements[kSizePosInMemRefDescriptor + rank + pos];
276 }
277 
278 //===----------------------------------------------------------------------===//
279 // UnrankedMemRefDescriptor implementation
280 //===----------------------------------------------------------------------===//
281 
282 /// Construct a helper for the given descriptor value.
284  : StructBuilder(descriptor) {}
285 
286 /// Builds IR creating an `undef` value of the descriptor type.
288  Location loc,
289  Type descriptorType) {
290  Value descriptor = builder.create<LLVM::UndefOp>(loc, descriptorType);
291  return UnrankedMemRefDescriptor(descriptor);
292 }
294  return extractPtr(builder, loc, kRankInUnrankedMemRefDescriptor);
295 }
297  Value v) {
298  setPtr(builder, loc, kRankInUnrankedMemRefDescriptor, v);
299 }
301  Location loc) {
302  return extractPtr(builder, loc, kPtrInUnrankedMemRefDescriptor);
303 }
305  Location loc, Value v) {
306  setPtr(builder, loc, kPtrInUnrankedMemRefDescriptor, v);
307 }
308 
309 /// Builds IR populating an unranked MemRef descriptor structure from a list
310 /// of individual constituent values in the following order:
311 /// - rank of the memref;
312 /// - pointer to the memref descriptor.
314  LLVMTypeConverter &converter,
315  UnrankedMemRefType type,
316  ValueRange values) {
317  Type llvmType = converter.convertType(type);
318  auto d = UnrankedMemRefDescriptor::undef(builder, loc, llvmType);
319 
320  d.setRank(builder, loc, values[kRankInUnrankedMemRefDescriptor]);
321  d.setMemRefDescPtr(builder, loc, values[kPtrInUnrankedMemRefDescriptor]);
322  return d;
323 }
324 
325 /// Builds IR extracting individual elements that compose an unranked memref
326 /// descriptor and returns them as `results` list.
328  Value packed,
329  SmallVectorImpl<Value> &results) {
330  UnrankedMemRefDescriptor d(packed);
331  results.reserve(results.size() + 2);
332  results.push_back(d.rank(builder, loc));
333  results.push_back(d.memRefDescPtr(builder, loc));
334 }
335 
337  OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter,
339  if (values.empty())
340  return;
341 
342  // Cache the index type.
343  Type indexType = typeConverter.getIndexType();
344 
345  // Initialize shared constants.
346  Value one = createIndexAttrConstant(builder, loc, indexType, 1);
347  Value two = createIndexAttrConstant(builder, loc, indexType, 2);
348  Value pointerSize = createIndexAttrConstant(
349  builder, loc, indexType, ceilDiv(typeConverter.getPointerBitwidth(), 8));
350  Value indexSize =
351  createIndexAttrConstant(builder, loc, indexType,
352  ceilDiv(typeConverter.getIndexTypeBitwidth(), 8));
353 
354  sizes.reserve(sizes.size() + values.size());
355  for (UnrankedMemRefDescriptor desc : values) {
356  // Emit IR computing the memory necessary to store the descriptor. This
357  // assumes the descriptor to be
358  // { type*, type*, index, index[rank], index[rank] }
359  // and densely packed, so the total size is
360  // 2 * sizeof(pointer) + (1 + 2 * rank) * sizeof(index).
361  // TODO: consider including the actual size (including eventual padding due
362  // to data layout) into the unranked descriptor.
363  Value doublePointerSize =
364  builder.create<LLVM::MulOp>(loc, indexType, two, pointerSize);
365 
366  // (1 + 2 * rank) * sizeof(index)
367  Value rank = desc.rank(builder, loc);
368  Value doubleRank = builder.create<LLVM::MulOp>(loc, indexType, two, rank);
369  Value doubleRankIncremented =
370  builder.create<LLVM::AddOp>(loc, indexType, doubleRank, one);
371  Value rankIndexSize = builder.create<LLVM::MulOp>(
372  loc, indexType, doubleRankIncremented, indexSize);
373 
374  // Total allocation size.
375  Value allocationSize = builder.create<LLVM::AddOp>(
376  loc, indexType, doublePointerSize, rankIndexSize);
377  sizes.push_back(allocationSize);
378  }
379 }
380 
383  Type elemPtrPtrType) {
384 
385  Value elementPtrPtr =
386  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
387  return builder.create<LLVM::LoadOp>(loc, elementPtrPtr);
388 }
389 
392  Type elemPtrPtrType,
394  Value elementPtrPtr =
395  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
396  builder.create<LLVM::StoreOp>(loc, allocatedPtr, elementPtrPtr);
397 }
398 
400  LLVMTypeConverter &typeConverter,
402  Type elemPtrPtrType) {
403  Value elementPtrPtr =
404  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
405 
406  Value one =
407  createIndexAttrConstant(builder, loc, typeConverter.getIndexType(), 1);
408  Value alignedGep = builder.create<LLVM::GEPOp>(
409  loc, elemPtrPtrType, elementPtrPtr, ValueRange({one}));
410  return builder.create<LLVM::LoadOp>(loc, alignedGep);
411 }
412 
414  LLVMTypeConverter &typeConverter,
416  Type elemPtrPtrType,
417  Value alignedPtr) {
418  Value elementPtrPtr =
419  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
420 
421  Value one =
422  createIndexAttrConstant(builder, loc, typeConverter.getIndexType(), 1);
423  Value alignedGep = builder.create<LLVM::GEPOp>(
424  loc, elemPtrPtrType, elementPtrPtr, ValueRange({one}));
425  builder.create<LLVM::StoreOp>(loc, alignedPtr, alignedGep);
426 }
427 
429  LLVMTypeConverter &typeConverter,
431  Type elemPtrPtrType) {
432  Value elementPtrPtr =
433  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
434 
435  Value two =
436  createIndexAttrConstant(builder, loc, typeConverter.getIndexType(), 2);
437  Value offsetGep = builder.create<LLVM::GEPOp>(
438  loc, elemPtrPtrType, elementPtrPtr, ValueRange({two}));
439  offsetGep = builder.create<LLVM::BitcastOp>(
440  loc, LLVM::LLVMPointerType::get(typeConverter.getIndexType()), offsetGep);
441  return builder.create<LLVM::LoadOp>(loc, offsetGep);
442 }
443 
445  LLVMTypeConverter &typeConverter,
447  Type elemPtrPtrType, Value offset) {
448  Value elementPtrPtr =
449  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
450 
451  Value two =
452  createIndexAttrConstant(builder, loc, typeConverter.getIndexType(), 2);
453  Value offsetGep = builder.create<LLVM::GEPOp>(
454  loc, elemPtrPtrType, elementPtrPtr, ValueRange({two}));
455  offsetGep = builder.create<LLVM::BitcastOp>(
456  loc, LLVM::LLVMPointerType::get(typeConverter.getIndexType()), offsetGep);
457  builder.create<LLVM::StoreOp>(loc, offset, offsetGep);
458 }
459 
461  OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter,
462  Value memRefDescPtr, LLVM::LLVMPointerType elemPtrPtrType) {
463  Type elemPtrTy = elemPtrPtrType.getElementType();
464  Type indexTy = typeConverter.getIndexType();
465  Type structPtrTy =
467  indexTy.getContext(), {elemPtrTy, elemPtrTy, indexTy, indexTy}));
468  Value structPtr =
469  builder.create<LLVM::BitcastOp>(loc, structPtrTy, memRefDescPtr);
470 
471  Type int32Type = typeConverter.convertType(builder.getI32Type());
472  Value zero =
473  createIndexAttrConstant(builder, loc, typeConverter.getIndexType(), 0);
474  Value three = builder.create<LLVM::ConstantOp>(loc, int32Type,
475  builder.getI32IntegerAttr(3));
476  return builder.create<LLVM::GEPOp>(loc, LLVM::LLVMPointerType::get(indexTy),
477  structPtr, ValueRange({zero, three}));
478 }
479 
481  LLVMTypeConverter &typeConverter,
482  Value sizeBasePtr, Value index) {
483  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
484  Value sizeStoreGep = builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizeBasePtr,
485  ValueRange({index}));
486  return builder.create<LLVM::LoadOp>(loc, sizeStoreGep);
487 }
488 
490  LLVMTypeConverter &typeConverter,
491  Value sizeBasePtr, Value index,
492  Value size) {
493  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
494  Value sizeStoreGep = builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizeBasePtr,
495  ValueRange({index}));
496  builder.create<LLVM::StoreOp>(loc, size, sizeStoreGep);
497 }
498 
500  LLVMTypeConverter &typeConverter,
502  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
503  return builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizeBasePtr,
504  ValueRange({rank}));
505 }
506 
508  LLVMTypeConverter &typeConverter,
509  Value strideBasePtr, Value index,
510  Value stride) {
511  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
512  Value strideStoreGep = builder.create<LLVM::GEPOp>(
513  loc, indexPtrTy, strideBasePtr, ValueRange({index}));
514  return builder.create<LLVM::LoadOp>(loc, strideStoreGep);
515 }
516 
518  LLVMTypeConverter &typeConverter,
519  Value strideBasePtr, Value index,
520  Value stride) {
521  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
522  Value strideStoreGep = builder.create<LLVM::GEPOp>(
523  loc, indexPtrTy, strideBasePtr, ValueRange({index}));
524  builder.create<LLVM::StoreOp>(loc, stride, strideStoreGep);
525 }
TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
static constexpr unsigned kSizePosInMemRefDescriptor
void setMemRefDescPtr(OpBuilder &builder, Location loc, Value value)
Builds IR setting ranked memref descriptor ptr.
static Value offset(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value memRefDescPtr, Type elemPtrPtrType)
Builds IR extracting the offset from the descriptor.
static constexpr unsigned kStridePosInMemRefDescriptor
static Value size(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value index)
Builds IR extracting the size[index] from the descriptor.
static constexpr unsigned kAlignedPtrPosInMemRefDescriptor
static void setAlignedPtr(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value memRefDescPtr, Type elemPtrPtrType, Value alignedPtr)
Builds IR inserting the aligned pointer into the descriptor.
static LLVMStructType getLiteral(MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
Gets or creates a literal struct with the given body in the provided context.
Definition: LLVMTypes.cpp:414
void setAllocatedPtr(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the allocated pointer into the descriptor.
static LLVMArrayType get(Type elementType, unsigned numElements)
Gets or creates an instance of LLVM dialect array type containing numElements of elementType, in the same context as elementType.
Definition: LLVMTypes.cpp:39
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results)
Convert the given type.
Value offset()
Returns the offset Value.
static constexpr unsigned kRankInUnrankedMemRefDescriptor
UnrankedMemRefDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
static unsigned getNumUnpackedValues(MemRefType type)
Returns the number of non-aggregate values that would be produced by unpack.
static Value createIndexAttrConstant(OpBuilder &builder, Location loc, Type resultType, int64_t value)
static Value stride(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value strideBasePtr, Value index, Value stride)
Builds IR extracting the stride[index] from the descriptor.
static Value sizeBasePtr(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value memRefDescPtr, LLVM::LLVMPointerType elemPtrPtrType)
Builds IR extracting the pointer to the first element of the size array.
Value allocatedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the allocated pointer from the descriptor.
static Value alignedPtr(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value memRefDescPtr, Type elemPtrPtrType)
Builds IR extracting the aligned pointer from the descriptor.
static Value pack(OpBuilder &builder, Location loc, LLVMTypeConverter &converter, MemRefType type, ValueRange values)
Builds IR populating a MemRef descriptor structure from a list of individual values composing that de...
unsigned getPointerBitwidth(unsigned addressSpace=0)
Gets the pointer bitwidth.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value...
Definition: LogicalResult.h:68
LLVM::LLVMPointerType getElementPtrType()
Returns the (LLVM) pointer type this descriptor contains.
ArrayAttr getI64ArrayAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:220
Value stride(unsigned pos)
Returns the pos-th stride Value.
Value offset(OpBuilder &builder, Location loc)
Builds IR extracting the offset from the descriptor.
static constexpr unsigned kOffsetPosInMemRefDescriptor
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:48
void setAlignedPtr(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the aligned pointer into the descriptor.
IntegerAttr getI32IntegerAttr(int32_t value)
Definition: Builders.cpp:148
static void setStride(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value strideBasePtr, Value index, Value stride)
Builds IR inserting the stride[index] into the descriptor.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:380
LogicalResult getStridesAndOffset(MemRefType t, SmallVectorImpl< int64_t > &strides, int64_t &offset)
Returns the strides of the MemRef if the layout map is in strided form.
void setConstantStride(OpBuilder &builder, Location loc, unsigned pos, uint64_t stride)
IntegerAttr getIntegerAttr(Type type, int64_t value)
Definition: Builders.cpp:170
Helper class to produce LLVM dialect operations extracting or inserting elements of a MemRef descript...
Definition: MemRefBuilder.h:33
void setConstantSize(OpBuilder &builder, Location loc, unsigned pos, uint64_t size)
Value stride(OpBuilder &builder, Location loc, unsigned pos)
Builds IR extracting the pos-th size from the descriptor.
Helper class to produce LLVM dialect operations extracting or inserting values to a struct...
Definition: StructBuilder.h:26
int64_t ceilDiv(int64_t lhs, int64_t rhs)
Returns the result of MLIR&#39;s ceildiv operation on constants.
Definition: MathExtras.h:23
static constexpr unsigned kPtrInUnrankedMemRefDescriptor
static void setSize(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value index, Value size)
Builds IR inserting the size[index] into the descriptor.
static MemRefDescriptor fromStaticShape(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, MemRefType type, Value memory)
Builds IR creating a MemRef descriptor that represents type and populates it with static shape and st...
static Value strideBasePtr(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value rank)
Builds IR extracting the pointer to the first element of the stride array.
Value allocatedPtr()
Returns the allocated pointer Value.
static LLVMPointerType get(MLIRContext *context, unsigned addressSpace=0)
Gets or creates an instance of LLVM dialect pointer type pointing to an object of pointee type in the...
Definition: LLVMTypes.cpp:188
static MemRefDescriptor undef(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating an undef value of the descriptor type.
Value alignedPtr()
Returns the aligned pointer Value.
static Value allocatedPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, Type elemPtrPtrType)
TODO: The following accessors don&#39;t take alignment rules between elements of the descriptor struct in...
static UnrankedMemRefDescriptor undef(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating an undef value of the descriptor type.
static constexpr unsigned kAllocatedPtrPosInMemRefDescriptor
MemRefDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:72
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition: Types.cpp:19
Value memRefDescPtr(OpBuilder &builder, Location loc)
Builds IR extracting ranked memref descriptor ptr.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
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.
void setOffset(OpBuilder &builder, Location loc, Value offset)
Builds IR inserting the offset into the descriptor.
Value alignedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the aligned pointer from the descriptor.
Type getType() const
Return the type of this value.
Definition: Value.h:118
IndexType getIndexType()
Definition: Builders.cpp:48
LLVM dialect structure type representing a collection of different-typed elements manipulated togethe...
Definition: LLVMTypes.h:277
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:30
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...
void setRank(OpBuilder &builder, Location loc, Value value)
Builds IR setting the rank in the descriptor.
static void setOffset(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value memRefDescPtr, Type elemPtrPtrType, Value offset)
Builds IR inserting the offset into the descriptor.
LLVM dialect pointer type.
Definition: LLVMTypes.h:190
Value extractPtr(OpBuilder &builder, Location loc, unsigned pos)
Builds IR to extract a value from the struct at position pos.
unsigned getIndexTypeBitwidth()
Gets the bitwidth of the index type when converted to LLVM.
Value size(unsigned pos)
Returns the pos-th size Value.
void setStride(OpBuilder &builder, Location loc, unsigned pos, Value stride)
Builds IR inserting the pos-th stride into the descriptor.
Type getIndexType()
Gets the LLVM representation of the index type.
void setSize(OpBuilder &builder, Location loc, unsigned pos, Value size)
Builds IR inserting the pos-th size into the descriptor.
static void setAllocatedPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, Type elemPtrPtrType, Value allocatedPtr)
Builds IR inserting the allocated pointer into the descriptor.
static Value pack(OpBuilder &builder, Location loc, LLVMTypeConverter &converter, UnrankedMemRefType type, ValueRange values)
Builds IR populating an unranked MemRef descriptor structure from a list of individual constituent va...
void setPtr(OpBuilder &builder, Location loc, unsigned pos, Value ptr)
Builds IR to set a value in the struct at position pos.
Value rank(OpBuilder &builder, Location loc)
Builds IR extracting the rank from the descriptor.
This class helps build Operations.
Definition: Builders.h:184
This class provides an abstraction over the different types of ranges over Values.
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 ...
MemRefDescriptorView(ValueRange range)
Constructs the view from a range of values.
static void computeSizes(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, ArrayRef< UnrankedMemRefDescriptor > values, SmallVectorImpl< Value > &sizes)
Builds IR computing the sizes in bytes (suitable for opaque allocation) and appends the corresponding...
Type getElementType() const
Returns the pointed-to type. It may be null if the pointer is opaque.
Definition: LLVMTypes.cpp:206
IntegerType getI32Type()
Definition: Builders.cpp:54
U cast() const
Definition: Types.h:262