MLIR 23.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
134MlirStringRef mlirFloatAttrGetName(void) { return wrap(FloatAttr::name); }
135
136MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type,
137 double value) {
138 return wrap(FloatAttr::get(unwrap(type), value));
139}
140
141MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type,
142 double value) {
143 return wrap(FloatAttr::getChecked(unwrap(loc), unwrap(type), value));
144}
145
146double mlirFloatAttrGetValueDouble(MlirAttribute attr) {
147 return llvm::cast<FloatAttr>(unwrap(attr)).getValueAsDouble();
148}
149
150MlirTypeID mlirFloatAttrGetTypeID(void) { return wrap(FloatAttr::getTypeID()); }
151
152//===----------------------------------------------------------------------===//
153// Integer attribute.
154//===----------------------------------------------------------------------===//
155
156bool mlirAttributeIsAInteger(MlirAttribute attr) {
157 return llvm::isa<IntegerAttr>(unwrap(attr));
158}
159
160MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value) {
161 return wrap(IntegerAttr::get(unwrap(type), value));
162}
163
164MlirStringRef mlirIntegerAttrGetName(void) { return wrap(IntegerAttr::name); }
165
167 return llvm::cast<IntegerAttr>(unwrap(attr)).getInt();
168}
169
171 return llvm::cast<IntegerAttr>(unwrap(attr)).getSInt();
172}
173
174uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr) {
175 return llvm::cast<IntegerAttr>(unwrap(attr)).getUInt();
176}
177
178unsigned mlirIntegerAttrGetValueBitWidth(MlirAttribute attr) {
179 return llvm::cast<IntegerAttr>(unwrap(attr)).getValue().getBitWidth();
180}
181
182unsigned mlirIntegerAttrGetValueNumWords(MlirAttribute attr) {
183 return llvm::cast<IntegerAttr>(unwrap(attr)).getValue().getNumWords();
184}
185
186void mlirIntegerAttrGetValueWords(MlirAttribute attr, uint64_t *words) {
187 const APInt &value = llvm::cast<IntegerAttr>(unwrap(attr)).getValue();
188 unsigned numWords = value.getNumWords();
189 const uint64_t *rawData = value.getRawData();
190 std::copy(rawData, rawData + numWords, words);
191}
192
193MlirAttribute mlirIntegerAttrGetFromWords(MlirType type, unsigned numWords,
194 const uint64_t *words) {
195 Type mlirType = unwrap(type);
196 unsigned bitWidth = mlirType.getIntOrFloatBitWidth();
197 APInt value(bitWidth, ArrayRef<uint64_t>(words, numWords));
198 return wrap(IntegerAttr::get(mlirType, value));
199}
200
201MlirTypeID mlirIntegerAttrGetTypeID(void) {
202 return wrap(IntegerAttr::getTypeID());
203}
204
205//===----------------------------------------------------------------------===//
206// Bool attribute.
207//===----------------------------------------------------------------------===//
208
209bool mlirAttributeIsABool(MlirAttribute attr) {
210 return llvm::isa<BoolAttr>(unwrap(attr));
211}
212
213MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value) {
214 return wrap(BoolAttr::get(unwrap(ctx), value));
215}
216
217bool mlirBoolAttrGetValue(MlirAttribute attr) {
218 return llvm::cast<BoolAttr>(unwrap(attr)).getValue();
219}
220
221//===----------------------------------------------------------------------===//
222// Integer set attribute.
223//===----------------------------------------------------------------------===//
224
225bool mlirAttributeIsAIntegerSet(MlirAttribute attr) {
226 return llvm::isa<IntegerSetAttr>(unwrap(attr));
227}
228
230 return wrap(IntegerSetAttr::getTypeID());
231}
232
233MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set) {
234 return wrap(IntegerSetAttr::get(unwrap(set)));
235}
236
238 return wrap(IntegerSetAttr::name);
239}
240
241MlirIntegerSet mlirIntegerSetAttrGetValue(MlirAttribute attr) {
242 return wrap(llvm::cast<IntegerSetAttr>(unwrap(attr)).getValue());
243}
244
245//===----------------------------------------------------------------------===//
246// Opaque attribute.
247//===----------------------------------------------------------------------===//
248
249bool mlirAttributeIsAOpaque(MlirAttribute attr) {
250 return llvm::isa<OpaqueAttr>(unwrap(attr));
251}
252
253MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
254 intptr_t dataLength, const char *data,
255 MlirType type) {
256 return wrap(
257 OpaqueAttr::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)),
258 StringRef(data, dataLength), unwrap(type)));
259}
260
261MlirStringRef mlirOpaqueAttrGetName(void) { return wrap(OpaqueAttr::name); }
262
264 return wrap(
265 llvm::cast<OpaqueAttr>(unwrap(attr)).getDialectNamespace().strref());
266}
267
269 return wrap(llvm::cast<OpaqueAttr>(unwrap(attr)).getAttrData());
270}
271
272MlirTypeID mlirOpaqueAttrGetTypeID(void) {
273 return wrap(OpaqueAttr::getTypeID());
274}
275
276//===----------------------------------------------------------------------===//
277// String attribute.
278//===----------------------------------------------------------------------===//
279
280bool mlirAttributeIsAString(MlirAttribute attr) {
281 return llvm::isa<StringAttr>(unwrap(attr));
282}
283
284MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str) {
285 return wrap((Attribute)StringAttr::get(unwrap(ctx), unwrap(str)));
286}
287
288MlirStringRef mlirStringAttrGetName(void) { return wrap(StringAttr::name); }
289
290MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str) {
291 return wrap((Attribute)StringAttr::get(unwrap(str), unwrap(type)));
292}
293
295 return wrap(llvm::cast<StringAttr>(unwrap(attr)).getValue());
296}
297
298MlirTypeID mlirStringAttrGetTypeID(void) {
299 return wrap(StringAttr::getTypeID());
300}
301
302//===----------------------------------------------------------------------===//
303// SymbolRef attribute.
304//===----------------------------------------------------------------------===//
305
306bool mlirAttributeIsASymbolRef(MlirAttribute attr) {
307 return llvm::isa<SymbolRefAttr>(unwrap(attr));
308}
309
310MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
311 intptr_t numReferences,
312 MlirAttribute const *references) {
314 refs.reserve(numReferences);
315 for (intptr_t i = 0; i < numReferences; ++i)
316 refs.push_back(llvm::cast<FlatSymbolRefAttr>(unwrap(references[i])));
317 auto symbolAttr = StringAttr::get(unwrap(ctx), unwrap(symbol));
318 return wrap(SymbolRefAttr::get(symbolAttr, refs));
319}
320
322 return wrap(SymbolRefAttr::name);
323}
324
326 return wrap(
327 llvm::cast<SymbolRefAttr>(unwrap(attr)).getRootReference().getValue());
328}
329
331 return wrap(
332 llvm::cast<SymbolRefAttr>(unwrap(attr)).getLeafReference().getValue());
333}
334
336 return static_cast<intptr_t>(
337 llvm::cast<SymbolRefAttr>(unwrap(attr)).getNestedReferences().size());
338}
339
340MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr,
341 intptr_t pos) {
342 return wrap(
343 llvm::cast<SymbolRefAttr>(unwrap(attr)).getNestedReferences()[pos]);
344}
345
347 return wrap(SymbolRefAttr::getTypeID());
348}
349
350MlirAttribute mlirDistinctAttrCreate(MlirAttribute referencedAttr) {
351 return wrap(mlir::DistinctAttr::create(unwrap(referencedAttr)));
352}
353
354//===----------------------------------------------------------------------===//
355// Flat SymbolRef attribute.
356//===----------------------------------------------------------------------===//
357
358bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr) {
359 return llvm::isa<FlatSymbolRefAttr>(unwrap(attr));
360}
361
362MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol) {
363 return wrap(FlatSymbolRefAttr::get(unwrap(ctx), unwrap(symbol)));
364}
365
367 return wrap(FlatSymbolRefAttr::name);
368}
369
371 return wrap(llvm::cast<FlatSymbolRefAttr>(unwrap(attr)).getValue());
372}
373
374//===----------------------------------------------------------------------===//
375// Type attribute.
376//===----------------------------------------------------------------------===//
377
378bool mlirAttributeIsAType(MlirAttribute attr) {
379 return llvm::isa<TypeAttr>(unwrap(attr));
380}
381
382MlirAttribute mlirTypeAttrGet(MlirType type) {
383 return wrap(TypeAttr::get(unwrap(type)));
384}
385
386MlirStringRef mlirTypeAttrGetName(void) { return wrap(TypeAttr::name); }
387
388MlirType mlirTypeAttrGetValue(MlirAttribute attr) {
389 return wrap(llvm::cast<TypeAttr>(unwrap(attr)).getValue());
390}
391
392MlirTypeID mlirTypeAttrGetTypeID(void) { return wrap(TypeAttr::getTypeID()); }
393
394//===----------------------------------------------------------------------===//
395// Unit attribute.
396//===----------------------------------------------------------------------===//
397
398bool mlirAttributeIsAUnit(MlirAttribute attr) {
399 return llvm::isa<UnitAttr>(unwrap(attr));
400}
401
402MlirAttribute mlirUnitAttrGet(MlirContext ctx) {
403 return wrap(UnitAttr::get(unwrap(ctx)));
404}
405
406MlirStringRef mlirUnitAttrGetName(void) { return wrap(UnitAttr::name); }
407
408MlirTypeID mlirUnitAttrGetTypeID(void) { return wrap(UnitAttr::getTypeID()); }
409
410//===----------------------------------------------------------------------===//
411// Elements attributes.
412//===----------------------------------------------------------------------===//
413
414bool mlirAttributeIsAElements(MlirAttribute attr) {
415 return llvm::isa<ElementsAttr>(unwrap(attr));
416}
417
418MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, intptr_t rank,
419 uint64_t *idxs) {
420 return wrap(llvm::cast<ElementsAttr>(unwrap(attr))
421 .getValues<Attribute>()[llvm::ArrayRef(idxs, rank)]);
422}
423
424bool mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank,
425 uint64_t *idxs) {
426 return llvm::cast<ElementsAttr>(unwrap(attr))
427 .isValidIndex(llvm::ArrayRef(idxs, rank));
428}
429
431 return llvm::cast<ElementsAttr>(unwrap(attr)).getNumElements();
432}
433
434//===----------------------------------------------------------------------===//
435// Dense array attribute.
436//===----------------------------------------------------------------------===//
437
439 return wrap(DenseArrayAttr::getTypeID());
440}
441
442//===----------------------------------------------------------------------===//
443// IsA support.
444//===----------------------------------------------------------------------===//
445
446bool mlirAttributeIsADenseBoolArray(MlirAttribute attr) {
447 return llvm::isa<DenseBoolArrayAttr>(unwrap(attr));
448}
449bool mlirAttributeIsADenseI8Array(MlirAttribute attr) {
450 return llvm::isa<DenseI8ArrayAttr>(unwrap(attr));
451}
452bool mlirAttributeIsADenseI16Array(MlirAttribute attr) {
453 return llvm::isa<DenseI16ArrayAttr>(unwrap(attr));
454}
455bool mlirAttributeIsADenseI32Array(MlirAttribute attr) {
456 return llvm::isa<DenseI32ArrayAttr>(unwrap(attr));
457}
458bool mlirAttributeIsADenseI64Array(MlirAttribute attr) {
459 return llvm::isa<DenseI64ArrayAttr>(unwrap(attr));
460}
461bool mlirAttributeIsADenseF32Array(MlirAttribute attr) {
462 return llvm::isa<DenseF32ArrayAttr>(unwrap(attr));
463}
464bool mlirAttributeIsADenseF64Array(MlirAttribute attr) {
465 return llvm::isa<DenseF64ArrayAttr>(unwrap(attr));
466}
467
468//===----------------------------------------------------------------------===//
469// Constructors.
470//===----------------------------------------------------------------------===//
471
472MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size,
473 int const *values) {
474 SmallVector<bool, 4> elements(values, values + size);
475 return wrap(DenseBoolArrayAttr::get(unwrap(ctx), elements));
476}
477MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size,
478 int8_t const *values) {
479 return wrap(
480 DenseI8ArrayAttr::get(unwrap(ctx), ArrayRef<int8_t>(values, size)));
481}
482MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size,
483 int16_t const *values) {
484 return wrap(
485 DenseI16ArrayAttr::get(unwrap(ctx), ArrayRef<int16_t>(values, size)));
486}
487MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size,
488 int32_t const *values) {
489 return wrap(
490 DenseI32ArrayAttr::get(unwrap(ctx), ArrayRef<int32_t>(values, size)));
491}
492MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size,
493 int64_t const *values) {
494 return wrap(
495 DenseI64ArrayAttr::get(unwrap(ctx), ArrayRef<int64_t>(values, size)));
496}
497MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size,
498 float const *values) {
499 return wrap(
500 DenseF32ArrayAttr::get(unwrap(ctx), ArrayRef<float>(values, size)));
501}
502MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size,
503 double const *values) {
504 return wrap(
505 DenseF64ArrayAttr::get(unwrap(ctx), ArrayRef<double>(values, size)));
506}
507
508//===----------------------------------------------------------------------===//
509// Accessors.
510//===----------------------------------------------------------------------===//
511
513 return llvm::cast<DenseArrayAttr>(unwrap(attr)).size();
514}
515
516//===----------------------------------------------------------------------===//
517// Indexed accessors.
518//===----------------------------------------------------------------------===//
519
520bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos) {
521 return llvm::cast<DenseBoolArrayAttr>(unwrap(attr))[pos];
522}
523int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos) {
524 return llvm::cast<DenseI8ArrayAttr>(unwrap(attr))[pos];
525}
526int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos) {
527 return llvm::cast<DenseI16ArrayAttr>(unwrap(attr))[pos];
528}
529int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
530 return llvm::cast<DenseI32ArrayAttr>(unwrap(attr))[pos];
531}
533 return llvm::cast<DenseI64ArrayAttr>(unwrap(attr))[pos];
534}
535float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos) {
536 return llvm::cast<DenseF32ArrayAttr>(unwrap(attr))[pos];
537}
538double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos) {
539 return llvm::cast<DenseF64ArrayAttr>(unwrap(attr))[pos];
540}
541
542//===----------------------------------------------------------------------===//
543// Dense elements attribute.
544//===----------------------------------------------------------------------===//
545
546//===----------------------------------------------------------------------===//
547// IsA support.
548//===----------------------------------------------------------------------===//
549
550bool mlirAttributeIsADenseElements(MlirAttribute attr) {
551 return llvm::isa<DenseElementsAttr>(unwrap(attr));
552}
553
554bool mlirAttributeIsADenseIntElements(MlirAttribute attr) {
555 return llvm::isa<DenseIntElementsAttr>(unwrap(attr));
556}
557
558bool mlirAttributeIsADenseFPElements(MlirAttribute attr) {
559 return llvm::isa<DenseFPElementsAttr>(unwrap(attr));
560}
561
563 return wrap(DenseTypedElementsAttr::getTypeID());
564}
565
566// Deprecated API. Will be removed in the future.
570
571//===----------------------------------------------------------------------===//
572// Constructors.
573//===----------------------------------------------------------------------===//
574
575MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType,
576 intptr_t numElements,
577 MlirAttribute const *elements) {
578 SmallVector<Attribute, 8> attributes;
579 return wrap(
580 DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
581 unwrapList(numElements, elements, attributes)));
582}
583
584MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType,
585 size_t rawBufferSize,
586 const void *rawBuffer) {
587 auto shapedTypeCpp = llvm::cast<ShapedType>(unwrap(shapedType));
588 ArrayRef<char> rawBufferCpp(static_cast<const char *>(rawBuffer),
589 rawBufferSize);
590 if (!DenseElementsAttr::isValidRawBuffer(shapedTypeCpp, rawBufferCpp))
591 return mlirAttributeGetNull();
592 return wrap(DenseElementsAttr::getFromRawBuffer(shapedTypeCpp, rawBufferCpp));
593}
594
595MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType,
596 MlirAttribute element) {
597 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
598 unwrap(element)));
599}
600MlirAttribute mlirDenseElementsAttrBoolSplatGet(MlirType shapedType,
601 bool element) {
602 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
603 element));
604}
605MlirAttribute mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType,
606 uint8_t element) {
607 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
608 element));
609}
610MlirAttribute mlirDenseElementsAttrInt8SplatGet(MlirType shapedType,
611 int8_t element) {
612 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
613 element));
614}
615MlirAttribute mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType,
616 uint32_t element) {
617 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
618 element));
619}
620MlirAttribute mlirDenseElementsAttrInt32SplatGet(MlirType shapedType,
621 int32_t element) {
622 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
623 element));
624}
625MlirAttribute mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType,
626 uint64_t element) {
627 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
628 element));
629}
630MlirAttribute mlirDenseElementsAttrInt64SplatGet(MlirType shapedType,
631 int64_t element) {
632 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
633 element));
634}
635MlirAttribute mlirDenseElementsAttrFloatSplatGet(MlirType shapedType,
636 float element) {
637 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
638 element));
639}
640MlirAttribute mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType,
641 double element) {
642 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
643 element));
644}
645
646MlirAttribute mlirDenseElementsAttrBoolGet(MlirType shapedType,
647 intptr_t numElements,
648 const int *elements) {
649 SmallVector<bool, 8> values(elements, elements + numElements);
650 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
651 values));
652}
653
654/// Creates a dense attribute with elements of the type deduced by templates.
655template <typename T>
656static MlirAttribute getDenseAttribute(MlirType shapedType,
657 intptr_t numElements,
658 const T *elements) {
659 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
660 llvm::ArrayRef(elements, numElements)));
661}
662
663MlirAttribute mlirDenseElementsAttrUInt8Get(MlirType shapedType,
664 intptr_t numElements,
665 const uint8_t *elements) {
666 return getDenseAttribute(shapedType, numElements, elements);
667}
668MlirAttribute mlirDenseElementsAttrInt8Get(MlirType shapedType,
669 intptr_t numElements,
670 const int8_t *elements) {
671 return getDenseAttribute(shapedType, numElements, elements);
672}
673MlirAttribute mlirDenseElementsAttrUInt16Get(MlirType shapedType,
674 intptr_t numElements,
675 const uint16_t *elements) {
676 return getDenseAttribute(shapedType, numElements, elements);
677}
678MlirAttribute mlirDenseElementsAttrInt16Get(MlirType shapedType,
679 intptr_t numElements,
680 const int16_t *elements) {
681 return getDenseAttribute(shapedType, numElements, elements);
682}
683MlirAttribute mlirDenseElementsAttrUInt32Get(MlirType shapedType,
684 intptr_t numElements,
685 const uint32_t *elements) {
686 return getDenseAttribute(shapedType, numElements, elements);
687}
688MlirAttribute mlirDenseElementsAttrInt32Get(MlirType shapedType,
689 intptr_t numElements,
690 const int32_t *elements) {
691 return getDenseAttribute(shapedType, numElements, elements);
692}
693MlirAttribute mlirDenseElementsAttrUInt64Get(MlirType shapedType,
694 intptr_t numElements,
695 const uint64_t *elements) {
696 return getDenseAttribute(shapedType, numElements, elements);
697}
698MlirAttribute mlirDenseElementsAttrInt64Get(MlirType shapedType,
699 intptr_t numElements,
700 const int64_t *elements) {
701 return getDenseAttribute(shapedType, numElements, elements);
702}
703MlirAttribute mlirDenseElementsAttrFloatGet(MlirType shapedType,
704 intptr_t numElements,
705 const float *elements) {
706 return getDenseAttribute(shapedType, numElements, elements);
707}
708MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType,
709 intptr_t numElements,
710 const double *elements) {
711 return getDenseAttribute(shapedType, numElements, elements);
712}
713MlirAttribute mlirDenseElementsAttrBFloat16Get(MlirType shapedType,
714 intptr_t numElements,
715 const uint16_t *elements) {
716 size_t bufferSize = numElements * 2;
717 const void *buffer = static_cast<const void *>(elements);
718 return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
719}
720MlirAttribute mlirDenseElementsAttrFloat16Get(MlirType shapedType,
721 intptr_t numElements,
722 const uint16_t *elements) {
723 size_t bufferSize = numElements * 2;
724 const void *buffer = static_cast<const void *>(elements);
725 return mlirDenseElementsAttrRawBufferGet(shapedType, bufferSize, buffer);
726}
727
728MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType,
729 intptr_t numElements,
730 MlirStringRef *strs) {
732 values.reserve(numElements);
733 for (intptr_t i = 0; i < numElements; ++i)
734 values.push_back(unwrap(strs[i]));
735
736 return wrap(DenseElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
737 values));
738}
739
740MlirAttribute mlirDenseElementsAttrReshapeGet(MlirAttribute attr,
741 MlirType shapedType) {
742 return wrap(llvm::cast<DenseElementsAttr>(unwrap(attr))
743 .reshape(llvm::cast<ShapedType>(unwrap(shapedType))));
744}
745
746//===----------------------------------------------------------------------===//
747// Splat accessors.
748//===----------------------------------------------------------------------===//
749
750bool mlirDenseElementsAttrIsSplat(MlirAttribute attr) {
751 return llvm::cast<DenseElementsAttr>(unwrap(attr)).isSplat();
752}
753
754MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr) {
755 return wrap(
756 llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<Attribute>());
757}
759 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<bool>();
760}
761int8_t mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr) {
762 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int8_t>();
763}
764uint8_t mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr) {
765 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint8_t>();
766}
767int32_t mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr) {
768 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int32_t>();
769}
770uint32_t mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr) {
771 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint32_t>();
772}
774 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<int64_t>();
775}
776uint64_t mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr) {
777 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<uint64_t>();
778}
780 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<float>();
781}
783 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<double>();
784}
786 return wrap(
787 llvm::cast<DenseElementsAttr>(unwrap(attr)).getSplatValue<StringRef>());
788}
789
790//===----------------------------------------------------------------------===//
791// Indexed accessors.
792//===----------------------------------------------------------------------===//
793
794bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos) {
795 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<bool>()[pos];
796}
797int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos) {
798 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int8_t>()[pos];
799}
800uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos) {
801 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint8_t>()[pos];
802}
803int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos) {
804 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int16_t>()[pos];
805}
806uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos) {
807 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint16_t>()[pos];
808}
809int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos) {
810 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int32_t>()[pos];
811}
812uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos) {
813 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint32_t>()[pos];
814}
816 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<int64_t>()[pos];
817}
818uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos) {
819 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
820}
821uint64_t mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos) {
822 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<uint64_t>()[pos];
823}
824float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos) {
825 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<float>()[pos];
826}
827double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos) {
828 return llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<double>()[pos];
829}
831 intptr_t pos) {
832 return wrap(
833 llvm::cast<DenseElementsAttr>(unwrap(attr)).getValues<StringRef>()[pos]);
834}
835
836//===----------------------------------------------------------------------===//
837// Raw data accessors.
838//===----------------------------------------------------------------------===//
839
840const void *mlirDenseElementsAttrGetRawData(MlirAttribute attr) {
841 return static_cast<const void *>(
842 llvm::cast<DenseElementsAttr>(unwrap(attr)).getRawData().data());
843}
844
845//===----------------------------------------------------------------------===//
846// Resource blob attributes.
847//===----------------------------------------------------------------------===//
848
850 return llvm::isa<DenseResourceElementsAttr>(unwrap(attr));
851}
852
854 MlirType shapedType, MlirStringRef name, void *data, size_t dataLength,
855 size_t dataAlignment, bool dataIsMutable,
856 void (*deleter)(void *userData, const void *data, size_t size,
857 size_t align),
858 void *userData) {
859 AsmResourceBlob::DeleterFn cppDeleter = {};
860 if (deleter) {
861 cppDeleter = [deleter, userData](void *data, size_t size, size_t align) {
862 deleter(userData, data, size, align);
863 };
864 }
865 AsmResourceBlob blob(
866 llvm::ArrayRef(static_cast<const char *>(data), dataLength),
867 dataAlignment, std::move(cppDeleter), dataIsMutable);
868 return wrap(
869 DenseResourceElementsAttr::get(llvm::cast<ShapedType>(unwrap(shapedType)),
870 unwrap(name), std::move(blob)));
871}
872
874 return wrap(DenseResourceElementsAttr::name);
875}
876
877template <typename U, typename T>
878static MlirAttribute getDenseResource(MlirType shapedType, MlirStringRef name,
879 intptr_t numElements, const T *elements) {
880 return wrap(U::get(llvm::cast<ShapedType>(unwrap(shapedType)), unwrap(name),
882 llvm::ArrayRef(elements, numElements))));
883}
884
886 MlirType shapedType, MlirStringRef name, intptr_t numElements,
887 const int *elements) {
889 numElements, elements);
890}
892 MlirType shapedType, MlirStringRef name, intptr_t numElements,
893 const uint8_t *elements) {
895 numElements, elements);
896}
898 MlirType shapedType, MlirStringRef name, intptr_t numElements,
899 const uint16_t *elements) {
901 numElements, elements);
902}
904 MlirType shapedType, MlirStringRef name, intptr_t numElements,
905 const uint32_t *elements) {
907 numElements, elements);
908}
910 MlirType shapedType, MlirStringRef name, intptr_t numElements,
911 const uint64_t *elements) {
913 numElements, elements);
914}
916 MlirType shapedType, MlirStringRef name, intptr_t numElements,
917 const int8_t *elements) {
919 numElements, elements);
920}
922 MlirType shapedType, MlirStringRef name, intptr_t numElements,
923 const int16_t *elements) {
925 numElements, elements);
926}
928 MlirType shapedType, MlirStringRef name, intptr_t numElements,
929 const int32_t *elements) {
931 numElements, elements);
932}
934 MlirType shapedType, MlirStringRef name, intptr_t numElements,
935 const int64_t *elements) {
937 numElements, elements);
938}
940 MlirType shapedType, MlirStringRef name, intptr_t numElements,
941 const float *elements) {
943 numElements, elements);
944}
946 MlirType shapedType, MlirStringRef name, intptr_t numElements,
947 const double *elements) {
949 numElements, elements);
950}
951template <typename U, typename T>
952static T getDenseResourceVal(MlirAttribute attr, intptr_t pos) {
953 return (*llvm::cast<U>(unwrap(attr)).tryGetAsArrayRef())[pos];
954}
955
1003
1004//===----------------------------------------------------------------------===//
1005// Sparse elements attribute.
1006//===----------------------------------------------------------------------===//
1007
1008bool mlirAttributeIsASparseElements(MlirAttribute attr) {
1009 return llvm::isa<SparseElementsAttr>(unwrap(attr));
1010}
1011
1012MlirAttribute mlirSparseElementsAttribute(MlirType shapedType,
1013 MlirAttribute denseIndices,
1014 MlirAttribute denseValues) {
1015 return wrap(SparseElementsAttr::get(
1016 llvm::cast<ShapedType>(unwrap(shapedType)),
1017 llvm::cast<DenseElementsAttr>(unwrap(denseIndices)),
1018 llvm::cast<DenseElementsAttr>(unwrap(denseValues))));
1019}
1020
1021MlirAttribute mlirSparseElementsAttrGetIndices(MlirAttribute attr) {
1022 return wrap(llvm::cast<SparseElementsAttr>(unwrap(attr)).getIndices());
1023}
1024
1025MlirAttribute mlirSparseElementsAttrGetValues(MlirAttribute attr) {
1026 return wrap(llvm::cast<SparseElementsAttr>(unwrap(attr)).getValues());
1027}
1028
1030 return wrap(SparseElementsAttr::getTypeID());
1031}
1032
1033//===----------------------------------------------------------------------===//
1034// Strided layout attribute.
1035//===----------------------------------------------------------------------===//
1036
1037bool mlirAttributeIsAStridedLayout(MlirAttribute attr) {
1038 return llvm::isa<StridedLayoutAttr>(unwrap(attr));
1039}
1040
1041MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset,
1042 intptr_t numStrides,
1043 const int64_t *strides) {
1044 return wrap(StridedLayoutAttr::get(unwrap(ctx), offset,
1045 ArrayRef<int64_t>(strides, numStrides)));
1046}
1047
1049 return wrap(StridedLayoutAttr::name);
1050}
1051
1053 return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getOffset();
1054}
1055
1057 return static_cast<intptr_t>(
1058 llvm::cast<StridedLayoutAttr>(unwrap(attr)).getStrides().size());
1059}
1060
1062 return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getStrides()[pos];
1063}
1064
1066 return wrap(StridedLayoutAttr::getTypeID());
1067}
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)
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)
unsigned mlirIntegerAttrGetValueBitWidth(MlirAttribute attr)
Returns the bit width of the integer attribute's underlying APInt value.
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()
MlirAttribute mlirDistinctAttrCreate(MlirAttribute referencedAttr)
Creates a DistinctAttr with the referenced attribute.
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.
MlirStringRef mlirFloatAttrGetName(void)
MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType, intptr_t numElements, MlirStringRef *strs)
Creates a dense elements attribute with the given shaped type from string elements.
MlirAttribute mlirIntegerAttrGetFromWords(MlirType type, unsigned numWords, const uint64_t *words)
Creates an integer attribute of the given type from an array of 64-bit words.
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...
MlirTypeID mlirDenseTypedElementsAttrGetTypeID(void)
Returns the typeID of a DenseTypedElements attribute.
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)
Deprecated API. Will be removed in the future.
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)
unsigned mlirIntegerAttrGetValueNumWords(MlirAttribute attr)
Returns the number of 64-bit words that make up the integer attribute's underlying APInt value.
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)
void mlirIntegerAttrGetValueWords(MlirAttribute attr, uint64_t *words)
Copies the 64-bit words making up the integer attribute's APInt value into the provided buffer.
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 bool isValidRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Returns true if the given buffer is a valid raw buffer for the given type.
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
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
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
Definition Types.cpp:124
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:78