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