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