MLIR  16.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/CAPI/AffineMap.h"
11 #include "mlir/CAPI/IR.h"
12 #include "mlir/CAPI/Support.h"
13 #include "mlir/IR/Attributes.h"
14 #include "mlir/IR/BuiltinTypes.h"
15 
16 using namespace mlir;
17 
18 MlirAttribute mlirAttributeGetNull() { return {nullptr}; }
19 
20 //===----------------------------------------------------------------------===//
21 // Affine map attribute.
22 //===----------------------------------------------------------------------===//
23 
24 bool mlirAttributeIsAAffineMap(MlirAttribute attr) {
25  return unwrap(attr).isa<AffineMapAttr>();
26 }
27 
28 MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map) {
29  return wrap(AffineMapAttr::get(unwrap(map)));
30 }
31 
32 MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr) {
33  return wrap(unwrap(attr).cast<AffineMapAttr>().getValue());
34 }
35 
36 //===----------------------------------------------------------------------===//
37 // Array attribute.
38 //===----------------------------------------------------------------------===//
39 
40 bool mlirAttributeIsAArray(MlirAttribute attr) {
41  return unwrap(attr).isa<ArrayAttr>();
42 }
43 
44 MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements,
45  MlirAttribute const *elements) {
47  return wrap(
48  ArrayAttr::get(unwrap(ctx), unwrapList(static_cast<size_t>(numElements),
49  elements, attrs)));
50 }
51 
52 intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr) {
53  return static_cast<intptr_t>(unwrap(attr).cast<ArrayAttr>().size());
54 }
55 
56 MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos) {
57  return wrap(unwrap(attr).cast<ArrayAttr>().getValue()[pos]);
58 }
59 
60 //===----------------------------------------------------------------------===//
61 // Dictionary attribute.
62 //===----------------------------------------------------------------------===//
63 
64 bool mlirAttributeIsADictionary(MlirAttribute attr) {
65  return unwrap(attr).isa<DictionaryAttr>();
66 }
67 
68 MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements,
69  MlirNamedAttribute const *elements) {
71  attributes.reserve(numElements);
72  for (intptr_t i = 0; i < numElements; ++i)
73  attributes.emplace_back(unwrap(elements[i].name),
74  unwrap(elements[i].attribute));
75  return wrap(DictionaryAttr::get(unwrap(ctx), attributes));
76 }
77 
78 intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr) {
79  return static_cast<intptr_t>(unwrap(attr).cast<DictionaryAttr>().size());
80 }
81 
83  intptr_t pos) {
84  NamedAttribute attribute =
85  unwrap(attr).cast<DictionaryAttr>().getValue()[pos];
86  return {wrap(attribute.getName()), wrap(attribute.getValue())};
87 }
88 
89 MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr,
90  MlirStringRef name) {
91  return wrap(unwrap(attr).cast<DictionaryAttr>().get(unwrap(name)));
92 }
93 
94 //===----------------------------------------------------------------------===//
95 // Floating point attribute.
96 //===----------------------------------------------------------------------===//
97 
98 bool mlirAttributeIsAFloat(MlirAttribute attr) {
99  return unwrap(attr).isa<FloatAttr>();
100 }
101 
102 MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type,
103  double value) {
104  return wrap(FloatAttr::get(unwrap(type), value));
105 }
106 
107 MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type,
108  double value) {
109  return wrap(FloatAttr::getChecked(unwrap(loc), unwrap(type), value));
110 }
111 
112 double mlirFloatAttrGetValueDouble(MlirAttribute attr) {
113  return unwrap(attr).cast<FloatAttr>().getValueAsDouble();
114 }
115 
116 //===----------------------------------------------------------------------===//
117 // Integer attribute.
118 //===----------------------------------------------------------------------===//
119 
120 bool mlirAttributeIsAInteger(MlirAttribute attr) {
121  return unwrap(attr).isa<IntegerAttr>();
122 }
123 
124 MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value) {
125  return wrap(IntegerAttr::get(unwrap(type), value));
126 }
127 
128 int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr) {
129  return unwrap(attr).cast<IntegerAttr>().getInt();
130 }
131 
132 int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr) {
133  return unwrap(attr).cast<IntegerAttr>().getSInt();
134 }
135 
136 uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr) {
137  return unwrap(attr).cast<IntegerAttr>().getUInt();
138 }
139 
140 //===----------------------------------------------------------------------===//
141 // Bool attribute.
142 //===----------------------------------------------------------------------===//
143 
144 bool mlirAttributeIsABool(MlirAttribute attr) {
145  return unwrap(attr).isa<BoolAttr>();
146 }
147 
148 MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value) {
149  return wrap(BoolAttr::get(unwrap(ctx), value));
150 }
151 
152 bool mlirBoolAttrGetValue(MlirAttribute attr) {
153  return unwrap(attr).cast<BoolAttr>().getValue();
154 }
155 
156 //===----------------------------------------------------------------------===//
157 // Integer set attribute.
158 //===----------------------------------------------------------------------===//
159 
160 bool mlirAttributeIsAIntegerSet(MlirAttribute attr) {
161  return unwrap(attr).isa<IntegerSetAttr>();
162 }
163 
164 //===----------------------------------------------------------------------===//
165 // Opaque attribute.
166 //===----------------------------------------------------------------------===//
167 
168 bool mlirAttributeIsAOpaque(MlirAttribute attr) {
169  return unwrap(attr).isa<OpaqueAttr>();
170 }
171 
172 MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
173  intptr_t dataLength, const char *data,
174  MlirType type) {
175  return wrap(
176  OpaqueAttr::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)),
177  StringRef(data, dataLength), unwrap(type)));
178 }
179 
181  return wrap(unwrap(attr).cast<OpaqueAttr>().getDialectNamespace().strref());
182 }
183 
185  return wrap(unwrap(attr).cast<OpaqueAttr>().getAttrData());
186 }
187 
188 //===----------------------------------------------------------------------===//
189 // String attribute.
190 //===----------------------------------------------------------------------===//
191 
192 bool mlirAttributeIsAString(MlirAttribute attr) {
193  return unwrap(attr).isa<StringAttr>();
194 }
195 
196 MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str) {
197  return wrap((Attribute)StringAttr::get(unwrap(ctx), unwrap(str)));
198 }
199 
200 MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str) {
201  return wrap((Attribute)StringAttr::get(unwrap(str), unwrap(type)));
202 }
203 
205  return wrap(unwrap(attr).cast<StringAttr>().getValue());
206 }
207 
208 //===----------------------------------------------------------------------===//
209 // SymbolRef attribute.
210 //===----------------------------------------------------------------------===//
211 
212 bool mlirAttributeIsASymbolRef(MlirAttribute attr) {
213  return unwrap(attr).isa<SymbolRefAttr>();
214 }
215 
216 MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
217  intptr_t numReferences,
218  MlirAttribute const *references) {
220  refs.reserve(numReferences);
221  for (intptr_t i = 0; i < numReferences; ++i)
222  refs.push_back(unwrap(references[i]).cast<FlatSymbolRefAttr>());
223  auto symbolAttr = StringAttr::get(unwrap(ctx), unwrap(symbol));
224  return wrap(SymbolRefAttr::get(symbolAttr, refs));
225 }
226 
228  return wrap(unwrap(attr).cast<SymbolRefAttr>().getRootReference().getValue());
229 }
230 
232  return wrap(unwrap(attr).cast<SymbolRefAttr>().getLeafReference().getValue());
233 }
234 
235 intptr_t mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr) {
236  return static_cast<intptr_t>(
237  unwrap(attr).cast<SymbolRefAttr>().getNestedReferences().size());
238 }
239 
240 MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr,
241  intptr_t pos) {
242  return wrap(unwrap(attr).cast<SymbolRefAttr>().getNestedReferences()[pos]);
243 }
244 
245 //===----------------------------------------------------------------------===//
246 // Flat SymbolRef attribute.
247 //===----------------------------------------------------------------------===//
248 
249 bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr) {
250  return unwrap(attr).isa<FlatSymbolRefAttr>();
251 }
252 
253 MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol) {
254  return wrap(FlatSymbolRefAttr::get(unwrap(ctx), unwrap(symbol)));
255 }
256 
258  return wrap(unwrap(attr).cast<FlatSymbolRefAttr>().getValue());
259 }
260 
261 //===----------------------------------------------------------------------===//
262 // Type attribute.
263 //===----------------------------------------------------------------------===//
264 
265 bool mlirAttributeIsAType(MlirAttribute attr) {
266  return unwrap(attr).isa<TypeAttr>();
267 }
268 
269 MlirAttribute mlirTypeAttrGet(MlirType type) {
270  return wrap(TypeAttr::get(unwrap(type)));
271 }
272 
273 MlirType mlirTypeAttrGetValue(MlirAttribute attr) {
274  return wrap(unwrap(attr).cast<TypeAttr>().getValue());
275 }
276 
277 //===----------------------------------------------------------------------===//
278 // Unit attribute.
279 //===----------------------------------------------------------------------===//
280 
281 bool mlirAttributeIsAUnit(MlirAttribute attr) {
282  return unwrap(attr).isa<UnitAttr>();
283 }
284 
285 MlirAttribute mlirUnitAttrGet(MlirContext ctx) {
286  return wrap(UnitAttr::get(unwrap(ctx)));
287 }
288 
289 //===----------------------------------------------------------------------===//
290 // Elements attributes.
291 //===----------------------------------------------------------------------===//
292 
293 bool mlirAttributeIsAElements(MlirAttribute attr) {
294  return unwrap(attr).isa<ElementsAttr>();
295 }
296 
297 MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, intptr_t rank,
298  uint64_t *idxs) {
299  return wrap(unwrap(attr)
300  .cast<ElementsAttr>()
301  .getValues<Attribute>()[llvm::makeArrayRef(idxs, rank)]);
302 }
303 
304 bool mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank,
305  uint64_t *idxs) {
306  return unwrap(attr).cast<ElementsAttr>().isValidIndex(
307  llvm::makeArrayRef(idxs, rank));
308 }
309 
310 int64_t mlirElementsAttrGetNumElements(MlirAttribute attr) {
311  return unwrap(attr).cast<ElementsAttr>().getNumElements();
312 }
313 
314 //===----------------------------------------------------------------------===//
315 // Dense array attribute.
316 //===----------------------------------------------------------------------===//
317 
318 //===----------------------------------------------------------------------===//
319 // IsA support.
320 
321 bool mlirAttributeIsADenseBoolArray(MlirAttribute attr) {
322  return unwrap(attr).isa<DenseBoolArrayAttr>();
323 }
324 bool mlirAttributeIsADenseI8Array(MlirAttribute attr) {
325  return unwrap(attr).isa<DenseI8ArrayAttr>();
326 }
327 bool mlirAttributeIsADenseI16Array(MlirAttribute attr) {
328  return unwrap(attr).isa<DenseI16ArrayAttr>();
329 }
330 bool mlirAttributeIsADenseI32Array(MlirAttribute attr) {
331  return unwrap(attr).isa<DenseI32ArrayAttr>();
332 }
333 bool mlirAttributeIsADenseI64Array(MlirAttribute attr) {
334  return unwrap(attr).isa<DenseI64ArrayAttr>();
335 }
336 bool mlirAttributeIsADenseF32Array(MlirAttribute attr) {
337  return unwrap(attr).isa<DenseF32ArrayAttr>();
338 }
339 bool mlirAttributeIsADenseF64Array(MlirAttribute attr) {
340  return unwrap(attr).isa<DenseF64ArrayAttr>();
341 }
342 
343 //===----------------------------------------------------------------------===//
344 // Constructors.
345 
346 MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size,
347  int const *values) {
348  SmallVector<bool, 4> elements(values, values + size);
349  return wrap(DenseBoolArrayAttr::get(unwrap(ctx), elements));
350 }
351 MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size,
352  int8_t const *values) {
353  return wrap(
354  DenseI8ArrayAttr::get(unwrap(ctx), ArrayRef<int8_t>(values, size)));
355 }
356 MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size,
357  int16_t const *values) {
358  return wrap(
359  DenseI16ArrayAttr::get(unwrap(ctx), ArrayRef<int16_t>(values, size)));
360 }
361 MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size,
362  int32_t const *values) {
363  return wrap(
364  DenseI32ArrayAttr::get(unwrap(ctx), ArrayRef<int32_t>(values, size)));
365 }
366 MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size,
367  int64_t const *values) {
368  return wrap(
369  DenseI64ArrayAttr::get(unwrap(ctx), ArrayRef<int64_t>(values, size)));
370 }
371 MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size,
372  float const *values) {
373  return wrap(
374  DenseF32ArrayAttr::get(unwrap(ctx), ArrayRef<float>(values, size)));
375 }
376 MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size,
377  double const *values) {
378  return wrap(
379  DenseF64ArrayAttr::get(unwrap(ctx), ArrayRef<double>(values, size)));
380 }
381 
382 //===----------------------------------------------------------------------===//
383 // Accessors.
384 
385 intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr) {
386  return unwrap(attr).cast<DenseArrayAttr>().size();
387 }
388 
389 //===----------------------------------------------------------------------===//
390 // Indexed accessors.
391 
392 bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos) {
393  return unwrap(attr).cast<DenseBoolArrayAttr>()[pos];
394 }
395 int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos) {
396  return unwrap(attr).cast<DenseI8ArrayAttr>()[pos];
397 }
398 int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos) {
399  return unwrap(attr).cast<DenseI16ArrayAttr>()[pos];
400 }
401 int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
402  return unwrap(attr).cast<DenseI32ArrayAttr>()[pos];
403 }
404 int64_t mlirDenseI64ArrayGetElement(MlirAttribute attr, intptr_t pos) {
405  return unwrap(attr).cast<DenseI64ArrayAttr>()[pos];
406 }
407 float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
408  return unwrap(attr).cast<DenseF32ArrayAttr>()[pos];
409 }
410 double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos) {
411  return unwrap(attr).cast<DenseF64ArrayAttr>()[pos];
412 }
413 
414 //===----------------------------------------------------------------------===//
415 // Dense elements attribute.
416 //===----------------------------------------------------------------------===//
417 
418 //===----------------------------------------------------------------------===//
419 // IsA support.
420 
421 bool mlirAttributeIsADenseElements(MlirAttribute attr) {
422  return unwrap(attr).isa<DenseElementsAttr>();
423 }
424 bool mlirAttributeIsADenseIntElements(MlirAttribute attr) {
425  return unwrap(attr).isa<DenseIntElementsAttr>();
426 }
427 bool mlirAttributeIsADenseFPElements(MlirAttribute attr) {
428  return unwrap(attr).isa<DenseFPElementsAttr>();
429 }
430 
431 //===----------------------------------------------------------------------===//
432 // Constructors.
433 
434 MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType,
435  intptr_t numElements,
436  MlirAttribute const *elements) {
437  SmallVector<Attribute, 8> attributes;
438  return wrap(
439  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(),
440  unwrapList(numElements, elements, attributes)));
441 }
442 
443 MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType,
444  size_t rawBufferSize,
445  const void *rawBuffer) {
446  auto shapedTypeCpp = unwrap(shapedType).cast<ShapedType>();
447  ArrayRef<char> rawBufferCpp(static_cast<const char *>(rawBuffer),
448  rawBufferSize);
449  bool isSplat = false;
450  if (!DenseElementsAttr::isValidRawBuffer(shapedTypeCpp, rawBufferCpp,
451  isSplat))
452  return mlirAttributeGetNull();
453  return wrap(DenseElementsAttr::getFromRawBuffer(shapedTypeCpp, rawBufferCpp));
454 }
455 
456 MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType,
457  MlirAttribute element) {
458  return wrap(DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(),
459  unwrap(element)));
460 }
461 MlirAttribute mlirDenseElementsAttrBoolSplatGet(MlirType shapedType,
462  bool element) {
463  return wrap(
464  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
465 }
466 MlirAttribute mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType,
467  uint8_t element) {
468  return wrap(
469  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
470 }
471 MlirAttribute mlirDenseElementsAttrInt8SplatGet(MlirType shapedType,
472  int8_t element) {
473  return wrap(
474  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
475 }
476 MlirAttribute mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType,
477  uint32_t element) {
478  return wrap(
479  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
480 }
481 MlirAttribute mlirDenseElementsAttrInt32SplatGet(MlirType shapedType,
482  int32_t element) {
483  return wrap(
484  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
485 }
486 MlirAttribute mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType,
487  uint64_t element) {
488  return wrap(
489  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
490 }
491 MlirAttribute mlirDenseElementsAttrInt64SplatGet(MlirType shapedType,
492  int64_t element) {
493  return wrap(
494  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
495 }
496 MlirAttribute mlirDenseElementsAttrFloatSplatGet(MlirType shapedType,
497  float element) {
498  return wrap(
499  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
500 }
501 MlirAttribute mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType,
502  double element) {
503  return wrap(
504  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), element));
505 }
506 
507 MlirAttribute mlirDenseElementsAttrBoolGet(MlirType shapedType,
508  intptr_t numElements,
509  const int *elements) {
510  SmallVector<bool, 8> values(elements, elements + numElements);
511  return wrap(
512  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), values));
513 }
514 
515 /// Creates a dense attribute with elements of the type deduced by templates.
516 template <typename T>
517 static MlirAttribute getDenseAttribute(MlirType shapedType,
518  intptr_t numElements,
519  const T *elements) {
520  return wrap(
521  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(),
522  llvm::makeArrayRef(elements, numElements)));
523 }
524 
525 MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType,
526  intptr_t numElements,
527  const uint8_t *elements) {
528  return getDenseAttribute(shapedType, numElements, elements);
529 }
530 MlirAttribute mlirDenseElementsAttrInt8Get(MlirType shapedType,
531  intptr_t numElements,
532  const int8_t *elements) {
533  return getDenseAttribute(shapedType, numElements, elements);
534 }
535 MlirAttribute mlirDenseElementsAttrUInt16Get(MlirType shapedType,
536  intptr_t numElements,
537  const uint16_t *elements) {
538  return getDenseAttribute(shapedType, numElements, elements);
539 }
540 MlirAttribute mlirDenseElementsAttrInt16Get(MlirType shapedType,
541  intptr_t numElements,
542  const int16_t *elements) {
543  return getDenseAttribute(shapedType, numElements, elements);
544 }
545 MlirAttribute mlirDenseElementsAttrUInt32Get(MlirType shapedType,
546  intptr_t numElements,
547  const uint32_t *elements) {
548  return getDenseAttribute(shapedType, numElements, elements);
549 }
550 MlirAttribute mlirDenseElementsAttrInt32Get(MlirType shapedType,
551  intptr_t numElements,
552  const int32_t *elements) {
553  return getDenseAttribute(shapedType, numElements, elements);
554 }
555 MlirAttribute mlirDenseElementsAttrUInt64Get(MlirType shapedType,
556  intptr_t numElements,
557  const uint64_t *elements) {
558  return getDenseAttribute(shapedType, numElements, elements);
559 }
560 MlirAttribute mlirDenseElementsAttrInt64Get(MlirType shapedType,
561  intptr_t numElements,
562  const int64_t *elements) {
563  return getDenseAttribute(shapedType, numElements, elements);
564 }
565 MlirAttribute mlirDenseElementsAttrFloatGet(MlirType shapedType,
566  intptr_t numElements,
567  const float *elements) {
568  return getDenseAttribute(shapedType, numElements, elements);
569 }
570 MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType,
571  intptr_t numElements,
572  const double *elements) {
573  return getDenseAttribute(shapedType, numElements, elements);
574 }
575 MlirAttribute mlirDenseElementsAttrBFloat16Get(MlirType shapedType,
576  intptr_t numElements,
577  const uint16_t *elements) {
578  size_t bufferSize = numElements * 2;
579  const void *buffer = static_cast<const void *>(elements);
580  return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
581 }
582 MlirAttribute mlirDenseElementsAttrFloat16Get(MlirType shapedType,
583  intptr_t numElements,
584  const uint16_t *elements) {
585  size_t bufferSize = numElements * 2;
586  const void *buffer = static_cast<const void *>(elements);
587  return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
588 }
589 
590 MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType,
591  intptr_t numElements,
592  MlirStringRef *strs) {
594  values.reserve(numElements);
595  for (intptr_t i = 0; i < numElements; ++i)
596  values.push_back(unwrap(strs[i]));
597 
598  return wrap(
599  DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(), values));
600 }
601 
602 MlirAttribute mlirDenseElementsAttrReshapeGet(MlirAttribute attr,
603  MlirType shapedType) {
604  return wrap(unwrap(attr).cast<DenseElementsAttr>().reshape(
605  unwrap(shapedType).cast<ShapedType>()));
606 }
607 
608 //===----------------------------------------------------------------------===//
609 // Splat accessors.
610 
611 bool mlirDenseElementsAttrIsSplat(MlirAttribute attr) {
612  return unwrap(attr).cast<DenseElementsAttr>().isSplat();
613 }
614 
615 MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr) {
616  return wrap(
617  unwrap(attr).cast<DenseElementsAttr>().getSplatValue<Attribute>());
618 }
619 int mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr) {
620  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<bool>();
621 }
622 int8_t mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr) {
623  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<int8_t>();
624 }
625 uint8_t mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr) {
626  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<uint8_t>();
627 }
628 int32_t mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr) {
629  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<int32_t>();
630 }
631 uint32_t mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr) {
632  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<uint32_t>();
633 }
634 int64_t mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr) {
635  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<int64_t>();
636 }
637 uint64_t mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr) {
638  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<uint64_t>();
639 }
640 float mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr) {
641  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<float>();
642 }
643 double mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr) {
644  return unwrap(attr).cast<DenseElementsAttr>().getSplatValue<double>();
645 }
647  return wrap(
648  unwrap(attr).cast<DenseElementsAttr>().getSplatValue<StringRef>());
649 }
650 
651 //===----------------------------------------------------------------------===//
652 // Indexed accessors.
653 
654 bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos) {
655  return unwrap(attr).cast<DenseElementsAttr>().getValues<bool>()[pos];
656 }
657 int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos) {
658  return unwrap(attr).cast<DenseElementsAttr>().getValues<int8_t>()[pos];
659 }
660 uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos) {
661  return unwrap(attr).cast<DenseElementsAttr>().getValues<uint8_t>()[pos];
662 }
663 int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos) {
664  return unwrap(attr).cast<DenseElementsAttr>().getValues<int16_t>()[pos];
665 }
666 uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos) {
667  return unwrap(attr).cast<DenseElementsAttr>().getValues<uint16_t>()[pos];
668 }
669 int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos) {
670  return unwrap(attr).cast<DenseElementsAttr>().getValues<int32_t>()[pos];
671 }
672 uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos) {
673  return unwrap(attr).cast<DenseElementsAttr>().getValues<uint32_t>()[pos];
674 }
675 int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos) {
676  return unwrap(attr).cast<DenseElementsAttr>().getValues<int64_t>()[pos];
677 }
678 uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos) {
679  return unwrap(attr).cast<DenseElementsAttr>().getValues<uint64_t>()[pos];
680 }
681 float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos) {
682  return unwrap(attr).cast<DenseElementsAttr>().getValues<float>()[pos];
683 }
684 double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos) {
685  return unwrap(attr).cast<DenseElementsAttr>().getValues<double>()[pos];
686 }
688  intptr_t pos) {
689  return wrap(
690  unwrap(attr).cast<DenseElementsAttr>().getValues<StringRef>()[pos]);
691 }
692 
693 //===----------------------------------------------------------------------===//
694 // Raw data accessors.
695 
696 const void *mlirDenseElementsAttrGetRawData(MlirAttribute attr) {
697  return static_cast<const void *>(
698  unwrap(attr).cast<DenseElementsAttr>().getRawData().data());
699 }
700 
701 //===----------------------------------------------------------------------===//
702 // Sparse elements attribute.
703 //===----------------------------------------------------------------------===//
704 
705 bool mlirAttributeIsASparseElements(MlirAttribute attr) {
706  return unwrap(attr).isa<SparseElementsAttr>();
707 }
708 
709 MlirAttribute mlirSparseElementsAttribute(MlirType shapedType,
710  MlirAttribute denseIndices,
711  MlirAttribute denseValues) {
712  return wrap(
713  SparseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(),
714  unwrap(denseIndices).cast<DenseElementsAttr>(),
715  unwrap(denseValues).cast<DenseElementsAttr>()));
716 }
717 
718 MlirAttribute mlirSparseElementsAttrGetIndices(MlirAttribute attr) {
719  return wrap(unwrap(attr).cast<SparseElementsAttr>().getIndices());
720 }
721 
722 MlirAttribute mlirSparseElementsAttrGetValues(MlirAttribute attr) {
723  return wrap(unwrap(attr).cast<SparseElementsAttr>().getValues());
724 }
725 
726 //===----------------------------------------------------------------------===//
727 // Strided layout attribute.
728 //===----------------------------------------------------------------------===//
729 
730 bool mlirAttributeIsAStridedLayout(MlirAttribute attr) {
731  return unwrap(attr).isa<StridedLayoutAttr>();
732 }
733 
734 MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset,
735  intptr_t numStrides,
736  const int64_t *strides) {
737  return wrap(StridedLayoutAttr::get(unwrap(ctx), offset,
738  ArrayRef<int64_t>(strides, numStrides)));
739 }
740 
741 int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr) {
742  return unwrap(attr).cast<StridedLayoutAttr>().getOffset();
743 }
744 
745 intptr_t mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr) {
746  return static_cast<intptr_t>(
747  unwrap(attr).cast<StridedLayoutAttr>().getStrides().size());
748 }
749 
750 int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr, intptr_t pos) {
751  return unwrap(attr).cast<StridedLayoutAttr>().getStrides()[pos];
752 }
Include the generated interface declarations.
int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirSparseElementsAttrGetValues(MlirAttribute attr)
Returns the dense elements attribute containing the non-null elements in the given sparse elements at...
bool mlirAttributeIsADenseF64Array(MlirAttribute attr)
An attribute that represents a reference to a dense float vector or tensor object.
MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type, double value)
Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a construction of a FloatAttr...
static MlirAttribute getDenseAttribute(MlirType shapedType, intptr_t numElements, const T *elements)
Creates a dense attribute with elements of the type deduced by templates.
bool mlirAttributeIsAStridedLayout(MlirAttribute attr)
MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value)
Creates an integer attribute of the given type with the given integer value.
MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size, int16_t const *values)
MlirAttribute mlirSparseElementsAttrGetIndices(MlirAttribute attr)
Returns the dense elements attribute containing 64-bit integer indices of non-null elements in the gi...
MlirAttribute mlirDenseElementsAttrFloatGet(MlirType shapedType, intptr_t numElements, const float *elements)
Attribute getValue() const
Return the value of the attribute.
Definition: Attributes.h:164
int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signed type and fit...
MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, intptr_t rank, uint64_t *idxs)
Returns the element at the given rank-dimensional index.
A symbol reference with a reference path containing a single element.
MlirAttribute mlirDenseElementsAttrInt16Get(MlirType shapedType, intptr_t numElements, const int16_t *elements)
int32_t mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr)
int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsADenseIntElements(MlirAttribute attr)
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...
uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrFloat16Get(MlirType shapedType, intptr_t numElements, const uint16_t *elements)
MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr)
Returns the single replicated value (splat) of a specific type contained by the given dense elements ...
MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType, intptr_t numElements, MlirStringRef *strs)
Creates a dense elements attribute with the given shaped type from string elements.
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...
bool mlirAttributeIsAAffineMap(MlirAttribute attr)
Checks whether the given attribute is an affine map attribute.
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
bool mlirAttributeIsAString(MlirAttribute attr)
Checks whether the given attribute is a string attribute.
MlirAttribute mlirDenseElementsAttrUInt32Get(MlirType shapedType, intptr_t numElements, const uint32_t *elements)
float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrInt8SplatGet(MlirType shapedType, int8_t element)
MlirAttribute mlirTypeAttrGet(MlirType type)
Creates a type attribute wrapping the given type in the same context as the type. ...
bool mlirAttributeIsADenseFPElements(MlirAttribute attr)
MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size, int const *values)
Create a dense array attribute with the given elements.
MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides, const int64_t *strides)
Named MLIR attribute.
Definition: IR.h:74
MlirStringRef mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value)
Creates a bool attribute in the given context with the given value.
intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr)
Returns the number of attributes contained in a dictionary attribute.
static constexpr const bool value
int64_t mlirElementsAttrGetNumElements(MlirAttribute attr)
Gets the total number of elements in the given elements attribute.
float mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr)
int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos)
intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr)
Returns the number of elements stored in the given array attribute.
NamedAttribute represents a combination of a name and an Attribute value.
Definition: Attributes.h:150
MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements)
Creates a dictionary attribute containing the given list of elements in the provided context...
MlirStringRef mlirSymbolRefAttrGetRootReference(MlirAttribute attr)
Returns the string reference to the root referenced symbol.
MlirAttribute mlirDenseElementsAttrInt64SplatGet(MlirType shapedType, int64_t element)
MlirAttribute mlirDenseElementsAttrInt8Get(MlirType shapedType, intptr_t numElements, const int8_t *elements)
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.
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 mlirDenseElementsAttrReshapeGet(MlirAttribute attr, MlirType shapedType)
Creates a dense elements attribute that has the same data as the given dense elements attribute and a...
int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr)
int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsADenseElements(MlirAttribute attr)
Checks whether the given attribute is a dense elements attribute.
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.
uint64_t mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr)
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...
An attribute that represents a reference to a dense vector or tensor object.
MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size, int32_t const *values)
MlirAttribute mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType, double element)
MlirAttribute mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType, uint32_t element)
MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map)
Creates an affine map attribute wrapping the given map.
MlirAttribute mlirUnitAttrGet(MlirContext ctx)
Creates a unit attribute in the given context.
bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos)
Get an element of a dense array.
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition: Wrap.h:40
Attributes are known-constant values of operations.
Definition: Attributes.h:25
MlirAttribute mlirDenseElementsAttrInt32SplatGet(MlirType shapedType, int32_t element)
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
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...
MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size, float const *values)
MlirAttribute mlirDenseElementsAttrBoolSplatGet(MlirType shapedType, bool element)
StringAttr getName() const
Return the name of the attribute.
Definition: Attributes.cpp:32
Operation::operand_range getIndices(Operation *op)
intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr)
Get the size of a dense array.
int8_t mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr)
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...
int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType, intptr_t numElements, const uint8_t *elements)
MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos)
double mlirFloatAttrGetValueDouble(MlirAttribute attr)
Returns the value stored in the given floating point attribute, interpreting the value as double...
MlirAttribute mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType, uint8_t element)
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...
const void * mlirDenseElementsAttrGetRawData(MlirAttribute attr)
Returns the raw data of the given dense elements attribute.
MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr)
Returns the affine map wrapped in the given affine map attribute.
MlirType mlirTypeAttrGetValue(MlirAttribute attr)
Returns the type stored in the given type attribute.
double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsADenseI32Array(MlirAttribute attr)
MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr)
Returns the raw data as a string reference.
bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr)
Checks whether the given attribute is a flat symbol reference attribute.
bool mlirAttributeIsADenseF32Array(MlirAttribute attr)
int64_t mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr)
MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element stored in the given array attribute.
bool mlirAttributeIsADenseI8Array(MlirAttribute attr)
MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos)
Returns pos-th reference nested in the given symbol reference attribute.
MlirStringRef mlirDenseElementsAttrGetStringSplatValue(MlirAttribute attr)
intptr_t mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr)
Returns the number of references nested in the given symbol reference attribute.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:71
MlirAttribute mlirDenseElementsAttrBFloat16Get(MlirType shapedType, intptr_t numElements, const uint16_t *elements)
MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size, int8_t const *values)
bool mlirAttributeIsAElements(MlirAttribute attr)
Checks whether the given attribute is an elements attribute.
bool mlirAttributeIsADenseI64Array(MlirAttribute attr)
double mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr)
float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos)
uint32_t mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr)
bool mlirAttributeIsAFloat(MlirAttribute attr)
Checks whether the given attribute is a floating point attribute.
double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos)
MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr)
Returns the referenced symbol as a string reference.
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
bool mlirAttributeIsASymbolRef(MlirAttribute attr)
Checks whether the given attribute is a symbol reference attribute.
static int64_t getNumElements(ShapedType type)
Definition: TensorOps.cpp:854
static FlatSymbolRefAttr get(StringAttr value)
Construct a symbol reference for the given value name.
MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size, double const *values)
uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrFloatSplatGet(MlirType shapedType, float element)
int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
bool mlirDenseElementsAttrIsSplat(MlirAttribute attr)
Checks whether the given dense elements attribute contains a single replicated value (splat)...
bool mlirAttributeIsABool(MlirAttribute attr)
Checks whether the given attribute is a bool attribute.
bool mlirAttributeIsADenseBoolArray(MlirAttribute attr)
Checks whether the given attribute is a dense array attribute.
bool mlirAttributeIsAArray(MlirAttribute attr)
Checks whether the given attribute is an array attribute.
MlirNamedAttribute mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element of the given dictionary attribute.
MlirStringRef mlirStringAttrGetValue(MlirAttribute attr)
Returns the attribute values as a string reference.
MlirAttribute mlirAttributeGetNull()
Returns an empty attribute.
bool mlirAttributeIsAIntegerSet(MlirAttribute attr)
Checks whether the given attribute is an integer set 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.
bool mlirAttributeIsAUnit(MlirAttribute attr)
Checks whether the given attribute is a unit attribute.
int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr, intptr_t pos)
int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos)
bool mlirAttributeIsAInteger(MlirAttribute attr)
Checks whether the given attribute is an integer attribute.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
bool mlirAttributeIsAOpaque(MlirAttribute attr)
Checks whether the given attribute is an opaque attribute.
intptr_t mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr)
uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDenseElementsAttrUInt64Get(MlirType shapedType, intptr_t numElements, const uint64_t *elements)
bool mlirAttributeIsASparseElements(MlirAttribute attr)
Checks whether the given attribute is a sparse elements attribute.
MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType, intptr_t numElements, const double *elements)
MlirAttribute mlirDenseElementsAttrUInt16Get(MlirType shapedType, intptr_t numElements, const uint16_t *elements)
static BoolAttr get(MLIRContext *context, bool value)
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 mlirDenseElementsAttrInt64Get(MlirType shapedType, intptr_t numElements, const int64_t *elements)
MlirStringRef mlirSymbolRefAttrGetLeafReference(MlirAttribute attr)
Returns the string reference to the leaf referenced symbol.
bool mlirBoolAttrGetValue(MlirAttribute attr)
Returns the value stored in the given bool attribute.
static DenseElementsAttr getFromRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Construct a dense elements attribute from a raw buffer representing the data for this attribute...
bool mlirAttributeIsADenseI16Array(MlirAttribute attr)
MlirAttribute mlirDenseElementsAttrInt32Get(MlirType shapedType, intptr_t numElements, const int32_t *elements)
int mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr)
bool mlirAttributeIsAType(MlirAttribute attr)
Checks whether the given attribute is a type 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...
MlirAttribute mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType, uint64_t element)
int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signless type and f...
bool mlirAttributeIsADictionary(MlirAttribute attr)
Checks whether the given attribute is a dictionary 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...
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< T > content)
Builder from ArrayRef<T>.
MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size, int64_t const *values)
An attribute that represents a reference to a dense integer vector or tensor object.
MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol)
Creates a flat symbol reference attribute in the given context referencing a symbol identified by the...
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)