MLIR  18.0.0git
BuiltinAttributes.cpp
Go to the documentation of this file.
1 //===- BuiltinAttributes.cpp - C Interface to MLIR Builtin Attributes -----===//
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 "mlir-c/Support.h"
11 #include "mlir/CAPI/AffineMap.h"
12 #include "mlir/CAPI/IR.h"
13 #include "mlir/CAPI/Support.h"
14 #include "mlir/IR/AsmState.h"
15 #include "mlir/IR/Attributes.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 
19 using namespace mlir;
20 
21 MlirAttribute mlirAttributeGetNull() { return {nullptr}; }
22 
23 //===----------------------------------------------------------------------===//
24 // Location attribute.
25 //===----------------------------------------------------------------------===//
26 
27 bool mlirAttributeIsALocation(MlirAttribute attr) {
28  return llvm::isa<LocationAttr>(unwrap(attr));
29 }
30 
31 //===----------------------------------------------------------------------===//
32 // Affine map attribute.
33 //===----------------------------------------------------------------------===//
34 
35 bool mlirAttributeIsAAffineMap(MlirAttribute attr) {
36  return llvm::isa<AffineMapAttr>(unwrap(attr));
37 }
38 
39 MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map) {
40  return wrap(AffineMapAttr::get(unwrap(map)));
41 }
42 
43 MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr) {
44  return wrap(llvm::cast<AffineMapAttr>(unwrap(attr)).getValue());
45 }
46 
47 MlirTypeID mlirAffineMapAttrGetTypeID(void) {
48  return wrap(AffineMapAttr::getTypeID());
49 }
50 
51 //===----------------------------------------------------------------------===//
52 // Array attribute.
53 //===----------------------------------------------------------------------===//
54 
55 bool mlirAttributeIsAArray(MlirAttribute attr) {
56  return llvm::isa<ArrayAttr>(unwrap(attr));
57 }
58 
59 MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements,
60  MlirAttribute const *elements) {
62  return wrap(
63  ArrayAttr::get(unwrap(ctx), unwrapList(static_cast<size_t>(numElements),
64  elements, attrs)));
65 }
66 
67 intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr) {
68  return static_cast<intptr_t>(llvm::cast<ArrayAttr>(unwrap(attr)).size());
69 }
70 
71 MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos) {
72  return wrap(llvm::cast<ArrayAttr>(unwrap(attr)).getValue()[pos]);
73 }
74 
75 MlirTypeID mlirArrayAttrGetTypeID(void) { return wrap(ArrayAttr::getTypeID()); }
76 
77 //===----------------------------------------------------------------------===//
78 // Dictionary attribute.
79 //===----------------------------------------------------------------------===//
80 
81 bool mlirAttributeIsADictionary(MlirAttribute attr) {
82  return llvm::isa<DictionaryAttr>(unwrap(attr));
83 }
84 
85 MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements,
86  MlirNamedAttribute const *elements) {
88  attributes.reserve(numElements);
89  for (intptr_t i = 0; i < numElements; ++i)
90  attributes.emplace_back(unwrap(elements[i].name),
91  unwrap(elements[i].attribute));
92  return wrap(DictionaryAttr::get(unwrap(ctx), attributes));
93 }
94 
95 intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr) {
96  return static_cast<intptr_t>(llvm::cast<DictionaryAttr>(unwrap(attr)).size());
97 }
98 
100  intptr_t pos) {
101  NamedAttribute attribute =
102  llvm::cast<DictionaryAttr>(unwrap(attr)).getValue()[pos];
103  return {wrap(attribute.getName()), wrap(attribute.getValue())};
104 }
105 
106 MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr,
107  MlirStringRef name) {
108  return wrap(llvm::cast<DictionaryAttr>(unwrap(attr)).get(unwrap(name)));
109 }
110 
111 MlirTypeID mlirDictionaryAttrGetTypeID(void) {
112  return wrap(DictionaryAttr::getTypeID());
113 }
114 
115 //===----------------------------------------------------------------------===//
116 // Floating point attribute.
117 //===----------------------------------------------------------------------===//
118 
119 bool mlirAttributeIsAFloat(MlirAttribute attr) {
120  return llvm::isa<FloatAttr>(unwrap(attr));
121 }
122 
123 MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type,
124  double value) {
125  return wrap(FloatAttr::get(unwrap(type), value));
126 }
127 
128 MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type,
129  double value) {
130  return wrap(FloatAttr::getChecked(unwrap(loc), unwrap(type), value));
131 }
132 
133 double mlirFloatAttrGetValueDouble(MlirAttribute attr) {
134  return llvm::cast<FloatAttr>(unwrap(attr)).getValueAsDouble();
135 }
136 
137 MlirTypeID mlirFloatAttrGetTypeID(void) { return wrap(FloatAttr::getTypeID()); }
138 
139 //===----------------------------------------------------------------------===//
140 // Integer attribute.
141 //===----------------------------------------------------------------------===//
142 
143 bool mlirAttributeIsAInteger(MlirAttribute attr) {
144  return llvm::isa<IntegerAttr>(unwrap(attr));
145 }
146 
147 MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value) {
148  return wrap(IntegerAttr::get(unwrap(type), value));
149 }
150 
151 int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr) {
152  return llvm::cast<IntegerAttr>(unwrap(attr)).getInt();
153 }
154 
155 int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr) {
156  return llvm::cast<IntegerAttr>(unwrap(attr)).getSInt();
157 }
158 
159 uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr) {
160  return llvm::cast<IntegerAttr>(unwrap(attr)).getUInt();
161 }
162 
163 MlirTypeID mlirIntegerAttrGetTypeID(void) {
164  return wrap(IntegerAttr::getTypeID());
165 }
166 
167 //===----------------------------------------------------------------------===//
168 // Bool attribute.
169 //===----------------------------------------------------------------------===//
170 
171 bool mlirAttributeIsABool(MlirAttribute attr) {
172  return llvm::isa<BoolAttr>(unwrap(attr));
173 }
174 
175 MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value) {
176  return wrap(BoolAttr::get(unwrap(ctx), value));
177 }
178 
179 bool mlirBoolAttrGetValue(MlirAttribute attr) {
180  return llvm::cast<BoolAttr>(unwrap(attr)).getValue();
181 }
182 
183 //===----------------------------------------------------------------------===//
184 // Integer set attribute.
185 //===----------------------------------------------------------------------===//
186 
187 bool mlirAttributeIsAIntegerSet(MlirAttribute attr) {
188  return llvm::isa<IntegerSetAttr>(unwrap(attr));
189 }
190 
191 MlirTypeID mlirIntegerSetAttrGetTypeID(void) {
192  return wrap(IntegerSetAttr::getTypeID());
193 }
194 
195 //===----------------------------------------------------------------------===//
196 // Opaque attribute.
197 //===----------------------------------------------------------------------===//
198 
199 bool mlirAttributeIsAOpaque(MlirAttribute attr) {
200  return llvm::isa<OpaqueAttr>(unwrap(attr));
201 }
202 
203 MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
204  intptr_t dataLength, const char *data,
205  MlirType type) {
206  return wrap(
207  OpaqueAttr::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)),
208  StringRef(data, dataLength), unwrap(type)));
209 }
210 
212  return wrap(
213  llvm::cast<OpaqueAttr>(unwrap(attr)).getDialectNamespace().strref());
214 }
215 
217  return wrap(llvm::cast<OpaqueAttr>(unwrap(attr)).getAttrData());
218 }
219 
220 MlirTypeID mlirOpaqueAttrGetTypeID(void) {
221  return wrap(OpaqueAttr::getTypeID());
222 }
223 
224 //===----------------------------------------------------------------------===//
225 // String attribute.
226 //===----------------------------------------------------------------------===//
227 
228 bool mlirAttributeIsAString(MlirAttribute attr) {
229  return llvm::isa<StringAttr>(unwrap(attr));
230 }
231 
232 MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str) {
233  return wrap((Attribute)StringAttr::get(unwrap(ctx), unwrap(str)));
234 }
235 
236 MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str) {
237  return wrap((Attribute)StringAttr::get(unwrap(str), unwrap(type)));
238 }
239 
241  return wrap(llvm::cast<StringAttr>(unwrap(attr)).getValue());
242 }
243 
244 MlirTypeID mlirStringAttrGetTypeID(void) {
245  return wrap(StringAttr::getTypeID());
246 }
247 
248 //===----------------------------------------------------------------------===//
249 // SymbolRef attribute.
250 //===----------------------------------------------------------------------===//
251 
252 bool mlirAttributeIsASymbolRef(MlirAttribute attr) {
253  return llvm::isa<SymbolRefAttr>(unwrap(attr));
254 }
255 
256 MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
257  intptr_t numReferences,
258  MlirAttribute const *references) {
260  refs.reserve(numReferences);
261  for (intptr_t i = 0; i < numReferences; ++i)
262  refs.push_back(llvm::cast<FlatSymbolRefAttr>(unwrap(references[i])));
263  auto symbolAttr = StringAttr::get(unwrap(ctx), unwrap(symbol));
264  return wrap(SymbolRefAttr::get(symbolAttr, refs));
265 }
266 
268  return wrap(
269  llvm::cast<SymbolRefAttr>(unwrap(attr)).getRootReference().getValue());
270 }
271 
273  return wrap(
274  llvm::cast<SymbolRefAttr>(unwrap(attr)).getLeafReference().getValue());
275 }
276 
277 intptr_t mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr) {
278  return static_cast<intptr_t>(
279  llvm::cast<SymbolRefAttr>(unwrap(attr)).getNestedReferences().size());
280 }
281 
282 MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr,
283  intptr_t pos) {
284  return wrap(
285  llvm::cast<SymbolRefAttr>(unwrap(attr)).getNestedReferences()[pos]);
286 }
287 
288 MlirTypeID mlirSymbolRefAttrGetTypeID(void) {
289  return wrap(SymbolRefAttr::getTypeID());
290 }
291 
292 //===----------------------------------------------------------------------===//
293 // Flat SymbolRef attribute.
294 //===----------------------------------------------------------------------===//
295 
296 bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr) {
297  return llvm::isa<FlatSymbolRefAttr>(unwrap(attr));
298 }
299 
300 MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol) {
301  return wrap(FlatSymbolRefAttr::get(unwrap(ctx), unwrap(symbol)));
302 }
303 
305  return wrap(llvm::cast<FlatSymbolRefAttr>(unwrap(attr)).getValue());
306 }
307 
308 //===----------------------------------------------------------------------===//
309 // Type attribute.
310 //===----------------------------------------------------------------------===//
311 
312 bool mlirAttributeIsAType(MlirAttribute attr) {
313  return llvm::isa<TypeAttr>(unwrap(attr));
314 }
315 
316 MlirAttribute mlirTypeAttrGet(MlirType type) {
317  return wrap(TypeAttr::get(unwrap(type)));
318 }
319 
320 MlirType mlirTypeAttrGetValue(MlirAttribute attr) {
321  return wrap(llvm::cast<TypeAttr>(unwrap(attr)).getValue());
322 }
323 
324 MlirTypeID mlirTypeAttrGetTypeID(void) { return wrap(TypeAttr::getTypeID()); }
325 
326 //===----------------------------------------------------------------------===//
327 // Unit attribute.
328 //===----------------------------------------------------------------------===//
329 
330 bool mlirAttributeIsAUnit(MlirAttribute attr) {
331  return llvm::isa<UnitAttr>(unwrap(attr));
332 }
333 
334 MlirAttribute mlirUnitAttrGet(MlirContext ctx) {
335  return wrap(UnitAttr::get(unwrap(ctx)));
336 }
337 
338 MlirTypeID mlirUnitAttrGetTypeID(void) { return wrap(UnitAttr::getTypeID()); }
339 
340 //===----------------------------------------------------------------------===//
341 // Elements attributes.
342 //===----------------------------------------------------------------------===//
343 
344 bool mlirAttributeIsAElements(MlirAttribute attr) {
345  return llvm::isa<ElementsAttr>(unwrap(attr));
346 }
347 
348 MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, intptr_t rank,
349  uint64_t *idxs) {
350  return wrap(llvm::cast<ElementsAttr>(unwrap(attr))
351  .getValues<Attribute>()[llvm::ArrayRef(idxs, rank)]);
352 }
353 
354 bool mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank,
355  uint64_t *idxs) {
356  return llvm::cast<ElementsAttr>(unwrap(attr))
357  .isValidIndex(llvm::ArrayRef(idxs, rank));
358 }
359 
360 int64_t mlirElementsAttrGetNumElements(MlirAttribute attr) {
361  return llvm::cast<ElementsAttr>(unwrap(attr)).getNumElements();
362 }
363 
364 //===----------------------------------------------------------------------===//
365 // Dense array attribute.
366 //===----------------------------------------------------------------------===//
367 
369  return wrap(DenseArrayAttr::getTypeID());
370 }
371 
372 //===----------------------------------------------------------------------===//
373 // IsA support.
374 //===----------------------------------------------------------------------===//
375 
376 bool mlirAttributeIsADenseBoolArray(MlirAttribute attr) {
377  return llvm::isa<DenseBoolArrayAttr>(unwrap(attr));
378 }
379 bool mlirAttributeIsADenseI8Array(MlirAttribute attr) {
380  return llvm::isa<DenseI8ArrayAttr>(unwrap(attr));
381 }
382 bool mlirAttributeIsADenseI16Array(MlirAttribute attr) {
383  return llvm::isa<DenseI16ArrayAttr>(unwrap(attr));
384 }
385 bool mlirAttributeIsADenseI32Array(MlirAttribute attr) {
386  return llvm::isa<DenseI32ArrayAttr>(unwrap(attr));
387 }
388 bool mlirAttributeIsADenseI64Array(MlirAttribute attr) {
389  return llvm::isa<DenseI64ArrayAttr>(unwrap(attr));
390 }
391 bool mlirAttributeIsADenseF32Array(MlirAttribute attr) {
392  return llvm::isa<DenseF32ArrayAttr>(unwrap(attr));
393 }
394 bool mlirAttributeIsADenseF64Array(MlirAttribute attr) {
395  return llvm::isa<DenseF64ArrayAttr>(unwrap(attr));
396 }
397 
398 //===----------------------------------------------------------------------===//
399 // Constructors.
400 //===----------------------------------------------------------------------===//
401 
402 MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size,
403  int const *values) {
404  SmallVector<bool, 4> elements(values, values + size);
405  return wrap(DenseBoolArrayAttr::get(unwrap(ctx), elements));
406 }
407 MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size,
408  int8_t const *values) {
409  return wrap(
410  DenseI8ArrayAttr::get(unwrap(ctx), ArrayRef<int8_t>(values, size)));
411 }
412 MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size,
413  int16_t const *values) {
414  return wrap(
415  DenseI16ArrayAttr::get(unwrap(ctx), ArrayRef<int16_t>(values, size)));
416 }
417 MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size,
418  int32_t const *values) {
419  return wrap(
420  DenseI32ArrayAttr::get(unwrap(ctx), ArrayRef<int32_t>(values, size)));
421 }
422 MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size,
423  int64_t const *values) {
424  return wrap(
425  DenseI64ArrayAttr::get(unwrap(ctx), ArrayRef<int64_t>(values, size)));
426 }
427 MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size,
428  float const *values) {
429  return wrap(
430  DenseF32ArrayAttr::get(unwrap(ctx), ArrayRef<float>(values, size)));
431 }
432 MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size,
433  double const *values) {
434  return wrap(
435  DenseF64ArrayAttr::get(unwrap(ctx), ArrayRef<double>(values, size)));
436 }
437 
438 //===----------------------------------------------------------------------===//
439 // Accessors.
440 //===----------------------------------------------------------------------===//
441 
442 intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr) {
443  return llvm::cast<DenseArrayAttr>(unwrap(attr)).size();
444 }
445 
446 //===----------------------------------------------------------------------===//
447 // Indexed accessors.
448 //===----------------------------------------------------------------------===//
449 
450 bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos) {
451  return llvm::cast<DenseBoolArrayAttr>(unwrap(attr))[pos];
452 }
453 int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos) {
454  return llvm::cast<DenseI8ArrayAttr>(unwrap(attr))[pos];
455 }
456 int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos) {
457  return llvm::cast<DenseI16ArrayAttr>(unwrap(attr))[pos];
458 }
459 int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
460  return llvm::cast<DenseI32ArrayAttr>(unwrap(attr))[pos];
461 }
462 int64_t mlirDenseI64ArrayGetElement(MlirAttribute attr, intptr_t pos) {
463  return llvm::cast<DenseI64ArrayAttr>(unwrap(attr))[pos];
464 }
465 float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
466  return llvm::cast<DenseF32ArrayAttr>(unwrap(attr))[pos];
467 }
468 double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos) {
469  return llvm::cast<DenseF64ArrayAttr>(unwrap(attr))[pos];
470 }
471 
472 //===----------------------------------------------------------------------===//
473 // Dense elements attribute.
474 //===----------------------------------------------------------------------===//
475 
476 //===----------------------------------------------------------------------===//
477 // IsA support.
478 //===----------------------------------------------------------------------===//
479 
480 bool mlirAttributeIsADenseElements(MlirAttribute attr) {
481  return llvm::isa<DenseElementsAttr>(unwrap(attr));
482 }
483 
484 bool mlirAttributeIsADenseIntElements(MlirAttribute attr) {
485  return llvm::isa<DenseIntElementsAttr>(unwrap(attr));
486 }
487 
488 bool mlirAttributeIsADenseFPElements(MlirAttribute attr) {
489  return llvm::isa<DenseFPElementsAttr>(unwrap(attr));
490 }
491 
493  return wrap(DenseIntOrFPElementsAttr::getTypeID());
494 }
495 
496 //===----------------------------------------------------------------------===//
497 // Constructors.
498 //===----------------------------------------------------------------------===//
499 
500 MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType,
501  intptr_t numElements,
502  MlirAttribute const *elements) {
503  SmallVector<Attribute, 8> attributes;
504  return wrap(
505  DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
506  unwrapList(numElements, elements, attributes)));
507 }
508 
509 MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType,
510  size_t rawBufferSize,
511  const void *rawBuffer) {
512  auto shapedTypeCpp = llvm::cast<ShapedType>(unwrap(shapedType));
513  ArrayRef<char> rawBufferCpp(static_cast<const char *>(rawBuffer),
514  rawBufferSize);
515  bool isSplat = false;
516  if (!DenseElementsAttr::isValidRawBuffer(shapedTypeCpp, rawBufferCpp,
517  isSplat))
518  return mlirAttributeGetNull();
519  return wrap(DenseElementsAttr::getFromRawBuffer(shapedTypeCpp, rawBufferCpp));
520 }
521 
522 MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType,
523  MlirAttribute element) {
524  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
525  unwrap(element)));
526 }
527 MlirAttribute mlirDenseElementsAttrBoolSplatGet(MlirType shapedType,
528  bool element) {
529  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
530  element));
531 }
532 MlirAttribute mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType,
533  uint8_t element) {
534  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
535  element));
536 }
537 MlirAttribute mlirDenseElementsAttrInt8SplatGet(MlirType shapedType,
538  int8_t element) {
539  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
540  element));
541 }
542 MlirAttribute mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType,
543  uint32_t element) {
544  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
545  element));
546 }
547 MlirAttribute mlirDenseElementsAttrInt32SplatGet(MlirType shapedType,
548  int32_t element) {
549  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
550  element));
551 }
552 MlirAttribute mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType,
553  uint64_t element) {
554  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
555  element));
556 }
557 MlirAttribute mlirDenseElementsAttrInt64SplatGet(MlirType shapedType,
558  int64_t element) {
559  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
560  element));
561 }
562 MlirAttribute mlirDenseElementsAttrFloatSplatGet(MlirType shapedType,
563  float element) {
564  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
565  element));
566 }
567 MlirAttribute mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType,
568  double element) {
569  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
570  element));
571 }
572 
573 MlirAttribute mlirDenseElementsAttrBoolGet(MlirType shapedType,
574  intptr_t numElements,
575  const int *elements) {
576  SmallVector<bool, 8> values(elements, elements + numElements);
577  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
578  values));
579 }
580 
581 /// Creates a dense attribute with elements of the type deduced by templates.
582 template <typename T>
583 static MlirAttribute getDenseAttribute(MlirType shapedType,
584  intptr_t numElements,
585  const T *elements) {
586  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
587  llvm::ArrayRef(elements, numElements)));
588 }
589 
590 MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType,
591  intptr_t numElements,
592  const uint8_t *elements) {
593  return getDenseAttribute(shapedType, numElements, elements);
594 }
595 MlirAttribute mlirDenseElementsAttrInt8Get(MlirType shapedType,
596  intptr_t numElements,
597  const int8_t *elements) {
598  return getDenseAttribute(shapedType, numElements, elements);
599 }
600 MlirAttribute mlirDenseElementsAttrUInt16Get(MlirType shapedType,
601  intptr_t numElements,
602  const uint16_t *elements) {
603  return getDenseAttribute(shapedType, numElements, elements);
604 }
605 MlirAttribute mlirDenseElementsAttrInt16Get(MlirType shapedType,
606  intptr_t numElements,
607  const int16_t *elements) {
608  return getDenseAttribute(shapedType, numElements, elements);
609 }
610 MlirAttribute mlirDenseElementsAttrUInt32Get(MlirType shapedType,
611  intptr_t numElements,
612  const uint32_t *elements) {
613  return getDenseAttribute(shapedType, numElements, elements);
614 }
615 MlirAttribute mlirDenseElementsAttrInt32Get(MlirType shapedType,
616  intptr_t numElements,
617  const int32_t *elements) {
618  return getDenseAttribute(shapedType, numElements, elements);
619 }
620 MlirAttribute mlirDenseElementsAttrUInt64Get(MlirType shapedType,
621  intptr_t numElements,
622  const uint64_t *elements) {
623  return getDenseAttribute(shapedType, numElements, elements);
624 }
625 MlirAttribute mlirDenseElementsAttrInt64Get(MlirType shapedType,
626  intptr_t numElements,
627  const int64_t *elements) {
628  return getDenseAttribute(shapedType, numElements, elements);
629 }
630 MlirAttribute mlirDenseElementsAttrFloatGet(MlirType shapedType,
631  intptr_t numElements,
632  const float *elements) {
633  return getDenseAttribute(shapedType, numElements, elements);
634 }
635 MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType,
636  intptr_t numElements,
637  const double *elements) {
638  return getDenseAttribute(shapedType, numElements, elements);
639 }
640 MlirAttribute mlirDenseElementsAttrBFloat16Get(MlirType shapedType,
641  intptr_t numElements,
642  const uint16_t *elements) {
643  size_t bufferSize = numElements * 2;
644  const void *buffer = static_cast<const void *>(elements);
645  return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
646 }
647 MlirAttribute mlirDenseElementsAttrFloat16Get(MlirType shapedType,
648  intptr_t numElements,
649  const uint16_t *elements) {
650  size_t bufferSize = numElements * 2;
651  const void *buffer = static_cast<const void *>(elements);
652  return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
653 }
654 
655 MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType,
656  intptr_t numElements,
657  MlirStringRef *strs) {
659  values.reserve(numElements);
660  for (intptr_t i = 0; i < numElements; ++i)
661  values.push_back(unwrap(strs[i]));
662 
663  return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
664  values));
665 }
666 
667 MlirAttribute mlirDenseElementsAttrReshapeGet(MlirAttribute attr,
668  MlirType shapedType) {
669  return wrap(llvm::cast<DenseElementsAttr>(unwrap(attr))
670  .reshape(llvm::cast<ShapedType>(unwrap(shapedType))));
671 }
672 
673 //===----------------------------------------------------------------------===//
674 // Splat accessors.
675 //===----------------------------------------------------------------------===//
676 
677 bool mlirDenseElementsAttrIsSplat(MlirAttribute attr) {
678  return llvm::cast<DenseElementsAttr>(unwrap(attr)).isSplat();
679 }
680 
681 MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr) {
682  return wrap(
683  llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<Attribute>());
684 }
685 int mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr) {
686  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<bool>();
687 }
688 int8_t mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr) {
689  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int8_t>();
690 }
691 uint8_t mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr) {
692  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint8_t>();
693 }
694 int32_t mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr) {
695  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int32_t>();
696 }
697 uint32_t mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr) {
698  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint32_t>();
699 }
700 int64_t mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr) {
701  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int64_t>();
702 }
703 uint64_t mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr) {
704  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint64_t>();
705 }
706 float mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr) {
707  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<float>();
708 }
709 double mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr) {
710  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<double>();
711 }
713  return wrap(
714  llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<StringRef>());
715 }
716 
717 //===----------------------------------------------------------------------===//
718 // Indexed accessors.
719 //===----------------------------------------------------------------------===//
720 
721 bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos) {
722  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<bool>()[pos];
723 }
724 int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos) {
725  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int8_t>()[pos];
726 }
727 uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos) {
728  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint8_t>()[pos];
729 }
730 int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos) {
731  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int16_t>()[pos];
732 }
733 uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos) {
734  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint16_t>()[pos];
735 }
736 int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos) {
737  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int32_t>()[pos];
738 }
739 uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos) {
740  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint32_t>()[pos];
741 }
742 int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos) {
743  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int64_t>()[pos];
744 }
745 uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos) {
746  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
747 }
748 float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos) {
749  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<float>()[pos];
750 }
751 double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos) {
752  return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<double>()[pos];
753 }
755  intptr_t pos) {
756  return wrap(
757  llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<StringRef>()[pos]);
758 }
759 
760 //===----------------------------------------------------------------------===//
761 // Raw data accessors.
762 //===----------------------------------------------------------------------===//
763 
764 const void *mlirDenseElementsAttrGetRawData(MlirAttribute attr) {
765  return static_cast<const void *>(
766  llvm::cast<DenseElementsAttr>(unwrap(attr)).getRawData().data());
767 }
768 
769 //===----------------------------------------------------------------------===//
770 // Resource blob attributes.
771 //===----------------------------------------------------------------------===//
772 
773 bool mlirAttributeIsADenseResourceElements(MlirAttribute attr) {
774  return llvm::isa<DenseResourceElementsAttr>(unwrap(attr));
775 }
776 
778  MlirType shapedType, MlirStringRef name, void *data, size_t dataLength,
779  size_t dataAlignment, bool dataIsMutable,
780  void (*deleter)(void *userData, const void *data, size_t size,
781  size_t align),
782  void *userData) {
783  AsmResourceBlob::DeleterFn cppDeleter = {};
784  if (deleter) {
785  cppDeleter = [deleter, userData](void *data, size_t size, size_t align) {
786  deleter(userData, data, size, align);
787  };
788  }
789  AsmResourceBlob blob(
790  llvm::ArrayRef(static_cast<const char *>(data), dataLength),
791  dataAlignment, std::move(cppDeleter), dataIsMutable);
792  return wrap(
793  DenseResourceElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
794  unwrap(name), std::move(blob)));
795 }
796 
797 template <typename U, typename T>
798 static MlirAttribute getDenseResource(MlirType shapedType, MlirStringRef name,
799  intptr_t numElements, const T *elements) {
800  return wrap(U::get(llvm::cast<ShapedType>(unwrap(shapedType)), unwrap(name),
802  llvm::ArrayRef(elements, numElements))));
803 }
804 
806  MlirType shapedType, MlirStringRef name, intptr_t numElements,
807  const int *elements) {
808  return getDenseResource<DenseBoolResourceElementsAttr>(shapedType, name,
809  numElements, elements);
810 }
812  MlirType shapedType, MlirStringRef name, intptr_t numElements,
813  const uint8_t *elements) {
814  return getDenseResource<DenseUI8ResourceElementsAttr>(shapedType, name,
815  numElements, elements);
816 }
818  MlirType shapedType, MlirStringRef name, intptr_t numElements,
819  const uint16_t *elements) {
820  return getDenseResource<DenseUI16ResourceElementsAttr>(shapedType, name,
821  numElements, elements);
822 }
824  MlirType shapedType, MlirStringRef name, intptr_t numElements,
825  const uint32_t *elements) {
826  return getDenseResource<DenseUI32ResourceElementsAttr>(shapedType, name,
827  numElements, elements);
828 }
830  MlirType shapedType, MlirStringRef name, intptr_t numElements,
831  const uint64_t *elements) {
832  return getDenseResource<DenseUI64ResourceElementsAttr>(shapedType, name,
833  numElements, elements);
834 }
836  MlirType shapedType, MlirStringRef name, intptr_t numElements,
837  const int8_t *elements) {
838  return getDenseResource<DenseUI8ResourceElementsAttr>(shapedType, name,
839  numElements, elements);
840 }
842  MlirType shapedType, MlirStringRef name, intptr_t numElements,
843  const int16_t *elements) {
844  return getDenseResource<DenseUI16ResourceElementsAttr>(shapedType, name,
845  numElements, elements);
846 }
848  MlirType shapedType, MlirStringRef name, intptr_t numElements,
849  const int32_t *elements) {
850  return getDenseResource<DenseUI32ResourceElementsAttr>(shapedType, name,
851  numElements, elements);
852 }
854  MlirType shapedType, MlirStringRef name, intptr_t numElements,
855  const int64_t *elements) {
856  return getDenseResource<DenseUI64ResourceElementsAttr>(shapedType, name,
857  numElements, elements);
858 }
860  MlirType shapedType, MlirStringRef name, intptr_t numElements,
861  const float *elements) {
862  return getDenseResource<DenseF32ResourceElementsAttr>(shapedType, name,
863  numElements, elements);
864 }
866  MlirType shapedType, MlirStringRef name, intptr_t numElements,
867  const double *elements) {
868  return getDenseResource<DenseF64ResourceElementsAttr>(shapedType, name,
869  numElements, elements);
870 }
871 template <typename U, typename T>
872 static T getDenseResourceVal(MlirAttribute attr, intptr_t pos) {
873  return (*llvm::cast<U>(unwrap(attr)).tryGetAsArrayRef())[pos];
874 }
875 
877  intptr_t pos) {
878  return getDenseResourceVal<DenseBoolResourceElementsAttr, uint8_t>(attr, pos);
879 }
881  intptr_t pos) {
882  return getDenseResourceVal<DenseUI8ResourceElementsAttr, uint8_t>(attr, pos);
883 }
885  intptr_t pos) {
886  return getDenseResourceVal<DenseUI16ResourceElementsAttr, uint16_t>(attr,
887  pos);
888 }
890  intptr_t pos) {
891  return getDenseResourceVal<DenseUI32ResourceElementsAttr, uint32_t>(attr,
892  pos);
893 }
895  intptr_t pos) {
896  return getDenseResourceVal<DenseUI64ResourceElementsAttr, uint64_t>(attr,
897  pos);
898 }
900  intptr_t pos) {
901  return getDenseResourceVal<DenseUI8ResourceElementsAttr, int8_t>(attr, pos);
902 }
904  intptr_t pos) {
905  return getDenseResourceVal<DenseUI16ResourceElementsAttr, int16_t>(attr, pos);
906 }
908  intptr_t pos) {
909  return getDenseResourceVal<DenseUI32ResourceElementsAttr, int32_t>(attr, pos);
910 }
912  intptr_t pos) {
913  return getDenseResourceVal<DenseUI64ResourceElementsAttr, int64_t>(attr, pos);
914 }
916  intptr_t pos) {
917  return getDenseResourceVal<DenseF32ResourceElementsAttr, float>(attr, pos);
918 }
920  intptr_t pos) {
921  return getDenseResourceVal<DenseF64ResourceElementsAttr, double>(attr, pos);
922 }
923 
924 //===----------------------------------------------------------------------===//
925 // Sparse elements attribute.
926 //===----------------------------------------------------------------------===//
927 
928 bool mlirAttributeIsASparseElements(MlirAttribute attr) {
929  return llvm::isa<SparseElementsAttr>(unwrap(attr));
930 }
931 
932 MlirAttribute mlirSparseElementsAttribute(MlirType shapedType,
933  MlirAttribute denseIndices,
934  MlirAttribute denseValues) {
936  llvm::cast<ShapedType>(unwrap(shapedType)),
937  llvm::cast<DenseElementsAttr>(unwrap(denseIndices)),
938  llvm::cast<DenseElementsAttr>(unwrap(denseValues))));
939 }
940 
941 MlirAttribute mlirSparseElementsAttrGetIndices(MlirAttribute attr) {
942  return wrap(llvm::cast<SparseElementsAttr>(unwrap(attr)).getIndices());
943 }
944 
945 MlirAttribute mlirSparseElementsAttrGetValues(MlirAttribute attr) {
946  return wrap(llvm::cast<SparseElementsAttr>(unwrap(attr)).getValues());
947 }
948 
950  return wrap(SparseElementsAttr::getTypeID());
951 }
952 
953 //===----------------------------------------------------------------------===//
954 // Strided layout attribute.
955 //===----------------------------------------------------------------------===//
956 
957 bool mlirAttributeIsAStridedLayout(MlirAttribute attr) {
958  return llvm::isa<StridedLayoutAttr>(unwrap(attr));
959 }
960 
961 MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset,
962  intptr_t numStrides,
963  const int64_t *strides) {
964  return wrap(StridedLayoutAttr::get(unwrap(ctx), offset,
965  ArrayRef<int64_t>(strides, numStrides)));
966 }
967 
968 int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr) {
969  return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getOffset();
970 }
971 
972 intptr_t mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr) {
973  return static_cast<intptr_t>(
974  llvm::cast<StridedLayoutAttr>(unwrap(attr)).getStrides().size());
975 }
976 
977 int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr, intptr_t pos) {
978  return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getStrides()[pos];
979 }
980 
982  return wrap(StridedLayoutAttr::getTypeID());
983 }
bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr)
Checks whether the given attribute is a flat symbol reference attribute.
MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr)
Returns the affine map wrapped in the given affine map attribute.
MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType, intptr_t numElements, MlirAttribute const *elements)
Creates a dense elements attribute with the given Shaped type and elements in the same context as the...
intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr)
Returns the number of attributes contained in a dictionary attribute.
MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value)
Creates a bool attribute in the given context with the given value.
float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos)
int64_t mlirDenseInt64ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr)
Returns the referenced symbol as a string reference.
MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size, float const *values)
int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirSparseElementsAttrGetIndices(MlirAttribute attr)
Returns the dense elements attribute containing 64-bit integer indices of non-null elements in the gi...
MlirAttribute mlirUnmanagedDenseDoubleResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const double *elements)
uint32_t mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr)
bool mlirAttributeIsALocation(MlirAttribute attr)
bool mlirAttributeIsAString(MlirAttribute attr)
Checks whether the given attribute is a string attribute.
MlirStringRef mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos)
int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos)
uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsADenseI32Array(MlirAttribute attr)
int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signless type and f...
MlirStringRef mlirSymbolRefAttrGetRootReference(MlirAttribute attr)
Returns the string reference to the root referenced symbol.
MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map)
Creates an affine map attribute wrapping the given map.
int mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr)
MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides, const int64_t *strides)
double mlirDenseDoubleResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrFloat16Get(MlirType shapedType, intptr_t numElements, const uint16_t *elements)
float mlirDenseFloatResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos)
uint8_t mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr)
uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of unsigned type and f...
bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos)
Get an element of a dense array.
MlirAttribute mlirSparseElementsAttribute(MlirType shapedType, MlirAttribute denseIndices, MlirAttribute denseValues)
Creates a sparse elements attribute of the given shape from a list of indices and a list of associate...
bool mlirAttributeIsADictionary(MlirAttribute attr)
Checks whether the given attribute is a dictionary attribute.
bool mlirDenseBoolResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
Returns the pos-th value (flat contiguous indexing) of a specific type contained by the given dense r...
MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol)
Creates a flat symbol reference attribute in the given context referencing a symbol identified by the...
MlirAttribute mlirDenseElementsAttrInt16Get(MlirType shapedType, intptr_t numElements, const int16_t *elements)
bool mlirAttributeIsADenseElements(MlirAttribute attr)
Checks whether the given attribute is a dense elements attribute.
uint16_t mlirDenseUInt16ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
MlirTypeID mlirFloatAttrGetTypeID(void)
Returns the typeID of a Float attribute.
MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol, intptr_t numReferences, MlirAttribute const *references)
Creates a symbol reference attribute in the given context referencing a symbol identified by the give...
uint64_t mlirDenseUInt64ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
const void * mlirDenseElementsAttrGetRawData(MlirAttribute attr)
Returns the raw data of the given dense elements attribute.
bool mlirAttributeIsASparseElements(MlirAttribute attr)
Checks whether the given attribute is a sparse elements attribute.
MlirTypeID mlirAffineMapAttrGetTypeID(void)
Returns the typeID of an AffineMap attribute.
bool mlirBoolAttrGetValue(MlirAttribute attr)
Returns the value stored in the given bool attribute.
MlirTypeID mlirDenseArrayAttrGetTypeID()
int16_t mlirDenseInt16ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrBoolGet(MlirType shapedType, intptr_t numElements, const int *elements)
Creates a dense elements attribute with the given shaped type from elements of a specific type.
uint64_t mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr)
int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signed type and fit...
MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size, int32_t const *values)
MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos)
Returns pos-th reference nested in the given symbol reference attribute.
MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType, intptr_t numElements, MlirStringRef *strs)
Creates a dense elements attribute with the given shaped type from string elements.
MlirTypeID mlirIntegerSetAttrGetTypeID(void)
Returns the typeID of an IntegerSet attribute.
MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, void *data, size_t dataLength, size_t dataAlignment, bool dataIsMutable, void(*deleter)(void *userData, const void *data, size_t size, size_t align), void *userData)
Unlike the typed accessors below, constructs the attribute with a raw data buffer and no type/alignme...
MlirAttribute mlirUnmanagedDenseInt16ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const int16_t *elements)
MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType, intptr_t numElements, const double *elements)
MlirAttribute mlirUnmanagedDenseUInt16ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const uint16_t *elements)
intptr_t mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr)
Returns the number of references nested in the given symbol reference attribute.
bool mlirAttributeIsADenseI16Array(MlirAttribute attr)
MlirAttribute mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType, double element)
intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr)
Get the size of a dense array.
bool mlirAttributeIsADenseBoolArray(MlirAttribute attr)
Checks whether the given attribute is a dense array attribute.
MlirAttribute mlirUnmanagedDenseBoolResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const int *elements)
bool mlirAttributeIsADenseI64Array(MlirAttribute attr)
MlirStringRef mlirStringAttrGetValue(MlirAttribute attr)
Returns the attribute values as a string reference.
bool mlirAttributeIsAElements(MlirAttribute attr)
Checks whether the given attribute is an elements attribute.
MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos)
uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType, uint8_t element)
MlirTypeID mlirTypeAttrGetTypeID(void)
Returns the typeID of a Type attribute.
MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements)
Creates a dictionary attribute containing the given list of elements in the provided context.
uint8_t mlirDenseUInt8ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
int8_t mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr)
MlirTypeID mlirDenseIntOrFPElementsAttrGetTypeID(void)
Returns the typeID of an DenseIntOrFPElements attribute.
MlirAttribute mlirDenseElementsAttrUInt16Get(MlirType shapedType, intptr_t numElements, const uint16_t *elements)
MlirNamedAttribute mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element of the given dictionary attribute.
MlirAttribute mlirDenseElementsAttrBFloat16Get(MlirType shapedType, intptr_t numElements, const uint16_t *elements)
int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos)
int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
bool mlirAttributeIsADenseFPElements(MlirAttribute attr)
bool mlirAttributeIsADenseI8Array(MlirAttribute attr)
MlirTypeID mlirOpaqueAttrGetTypeID(void)
Returns the typeID of an Opaque attribute.
MlirStringRef mlirSymbolRefAttrGetLeafReference(MlirAttribute attr)
Returns the string reference to the leaf referenced symbol.
bool mlirAttributeIsAType(MlirAttribute attr)
Checks whether the given attribute is a type attribute.
MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value)
Creates an integer attribute of the given type with the given integer value.
MlirType mlirTypeAttrGetValue(MlirAttribute attr)
Returns the type stored in the given type attribute.
MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements, MlirAttribute const *elements)
Creates an array element containing the given list of elements in the given context.
double mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr)
MlirAttribute mlirUnmanagedDenseFloatResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const float *elements)
MlirAttribute mlirDenseElementsAttrInt64SplatGet(MlirType shapedType, int64_t element)
double mlirFloatAttrGetValueDouble(MlirAttribute attr)
Returns the value stored in the given floating point attribute, interpreting the value as double.
bool mlirAttributeIsAArray(MlirAttribute attr)
Checks whether the given attribute is an array attribute.
bool mlirAttributeIsAOpaque(MlirAttribute attr)
Checks whether the given attribute is an opaque attribute.
MlirAttribute mlirDenseElementsAttrFloatSplatGet(MlirType shapedType, float element)
MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size, double const *values)
bool mlirAttributeIsAAffineMap(MlirAttribute attr)
Checks whether the given attribute is an affine map attribute.
MlirAttribute mlirDenseElementsAttrFloatGet(MlirType shapedType, intptr_t numElements, const float *elements)
MlirAttribute mlirSparseElementsAttrGetValues(MlirAttribute attr)
Returns the dense elements attribute containing the non-null elements in the given sparse elements at...
int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element stored in the given array attribute.
MlirStringRef mlirDenseElementsAttrGetStringSplatValue(MlirAttribute attr)
bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos)
Returns the pos-th value (flat contiguous indexing) of a specific type contained by the given dense e...
int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos)
intptr_t mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr)
bool mlirAttributeIsADenseIntElements(MlirAttribute attr)
MlirTypeID mlirUnitAttrGetTypeID(void)
Returns the typeID of a Unit attribute.
bool mlirAttributeIsADenseF64Array(MlirAttribute attr)
MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size, int const *values)
Create a dense array attribute with the given elements.
MlirAttribute mlirDenseElementsAttrUInt32Get(MlirType shapedType, intptr_t numElements, const uint32_t *elements)
bool mlirAttributeIsABool(MlirAttribute attr)
Checks whether the given attribute is a bool attribute.
bool mlirAttributeIsADenseF32Array(MlirAttribute attr)
MlirAttribute mlirUnitAttrGet(MlirContext ctx)
Creates a unit attribute in the given context.
MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size, int16_t const *values)
int32_t mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr)
int64_t mlirElementsAttrGetNumElements(MlirAttribute attr)
Gets the total number of elements in the given elements attribute.
MlirTypeID mlirStridedLayoutAttrGetTypeID(void)
Returns the typeID of a StridedLayout attribute.
double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos)
bool mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank, uint64_t *idxs)
Checks whether the given rank-dimensional index is valid in the given elements attribute.
MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType, size_t rawBufferSize, const void *rawBuffer)
Creates a dense elements attribute with the given Shaped type and elements populated from a packed,...
bool mlirAttributeIsAFloat(MlirAttribute attr)
Checks whether the given attribute is a floating point attribute.
MlirAttribute mlirUnmanagedDenseInt32ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const int32_t *elements)
MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type, double value)
Creates a floating point attribute in the given context with the given double value and double-precis...
MlirAttribute mlirUnmanagedDenseInt8ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const int8_t *elements)
intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr)
Returns the number of elements stored in the given array attribute.
MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size, int64_t const *values)
int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsAStridedLayout(MlirAttribute attr)
bool mlirAttributeIsAIntegerSet(MlirAttribute attr)
Checks whether the given attribute is an integer set attribute.
int8_t mlirDenseInt8ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr)
Returns the single replicated value (splat) of a specific type contained by the given dense elements ...
MlirTypeID mlirStringAttrGetTypeID(void)
Returns the typeID of a String attribute.
static MlirAttribute getDenseResource(MlirType shapedType, MlirStringRef name, intptr_t numElements, const T *elements)
MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType, intptr_t numElements, const uint8_t *elements)
static MlirAttribute getDenseAttribute(MlirType shapedType, intptr_t numElements, const T *elements)
Creates a dense attribute with elements of the type deduced by templates.
MlirAttribute mlirUnmanagedDenseInt64ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const int64_t *elements)
bool mlirDenseElementsAttrIsSplat(MlirAttribute attr)
Checks whether the given dense elements attribute contains a single replicated value (splat).
MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, intptr_t rank, uint64_t *idxs)
Returns the element at the given rank-dimensional index.
MlirTypeID mlirSparseElementsAttrGetTypeID(void)
Returns the typeID of a SparseElements attribute.
MlirTypeID mlirIntegerAttrGetTypeID(void)
Returns the typeID of an Integer attribute.
MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name)
Returns the dictionary attribute element with the given name or NULL if the given name does not exist...
MlirAttribute mlirUnmanagedDenseUInt8ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const uint8_t *elements)
double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrInt8SplatGet(MlirType shapedType, int8_t element)
MlirAttribute mlirDenseElementsAttrInt32Get(MlirType shapedType, intptr_t numElements, const int32_t *elements)
MlirAttribute mlirDenseElementsAttrReshapeGet(MlirAttribute attr, MlirType shapedType)
Creates a dense elements attribute that has the same data as the given dense elements attribute and a...
MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element)
Creates a dense elements attribute with the given Shaped type containing a single replicated element ...
MlirStringRef mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr)
Returns the namespace of the dialect with which the given opaque attribute is associated.
MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace, intptr_t dataLength, const char *data, MlirType type)
Creates an opaque attribute in the given context associated with the dialect identified by its namesp...
int64_t mlirDenseI64ArrayGetElement(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type, double value)
Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a construction of a FloatAttr,...
int64_t mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr)
MlirAttribute mlirDenseElementsAttrInt8Get(MlirType shapedType, intptr_t numElements, const int8_t *elements)
MlirAttribute mlirDenseElementsAttrUInt64Get(MlirType shapedType, intptr_t numElements, const uint64_t *elements)
float mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr)
MlirAttribute mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType, uint32_t element)
MlirAttribute mlirUnmanagedDenseUInt64ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const uint64_t *elements)
bool mlirAttributeIsAUnit(MlirAttribute attr)
Checks whether the given attribute is a unit attribute.
MlirAttribute mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType, uint64_t element)
MlirTypeID mlirArrayAttrGetTypeID(void)
Returns the typeID of an Array attribute.
MlirAttribute mlirDenseElementsAttrBoolSplatGet(MlirType shapedType, bool element)
int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size, int8_t const *values)
MlirAttribute mlirDenseElementsAttrInt32SplatGet(MlirType shapedType, int32_t element)
MlirTypeID mlirSymbolRefAttrGetTypeID(void)
Returns the typeID of an SymbolRef attribute.
uint32_t mlirDenseUInt32ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsAInteger(MlirAttribute attr)
Checks whether the given attribute is an integer attribute.
MlirAttribute mlirDenseElementsAttrInt64Get(MlirType shapedType, intptr_t numElements, const int64_t *elements)
static T getDenseResourceVal(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsADenseResourceElements(MlirAttribute attr)
bool mlirAttributeIsASymbolRef(MlirAttribute attr)
Checks whether the given attribute is a symbol reference attribute.
MlirAttribute mlirUnmanagedDenseUInt32ResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, intptr_t numElements, const uint32_t *elements)
int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr)
MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr)
Returns the raw data as a string reference.
MlirTypeID mlirDictionaryAttrGetTypeID(void)
Returns the typeID of a Dictionary attribute.
MlirAttribute mlirTypeAttrGet(MlirType type)
Creates a type attribute wrapping the given type in the same context as the type.
int32_t mlirDenseInt32ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirAttributeGetNull()
Returns an empty attribute.
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition: Wrap.h:40
The following classes enable support for parsing and printing resources within MLIR assembly formats.
Definition: AsmState.h:88
llvm::unique_function< void(void *data, size_t size, size_t align)> DeleterFn
A deleter function that frees a blob given the data, allocation size, and allocation aligment.
Definition: AsmState.h:93
Attributes are known-constant values of operations.
Definition: Attributes.h:25
static BoolAttr get(MLIRContext *context, bool value)
static DenseElementsAttr getFromRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Construct a dense elements attribute from a raw buffer representing the data for this attribute.
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
static bool isValidRawBuffer(ShapedType type, ArrayRef< char > rawBuffer, bool &detectedSplat)
Returns true if the given buffer is a valid raw buffer for the given type.
static FlatSymbolRefAttr get(StringAttr value)
Construct a symbol reference for the given value name.
NamedAttribute represents a combination of a name and an Attribute value.
Definition: Attributes.h:198
StringAttr getName() const
Return the name of the attribute.
Definition: Attributes.cpp:49
Attribute getValue() const
Return the value of the attribute.
Definition: Attributes.h:212
static AsmResourceBlob allocateInferAlign(ArrayRef< T > data, AsmResourceBlob::DeleterFn deleter={}, bool dataIsMutable=false)
Definition: AsmState.h:227
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< T > content)
Builder from ArrayRef<T>.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
Operation::operand_range getIndices(Operation *op)
Get the indices that the given load/store operation is operating on.
Definition: Utils.cpp:18
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Named MLIR attribute.
Definition: IR.h:76
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73