summaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/Test/TestAttributes.cpp
AgeCommit message (Collapse)Author
2025-10-15[mlir][bufferization] Test tensor encoding -> memref layout conversion (#161166)Andrei Golubev
Support custom types (4/N): test that it is possible to customize memref layout specification for custom operations and function boundaries. This is purely a test setup (no API modifications) to ensure users are able to pass information from tensors to memrefs within bufferization process. To achieve this, a test pass is required (since bufferization options have to be set manually). As there is already a --test-one-shot-module-bufferize pass present, it is extended for the purpose.
2025-09-02[mlir][LLVM|ptr] Add the `#llvm.address_space` attribute, and allow `ptr` ↵Fabian Mora
translation (#156333) This commit introduces the `#llvm.address_space` attribute. This attribute implements the `ptr::MemorySpaceAttrInterface`, establishing the semantics of the LLVM address space. This allows making `!ptr.ptr` translatable to LLVM IR as long it uses the `#llvm.address_space` attribute. Concretely, `!ptr.ptr<#llvm.address_space<N>>` now translates to `ptr addrspace(N)`. Additionally, this patch makes `PtrLikeTypes` with no metadata, no element type, and with `#llvm.address_space` memory space, compatible with the LLVM dialect. **Infrastructure Updates:** - Refactor `ptr::MemorySpaceAttrInterface` to include DataLayout parameter for better validation - Add new utility functions `LLVM::isLoadableType()` and `LLVM::isTypeCompatibleWithAtomicOp()` - Update type compatibility checks to support ptr-like types with LLVM address spaces - Splice the `MemorySpaceAttrInterface` to its own library, so the LLVMDialect won't depend on the PtrDialect yet **Translation Support:** - New `PtrToLLVMIRTranslation` module for converting ptr dialect to LLVM IR - Type translation support for ptr types with LLVM address spaces - Proper address space preservation during IR lowering Example: ```mlir llvm.func @llvm_ops_with_ptr_values(%arg0: !llvm.ptr) { %1 = llvm.load %arg0 : !llvm.ptr -> !ptr.ptr<#llvm.address_space<1>> llvm.store %1, %arg0 : !ptr.ptr<#llvm.address_space<1>>, !llvm.ptr llvm.return } ``` Translates to: ```llvmir ; ModuleID = 'LLVMDialectModule' source_filename = "LLVMDialectModule" define void @llvm_ops_with_ptr_values(ptr %0) { %2 = load ptr addrspace(1), ptr %0, align 8 store ptr addrspace(1) %2, ptr %0, align 8 ret void } !llvm.module.flags = !{!0} !0 = !{i32 2, !"Debug Info Version", i32 3} ```
2025-09-01[mlir][ptr] Add load and store ops. (#156093)Fabian Mora
This patch adds the load and store operations to the ptr dialect. It's future work to implement SROA and Mem2Reg interfaces, as well as conversion to LLVM, and add alias information. This patch also fixes a bug in `OptionalProp` that was causing the bytecode writer to exit early of writing the Op props if an optional prop had the default value. Example: ```mlir func.func @load_ops(%arg0: !ptr.ptr<#ptr.generic_space>) -> (f32, f32, f32, f32, f32, i64, i32) { %0 = ptr.load %arg0 : !ptr.ptr<#ptr.generic_space> -> f32 %1 = ptr.load volatile %arg0 : !ptr.ptr<#ptr.generic_space> -> f32 %2 = ptr.load %arg0 nontemporal : !ptr.ptr<#ptr.generic_space> -> f32 %3 = ptr.load %arg0 invariant : !ptr.ptr<#ptr.generic_space> -> f32 %4 = ptr.load %arg0 invariant_group : !ptr.ptr<#ptr.generic_space> -> f32 %5 = ptr.load %arg0 atomic monotonic alignment = 8 : !ptr.ptr<#ptr.generic_space> -> i64 %6 = ptr.load volatile %arg0 atomic syncscope("workgroup") acquire nontemporal alignment = 4 : !ptr.ptr<#ptr.generic_space> -> i32 return %0, %1, %2, %3, %4, %5, %6 : f32, f32, f32, f32, f32, i64, i32 } func.func @store_ops(%arg0: !ptr.ptr<#ptr.generic_space>, %arg1: f32, %arg2: i64, %arg3: i32) { ptr.store %arg1, %arg0 : f32, !ptr.ptr<#ptr.generic_space> ptr.store volatile %arg1, %arg0 : f32, !ptr.ptr<#ptr.generic_space> ptr.store %arg1, %arg0 nontemporal : f32, !ptr.ptr<#ptr.generic_space> ptr.store %arg1, %arg0 invariant_group : f32, !ptr.ptr<#ptr.generic_space> ptr.store %arg2, %arg0 atomic monotonic alignment = 8 : i64, !ptr.ptr<#ptr.generic_space> ptr.store volatile %arg3, %arg0 atomic syncscope("workgroup") release nontemporal alignment = 4 : i32, !ptr.ptr<#ptr.generic_space> return } ``` Finally, this patch allows testing more advanced features of ptr memory spaces, for example: ```mlir // mlir-opt -verify-diagnostics func.func @store_const(%arg0: !ptr.ptr<#test.const_memory_space>, %arg1: i64) { // expected-error@+1 {{memory space is read-only}} ptr.store %arg1, %arg0 atomic monotonic alignment = 8 : i64, !ptr.ptr<#test.const_memory_space> return } ```
2025-07-29Avoid copies in getChecked (#147721)Alexandru Lorinti
Following-up on #68067 ; adding std::move to getChecked method as well.
2025-07-11[mlir][ODS] Fix TableGen for AttrOrTypeDef::hasStorageCustomConstructor ↵Andrei Golubev
(#147957) There is a `hasStorageCustomConstructor` flag that allows one to provide custom attribute/type construction implementation. Unfortunately, it seems like the flag does not work properly: the generated C++ produces *empty body* method instead of producing only a declaration.
2025-06-21[mlir] Migrate away from ArrayRef(std::nullopt) (NFC) (#145140)Kazu Hirata
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch takes care of the mlir side of the migration, starting with straightforward places like "return std::nullopt;" and ternally expressions involving std::nullopt.
2025-05-14[MLIR][parser] Add token type and parser methods for forward slashes (#125056)Andi Drebes
This adds a token for a forward slash to the token definition list and the methods to `AsmParser::parseSlash()` and `AsmParser::parseOptionalSlash()`, similar to other tokens used as operators (e.g., star, plus, etc.). This allows implementations of attributes that contain arithmetic expressions to support operators with a forward slash, e.g., a division. The newly added check tests trigger the parsing of a slash in an attribute.
2025-04-30[mlir][tblgen] Add custom parsing and printing within struct (#133939)Jorn Tuyls
This PR extends the `struct` directive in tablegen to support nested `custom` directives. Note that this assumes/verifies that that `custom` directive has a single parameter. This enables defining custom field parsing and printing functions if the `struct` directive doesn't suffice. There is some existing potential downstream usage for it: https://github.com/openxla/stablehlo/blob/a3c7de92425e8035437dae67ab2318a82eca79a1/stablehlo/dialect/StablehloOps.cpp#L3102
2025-04-27[mlir][ptr] Switch `LogicalResult` to `bool` in `MemorySpaceAttrInterrface` ↵Fabian Mora
(#137513) This patch switches the return type in `MemorySpaceAttrInterface` methods from `LogicalResult` to `bool`. As `is*` methods are predicates. Users of the `MemorySpaceAttrInterface` API must note that, if `emitError` is non-null and the result of a `is*` method is `false`, then an error was likely emitted. To avoid the emission of an error the user can pass a default constructed `emitError`.
2025-03-19[mlir][Ptr] Add the `MemorySpaceAttrInterface` interface and dependencies. ↵Fabian Mora
(#86870) This patch introduces the `MemorySpaceAttrInterface` interface. This interface is responsible for handling the semantics of `ptr` operations. For example, this interface can be used to create read-only memory spaces, making any other operation other than a load a verification error, see `TestConstMemorySpaceAttr` for a possible implementation of this concept. This patch also introduces Enum dependencies `AtomicOrdering`, and `AtomicBinOp`, both enumerations are clones of the Enums with the same name in the LLVM Dialect. Also, see: - [[RFC] `ptr` dialect & modularizing ptr ops in the LLVM dialect](https://discourse.llvm.org/t/rfc-ptr-dialect-modularizing-ptr-ops-in-the-llvm-dialect/75142) for rationale. - https://github.com/llvm/llvm-project/pull/73057 for a prototype implementation of the full change. **Note: Ignore the first commit, that's being reviewed in https://github.com/llvm/llvm-project/pull/86860 .**
2025-02-19[mlir] Introduce OpAsmAttrInterface for pretty-print (#124721)Hongren Zheng
See https://discourse.llvm.org/t/rfc-introduce-opasm-type-attr-interface-for-pretty-print-in-asmprinter/83792 for detailed introduction. This PR adds * Definition of `OpAsmAttrInterface` * Integration of `OpAsmAttrInterface` with `AsmPrinter` In https://github.com/llvm/llvm-project/pull/121187#discussion_r1931472250 I mentioned splitting them into two PRs, but I realized that a PR with only definition of `OpAsmAttrInterface` is hard to test as it requires a custom Dialect with `OpAsmDialectInterface` to hook with `AsmPrinter`, so I just put them together to have a e2e test. Cc @River707 @jpienaar @ftynse for review.
2024-07-23Add AsmParser::parseDecimalInteger. (#96255)quartersdg
An attribute parser needs to parse lists of possibly negative integers separated by x in a way which is foiled by parseInteger handling hex formats and parseIntegerInDimensionList does not allow negatives. --------- Co-authored-by: Jacques Pienaar <jpienaar@google.com>
2024-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-05-04[MLIR] Extend floating point parsing support (#90442)orbiri
Parsing support for floating point types was missing a few features: 1. Parsing floating point attributes from integer literals was supported only for types with bitwidth smaller or equal to 64. 2. Downstream users could not use `AsmParser::parseFloat` to parse float types which are printed as integer literals. This commit addresses both these points. It extends `Parser::parseFloatFromIntegerLiteral` to support arbitrary bitwidth, and exposes a new API to parse arbitrary floating point given an fltSemantics as input. The usage of this new API is introduced in the Test Dialect.
2024-04-22[mlir][test] Reorganize the test dialect (#89424)Jeff Niu
This PR massively reorganizes the Test dialect's source files. It moves manually-written op hooks into `TestOpDefs.cpp`, moves format custom directive parsers and printers into `TestFormatUtils`, adds missing comment blocks, and moves around where generated source files are included for types, attributes, enums, etc. into their own source file. This will hopefully help navigate the test dialect source code, but also speeds up compile time of the test dialect by putting generated source files into separate compilation units. This also sets up the test dialect to shard its op definitions, done in the next PR.
2024-02-25Fix TestI64ElementsAttr printer (#82931)Matteo Franciolini
This enables to correctly roundtrip the attribute to text or bytecode.
2024-01-23[mlir] Add example of `printAlias` to test dialect (NFC) (#79232)Jeff Niu
Follow-up from previous pull request. Motivate the API change with an attribute that decides between sugaring a sub-attribute or using an alias
2023-10-03Improve MLIR Attribute::get() method efficiency by reducing the amount of ↵Mehdi Amini
argument copies (#68067) This ensures that the proper std::forward/std::move are involved, we go from 6 copy-constructions to 0 (!) on Attribute creation in release builds.
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-04-03[mlir] Improve FieldParser list container detectionrkayaith
The current detection logic will fail for containers with an overloaded `push_back` member. This causes issues with types like `std::vector` and `SmallVector<SomeNonTriviallyCopyableT>`, which have both `push_back(const T&)` and `push_back(T&&)`. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D147101
2023-01-22[mlir][ods] Simplify signature of `custom` printers and parsers of ↵Markus Böck
Attributes and Types in presence of default constructible parameters The vast majority of parameters of C++ types used as parameters for Attributes and Types are likely to be default constructible. Nevertheless, TableGen conservatively generates code for the custom directive, expecting signatures using FailureOr<T> for all parameter types T to accomodate them possibly not being default constructible. This however reduces the ergonomics of the likely case of default constructible parameters. This patch fixes that issue, while barely changing the generated TableGen code, by using a helper function that is used to pass any parameters into custom parser methods. If the type is default constructible, as deemed by the C++ compiler, a default constructible instance is created and passed into the parser method by reference. In all other cases it is a Noop and a FailureOr is passed as before. Documentation was also updated to document the new behaviour. Fixes https://github.com/llvm/llvm-project/issues/60178 Differential Revision: https://reviews.llvm.org/D142301
2022-12-20mlir/{SPIRV,Bufferization}: use std::optional in .td files (NFC)Ramkumar Ramachandra
This is part of an effort to migrate from llvm::Optional to std::optional. 22426110c5ef changed the way mlir-tblgen generates .inc files, emitting std::optional when an Optional attribute is specified in a .td file. It also changed several .td files hard-coding llvm::Optional to use std::optional. However, the patch excluded a few .td files in SPIRV and Bufferization hard-coding llvm::Optional. This patch fixes that defect, and after this patch, references to llvm::Optional in .cpp and .h files can be replaced mechanically. See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Signed-off-by: Ramkumar Ramachandra <r@artagnon.com> Differential Revision: https://reviews.llvm.org/D140329
2022-12-03[mlir] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-18[MLIR] Add FieldParser implementation for Optional<> integer types.Nick Kreeger
This patch introduces a templated FieldParser to handle optional signed and unsigned integer types - NFC. Additionally, I've added an extra test to ensure that both signed and unsigned integers are properly tested in the templated integer types for FieldParser as well.
2022-11-04[mlir] Infer SubElementInterface implementations using the storage KeyTyRiver Riddle
The KeyTy of attribute/type storage classes provide enough information for automatically implementing the necessary sub element interface methods. This removes the need for derived classes to do it themselves, which is both much nicer and easier to handle certain invariants (e.g. null handling). In cases where explicitly handling for parameter types is necessary, they can provide an implementation of `AttrTypeSubElementHandler` to opt-in to support. This tickles a few things alias wise, which annoyingly messes with tests that hard code specific affine map numbers. Differential Revision: https://reviews.llvm.org/D137374
2022-10-12[mlir][ods] Allow custom directives in optional groupsJeff Niu
Attributes and types only (so far). Since `struct` and `params` are allowed, it makes sense to allow custom directives as long as their arguments contain at least one bound argument. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D135001
2022-09-17[mlir] Don't include SetVector.h (NFC)Kazu Hirata
2022-08-01[mlir] Add a generic DialectResourceBlobManager to simplify resource blob ↵River Riddle
management The DialectResourceBlobManager class provides functionality for managing resource blobs in a generic, dialect-agnostic fashion. In addition to this class, a dialect interface and custom resource handle are provided to simplify referencing and interacting with the manager. These classes intend to simplify the work required for dialects that want to manage resource blobs during compilation, such as for large elements attrs. The old manager for the resource example in the test dialect has been updated to use this, which provides and cleaner and more consistent API. This commit also adds new HeapAsmResourceBlob and ImmortalAsmResourceBlob to simplify creating resource blobs in common scenarios. Differential Revision: https://reviews.llvm.org/D130021
2022-07-31[mlir] Remove types from attributesJeff Niu
This patch removes the `type` field from `Attribute` along with the `Attribute::getType` accessor. Going forward, this means that attributes in MLIR will no longer have types as a first-class concept. This patch lays the groundwork to incrementally remove or refactor code that relies on generic attributes being typed. The immediate impact will be on attributes that rely on `Attribute` containing a type, such as `IntegerAttr`, `DenseElementsAttr`, and `ml_program::ExternAttr`, which will now need to define a type parameter on their storage classes. This will save memory as all other attribute kinds will no longer contain a type. Moreover, it will not be possible to generically query the type of an attribute directly. This patch provides an attribute interface `TypedAttr` that implements only one method, `getType`, which can be used to generically query the types of attributes that implement the interface. This interface can be used to retain the concept of a "typed attribute". The ODS-generated accessor for a `type` parameter automatically implements this method. Next steps will be to refactor the assembly formats of certain operations that rely on `parseAttribute(type)` and `printAttributeWithoutType` to remove special handling of type elision until `type` can be removed from the dialect parsing hook entirely; and incrementally remove uses of `TypedAttr`. Reviewed By: lattner, rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D130092
2022-07-26[mlir] Refactor SubElementInterface replace supportRiver Riddle
The current support was essentially the amount necessary to support replacing SymbolRefAttrs, but suffers from various deficiencies (both ergonomic and functional): * Replace crashes if unsupported This makes it really hard to use safely, given that you don't know if you are going to crash or not when using it. * Types aren't supported This seems like a simple missed addition when the attribute replacement support was originally added. * The ergonomics are weird It currently uses an index based replacement, which makes the implementations quite clunky. This commit refactors support to be a bit more ergonomic, and also adds support for types in the process. This was also a great oppurtunity to greatly simplify how replacement is done in the symbol table. Fixes #56355 Differential Revision: https://reviews.llvm.org/D130589
2022-06-29[mlir] Allow for attaching external resources to .mlir filesRiver Riddle
This commit enables support for providing and processing external resources within MLIR assembly formats. This is a mechanism with which dialects, and external clients, may attach additional information when printing IR without that information being encoded in the IR itself. External resources are not uniqued within the MLIR context, are not attached directly to any operation, and are solely intended to live and be processed outside of the immediate IR. There are many potential uses of this functionality, for example MLIR's pass crash reproducer could utilize this to attach the pass resource executing when a crash occurs. Other types of uses may be embedding large amounts of binary data, such as weights in ML applications, that shouldn't be copied directly into the MLIR context, but need to be kept adjacent to the IR. External resources are encoded using a key-value pair nested within a dictionary anchored by name either on a dialect, or an externally registered entity. The key is an identifier used to disambiguate the data. The value may be stored in various limited forms, but general encodings use a string (human readable) or blob format (binary). Within the textual format, an example may be of the form: ```mlir {-# // The `dialect_resources` section within the file-level metadata // dictionary is used to contain any dialect resource entries. dialect_resources: { // Here is a dictionary anchored on "foo_dialect", which is a dialect // namespace. foo_dialect: { // `some_dialect_resource` is a key to be interpreted by the dialect, // and used to initialize/configure/etc. some_dialect_resource: "Some important resource value" } }, // The `external_resources` section within the file-level metadata // dictionary is used to contain any non-dialect resource entries. external_resources: { // Here is a dictionary anchored on "mlir_reproducer", which is an // external entity representing MLIR's crash reproducer functionality. mlir_reproducer: { // `pipeline` is an entry that holds a crash reproducer pipeline // resource. pipeline: "func.func(canonicalize,cse)" } } ``` Differential Revision: https://reviews.llvm.org/D126446
2022-06-28Fix printing for ArrayRef attributes/types in declarative assembly formatMehdi Amini
These were abbreviated when parsing, but not when printing. Reviewed By: Mogball, rriddle Differential Revision: https://reviews.llvm.org/D128720
2022-05-16[mlir][ods] Ignore AttributeSelfTypeParameter in assembly formatsMogball
The attribute self type parameter is currently treated like any other attribute parameter in the assembly format. The self type parameter should be handled by the operation parser and printer and play no role in the generated parsers and printers of attributes. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D125724
2022-04-26[mlir] Add extensible dialectsMathieu Fehr
Depends on D104534 Add support for extensible dialects, which are dialects that can be extended at runtime with new operations and types. These operations and types cannot at the moment implement traits or interfaces. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D104554
2022-03-03Revert "[mlir] Add extensible dialects"Andrzej Warzynski
This reverts commit dbe9f0914fcfd8444fd9656821af0f1a34a27e7a. The flang-x86_64-windows buildbot has been failing since this has been merged: * https://lab.llvm.org/buildbot/#/builders/172/builds/9124 Similar failure was reported by the pre-commit CI.
2022-03-02[mlir] Add extensible dialectsMathieu Fehr
Add support for extensible dialects, which are dialects that can be extended at runtime with new operations and types. These operations and types cannot at the moment implement traits or interfaces. Differential Revision: https://reviews.llvm.org/D104554
2022-01-03Revert "Define a `cppAccessorType` to const-ref in APFloatParameter and ↵Mehdi Amini
update ODS emitter to use it for verifier signatures" This reverts commit 89af17c0c74eb9d8d11870f6510e475eff74eef4. This broke the gcc5 build.
2022-01-03Define a `cppAccessorType` to const-ref in APFloatParameter and update ODS ↵Mehdi Amini
emitter to use it for verifier signatures This reduce an unnecessary amount of copy of non-trivial objects, like APFloat. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D116505
2021-11-11Use base class AsmParser/AsmPrinter in Types and Attribute print/parse ↵Mehdi Amini
method (NFC) This decouples the printing/parsing from the "context" in which the parsing occurs. This will allow to invoke these methods directly using an OpAsmParser/OpAsmPrinter. Differential Revision: https://reviews.llvm.org/D113637
2021-11-10Change the contract with the type/attribute parsing to let the dispatch ↵Mehdi Amini
handle the mnemonic This breaking change requires to remove printing the mnemonic in the print() method on Type/Attribute classes. This makes it consistent with the parsing code which alread handles the mnemonic outside of the parsing method. This likely won't break the build for anyone, but tests will start failing for dialects downstream. The fix is trivial and look like going from: void emitc::OpaqueType::print(DialectAsmPrinter &printer) const { printer << "opaque<\""; to: void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) const { printer << "<\""; Reviewed By: rriddle, aartbik Differential Revision: https://reviews.llvm.org/D113334
2021-11-10Emit the boilerplate for Attribute printer/parser dialect dispatching from ODSMehdi Amini
Add a new `useDefaultAttributePrinterParser` boolean settings on the dialect (default to false for now) that emits the boilerplate to dispatch attribute parsing/printing to the auto-generated method. We will likely turn this on by default in the future. Differential Revision: https://reviews.llvm.org/D113329
2021-11-08[MLIR] Attribute and type formats in ODSJeff Niu
Declarative attribute and type formats with assembly formats. Define an `assemblyFormat` field in attribute and type defs with a `mnemonic` to generate a parser and printer. ```tablegen def MyAttr : AttrDef<MyDialect, "MyAttr"> { let parameters = (ins "int64_t":$count, "AffineMap":$map); let mnemonic = "my_attr"; let assemblyFormat = "`<` $count `,` $map `>`"; } ``` Use `struct` to define a comma-separated list of key-value pairs: ```tablegen def MyType : TypeDef<MyDialect, "MyType"> { let parameters = (ins "int":$one, "int":$two, "int":$three); let mnemonic = "my_attr"; let assemblyFormat = "`<` $three `:` struct($one, $two) `>`"; } ``` Use `struct(*)` to capture all parameters. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D111594
2021-10-28[mlir] Implement replacement of SymbolRefAttrs in Dialect attributes using ↵Markus Böck
SubElementAttr interface This patch extends the SubElementAttr interface to allow replacing a contained sub attribute. The attribute that should be replaced is identified by an index which denotes the n-th element returned by the accompanying walkImmediateSubElements method. Using this addition the patch implements replacing SymbolRefAttrs contained within any dialect attributes. Differential Revision: https://reviews.llvm.org/D111357
2021-09-30[ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser.Chris Lattner
The former is redundant because the later carries it as part of its builder. Add a getContext() helper method to DialectAsmParser to make this more convenient, and stop passing the context around explicitly. This simplifies ODS generated parser hooks for attrs and types. This resolves PR51985 Recommit 4b32f8bac4 after fixing a dependency. Differential Revision: https://reviews.llvm.org/D110796
2021-09-30Revert "[ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser."Mehdi Amini
This reverts commit 4b32f8bac40dcd1535bfe95757c3de0911bf6d1a. Seems like the build is broken with -DDBUILD_SHARED_LIBS=ON
2021-09-29[ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser.Chris Lattner
The former is redundant because the later carries it as part of its builder. Add a getContext() helper method to DialectAsmParser to make this more convenient, and stop passing the context around explicitly. This simplifies ODS generated parser hooks for attrs and types. This resolves PR51985 Differential Revision: https://reviews.llvm.org/D110796
2021-09-21[mlir] Refactor ElementsAttr into an AttrInterfaceRiver Riddle
This revision refactors ElementsAttr into an Attribute Interface. This enables a common interface with which to interact with element attributes, without needing to modify the builtin dialect. It also removes a majority (if not all?) of the need for the current OpaqueElementsAttr, which was originally intended as a way to opaquely represent data that was not representable by the other builtin constructs. The new ElementsAttr interface not only allows for users to natively represent their data in the way that best suits them, it also allows for efficient opaque access and iteration of the underlying data. Attributes using the ElementsAttr interface can directly expose support for interacting with the held elements using any C++ data type they claim to support. For example, DenseIntOrFpElementsAttr supports iteration using various native C++ integer/float data types, as well as APInt/APFloat, and more. ElementsAttr instances that refer to DenseIntOrFpElementsAttr can use all of these data types for iteration: ```c++ DenseIntOrFpElementsAttr intElementsAttr = ...; ElementsAttr attr = intElementsAttr; for (uint64_t value : attr.getValues<uint64_t>()) ...; for (APInt value : attr.getValues<APInt>()) ...; for (IntegerAttr value : attr.getValues<IntegerAttr>()) ...; ``` ElementsAttr also supports failable range/iterator access, allowing for selective code paths depending on data type support: ```c++ ElementsAttr attr = ...; if (auto range = attr.tryGetValues<uint64_t>()) { for (uint64_t value : *range) ...; } ``` Differential Revision: https://reviews.llvm.org/D109190
2021-08-14[MLIR] Move TestDialect to ::test namespaceStephen Neuendorffer
While the changes are extensive, they basically fall into a few categories: 1) Moving the TestDialect itself. 2) Updating C++ code in tablegen to explicitly use ::mlir, since it will be put in a headers that shouldn't expect a 'using'. 3) Updating some generic MLIR Interface definitions to do the same thing. 4) Updating the Tablegen generator in a few places to be explicit about namespaces 5) Doing the same thing for llvm references, since we no longer pick up the definitions from mlir/Support/LLVM.h Differential Revision: https://reviews.llvm.org/D88251
2021-06-15[mlir] separable registration of attribute and type interfacesAlex Zinenko
It may be desirable to provide an interface implementation for an attribute or a type without modifying the definition of said attribute or type. Notably, this allows to implement interfaces for attributes and types outside of the dialect that defines them and, in particular, provide interfaces for built-in types. Provide the mechanism to do so. Currently, separable registration requires the attribute or type to have been registered with the context, i.e. for the dialect containing the attribute or type to be loaded. This can be relaxed in the future using a mechanism similar to delayed dialect interface registration. See https://llvm.discourse.group/t/rfc-separable-attribute-type-interfaces/3637 Depends On D104233 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D104234
2021-03-11[mlir][StorageUniquer] Properly call the destructor on non-trivially ↵River Riddle
destructible storage instances This allows for storage instances to store data that isn't uniqued in the context, or contain otherwise non-trivial logic, in the rare situations that they occur. Storage instances with trivial destructors will still have their destructor skipped. A consequence of this is that the storage instance definition must be visible from the place that registers the type. Differential Revision: https://reviews.llvm.org/D98311