MLIR  16.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  return fromStaticShape(builder, loc, typeConverter, type, memory, memory);
47 }
48 
50  OpBuilder &builder, Location loc, 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  int64_t offset;
57  auto result = getStridesAndOffset(type, strides, offset);
58  (void)result;
59  assert(succeeded(result) && "unexpected failure in stride computation");
60  assert(!ShapedType::isDynamic(offset) &&
61  "expected static offset");
62  assert(!llvm::any_of(strides, ShapedType::isDynamic) &&
63  "expected static strides");
64 
65  auto convertedType = typeConverter.convertType(type);
66  assert(convertedType && "unexpected failure in memref type conversion");
67 
68  auto descr = MemRefDescriptor::undef(builder, loc, convertedType);
69  descr.setAllocatedPtr(builder, loc, memory);
70  descr.setAlignedPtr(builder, loc, alignedMemory);
71  descr.setConstantOffset(builder, loc, offset);
72 
73  // Fill in sizes and strides
74  for (unsigned i = 0, e = type.getRank(); i != e; ++i) {
75  descr.setConstantSize(builder, loc, i, type.getDimSize(i));
76  descr.setConstantStride(builder, loc, i, strides[i]);
77  }
78  return descr;
79 }
80 
81 /// Builds IR extracting the allocated pointer from the descriptor.
83  return extractPtr(builder, loc, kAllocatedPtrPosInMemRefDescriptor);
84 }
85 
86 /// Builds IR inserting the allocated pointer into the descriptor.
88  Value ptr) {
89  setPtr(builder, loc, kAllocatedPtrPosInMemRefDescriptor, ptr);
90 }
91 
92 /// Builds IR extracting the aligned pointer from the descriptor.
94  return extractPtr(builder, loc, kAlignedPtrPosInMemRefDescriptor);
95 }
96 
97 /// Builds IR inserting the aligned pointer into the descriptor.
99  Value ptr) {
100  setPtr(builder, loc, kAlignedPtrPosInMemRefDescriptor, ptr);
101 }
102 
103 // Creates a constant Op producing a value of `resultType` from an index-typed
104 // integer attribute.
106  Type resultType, int64_t value) {
107  return builder.create<LLVM::ConstantOp>(loc, resultType,
108  builder.getIndexAttr(value));
109 }
110 
111 /// Builds IR extracting the offset from the descriptor.
113  return builder.create<LLVM::ExtractValueOp>(loc, value,
115 }
116 
117 /// Builds IR inserting the offset into the descriptor.
119  Value offset) {
120  value = builder.create<LLVM::InsertValueOp>(loc, value, offset,
122 }
123 
124 /// Builds IR inserting the offset into the descriptor.
126  uint64_t offset) {
127  setOffset(builder, loc,
128  createIndexAttrConstant(builder, loc, indexType, offset));
129 }
130 
131 /// Builds IR extracting the pos-th size from the descriptor.
132 Value MemRefDescriptor::size(OpBuilder &builder, Location loc, unsigned pos) {
133  return builder.create<LLVM::ExtractValueOp>(
135 }
136 
138  int64_t rank) {
139  auto indexPtrTy = LLVM::LLVMPointerType::get(indexType);
140  auto arrayTy = LLVM::LLVMArrayType::get(indexType, rank);
141  auto arrayPtrTy = LLVM::LLVMPointerType::get(arrayTy);
142 
143  // Copy size values to stack-allocated memory.
144  auto one = createIndexAttrConstant(builder, loc, indexType, 1);
145  auto sizes = builder.create<LLVM::ExtractValueOp>(
146  loc, value, llvm::makeArrayRef<int64_t>({kSizePosInMemRefDescriptor}));
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  ArrayRef<LLVM::GEPArg>{0, 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>(
162 }
163 
165  unsigned pos, uint64_t size) {
166  setSize(builder, loc, pos,
167  createIndexAttrConstant(builder, loc, indexType, size));
168 }
169 
170 /// Builds IR extracting the pos-th stride from the descriptor.
171 Value MemRefDescriptor::stride(OpBuilder &builder, Location loc, unsigned pos) {
172  return builder.create<LLVM::ExtractValueOp>(
174 }
175 
176 /// Builds IR inserting the pos-th stride into the descriptor
177 void MemRefDescriptor::setStride(OpBuilder &builder, Location loc, unsigned pos,
178  Value stride) {
179  value = builder.create<LLVM::InsertValueOp>(
180  loc, value, stride,
182 }
183 
185  unsigned pos, uint64_t stride) {
186  setStride(builder, loc, pos,
187  createIndexAttrConstant(builder, loc, indexType, stride));
188 }
189 
190 LLVM::LLVMPointerType MemRefDescriptor::getElementPtrType() {
191  return value.getType()
194  .cast<LLVM::LLVMPointerType>();
195 }
196 
197 /// Creates a MemRef descriptor structure from a list of individual values
198 /// composing that descriptor, in the following order:
199 /// - allocated pointer;
200 /// - aligned pointer;
201 /// - offset;
202 /// - <rank> sizes;
203 /// - <rank> shapes;
204 /// where <rank> is the MemRef rank as provided in `type`.
206  LLVMTypeConverter &converter, MemRefType type,
207  ValueRange values) {
208  Type llvmType = converter.convertType(type);
209  auto d = MemRefDescriptor::undef(builder, loc, llvmType);
210 
211  d.setAllocatedPtr(builder, loc, values[kAllocatedPtrPosInMemRefDescriptor]);
212  d.setAlignedPtr(builder, loc, values[kAlignedPtrPosInMemRefDescriptor]);
213  d.setOffset(builder, loc, values[kOffsetPosInMemRefDescriptor]);
214 
215  int64_t rank = type.getRank();
216  for (unsigned i = 0; i < rank; ++i) {
217  d.setSize(builder, loc, i, values[kSizePosInMemRefDescriptor + i]);
218  d.setStride(builder, loc, i, values[kSizePosInMemRefDescriptor + rank + i]);
219  }
220 
221  return d;
222 }
223 
224 /// Builds IR extracting individual elements of a MemRef descriptor structure
225 /// and returning them as `results` list.
227  MemRefType type,
228  SmallVectorImpl<Value> &results) {
229  int64_t rank = type.getRank();
230  results.reserve(results.size() + getNumUnpackedValues(type));
231 
232  MemRefDescriptor d(packed);
233  results.push_back(d.allocatedPtr(builder, loc));
234  results.push_back(d.alignedPtr(builder, loc));
235  results.push_back(d.offset(builder, loc));
236  for (int64_t i = 0; i < rank; ++i)
237  results.push_back(d.size(builder, loc, i));
238  for (int64_t i = 0; i < rank; ++i)
239  results.push_back(d.stride(builder, loc, i));
240 }
241 
242 /// Returns the number of non-aggregate values that would be produced by
243 /// `unpack`.
244 unsigned MemRefDescriptor::getNumUnpackedValues(MemRefType type) {
245  // Two pointers, offset, <rank> sizes, <rank> shapes.
246  return 3 + 2 * type.getRank();
247 }
248 
249 //===----------------------------------------------------------------------===//
250 // MemRefDescriptorView implementation.
251 //===----------------------------------------------------------------------===//
252 
254  : rank((range.size() - kSizePosInMemRefDescriptor) / 2), elements(range) {}
255 
257  return elements[kAllocatedPtrPosInMemRefDescriptor];
258 }
259 
261  return elements[kAlignedPtrPosInMemRefDescriptor];
262 }
263 
265  return elements[kOffsetPosInMemRefDescriptor];
266 }
267 
269  return elements[kSizePosInMemRefDescriptor + pos];
270 }
271 
273  return elements[kSizePosInMemRefDescriptor + rank + pos];
274 }
275 
276 //===----------------------------------------------------------------------===//
277 // UnrankedMemRefDescriptor implementation
278 //===----------------------------------------------------------------------===//
279 
280 /// Construct a helper for the given descriptor value.
282  : StructBuilder(descriptor) {}
283 
284 /// Builds IR creating an `undef` value of the descriptor type.
286  Location loc,
287  Type descriptorType) {
288  Value descriptor = builder.create<LLVM::UndefOp>(loc, descriptorType);
289  return UnrankedMemRefDescriptor(descriptor);
290 }
292  return extractPtr(builder, loc, kRankInUnrankedMemRefDescriptor);
293 }
295  Value v) {
296  setPtr(builder, loc, kRankInUnrankedMemRefDescriptor, v);
297 }
299  Location loc) {
300  return extractPtr(builder, loc, kPtrInUnrankedMemRefDescriptor);
301 }
303  Location loc, Value v) {
304  setPtr(builder, loc, kPtrInUnrankedMemRefDescriptor, v);
305 }
306 
307 /// Builds IR populating an unranked MemRef descriptor structure from a list
308 /// of individual constituent values in the following order:
309 /// - rank of the memref;
310 /// - pointer to the memref descriptor.
312  LLVMTypeConverter &converter,
313  UnrankedMemRefType type,
314  ValueRange values) {
315  Type llvmType = converter.convertType(type);
316  auto d = UnrankedMemRefDescriptor::undef(builder, loc, llvmType);
317 
318  d.setRank(builder, loc, values[kRankInUnrankedMemRefDescriptor]);
319  d.setMemRefDescPtr(builder, loc, values[kPtrInUnrankedMemRefDescriptor]);
320  return d;
321 }
322 
323 /// Builds IR extracting individual elements that compose an unranked memref
324 /// descriptor and returns them as `results` list.
326  Value packed,
327  SmallVectorImpl<Value> &results) {
328  UnrankedMemRefDescriptor d(packed);
329  results.reserve(results.size() + 2);
330  results.push_back(d.rank(builder, loc));
331  results.push_back(d.memRefDescPtr(builder, loc));
332 }
333 
335  OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter,
337  if (values.empty())
338  return;
339 
340  // Cache the index type.
341  Type indexType = typeConverter.getIndexType();
342 
343  // Initialize shared constants.
344  Value one = createIndexAttrConstant(builder, loc, indexType, 1);
345  Value two = createIndexAttrConstant(builder, loc, indexType, 2);
346  Value pointerSize = createIndexAttrConstant(
347  builder, loc, indexType, ceilDiv(typeConverter.getPointerBitwidth(), 8));
348  Value indexSize =
349  createIndexAttrConstant(builder, loc, indexType,
350  ceilDiv(typeConverter.getIndexTypeBitwidth(), 8));
351 
352  sizes.reserve(sizes.size() + values.size());
353  for (UnrankedMemRefDescriptor desc : values) {
354  // Emit IR computing the memory necessary to store the descriptor. This
355  // assumes the descriptor to be
356  // { type*, type*, index, index[rank], index[rank] }
357  // and densely packed, so the total size is
358  // 2 * sizeof(pointer) + (1 + 2 * rank) * sizeof(index).
359  // TODO: consider including the actual size (including eventual padding due
360  // to data layout) into the unranked descriptor.
361  Value doublePointerSize =
362  builder.create<LLVM::MulOp>(loc, indexType, two, pointerSize);
363 
364  // (1 + 2 * rank) * sizeof(index)
365  Value rank = desc.rank(builder, loc);
366  Value doubleRank = builder.create<LLVM::MulOp>(loc, indexType, two, rank);
367  Value doubleRankIncremented =
368  builder.create<LLVM::AddOp>(loc, indexType, doubleRank, one);
369  Value rankIndexSize = builder.create<LLVM::MulOp>(
370  loc, indexType, doubleRankIncremented, indexSize);
371 
372  // Total allocation size.
373  Value allocationSize = builder.create<LLVM::AddOp>(
374  loc, indexType, doublePointerSize, rankIndexSize);
375  sizes.push_back(allocationSize);
376  }
377 }
378 
380  Value memRefDescPtr,
381  Type elemPtrPtrType) {
382 
383  Value elementPtrPtr =
384  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
385  return builder.create<LLVM::LoadOp>(loc, elementPtrPtr);
386 }
387 
389  Value memRefDescPtr,
390  Type elemPtrPtrType,
391  Value allocatedPtr) {
392  Value elementPtrPtr =
393  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
394  builder.create<LLVM::StoreOp>(loc, allocatedPtr, elementPtrPtr);
395 }
396 
398  LLVMTypeConverter &typeConverter,
399  Value memRefDescPtr,
400  Type elemPtrPtrType) {
401  Value elementPtrPtr =
402  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
403 
404  Value alignedGep = builder.create<LLVM::GEPOp>(
405  loc, elemPtrPtrType, elementPtrPtr, ArrayRef<LLVM::GEPArg>{1});
406  return builder.create<LLVM::LoadOp>(loc, alignedGep);
407 }
408 
410  LLVMTypeConverter &typeConverter,
411  Value memRefDescPtr,
412  Type elemPtrPtrType,
413  Value alignedPtr) {
414  Value elementPtrPtr =
415  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
416 
417  Value alignedGep = builder.create<LLVM::GEPOp>(
418  loc, elemPtrPtrType, elementPtrPtr, ArrayRef<LLVM::GEPArg>{1});
419  builder.create<LLVM::StoreOp>(loc, alignedPtr, alignedGep);
420 }
421 
423  LLVMTypeConverter &typeConverter,
424  Value memRefDescPtr,
425  Type elemPtrPtrType) {
426  Value elementPtrPtr =
427  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
428 
429  Value offsetGep = builder.create<LLVM::GEPOp>(
430  loc, elemPtrPtrType, elementPtrPtr, ArrayRef<LLVM::GEPArg>{2});
431  offsetGep = builder.create<LLVM::BitcastOp>(
432  loc, LLVM::LLVMPointerType::get(typeConverter.getIndexType()), offsetGep);
433  return builder.create<LLVM::LoadOp>(loc, offsetGep);
434 }
435 
437  LLVMTypeConverter &typeConverter,
438  Value memRefDescPtr,
439  Type elemPtrPtrType, Value offset) {
440  Value elementPtrPtr =
441  builder.create<LLVM::BitcastOp>(loc, elemPtrPtrType, memRefDescPtr);
442 
443  Value offsetGep = builder.create<LLVM::GEPOp>(
444  loc, elemPtrPtrType, elementPtrPtr, ArrayRef<LLVM::GEPArg>{2});
445  offsetGep = builder.create<LLVM::BitcastOp>(
446  loc, LLVM::LLVMPointerType::get(typeConverter.getIndexType()), offsetGep);
447  builder.create<LLVM::StoreOp>(loc, offset, offsetGep);
448 }
449 
451  OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter,
452  Value memRefDescPtr, LLVM::LLVMPointerType elemPtrPtrType) {
453  Type elemPtrTy = elemPtrPtrType.getElementType();
454  Type indexTy = typeConverter.getIndexType();
455  Type structPtrTy =
456  LLVM::LLVMPointerType::get(LLVM::LLVMStructType::getLiteral(
457  indexTy.getContext(), {elemPtrTy, elemPtrTy, indexTy, indexTy}));
458  Value structPtr =
459  builder.create<LLVM::BitcastOp>(loc, structPtrTy, memRefDescPtr);
460 
461  return builder.create<LLVM::GEPOp>(loc, LLVM::LLVMPointerType::get(indexTy),
462  structPtr, ArrayRef<LLVM::GEPArg>{0, 3});
463 }
464 
466  LLVMTypeConverter &typeConverter,
467  Value sizeBasePtr, Value index) {
468  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
469  Value sizeStoreGep =
470  builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizeBasePtr, index);
471  return builder.create<LLVM::LoadOp>(loc, sizeStoreGep);
472 }
473 
475  LLVMTypeConverter &typeConverter,
476  Value sizeBasePtr, Value index,
477  Value size) {
478  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
479  Value sizeStoreGep =
480  builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizeBasePtr, index);
481  builder.create<LLVM::StoreOp>(loc, size, sizeStoreGep);
482 }
483 
485  LLVMTypeConverter &typeConverter,
486  Value sizeBasePtr, Value rank) {
487  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
488  return builder.create<LLVM::GEPOp>(loc, indexPtrTy, sizeBasePtr, rank);
489 }
490 
492  LLVMTypeConverter &typeConverter,
493  Value strideBasePtr, Value index,
494  Value stride) {
495  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
496  Value strideStoreGep =
497  builder.create<LLVM::GEPOp>(loc, indexPtrTy, strideBasePtr, index);
498  return builder.create<LLVM::LoadOp>(loc, strideStoreGep);
499 }
500 
502  LLVMTypeConverter &typeConverter,
503  Value strideBasePtr, Value index,
504  Value stride) {
505  Type indexPtrTy = LLVM::LLVMPointerType::get(typeConverter.getIndexType());
506  Value strideStoreGep =
507  builder.create<LLVM::GEPOp>(loc, indexPtrTy, strideBasePtr, index);
508  builder.create<LLVM::StoreOp>(loc, stride, strideStoreGep);
509 }
static constexpr const bool value
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:109
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:30
unsigned getPointerBitwidth(unsigned addressSpace=0)
Gets the pointer bitwidth.
Type getIndexType()
Gets the LLVM representation of the index type.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results)
Convert the given type.
unsigned getIndexTypeBitwidth()
Gets the bitwidth of the index type when converted to LLVM.
LLVM dialect structure type representing a collection of different-typed elements manipulated togethe...
Definition: LLVMTypes.h:107
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:449
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:64
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...
Definition: MemRefBuilder.h:33
void setConstantSize(OpBuilder &builder, Location loc, unsigned pos, uint64_t size)
void setSize(OpBuilder &builder, Location loc, unsigned pos, Value size)
Builds IR inserting the pos-th size into the descriptor.
Value size(OpBuilder &builder, Location loc, unsigned pos)
Builds IR extracting the pos-th size from the descriptor.
Value offset(OpBuilder &builder, Location loc)
Builds IR extracting the offset from the descriptor.
Value allocatedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the allocated 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...
static MemRefDescriptor undef(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating an undef value of the descriptor type.
static unsigned getNumUnpackedValues(MemRefType type)
Returns the number of non-aggregate values that would be produced by unpack.
Value stride(OpBuilder &builder, Location loc, unsigned pos)
Builds IR extracting the pos-th size from the descriptor.
void setOffset(OpBuilder &builder, Location loc, Value offset)
Builds IR inserting the offset into the descriptor.
void setStride(OpBuilder &builder, Location loc, unsigned pos, Value stride)
Builds IR inserting the pos-th stride into the descriptor.
void setAlignedPtr(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the aligned pointer 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...
LLVM::LLVMPointerType getElementPtrType()
Returns the (LLVM) pointer type this descriptor contains.
void setConstantOffset(OpBuilder &builder, Location loc, uint64_t offset)
Builds IR inserting the offset into the descriptor.
Value alignedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the aligned pointer from the descriptor.
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 setConstantStride(OpBuilder &builder, Location loc, unsigned pos, uint64_t stride)
MemRefDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
void setAllocatedPtr(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the allocated pointer into the descriptor.
This class helps build Operations.
Definition: Builders.h:198
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:422
Helper class to produce LLVM dialect operations extracting or inserting values to a struct.
Definition: StructBuilder.h:26
void setPtr(OpBuilder &builder, Location loc, unsigned pos, Value ptr)
Builds IR to set a value in the struct at position pos.
Value extractPtr(OpBuilder &builder, Location loc, unsigned pos)
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
U cast() const
Definition: Types.h:280
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition: Types.cpp:19
void setRank(OpBuilder &builder, Location loc, Value value)
Builds IR setting the rank in the descriptor.
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 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 rank(OpBuilder &builder, Location loc)
Builds IR extracting the rank from 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.
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 UnrankedMemRefDescriptor undef(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating an undef value of the descriptor type.
UnrankedMemRefDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
Value memRefDescPtr(OpBuilder &builder, Location loc)
Builds IR extracting ranked memref descriptor ptr.
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.
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...
static Value offset(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value memRefDescPtr, Type elemPtrPtrType)
Builds IR extracting the offset 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 size(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value sizeBasePtr, Value index)
Builds IR extracting the size[index] from 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 allocatedPtr(OpBuilder &builder, Location loc, Value memRefDescPtr, Type elemPtrPtrType)
TODO: The following accessors don't take alignment rules between elements of the descriptor struct in...
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 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...
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 void setStride(OpBuilder &builder, Location loc, LLVMTypeConverter &typeConverter, Value strideBasePtr, Value index, Value stride)
Builds IR inserting the stride[index] into the descriptor.
void setMemRefDescPtr(OpBuilder &builder, Location loc, Value value)
Builds IR setting ranked memref descriptor ptr.
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:349
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
Type getType() const
Return the type of this value.
Definition: Value.h:114
Include the generated interface declarations.
int64_t ceilDiv(int64_t lhs, int64_t rhs)
Returns the result of MLIR's ceildiv operation on constants.
Definition: MathExtras.h:23
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.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:68