MLIR 22.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"
14#include "mlir/CAPI/Support.h"
15#include "mlir/IR/AsmState.h"
16#include "mlir/IR/Attributes.h"
19
20using namespace mlir;
21
22MlirAttribute mlirAttributeGetNull() { return {nullptr}; }
23
24//===----------------------------------------------------------------------===//
25// Location attribute.
26//===----------------------------------------------------------------------===//
27
28bool mlirAttributeIsALocation(MlirAttribute attr) {
29 return llvm::isa<LocationAttr>(unwrap(attr));
30}
31
32//===----------------------------------------------------------------------===//
33// Affine map attribute.
34//===----------------------------------------------------------------------===//
35
36bool mlirAttributeIsAAffineMap(MlirAttribute attr) {
37 return llvm::isa<AffineMapAttr>(unwrap(attr));
38}
39
40MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map) {
41 return wrap(AffineMapAttr::get(unwrap(map)));
42}
43
45 return wrap(AffineMapAttr::name);
46}
47
48MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr) {
49 return wrap(llvm::cast<AffineMapAttr>(unwrap(attr)).getValue());
50}
51
53 return wrap(AffineMapAttr::getTypeID());
54}
55
56//===----------------------------------------------------------------------===//
57// Array attribute.
58//===----------------------------------------------------------------------===//
59
60bool mlirAttributeIsAArray(MlirAttribute attr) {
61 return llvm::isa<ArrayAttr>(unwrap(attr));
62}
63
64MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements,
65 MlirAttribute const *elements) {
67 return wrap(
68 ArrayAttr::get(unwrap(ctx), unwrapList(static_cast<size_t>(numElements),
69 elements, attrs)));
70}
71
72MlirStringRef mlirArrayAttrGetName(void) { return wrap(ArrayAttr::name); }
73
75 return static_cast<intptr_t>(llvm::cast<ArrayAttr>(unwrap(attr)).size());
76}
77
78MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos) {
79 return wrap(llvm::cast<ArrayAttr>(unwrap(attr)).getValue()[pos]);
80}
81
82MlirTypeID mlirArrayAttrGetTypeID(void) { return wrap(ArrayAttr::getTypeID()); }
83
84//===----------------------------------------------------------------------===//
85// Dictionary attribute.
86//===----------------------------------------------------------------------===//
87
88bool mlirAttributeIsADictionary(MlirAttribute attr) {
89 return llvm::isa<DictionaryAttr>(unwrap(attr));
90}
91
92MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements,
93 MlirNamedAttribute const *elements) {
95 attributes.reserve(numElements);
96 for (intptr_t i = 0; i < numElements; ++i)
97 attributes.emplace_back(unwrap(elements[i].name),
98 unwrap(elements[i].attribute));
99 return wrap(DictionaryAttr::get(unwrap(ctx), attributes));
100}
101
103 return wrap(DictionaryAttr::name);
104}
105
107 return static_cast<intptr_t>(llvm::cast<DictionaryAttr>(unwrap(attr)).size());
108}
109
111 intptr_t pos) {
112 NamedAttribute attribute =
113 llvm::cast<DictionaryAttr>(unwrap(attr)).getValue()[pos];
114 return {wrap(attribute.getName()), wrap(attribute.getValue())};
115}
116
117MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr,
118 MlirStringRef name) {
119 return wrap(llvm::cast<DictionaryAttr>(unwrap(attr)).get(unwrap(name)));
120}
121
123 return wrap(DictionaryAttr::getTypeID());
124}
125
126//===----------------------------------------------------------------------===//
127// Floating point attribute.
128//===----------------------------------------------------------------------===//
129
130bool mlirAttributeIsAFloat(MlirAttribute attr) {
131 return llvm::isa<FloatAttr>(unwrap(attr));
132}
133
134MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type,
135 double value) {
136 return wrap(FloatAttr::get(unwrap(type), value));
137}
138
139MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type,
140 double value) {
141 return wrap(FloatAttr::getChecked(unwrap(loc), unwrap(type), value));
142}
143
144double mlirFloatAttrGetValueDouble(MlirAttribute attr) {
145 return llvm::cast<FloatAttr>(unwrap(attr)).getValueAsDouble();
146}
147
148MlirTypeID mlirFloatAttrGetTypeID(void) { return wrap(FloatAttr::getTypeID()); }
149
150//===----------------------------------------------------------------------===//
151// Integer attribute.
152//===----------------------------------------------------------------------===//
153
154bool mlirAttributeIsAInteger(MlirAttribute attr) {
155 return llvm::isa<IntegerAttr>(unwrap(attr));
156}
157
158MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value) {
159 return wrap(IntegerAttr::get(unwrap(type), value));
160}
161
162MlirStringRef mlirIntegerAttrGetName(void) { return wrap(IntegerAttr::name); }
163
165 return llvm::cast<IntegerAttr>(unwrap(attr)).getInt();
166}
167
169 return llvm::cast<IntegerAttr>(unwrap(attr)).getSInt();
170}
171
172uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr) {
173 return llvm::cast<IntegerAttr>(unwrap(attr)).getUInt();
174}
175
176MlirTypeID mlirIntegerAttrGetTypeID(void) {
177 return wrap(IntegerAttr::getTypeID());
178}
179
180//===----------------------------------------------------------------------===//
181// Bool attribute.
182//===----------------------------------------------------------------------===//
183
184bool mlirAttributeIsABool(MlirAttribute attr) {
185 return llvm::isa<BoolAttr>(unwrap(attr));
186}
187
188MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value) {
189 return wrap(BoolAttr::get(unwrap(ctx), value));
190}
191
192bool mlirBoolAttrGetValue(MlirAttribute attr) {
193 return llvm::cast<BoolAttr>(unwrap(attr)).getValue();
194}
195
196//===----------------------------------------------------------------------===//
197// Integer set attribute.
198//===----------------------------------------------------------------------===//
199
200bool mlirAttributeIsAIntegerSet(MlirAttribute attr) {
201 return llvm::isa<IntegerSetAttr>(unwrap(attr));
202}
203
205 return wrap(IntegerSetAttr::getTypeID());
206}
207
208MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set) {
209 return wrap(IntegerSetAttr::get(unwrap(set)));
210}
211
213 return wrap(IntegerSetAttr::name);
214}
215
216MlirIntegerSet mlirIntegerSetAttrGetValue(MlirAttribute attr) {
217 return wrap(llvm::cast<IntegerSetAttr>(unwrap(attr)).getValue());
218}
219
220//===----------------------------------------------------------------------===//
221// Opaque attribute.
222//===----------------------------------------------------------------------===//
223
224bool mlirAttributeIsAOpaque(MlirAttribute attr) {
225 return llvm::isa<OpaqueAttr>(unwrap(attr));
226}
227
228MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
229 intptr_t dataLength, const char *data,
230 MlirType type) {
231 return wrap(
232 OpaqueAttr::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)),
233 StringRef(data, dataLength), unwrap(type)));
234}
235
236MlirStringRef mlirOpaqueAttrGetName(void) { return wrap(OpaqueAttr::name); }
237
239 return wrap(
240 llvm::cast<OpaqueAttr>(unwrap(attr)).getDialectNamespace().strref());
241}
242
244 return wrap(llvm::cast<OpaqueAttr>(unwrap(attr)).getAttrData());
245}
246
247MlirTypeID mlirOpaqueAttrGetTypeID(void) {
248 return wrap(OpaqueAttr::getTypeID());
249}
250
251//===----------------------------------------------------------------------===//
252// String attribute.
253//===----------------------------------------------------------------------===//
254
255bool mlirAttributeIsAString(MlirAttribute attr) {
256 return llvm::isa<StringAttr>(unwrap(attr));
257}
258
259MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str) {
260 return wrap((Attribute)StringAttr::get(unwrap(ctx), unwrap(str)));
261}
262
263MlirStringRef mlirStringAttrGetName(void) { return wrap(StringAttr::name); }
264
265MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str) {
266 return wrap((Attribute)StringAttr::get(unwrap(str), unwrap(type)));
267}
268
270 return wrap(llvm::cast<StringAttr>(unwrap(attr)).getValue());
271}
272
273MlirTypeID mlirStringAttrGetTypeID(void) {
274 return wrap(StringAttr::getTypeID());
275}
276
277//===----------------------------------------------------------------------===//
278// SymbolRef attribute.
279//===----------------------------------------------------------------------===//
280
281bool mlirAttributeIsASymbolRef(MlirAttribute attr) {
282 return llvm::isa<SymbolRefAttr>(unwrap(attr));
283}
284
285MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
286 intptr_t numReferences,
287 MlirAttribute const *references) {
289 refs.reserve(numReferences);
290 for (intptr_t i = 0; i < numReferences; ++i)
291 refs.push_back(llvm::cast<FlatSymbolRefAttr>(unwrap(references[i])));
292 auto symbolAttr = StringAttr::get(unwrap(ctx), unwrap(symbol));
293 return wrap(SymbolRefAttr::get(symbolAttr, refs));
294}
295
297 return wrap(SymbolRefAttr::name);
298}
299
301 return wrap(
302 llvm::cast<SymbolRefAttr>(unwrap(attr)).getRootReference().getValue());
303}
304
306 return wrap(
307 llvm::cast<SymbolRefAttr>(unwrap(attr)).getLeafReference().getValue());
308}
309
311 return static_cast<intptr_t>(
312 llvm::cast<SymbolRefAttr>(unwrap(attr)).getNestedReferences().size());
313}
314
315MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr,
316 intptr_t pos) {
317 return wrap(
318 llvm::cast<SymbolRefAttr>(unwrap(attr)).getNestedReferences()[pos]);
319}
320
322 return wrap(SymbolRefAttr::getTypeID());
323}
324
325MlirAttribute mlirDisctinctAttrCreate(MlirAttribute referencedAttr) {
326 return wrap(mlir::DistinctAttr::create(unwrap(referencedAttr)));
327}
328
329//===----------------------------------------------------------------------===//
330// Flat SymbolRef attribute.
331//===----------------------------------------------------------------------===//
332
333bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr) {
334 return llvm::isa<FlatSymbolRefAttr>(unwrap(attr));
335}
336
337MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol) {
338 return wrap(FlatSymbolRefAttr::get(unwrap(ctx), unwrap(symbol)));
339}
340
342 return wrap(FlatSymbolRefAttr::name);
343}
344
346 return wrap(llvm::cast<FlatSymbolRefAttr>(unwrap(attr)).getValue());
347}
348
349//===----------------------------------------------------------------------===//
350// Type attribute.
351//===----------------------------------------------------------------------===//
352
353bool mlirAttributeIsAType(MlirAttribute attr) {
354 return llvm::isa<TypeAttr>(unwrap(attr));
355}
356
357MlirAttribute mlirTypeAttrGet(MlirType type) {
358 return wrap(TypeAttr::get(unwrap(type)));
359}
360
361MlirStringRef mlirTypeAttrGetName(void) { return wrap(TypeAttr::name); }
362
363MlirType mlirTypeAttrGetValue(MlirAttribute attr) {
364 return wrap(llvm::cast<TypeAttr>(unwrap(attr)).getValue());
365}
366
367MlirTypeID mlirTypeAttrGetTypeID(void) { return wrap(TypeAttr::getTypeID()); }
368
369//===----------------------------------------------------------------------===//
370// Unit attribute.
371//===----------------------------------------------------------------------===//
372
373bool mlirAttributeIsAUnit(MlirAttribute attr) {
374 return llvm::isa<UnitAttr>(unwrap(attr));
375}
376
377MlirAttribute mlirUnitAttrGet(MlirContext ctx) {
378 return wrap(UnitAttr::get(unwrap(ctx)));
379}
380
381MlirStringRef mlirUnitAttrGetName(void) { return wrap(UnitAttr::name); }
382
383MlirTypeID mlirUnitAttrGetTypeID(void) { return wrap(UnitAttr::getTypeID()); }
384
385//===----------------------------------------------------------------------===//
386// Elements attributes.
387//===----------------------------------------------------------------------===//
388
389bool mlirAttributeIsAElements(MlirAttribute attr) {
390 return llvm::isa<ElementsAttr>(unwrap(attr));
391}
392
393MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, intptr_t rank,
394 uint64_t *idxs) {
395 return wrap(llvm::cast<ElementsAttr>(unwrap(attr))
396 .getValues<Attribute>()[llvm::ArrayRef(idxs, rank)]);
397}
398
399bool mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank,
400 uint64_t *idxs) {
401 return llvm::cast<ElementsAttr>(unwrap(attr))
402 .isValidIndex(llvm::ArrayRef(idxs, rank));
403}
404
406 return llvm::cast<ElementsAttr>(unwrap(attr)).getNumElements();
407}
408
409//===----------------------------------------------------------------------===//
410// Dense array attribute.
411//===----------------------------------------------------------------------===//
412
414 return wrap(DenseArrayAttr::getTypeID());
415}
416
417//===----------------------------------------------------------------------===//
418// IsA support.
419//===----------------------------------------------------------------------===//
420
421bool mlirAttributeIsADenseBoolArray(MlirAttribute attr) {
422 return llvm::isa<DenseBoolArrayAttr>(unwrap(attr));
423}
424bool mlirAttributeIsADenseI8Array(MlirAttribute attr) {
425 return llvm::isa<DenseI8ArrayAttr>(unwrap(attr));
426}
427bool mlirAttributeIsADenseI16Array(MlirAttribute attr) {
428 return llvm::isa<DenseI16ArrayAttr>(unwrap(attr));
429}
430bool mlirAttributeIsADenseI32Array(MlirAttribute attr) {
431 return llvm::isa<DenseI32ArrayAttr>(unwrap(attr));
432}
433bool mlirAttributeIsADenseI64Array(MlirAttribute attr) {
434 return llvm::isa<DenseI64ArrayAttr>(unwrap(attr));
435}
436bool mlirAttributeIsADenseF32Array(MlirAttribute attr) {
437 return llvm::isa<DenseF32ArrayAttr>(unwrap(attr));
438}
439bool mlirAttributeIsADenseF64Array(MlirAttribute attr) {
440 return llvm::isa<DenseF64ArrayAttr>(unwrap(attr));
441}
442
443//===----------------------------------------------------------------------===//
444// Constructors.
445//===----------------------------------------------------------------------===//
446
447MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size,
448 int const *values) {
449 SmallVector<bool, 4> elements(values, values + size);
450 return wrap(DenseBoolArrayAttr::get(unwrap(ctx), elements));
451}
452MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size,
453 int8_t const *values) {
454 return wrap(
455 DenseI8ArrayAttr::get(unwrap(ctx), ArrayRef<int8_t>(values, size)));
456}
457MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size,
458 int16_t const *values) {
459 return wrap(
460 DenseI16ArrayAttr::get(unwrap(ctx), ArrayRef<int16_t>(values, size)));
461}
462MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size,
463 int32_t const *values) {
464 return wrap(
465 DenseI32ArrayAttr::get(unwrap(ctx), ArrayRef<int32_t>(values, size)));
466}
467MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size,
468 int64_t const *values) {
469 return wrap(
470 DenseI64ArrayAttr::get(unwrap(ctx), ArrayRef<int64_t>(values, size)));
471}
472MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size,
473 float const *values) {
474 return wrap(
475 DenseF32ArrayAttr::get(unwrap(ctx), ArrayRef<float>(values, size)));
476}
477MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size,
478 double const *values) {
479 return wrap(
480 DenseF64ArrayAttr::get(unwrap(ctx), ArrayRef<double>(values, size)));
481}
482
483//===----------------------------------------------------------------------===//
484// Accessors.
485//===----------------------------------------------------------------------===//
486
488 return llvm::cast<DenseArrayAttr>(unwrap(attr)).size();
489}
490
491//===----------------------------------------------------------------------===//
492// Indexed accessors.
493//===----------------------------------------------------------------------===//
494
495bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos) {
496 return llvm::cast<DenseBoolArrayAttr>(unwrap(attr))[pos];
497}
498int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos) {
499 return llvm::cast<DenseI8ArrayAttr>(unwrap(attr))[pos];
500}
501int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos) {
502 return llvm::cast<DenseI16ArrayAttr>(unwrap(attr))[pos];
503}
504int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
505 return llvm::cast<DenseI32ArrayAttr>(unwrap(attr))[pos];
506}
508 return llvm::cast<DenseI64ArrayAttr>(unwrap(attr))[pos];
509}
510float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
511 return llvm::cast<DenseF32ArrayAttr>(unwrap(attr))[pos];
512}
513double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos) {
514 return llvm::cast<DenseF64ArrayAttr>(unwrap(attr))[pos];
515}
516
517//===----------------------------------------------------------------------===//
518// Dense elements attribute.
519//===----------------------------------------------------------------------===//
520
521//===----------------------------------------------------------------------===//
522// IsA support.
523//===----------------------------------------------------------------------===//
524
525bool mlirAttributeIsADenseElements(MlirAttribute attr) {
526 return llvm::isa<DenseElementsAttr>(unwrap(attr));
527}
528
529bool mlirAttributeIsADenseIntElements(MlirAttribute attr) {
530 return llvm::isa<DenseIntElementsAttr>(unwrap(attr));
531}
532
533bool mlirAttributeIsADenseFPElements(MlirAttribute attr) {
534 return llvm::isa<DenseFPElementsAttr>(unwrap(attr));
535}
536
538 return wrap(DenseIntOrFPElementsAttr::getTypeID());
539}
540
541//===----------------------------------------------------------------------===//
542// Constructors.
543//===----------------------------------------------------------------------===//
544
545MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType,
546 intptr_t numElements,
547 MlirAttribute const *elements) {
548 SmallVector<Attribute, 8> attributes;
549 return wrap(
550 DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
551 unwrapList(numElements, elements, attributes)));
552}
553
554MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType,
555 size_t rawBufferSize,
556 const void *rawBuffer) {
557 auto shapedTypeCpp = llvm::cast<ShapedType>(unwrap(shapedType));
558 ArrayRef<char> rawBufferCpp(static_cast<const char *>(rawBuffer),
559 rawBufferSize);
560 bool isSplat = false;
561 if (!DenseElementsAttr::isValidRawBuffer(shapedTypeCpp, rawBufferCpp,
562 isSplat))
563 return mlirAttributeGetNull();
564 return wrap(DenseElementsAttr::getFromRawBuffer(shapedTypeCpp, rawBufferCpp));
565}
566
567MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType,
568 MlirAttribute element) {
569 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
570 unwrap(element)));
571}
572MlirAttribute mlirDenseElementsAttrBoolSplatGet(MlirType shapedType,
573 bool element) {
574 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
575 element));
576}
577MlirAttribute mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType,
578 uint8_t element) {
579 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
580 element));
581}
582MlirAttribute mlirDenseElementsAttrInt8SplatGet(MlirType shapedType,
583 int8_t element) {
584 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
585 element));
586}
587MlirAttribute mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType,
588 uint32_t element) {
589 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
590 element));
591}
592MlirAttribute mlirDenseElementsAttrInt32SplatGet(MlirType shapedType,
593 int32_t element) {
594 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
595 element));
596}
597MlirAttribute mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType,
598 uint64_t element) {
599 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
600 element));
601}
602MlirAttribute mlirDenseElementsAttrInt64SplatGet(MlirType shapedType,
603 int64_t element) {
604 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
605 element));
606}
607MlirAttribute mlirDenseElementsAttrFloatSplatGet(MlirType shapedType,
608 float element) {
609 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
610 element));
611}
612MlirAttribute mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType,
613 double element) {
614 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
615 element));
616}
617
618MlirAttribute mlirDenseElementsAttrBoolGet(MlirType shapedType,
619 intptr_t numElements,
620 const int *elements) {
621 SmallVector<bool, 8> values(elements, elements + numElements);
622 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
623 values));
624}
625
626/// Creates a dense attribute with elements of the type deduced by templates.
627template <typename T>
628static MlirAttribute getDenseAttribute(MlirType shapedType,
629 intptr_t numElements,
630 const T *elements) {
631 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
632 llvm::ArrayRef(elements, numElements)));
633}
634
635MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType,
636 intptr_t numElements,
637 const uint8_t *elements) {
638 return getDenseAttribute(shapedType, numElements, elements);
639}
640MlirAttribute mlirDenseElementsAttrInt8Get(MlirType shapedType,
641 intptr_t numElements,
642 const int8_t *elements) {
643 return getDenseAttribute(shapedType, numElements, elements);
644}
645MlirAttribute mlirDenseElementsAttrUInt16Get(MlirType shapedType,
646 intptr_t numElements,
647 const uint16_t *elements) {
648 return getDenseAttribute(shapedType, numElements, elements);
649}
650MlirAttribute mlirDenseElementsAttrInt16Get(MlirType shapedType,
651 intptr_t numElements,
652 const int16_t *elements) {
653 return getDenseAttribute(shapedType, numElements, elements);
654}
655MlirAttribute mlirDenseElementsAttrUInt32Get(MlirType shapedType,
656 intptr_t numElements,
657 const uint32_t *elements) {
658 return getDenseAttribute(shapedType, numElements, elements);
659}
660MlirAttribute mlirDenseElementsAttrInt32Get(MlirType shapedType,
661 intptr_t numElements,
662 const int32_t *elements) {
663 return getDenseAttribute(shapedType, numElements, elements);
664}
665MlirAttribute mlirDenseElementsAttrUInt64Get(MlirType shapedType,
666 intptr_t numElements,
667 const uint64_t *elements) {
668 return getDenseAttribute(shapedType, numElements, elements);
669}
670MlirAttribute mlirDenseElementsAttrInt64Get(MlirType shapedType,
671 intptr_t numElements,
672 const int64_t *elements) {
673 return getDenseAttribute(shapedType, numElements, elements);
674}
675MlirAttribute mlirDenseElementsAttrFloatGet(MlirType shapedType,
676 intptr_t numElements,
677 const float *elements) {
678 return getDenseAttribute(shapedType, numElements, elements);
679}
680MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType,
681 intptr_t numElements,
682 const double *elements) {
683 return getDenseAttribute(shapedType, numElements, elements);
684}
685MlirAttribute mlirDenseElementsAttrBFloat16Get(MlirType shapedType,
686 intptr_t numElements,
687 const uint16_t *elements) {
688 size_t bufferSize = numElements * 2;
689 const void *buffer = static_cast<const void *>(elements);
690 return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
691}
692MlirAttribute mlirDenseElementsAttrFloat16Get(MlirType shapedType,
693 intptr_t numElements,
694 const uint16_t *elements) {
695 size_t bufferSize = numElements * 2;
696 const void *buffer = static_cast<const void *>(elements);
697 return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
698}
699
700MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType,
701 intptr_t numElements,
702 MlirStringRef *strs) {
704 values.reserve(numElements);
705 for (intptr_t i = 0; i < numElements; ++i)
706 values.push_back(unwrap(strs[i]));
707
708 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
709 values));
710}
711
712MlirAttribute mlirDenseElementsAttrReshapeGet(MlirAttribute attr,
713 MlirType shapedType) {
714 return wrap(llvm::cast<DenseElementsAttr>(unwrap(attr))
715 .reshape(llvm::cast<ShapedType>(unwrap(shapedType))));
716}
717
718//===----------------------------------------------------------------------===//
719// Splat accessors.
720//===----------------------------------------------------------------------===//
721
722bool mlirDenseElementsAttrIsSplat(MlirAttribute attr) {
723 return llvm::cast<DenseElementsAttr>(unwrap(attr)).isSplat();
724}
725
726MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr) {
727 return wrap(
728 llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<Attribute>());
729}
731 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<bool>();
732}
733int8_t mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr) {
734 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int8_t>();
735}
736uint8_t mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr) {
737 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint8_t>();
738}
739int32_t mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr) {
740 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int32_t>();
741}
742uint32_t mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr) {
743 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint32_t>();
744}
746 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int64_t>();
747}
748uint64_t mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr) {
749 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint64_t>();
750}
752 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<float>();
753}
755 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<double>();
756}
758 return wrap(
759 llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<StringRef>());
760}
761
762//===----------------------------------------------------------------------===//
763// Indexed accessors.
764//===----------------------------------------------------------------------===//
765
766bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos) {
767 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<bool>()[pos];
768}
769int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos) {
770 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int8_t>()[pos];
771}
772uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos) {
773 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint8_t>()[pos];
774}
775int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos) {
776 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int16_t>()[pos];
777}
778uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos) {
779 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint16_t>()[pos];
780}
781int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos) {
782 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int32_t>()[pos];
783}
784uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos) {
785 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint32_t>()[pos];
786}
788 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int64_t>()[pos];
789}
790uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos) {
791 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
792}
793uint64_t mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos) {
794 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
795}
796float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos) {
797 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<float>()[pos];
798}
799double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos) {
800 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<double>()[pos];
801}
803 intptr_t pos) {
804 return wrap(
805 llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<StringRef>()[pos]);
806}
807
808//===----------------------------------------------------------------------===//
809// Raw data accessors.
810//===----------------------------------------------------------------------===//
811
812const void *mlirDenseElementsAttrGetRawData(MlirAttribute attr) {
813 return static_cast<const void *>(
814 llvm::cast<DenseElementsAttr>(unwrap(attr)).getRawData().data());
815}
816
817//===----------------------------------------------------------------------===//
818// Resource blob attributes.
819//===----------------------------------------------------------------------===//
820
822 return llvm::isa<DenseResourceElementsAttr>(unwrap(attr));
823}
824
826 MlirType shapedType, MlirStringRef name, void *data, size_t dataLength,
827 size_t dataAlignment, bool dataIsMutable,
828 void (*deleter)(void *userData, const void *data, size_t size,
829 size_t align),
830 void *userData) {
831 AsmResourceBlob::DeleterFn cppDeleter = {};
832 if (deleter) {
833 cppDeleter = [deleter, userData](void *data, size_t size, size_t align) {
834 deleter(userData, data, size, align);
835 };
836 }
837 AsmResourceBlob blob(
838 llvm::ArrayRef(static_cast<const char *>(data), dataLength),
839 dataAlignment, std::move(cppDeleter), dataIsMutable);
840 return wrap(
841 DenseResourceElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
842 unwrap(name), std::move(blob)));
843}
844
846 return wrap(DenseResourceElementsAttr::name);
847}
848
849template <typename U, typename T>
850static MlirAttribute getDenseResource(MlirType shapedType, MlirStringRef name,
851 intptr_t numElements, const T *elements) {
852 return wrap(U::get(llvm::cast<ShapedType>(unwrap(shapedType)), unwrap(name),
854 llvm::ArrayRef(elements, numElements))));
855}
856
858 MlirType shapedType, MlirStringRef name, intptr_t numElements,
859 const int *elements) {
861 numElements, elements);
862}
864 MlirType shapedType, MlirStringRef name, intptr_t numElements,
865 const uint8_t *elements) {
867 numElements, elements);
868}
870 MlirType shapedType, MlirStringRef name, intptr_t numElements,
871 const uint16_t *elements) {
873 numElements, elements);
874}
876 MlirType shapedType, MlirStringRef name, intptr_t numElements,
877 const uint32_t *elements) {
879 numElements, elements);
880}
882 MlirType shapedType, MlirStringRef name, intptr_t numElements,
883 const uint64_t *elements) {
885 numElements, elements);
886}
888 MlirType shapedType, MlirStringRef name, intptr_t numElements,
889 const int8_t *elements) {
891 numElements, elements);
892}
894 MlirType shapedType, MlirStringRef name, intptr_t numElements,
895 const int16_t *elements) {
897 numElements, elements);
898}
900 MlirType shapedType, MlirStringRef name, intptr_t numElements,
901 const int32_t *elements) {
903 numElements, elements);
904}
906 MlirType shapedType, MlirStringRef name, intptr_t numElements,
907 const int64_t *elements) {
909 numElements, elements);
910}
912 MlirType shapedType, MlirStringRef name, intptr_t numElements,
913 const float *elements) {
915 numElements, elements);
916}
918 MlirType shapedType, MlirStringRef name, intptr_t numElements,
919 const double *elements) {
921 numElements, elements);
922}
923template <typename U, typename T>
924static T getDenseResourceVal(MlirAttribute attr, intptr_t pos) {
925 return (*llvm::cast<U>(unwrap(attr)).tryGetAsArrayRef())[pos];
926}
927
975
976//===----------------------------------------------------------------------===//
977// Sparse elements attribute.
978//===----------------------------------------------------------------------===//
979
980bool mlirAttributeIsASparseElements(MlirAttribute attr) {
981 return llvm::isa<SparseElementsAttr>(unwrap(attr));
982}
983
984MlirAttribute mlirSparseElementsAttribute(MlirType shapedType,
985 MlirAttribute denseIndices,
986 MlirAttribute denseValues) {
987 return wrap(SparseElementsAttr::get(
988 llvm::cast<ShapedType>(unwrap(shapedType)),
989 llvm::cast<DenseElementsAttr>(unwrap(denseIndices)),
990 llvm::cast<DenseElementsAttr>(unwrap(denseValues))));
991}
992
993MlirAttribute mlirSparseElementsAttrGetIndices(MlirAttribute attr) {
994 return wrap(llvm::cast<SparseElementsAttr>(unwrap(attr)).getIndices());
995}
996
997MlirAttribute mlirSparseElementsAttrGetValues(MlirAttribute attr) {
998 return wrap(llvm::cast<SparseElementsAttr>(unwrap(attr)).getValues());
999}
1000
1002 return wrap(SparseElementsAttr::getTypeID());
1003}
1004
1005//===----------------------------------------------------------------------===//
1006// Strided layout attribute.
1007//===----------------------------------------------------------------------===//
1008
1009bool mlirAttributeIsAStridedLayout(MlirAttribute attr) {
1010 return llvm::isa<StridedLayoutAttr>(unwrap(attr));
1011}
1012
1013MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset,
1014 intptr_t numStrides,
1015 const int64_t *strides) {
1016 return wrap(StridedLayoutAttr::get(unwrap(ctx), offset,
1017 ArrayRef<int64_t>(strides, numStrides)));
1018}
1019
1021 return wrap(StridedLayoutAttr::name);
1022}
1023
1025 return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getOffset();
1026}
1027
1029 return static_cast<intptr_t>(
1030 llvm::cast<StridedLayoutAttr>(unwrap(attr)).getStrides().size());
1031}
1032
1034 return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getStrides()[pos];
1035}
1036
1038 return wrap(StridedLayoutAttr::getTypeID());
1039}
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 mlirStringAttrGetName(void)
MlirStringRef mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos)
const void * mlirDenseElementsAttrGetRawData(MlirAttribute attr)
Returns the raw data of the given dense elements attribute.
int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos)
uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos)
MlirStringRef mlirArrayAttrGetName(void)
MlirIntegerSet mlirIntegerSetAttrGetValue(MlirAttribute attr)
Returns the integer set wrapped in the given integer set attribute.
bool mlirAttributeIsADenseI32Array(MlirAttribute attr)
MlirStringRef mlirTypeAttrGetName(void)
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)
MlirStringRef mlirIntegerSetAttrGetName(void)
double mlirDenseDoubleResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos)
MlirAttribute mlirDisctinctAttrCreate(MlirAttribute referencedAttr)
Creates a DisctinctAttr with the referenced attribute.
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...
MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set)
Creates an integer set attribute wrapping the given set.
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)
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.
MlirStringRef mlirUnitAttrGetName(void)
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)
MlirStringRef mlirAffineMapAttrGetName(void)
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.
MlirStringRef mlirStridedLayoutAttrGetName(void)
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)
MlirStringRef mlirDenseResourceElementsAttrGetName(void)
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.
MlirStringRef mlirDictionaryAttrGetName(void)
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)
MlirStringRef mlirSymbolRefAttrGetName(void)
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)
MlirStringRef mlirIntegerAttrGetName(void)
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.
uint64_t mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos)
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)
MlirStringRef mlirOpaqueAttrGetName(void)
MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType, intptr_t numElements, const uint8_t *elements)
MlirStringRef mlirFlatSymbolRefAttrGetName(void)
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
This class represents a processed binary blob of data.
Definition AsmState.h:91
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:95
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 DistinctAttr create(Attribute referencedAttr)
Creates a distinct attribute that associates a referenced attribute with a unique identifier.
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:164
StringAttr getName() const
Return the name of the attribute.
Attribute getValue() const
Return the value of the attribute.
Definition Attributes.h:179
static AsmResourceBlob allocateInferAlign(ArrayRef< T > data, AsmResourceBlob::DeleterFn deleter={}, bool dataIsMutable=false)
Definition AsmState.h:235
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< bool > content)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
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:75