2020-12-04 09:22:57 +08:00
|
|
|
//===-- mlir-c/BuiltinAttributes.h - C API for Builtin Attributes -*- C -*-===//
|
2020-11-05 02:08:34 +08:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
|
|
|
|
// Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2020-12-04 09:22:57 +08:00
|
|
|
// This header declares the C interface to MLIR Builtin attributes.
|
2020-11-05 02:08:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-12-04 09:22:57 +08:00
|
|
|
#ifndef MLIR_C_BUILTINATTRIBUTES_H
|
|
|
|
#define MLIR_C_BUILTINATTRIBUTES_H
|
2020-08-20 00:38:56 +08:00
|
|
|
|
|
|
|
#include "mlir-c/AffineMap.h"
|
|
|
|
#include "mlir-c/IR.h"
|
2020-09-15 18:04:59 +08:00
|
|
|
#include "mlir-c/Support.h"
|
2020-08-20 00:38:56 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
[mlir] introduce "encoding" attribute to tensor type
This CL introduces a generic attribute (called "encoding") on tensors.
The attribute currently does not carry any concrete information, but the type
system already correctly determines that tensor<8xi1,123> != tensor<8xi1,321>.
The attribute will be given meaning through an interface in subsequent CLs.
See ongoing discussion on discourse:
[RFC] Introduce a sparse tensor type to core MLIR
https://llvm.discourse.group/t/rfc-introduce-a-sparse-tensor-type-to-core-mlir/2944
A sparse tensor will look something like this:
```
// named alias with all properties we hold dear:
#CSR = {
// individual named attributes
}
// actual sparse tensor type:
tensor<?x?xf64, #CSR>
```
I see the following rough 5 step plan going forward:
(1) introduce this format attribute in this CL, currently still empty
(2) introduce attribute interface that gives it "meaning", focused on sparse in first phase
(3) rewrite sparse compiler to use new type, remove linalg interface and "glue"
(4) teach passes to deal with new attribute, by rejecting/asserting on non-empty attribute as simplest solution, or doing meaningful rewrite in the longer run
(5) add FE support, document, test, publicize new features, extend "format" meaning to other domains if useful
Reviewed By: stellaraccident, bondhugula
Differential Revision: https://reviews.llvm.org/D99548
2021-04-13 00:28:41 +08:00
|
|
|
/// Returns an empty attribute.
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull();
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine map attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an affine map attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAAffineMap(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates an affine map attribute wrapping the given map. The attribute
|
|
|
|
/// belongs to the same context as the affine map.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the affine map wrapped in the given affine map attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Array attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an array attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAArray(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates an array element containing the given list of elements in the given
|
|
|
|
/// context.
|
2020-12-04 09:22:57 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(
|
|
|
|
MlirContext ctx, intptr_t numElements, MlirAttribute const *elements);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the number of elements stored in the given array attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns pos-th element stored in the given array attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr,
|
|
|
|
intptr_t pos);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dictionary attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a dictionary attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsADictionary(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a dictionary attribute containing the given list of elements in the
|
|
|
|
/// provided context.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(
|
2020-11-20 02:45:43 +08:00
|
|
|
MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the number of attributes contained in a dictionary attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED intptr_t
|
|
|
|
mlirDictionaryAttrGetNumElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns pos-th element of the given dictionary attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirNamedAttribute
|
|
|
|
mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the dictionary attribute element with the given name or NULL if the
|
|
|
|
/// given name does not exist in the dictionary.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
2020-12-04 08:01:32 +08:00
|
|
|
mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Floating point attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
// TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
|
|
|
|
// relevant functions here.
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a floating point attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a floating point attribute in the given context with the given
|
|
|
|
/// double value and double-precision FP semantics.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx,
|
|
|
|
MlirType type,
|
|
|
|
double value);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a
|
|
|
|
/// construction of a FloatAttr, returns a null MlirAttribute.
|
2021-02-23 09:30:19 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc,
|
|
|
|
MlirType type,
|
|
|
|
double value);
|
2020-09-30 14:11:46 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the value stored in the given floating point attribute, interpreting
|
|
|
|
/// the value as double.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED double mlirFloatAttrGetValueDouble(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Integer attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
// TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
|
|
|
|
// relevant functions here.
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an integer attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates an integer attribute of the given type with the given integer
|
|
|
|
/// value.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type,
|
|
|
|
int64_t value);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the value stored in the given integer attribute, assuming the value
|
|
|
|
/// fits into a 64-bit integer.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Bool attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a bool attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsABool(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates a bool attribute in the given context with the given value.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the value stored in the given bool attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirBoolAttrGetValue(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Integer set attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an integer set attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAIntegerSet(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Opaque attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an opaque attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaque(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates an opaque attribute in the given context associated with the dialect
|
|
|
|
/// identified by its namespace. The attribute contains opaque byte data of the
|
|
|
|
/// specified length (data need not be null-terminated).
|
2020-12-04 08:01:32 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
|
|
|
|
intptr_t dataLength, const char *data, MlirType type);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the namespace of the dialect with which the given opaque attribute
|
|
|
|
/// is associated. The namespace string is owned by the context.
|
2020-12-04 08:01:32 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef
|
2020-11-09 08:49:36 +08:00
|
|
|
mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the raw data as a string reference. The data remains live as long as
|
|
|
|
/// the context in which the attribute lives.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// String attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a string attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAString(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a string attribute in the given context containing the given string.
|
|
|
|
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx,
|
2020-12-04 08:01:32 +08:00
|
|
|
MlirStringRef str);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a string attribute in the given context containing the given string.
|
|
|
|
/// Additionally, the attribute has the given type.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type,
|
2020-12-04 08:01:32 +08:00
|
|
|
MlirStringRef str);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the attribute values as a string reference. The data remains live as
|
|
|
|
/// long as the context in which the attribute lives.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetValue(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SymbolRef attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a symbol reference attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsASymbolRef(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a symbol reference attribute in the given context referencing a
|
|
|
|
/// symbol identified by the given string inside a list of nested references.
|
|
|
|
/// Each of the references in the list must not be nested.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
2020-12-04 08:01:32 +08:00
|
|
|
mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
|
2020-11-20 02:45:43 +08:00
|
|
|
intptr_t numReferences, MlirAttribute const *references);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the string reference to the root referenced symbol. The data remains
|
|
|
|
/// live as long as the context in which the attribute lives.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef
|
|
|
|
mlirSymbolRefAttrGetRootReference(MlirAttribute attr);
|
2020-09-15 18:04:59 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the string reference to the leaf referenced symbol. The data remains
|
|
|
|
/// live as long as the context in which the attribute lives.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef
|
|
|
|
mlirSymbolRefAttrGetLeafReference(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the number of references nested in the given symbol reference
|
|
|
|
/// attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED intptr_t
|
|
|
|
mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns pos-th reference nested in the given symbol reference attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Flat SymbolRef attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a flat symbol reference attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a flat symbol reference attribute in the given context referencing a
|
|
|
|
/// symbol identified by the given string.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx,
|
2020-12-04 08:01:32 +08:00
|
|
|
MlirStringRef symbol);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the referenced symbol as a string reference. The data remains live
|
|
|
|
/// as long as the context in which the attribute lives.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef
|
|
|
|
mlirFlatSymbolRefAttrGetValue(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a type attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAType(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a type attribute wrapping the given type in the same context as the
|
|
|
|
/// type.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the type stored in the given type attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Unit attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a unit attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAUnit(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates a unit attribute in the given context.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Elements attributes.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an elements attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the element at the given rank-dimensional index.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr,
|
|
|
|
intptr_t rank,
|
|
|
|
uint64_t *idxs);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Checks whether the given rank-dimensional index is valid in the given
|
|
|
|
/// elements attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool
|
2020-11-09 08:49:36 +08:00
|
|
|
mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank, uint64_t *idxs);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Gets the total number of elements in the given elements attribute. In order
|
|
|
|
/// to iterate over the attribute, obtain its type, which must be a statically
|
|
|
|
/// shaped type and use its sizes to build a multi-dimensional index.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED int64_t mlirElementsAttrGetNumElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dense elements attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
// TODO: decide on the interface and add support for complex elements.
|
2021-01-25 22:22:16 +08:00
|
|
|
// TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
|
|
|
|
// relevant functions here.
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a dense elements attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseElements(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseIntElements(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseFPElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a dense elements attribute with the given Shaped type and elements
|
|
|
|
/// in the same context as the type.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGet(
|
2020-11-20 05:48:03 +08:00
|
|
|
MlirType shapedType, intptr_t numElements, MlirAttribute const *elements);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-10-07 09:41:22 +08:00
|
|
|
/// Creates a dense elements attribute with the given Shaped type and elements
|
|
|
|
/// populated from a packed, row-major opaque buffer of contents.
|
|
|
|
///
|
|
|
|
/// The format of the raw buffer is a densely packed array of values that
|
|
|
|
/// can be bitcast to the storage format of the element type specified.
|
|
|
|
/// Types that are not byte aligned will be:
|
|
|
|
/// - For bitwidth > 1: Rounded up to the next byte.
|
|
|
|
/// - For bitwidth = 1: Packed into 8bit bytes with bits corresponding to
|
|
|
|
/// the linear order of the shape type from MSB to LSB, padded to on the
|
|
|
|
/// right.
|
|
|
|
///
|
|
|
|
/// A raw buffer of a single element (or for 1-bit, a byte of value 0 or 255)
|
|
|
|
/// will be interpreted as a splat. User code should be prepared for additional,
|
|
|
|
/// conformant patterns to be identified as splats in the future.
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrRawBufferGet(
|
|
|
|
MlirType shapedType, size_t rawBufferSize, const void *rawBuffer);
|
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a dense elements attribute with the given Shaped type containing a
|
|
|
|
/// single replicated element (splat).
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
2020-11-30 10:31:11 +08:00
|
|
|
mlirDenseElementsAttrBoolSplatGet(MlirType shapedType, bool element);
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
2021-05-20 02:58:42 +08:00
|
|
|
mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType, uint8_t element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrInt8SplatGet(MlirType shapedType, int8_t element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
2020-11-09 08:49:36 +08:00
|
|
|
mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType, uint32_t element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrInt32SplatGet(MlirType shapedType, int32_t element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType, uint64_t element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrInt64SplatGet(MlirType shapedType, int64_t element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrFloatSplatGet(MlirType shapedType, float element);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType, double element);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a dense elements attribute with the given shaped type from elements
|
|
|
|
/// of a specific type. Expects the element type of the shaped type to match the
|
|
|
|
/// data element type.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBoolGet(
|
|
|
|
MlirType shapedType, intptr_t numElements, const int *elements);
|
2021-05-20 02:58:42 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt8Get(
|
|
|
|
MlirType shapedType, intptr_t numElements, const uint8_t *elements);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt8Get(
|
|
|
|
MlirType shapedType, intptr_t numElements, const int8_t *elements);
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt32Get(
|
|
|
|
MlirType shapedType, intptr_t numElements, const uint32_t *elements);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt32Get(
|
|
|
|
MlirType shapedType, intptr_t numElements, const int32_t *elements);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt64Get(
|
|
|
|
MlirType shapedType, intptr_t numElements, const uint64_t *elements);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt64Get(
|
|
|
|
MlirType shapedType, intptr_t numElements, const int64_t *elements);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloatGet(
|
|
|
|
MlirType shapedType, intptr_t numElements, const float *elements);
|
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrDoubleGet(
|
|
|
|
MlirType shapedType, intptr_t numElements, const double *elements);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a dense elements attribute with the given shaped type from string
|
|
|
|
/// elements.
|
2020-12-04 08:01:32 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrStringGet(
|
|
|
|
MlirType shapedType, intptr_t numElements, MlirStringRef *strs);
|
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a dense elements attribute that has the same data as the given dense
|
|
|
|
/// elements attribute and a different shaped type. The new type must have the
|
|
|
|
/// same total number of elements.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrReshapeGet(MlirAttribute attr, MlirType shapedType);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Checks whether the given dense elements attribute contains a single
|
|
|
|
/// replicated value (splat).
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the single replicated value (splat) of a specific type contained by
|
|
|
|
/// the given dense elements attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirDenseElementsAttrGetSplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED int
|
|
|
|
mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr);
|
2021-05-20 02:58:42 +08:00
|
|
|
MLIR_CAPI_EXPORTED int8_t
|
|
|
|
mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED uint8_t
|
|
|
|
mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr);
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED int32_t
|
|
|
|
mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED uint32_t
|
|
|
|
mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED int64_t
|
|
|
|
mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED uint64_t
|
|
|
|
mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED float
|
|
|
|
mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED double
|
|
|
|
mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr);
|
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef
|
|
|
|
mlirDenseElementsAttrGetStringSplatValue(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the pos-th value (flat contiguous indexing) of a specific type
|
|
|
|
/// contained by the given dense elements attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr,
|
|
|
|
intptr_t pos);
|
2021-05-20 02:58:42 +08:00
|
|
|
MLIR_CAPI_EXPORTED int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr,
|
|
|
|
intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED uint8_t
|
|
|
|
mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos);
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED int32_t
|
|
|
|
mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED uint32_t
|
|
|
|
mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED int64_t
|
|
|
|
mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED uint64_t
|
|
|
|
mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr,
|
|
|
|
intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED double
|
|
|
|
mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos);
|
|
|
|
MLIR_CAPI_EXPORTED MlirStringRef
|
|
|
|
mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the raw data of the given dense elements attribute.
|
2020-11-08 09:28:35 +08:00
|
|
|
MLIR_CAPI_EXPORTED const void *
|
|
|
|
mlirDenseElementsAttrGetRawData(MlirAttribute attr);
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Opaque elements attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
// TODO: expose Dialect to the bindings and implement accessors here.
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is an opaque elements attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaqueElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Sparse elements attribute.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given attribute is a sparse elements attribute.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseElements(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Creates a sparse elements attribute of the given shape from a list of
|
|
|
|
/// indices and a list of associated values. Both lists are expected to be dense
|
|
|
|
/// elements attributes with the same number of elements. The list of indices is
|
|
|
|
/// expected to contain 64-bit integers. The attribute is created in the same
|
|
|
|
/// context as the type.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseElementsAttribute(
|
|
|
|
MlirType shapedType, MlirAttribute denseIndices, MlirAttribute denseValues);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the dense elements attribute containing 64-bit integer indices of
|
|
|
|
/// non-null elements in the given sparse elements attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirSparseElementsAttrGetIndices(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the dense elements attribute containing the non-null elements in the
|
|
|
|
/// given sparse elements attribute.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAttribute
|
|
|
|
mlirSparseElementsAttrGetValues(MlirAttribute attr);
|
2020-08-20 00:38:56 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-04 09:22:57 +08:00
|
|
|
#endif // MLIR_C_BUILTINATTRIBUTES_H
|