summaryrefslogtreecommitdiff
path: root/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
AgeCommit message (Collapse)Author
2025-01-29Reapply "[mlir][python] allow DenseIntElementsAttr for index type (#118947)" ↵Matthias Gehre
(#124804) This reapplies #118947 and adapts to nanobind.
2025-01-28Revert "[mlir][python] allow DenseIntElementsAttr for index type (#118947)"Matthias Gehre
This reverts commit 9dd762e8b10586e749b0ddf3542e5dccf8392395.
2025-01-28[mlir][python] allow DenseIntElementsAttr for index type (#118947)Matthias Gehre
Model the `IndexType` as `uint64_t` when converting to a python integer. With the python bindings, ```python DenseIntElementsAttr(op.attributes["attr"]) ``` used to `assert` when `attr` had `index` type like `dense<[1, 2, 3, 4]> : vector<4xindex>`. --------- Co-authored-by: Christopher McGirr <christopher.mcgirr@amd.com> Co-authored-by: Tiago Trevisan Jost <tiago.trevisanjost@amd.com>
2024-09-11[MLIR][Python] Python binding support for IntegerSet attribute (#107640)Amy Wang
Support IntegerSet attribute python binding.
2024-03-07[MLIR] Add llvm (debug) attributes to CAPI (#83992)Edgar
This PR adds the following to the mlir c api: - The disctinct mlir builtin attribute. - LLVM attributes (mostly debug related ones)
2023-09-14[mlir] Add Python bindings for DenseResourceElementsAttr. (#66319)Stella Laurenzo
Only construction and type casting are implemented. The method to create is explicitly named "unsafe" and the documentation calls out what the caller is responsible for. There really isn't a better way to do this and retain the power-user feature this represents.
2023-09-11[mlir] Make it possible to build a DenseResourceElementsAttr from untyped ↵Stella Laurenzo
memory. (#66009) Exposes the existing `get(ShapedType, StringRef, AsmResourceBlob)` builder publicly (was protected) and adds a CAPI `mlirUnmanagedDenseBlobResourceElementsAttrGet`. While such a generic construction interface is a big help when it comes to interop, it is also necessary for creating resources that don't have a standard C type (i.e. f16, the f8s, etc). Previously reviewed/approved as part of https://reviews.llvm.org/D157064
2023-07-05Add SymbolRefAttr to python bindingsmax
Differential Revision: https://reviews.llvm.org/D154541
2023-06-07[MLIR][python bindings] TypeCasters for Attributesmax
Differential Revision: https://reviews.llvm.org/D151840
2023-05-12[mlir] Update method cast calls to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Context: * https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" * Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This follows a previous patch that updated calls `op.cast<T>()-> cast<T>(op)`. However some cases could not handle an unprefixed `cast` call due to occurrences of variables named cast, or occurring inside of class definitions which would resolve to the method. All C++ files that did not work automatically with `cast<T>()` are updated here to `llvm::cast` and similar with the intention that they can be easily updated after the methods are removed through a find-replace. See https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check for the clang-tidy check that is used and then update printed occurrences of the function to include `llvm::` before. One can then run the following: ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -export-fixes /tmp/cast/casts.yaml mlir/*\ -header-filter=mlir/ -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc ``` Differential Revision: https://reviews.llvm.org/D150348
2023-01-24[MLIR] Expose LocationAttrs in the C APIAndrew Young
This patch adds three functions to the C API: - mlirAttributeIsALocation: returns true if the attribute is a LocationAttr, false otherwise. - mlirLocationGetAttribute: returns the underlying LocationAttr of a Location. - mlirLocationFromAttribute: gets a Location from a LocationAttr. Reviewed By: mikeurbach, Mogball Differential Revision: https://reviews.llvm.org/D142182
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2022-12-16[mlir-c] Add method to create unmanaged dense resource elements attrJacques Pienaar
Following DenseElementsAttr pattern. Differential Revision: https://reviews.llvm.org/D140189
2022-09-29[mlir] Add Python bindings for StridedLayoutAttrDenys Shabalin
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D134869
2022-09-29[mlir] Add C bindings for StridedArrayAttrDenys Shabalin
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D134808
2022-08-30[mlir] Make DenseArrayAttr genericJeff Niu
This patch turns `DenseArrayBaseAttr` into a fully-functional attribute by adding a generic parser and printer, supporting bool or integer and floating point element types with bitwidths divisible by 8. It has been renamed to `DenseArrayAttr`. The patch maintains the specialized subclasses, e.g. `DenseI32ArrayAttr`, which remain the preferred API for accessing elements in C++. This allows `DenseArrayAttr` to hold signed and unsigned integer elements: ``` array<si8: -128, 127> array<ui8: 255> ``` "Exotic" floating point elements: ``` array<bf16: 1.2, 3.4> ``` And integers of other bitwidths: ``` array<i24: 8388607> ``` Reviewed By: rriddle, lattner Differential Revision: https://reviews.llvm.org/D132758
2022-08-12[mlir][python] Add python bindings for DenseArrayAttrJeff Niu
This patch adds python bindings for the dense array variants. Fixes #56975 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131801
2022-08-01[mlir] Remove OpaqueElementsAttrRiver Riddle
This attribute is technical debt from the early stages of MLIR, before ElementsAttr was an interface and when it was more difficult for dialects to define their own types of attributes. At present it isn't used at all in tree (aside from being convenient for eliding other ElementsAttr), and has had little to no evolution in the past three years. Differential Revision: https://reviews.llvm.org/D129917
2022-07-20[MLIR] Add function to create Float16 array attributeTanyo Kwok
This patch adds a new function mlirDenseElementsAttrFloat16Get(), which accepts the shaped type, the number of Float16 values, and a pointer to an array of Float16 values, each of which is a uint16_t value. This commit is repeating https://reviews.llvm.org/D123981 + #761 but for Float16 Differential Revision: https://reviews.llvm.org/D130069
2022-05-12[DenseElementAttr] Simplify the public API for creating these.Chris Lattner
Instead of requiring the client to compute the "isSplat" bit, compute it internally. This makes the logic more consistent and defines away a lot of "elements.size()==1" in the clients. This addresses Issue #55185 Differential Revision: https://reviews.llvm.org/D125447
2022-04-19[MLIR] Add function to create BFloat16 array attributeAshay Rane
This patch adds a new function `mlirDenseElementsAttrBFloat16Get()`, which accepts the shaped type, the number of BFloat16 values, and a pointer to an array of BFloat16 values, each of which is a `uint16_t` value. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D123981
2022-02-24[mlir][python] Support more types in IntegerAttr.valuerkayaith
Previously only accessing values for `index` and signless int types would work; signed and unsigned ints would hit an assert in `IntegerAttr::getInt`. This exposes `IntegerAttr::get{S,U}Int` to the C API and calls the appropriate function from the python bindings. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D120194
2022-01-21[mlir][python] 8b/16b DenseIntElements accessRahul Kayaith
This extends dense attribute element access to support 8b and 16b ints. Also extends the corresponding parts of the C api. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D117731
2021-11-18[mlir] Convert NamedAttribute to be a classRiver Riddle
NamedAttribute is currently represented as an std::pair, but this creates an extremely clunky .first/.second API. This commit converts it to a class, with better accessors (getName/getValue) and also opens the door for more convenient API in the future. Differential Revision: https://reviews.llvm.org/D113956
2021-11-16[mlir][NFC] Replace references to Identifier with StringAttrRiver Riddle
This is part of the replacement of Identifier with StringAttr. Differential Revision: https://reviews.llvm.org/D113953
2021-11-11[mlir] Replace usages of Identifier with StringAttrRiver Riddle
Identifier and StringAttr essentially serve the same purpose, i.e. to hold a string value. Keeping these seemingly identical pieces of functionality separate has caused problems in certain situations: * Identifier has nice accessors that StringAttr doesn't * Identifier can't be used as an Attribute, meaning strings are often duplicated between Identifier/StringAttr (e.g. in PDL) The only thing that Identifier has that StringAttr doesn't is support for caching a dialect that is referenced by the string (e.g. dialect.foo). This functionality is added to StringAttr, as this is useful for StringAttr in generally the same ways it was useful for Identifier. Differential Revision: https://reviews.llvm.org/D113536
2021-11-09[mlir] Refactor ElementsAttr's value access APIRiver Riddle
There are several aspects of the API that either aren't easy to use, or are deceptively easy to do the wrong thing. The main change of this commit is to remove all of the `getValue<T>`/`getFlatValue<T>` from ElementsAttr and instead provide operator[] methods on the ranges returned by `getValues<T>`. This provides a much more convenient API for the value ranges. It also removes the easy-to-be-inefficient nature of getValue/getFlatValue, which under the hood would construct a new range for the type `T`. Constructing a range is not necessarily cheap in all cases, and could lead to very poor performance if used within a loop; i.e. if you were to naively write something like: ``` DenseElementsAttr attr = ...; for (int i = 0; i < size; ++i) { // We are internally rebuilding the APFloat value range on each iteration!! APFloat it = attr.getFlatValue<APFloat>(i); } ``` Differential Revision: https://reviews.llvm.org/D113229
2021-10-07[mlir] Extend C and Python API to support bulk loading of DenseElementsAttr.Stella Laurenzo
* This already half existed in terms of reading the raw buffer backing a DenseElementsAttr. * Documented the precise expectations of the buffer layout. * Extended the Python API to support construction from bitcasted buffers, allowing construction of all primitive element types (even those that lack a compatible representation in Python). * Specifically, the Python API can now load all integer types at all bit widths and all floating point types (f16, f32, f64, bf16). Differential Revision: https://reviews.llvm.org/D111284
2021-09-21[mlir] Add value_begin/value_end methods to DenseElementsAttrRiver Riddle
Currently DenseElementsAttr only exposes the ability to get the full range of values for a given type T, but there are many situations where we just want the beginning/end iterator. This revision adds proper value_begin/value_end methods for all of the supported T types, and also cleans up a bit of the interface. Differential Revision: https://reviews.llvm.org/D104173
2021-08-29[SymbolRefAttr] Revise SymbolRefAttr to hold a StringAttr.Chris Lattner
SymbolRefAttr is fundamentally a base string plus a sequence of nested references. Instead of storing the string data as a copies StringRef, store it as an already-uniqued StringAttr. This makes a lot of things simpler and more efficient because: 1) references to the symbol are already stored as StringAttr's: there is no need to copy the string data into MLIRContext multiple times. 2) This allows pointer comparisons instead of string comparisons (or redundant uniquing) within SymbolTable.cpp. 3) This allows SymbolTable to hold a DenseMap instead of a StringMap (which again copies the string data and slows lookup). This is a moderately invasive patch, so I kept a lot of compatibility APIs around. It would be nice to explore changing getName() to return a StringAttr for example (right now you have to use getNameAttr()), and eliminate things like the StringRef version of getSymbol. Differential Revision: https://reviews.llvm.org/D108899
2021-06-08[Core] Add Twine support for StringAttr and Identifier. NFC.Chris Lattner
This is both more efficient and more ergonomic than going through an std::string, e.g. when using llvm::utostr and in string concat cases. Unfortunately we can't just overload ::get(). This causes an ambiguity because both twine and stringref implicitly convert from std::string. Differential Revision: https://reviews.llvm.org/D103754
2021-05-19[mlir][CAPI] Expose [u]int8 DenseElementsAttr.Sean Silva
Also, fix a small typo where the "unsigned" splat variants were not being created with an unsigned type. Differential Revision: https://reviews.llvm.org/D102797
2021-04-12[mlir] introduce "encoding" attribute to tensor typeAart Bik
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-02-26[mlir] Simplify various pieces of code now that Identifier has access to the ↵River Riddle
Context/Dialect This also exposed a bug in Dialect loading where it was not correctly identifying identifiers that had the dialect namespace as a prefix. Differential Revision: https://reviews.llvm.org/D97431
2021-02-22[mlir][IR] Refactor the `getChecked` and `verifyConstructionInvariants` ↵River Riddle
methods on Attributes/Types `verifyConstructionInvariants` is intended to allow for verifying the invariants of an attribute/type on construction, and `getChecked` is intended to enable more graceful error handling aside from an assert. There are a few problems with the current implementation of these methods: * `verifyConstructionInvariants` requires an mlir::Location for emitting errors, which is prohibitively costly in the situations that would most likely use them, e.g. the parser. This creates an unfortunate code duplication between the verifier code and the parser code, given that the parser operates on llvm::SMLoc and it is an undesirable overhead to pre-emptively convert from that to an mlir::Location. * `getChecked` effectively requires duplicating the definition of the `get` method, creating a quite clunky workflow due to the subtle different in its signature. This revision aims to talk the above problems by refactoring the implementation to use a callback for error emission. Using a callback allows for deferring the costly part of error emission until it is actually necessary. Due to the necessary signature change in each instance of these methods, this revision also takes this opportunity to cleanup the definition of these methods by: * restructuring the signature of `getChecked` such that it can be generated from the same code block as the `get` method. * renaming `verifyConstructionInvariants` to `verify` to match the naming scheme of the rest of the compiler. Differential Revision: https://reviews.llvm.org/D97100
2021-02-08Revert "Revert "Reorder MLIRContext location in BuiltinAttributes.h""Tres Popp
This reverts commit 511dd4f4383b1c2873beac4dbea2df302f1f9d0c along with a couple fixes. Original message: Now the context is the first, rather than the last input. This better matches the rest of the infrastructure and makes it easier to move these types to being declaratively specified. Phabricator: https://reviews.llvm.org/D96111
2021-02-08Revert "Reorder MLIRContext location in BuiltinAttributes.h"Tres Popp
This reverts commit 7827753f9810e846fb702f3e8dcff0bfb37344e1.
2021-02-08Reorder MLIRContext location in BuiltinAttributes.hTres Popp
Now the context is the first, rather than the last input. This better matches the rest of the infrastructure and makes it easier to move these types to being declaratively specified. Differential Revision: https://reviews.llvm.org/D96111
2020-12-11Store a MlirIdentifier instead of a MlirStringRef in MlirNameAttributeMehdi Amini
This mirror the C++ API for NamedAttribute, and has the advantage or internalizing earlier in the Context and not requiring the caller to keep the StringRef alive beyong this call. Differential Revision: https://reviews.llvm.org/D93133
2020-12-03[mlir][Attributes][NFC] Move all builtin Attribute classes to ↵River Riddle
BuiltinAttributes.h This mirrors the file structure of Types. Differential Revision: https://reviews.llvm.org/D92499