summaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/Test/TestDialect.cpp
AgeCommit message (Collapse)Author
2025-11-08[mlir] Remove duplicate includes (NFC) (#167187)Kazu Hirata
Identified with readability-duplicate-include.
2025-09-26Allowing RDV to call `getArgOperandsMutable()` (#160415)Francisco Geiman Thiesen
## Problem `RemoveDeadValues` can legally drop dead function arguments on private `func.func` callees. But call-sites to such functions aren't fixed if the call operation keeps its call arguments in a **segmented operand group** (i.ie, uses `AttrSizedOperandSegments`), unless the call op implements `getArgOperandsMutable` and the RDV pass actually uses it. ## Fix When RDV decides to drop callee function args, it should, for each call-site that implements `CallOpInterface`, **shrink the call's argument segment** via `getArgOperandsMutable()` using the same dead-arg indices. This keeps both the flat operand list and the `operand_segment_sizes` attribute in sync (that's what `MutableOperandRange` does when bound to the segment). ## Note This change is a no-op for: * call ops without segment operands (they still get their flat operands erased via the generic path) * call ops whose calle args weren't dropped (public, external, non-`func-func`, unresolved symbol, etc) * `llvm.call`/`llvm.invoke` (RDV doesn't drop `llvm.func` args --------- Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2025-08-27[MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in ↵Mehdi Amini
TestDialect.cpp (NFC)
2025-07-25[mlir][NFC] update `mlir/Dialect` create APIs (28/n) (#150641)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
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-04-24[mlir][test] Shard the Test Dialect (NFC) (#89628)Jeff Niu
This PR uses the new op sharding mechanism in tablegen to shard the test dialect's op definitions. This breaks the definition of ops into multiple source files, speeding up compile time of the test dialect dramatically. This improves developer cycle times when iterating on 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-04-16[mlir][test] Fix -Wsign-compare in TestDialect.cpp (NFC)Jie Fu
llvm-project/mlir/test/lib/Dialect/Test/TestDialect.cpp:597:31: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int64_t' (aka 'long') [-Werror,-Wsign-compare] if (getVarOperands().size() != expectedNumOperands) ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~ 1 error generated.
2024-04-16[mlir][Interfaces] `Variable` abstraction for `ValueBoundsOpInterface` (#87980)Matthias Springer
This commit generalizes and cleans up the `ValueBoundsConstraintSet` API. The API used to provide function overloads for comparing/computing bounds of: - index-typed SSA value - dimension of shaped value - affine map + operands This commit removes all overloads. There is now a single entry point for each `compare` variant and each `computeBound` variant. These functions now take a `Variable`, which is internally represented as an affine map and map operands. This commit also adds support for computing bounds for an affine map + operands. There was previously no public API for that.
2024-04-15[mlir][Interfaces][NFC] Add TableGen test op for value bounds tests (#88717)Matthias Springer
This commit is a code cleanup. It defines the test ops the are used for the `ValueBoundsOpInterface` tests in TableGen, along with proper verifiers. --------- Co-authored-by: Benjamin Maxwell <benjamin.maxwell@arm.com>
2024-04-15[mlir][ODS] Make `prop-dict` behave closer to `attr-dict` (#88659)Markus Böck
`attr-dict` currently prints any attribute (inherent or discardable) that does not occur elsewhere in the assembly format. `prop-dict` on the other hand, always prints and parses all properties (including inherent attributes stored as properties) as part of the property dictionary, regardless of whether the properties or attributes are used elsewhere. (with the exception of default-valued attributes implemented recently in https://github.com/llvm/llvm-project/pull/87970). This PR changes the behavior of `prop-dict` to only print and parse attributes and properties that do not occur elsewhere in the assembly format. This is achieved by 1) adding used attributes and properties to the elision list when printing and 2) using a custom version of `setPropertiesFromAttr` called `setPropertiesFromParsedAttr` that is sensitive to the assembly format and auto-generated by ODS. The current and new behavior of `prop-dict` and `attr-dict` were also documented. Happens to also fix https://github.com/llvm/llvm-project/issues/88506
2024-03-13[mlir][ods] Fix generation of optional custom parsers (#84821)Jeff Niu
We need to generate `.has_value` for `OptionalParseResult`, also ensure that `auto result` doesn't conflict with `result` which is the variable name for `OperationState`.
2024-01-21[mlir][bufferization] Buffer deallocation: Make op preconditions stricter ↵Matthias Springer
(#75127) The buffer deallocation pass checks the IR ("operation preconditions") to make sure that there is no IR that is unsupported. In such a case, the pass signals a failure. The pass now rejects all ops with unknown memory effects. We do not know whether such an op allocates memory or not. Therefore, the buffer deallocation pass does not know whether a deallocation op should be inserted or not. Memory effects are queried from the `MemoryEffectOpInterface` interface. Ops that do not implement this interface but have the `RecursiveMemoryEffects` trait do not have any side effects (apart from the ones that their nested ops may have). Unregistered ops are now rejected by the pass because they do not implement the `MemoryEffectOpInterface` and neither do we know if they have `RecursiveMemoryEffects` or not. All test cases that currently have unregistered ops are updated to use registered ops.
2024-01-04[mlir][RegionBranchOpInterface] explicitly check for existance of block ↵Maksim Levental
terminator (#76831)
2023-12-20[mlir] Require folders to produce Values of same type (#75887)Matthias Springer
This commit adds extra assertions to `OperationFolder` and `OpBuilder` to ensure that the types of the folded SSA values match with the result types of the op. There used to be checks that discard the folded results if the types do not match. This commit makes these checks stricter and turns them into assertions. Discarding folded results with the wrong type (without failing explicitly) can hide bugs in op folders. Two such bugs became apparent in MLIR (and some more in downstream projects) and are fixed with this change. Note: The existing type checks were introduced in https://reviews.llvm.org/D95991. Migration guide: If you see failing assertions (`folder produced value of incorrect type`; make sure to run with assertions enabled!), run with `-debug` or dump the operation right before the failing assertion. This will point you to the op that has the broken folder. A common mistake is a mismatch between static/dynamic dimensions (e.g., input has a static dimension but folded result has a dynamic dimension).
2023-10-31[mlir][bytecode] Implements back deployment capability for MLIR dialects ↵Matteo Franciolini
(#70724) When emitting bytecode, clients can specify a target dialect version to emit in `BytecodeWriterConfig`. This exposes a target dialect version to the DialectBytecodeWriter, which can be queried by name and used to back-deploy attributes, types, and properties.
2023-10-25[MLIR] Properly add operations to blocks during `createOrFold` (#70010)Morten Borup Petersen
Fixes #68884.
2023-10-04[mlir][ODS] Change `get...Mutable` to return `OpOperand &` for single ↵Matthias Springer
operands (#66519) The TableGen code generator now generates C++ code that returns a single `OpOperand &` for `get...Mutable` of operands that are not variadic and not optional. `OpOperand::set`/`assign` can be used to set a value (same as `MutableOperandRange::assign`). This is safer than `MutableOperandRange` because only single values (and no longer `ValueRange`) can be assigned. E.g.: ``` // Assignment of multiple values to non-variadic operand. // Before: Compiles, but produces invalid op. // After: Compilation error. extractSliceOp.getSourceMutable().assign({v1, v2}); ```
2023-09-26Simplify diagnostic error management for MLIR properties API (NFC) (#67409)Mehdi Amini
This is a follow-up to 8c2bff1ab929 which lazy-initialized the diagnostic and removed the need to dynamically abandon() an InFlightDiagnostic. This further simplifies the code to not needed to return a reference to an InFlightDiagnostic and instead eagerly emit errors. Also use `emitError` as name instead of `getDiag` which seems more explicit and in-line with the common usage.
2023-09-14[mlir] Allow loop-like operations in `AbstractDenseForwardDataFlowAnalysis` ↵vic
(#66179) Remove assertion violated by loop-like operations. Signed-off-by: Victor Perez <victor.perez@codeplay.com>
2023-09-12Update some uses of `getAttr()` to be explicit about Inherent vs Discardable ↵Mehdi Amini
(NFC)
2023-09-11Lazy initialize diagnostic when handling MLIR properties (#65868)Mehdi Amini
Instead of eagerly creating a diagnostic that will be discarded in the normal case, switch to lazy initialization on error.
2023-09-05[mlir] Add `empty` to `StringAttr`Mogball
It was common to see `value.getValue().empty()` or `value.size()` instead of the idiomatic `value.empty()`. Depends on D159455 Differential Revision: https://reviews.llvm.org/D159456
2023-08-31[mlir] Move FunctionInterfaces to Interfaces directory and inherit from ↵Martin Erhart
CallableOpInterface Functions are always callable operations and thus every operation implementing the `FunctionOpInterface` also implements the `CallableOpInterface`. The only exception was the FuncOp in the toy example. To make implementation of the `FunctionOpInterface` easier, this commit lets `FunctionOpInterface` inherit from `CallableOpInterface` and merges some of their methods. More precisely, the `CallableOpInterface` has methods to get the argument and result attributes and a method to get the result types of the callable region. These methods are always implemented the same way as their analogues in `FunctionOpInterface` and thus this commit moves all the argument and result attribute handling methods to the callable interface as well as the methods to get the argument and result types. The `FuntionOpInterface` then does not have to declare them as well, but just inherits them from the `CallableOpInterface`. Adding the inheritance relation also required to move the `FunctionOpInterface` from the IR directory to the Interfaces directory since IR should not depend on Interfaces. Reviewed By: jpienaar, springerm Differential Revision: https://reviews.llvm.org/D157988
2023-08-30Reland "[mlir] Use a type for representing branch points in ↵Markus Böck
`RegionBranchOpInterface`" This reverts commit b26bb30b467b996c9786e3bd426c07684d84d406.
2023-08-29Revert "[mlir] Use a type for representing branch points in ↵Markus Böck
`RegionBranchOpInterface`" This reverts commit 024f562da67180b7be1663048c960b26c2cc16f8. Forgot to update flang
2023-08-29[mlir] Use a type for representing branch points in `RegionBranchOpInterface`Markus Böck
The current implementation is not very ergonomic or descriptive: It uses `std::optional<unsigned>` where `std::nullopt` represents the parent op and `unsigned` is the region number. This doesn't give us any useful methods specific to region control flow and makes the code fragile to changes due to now taking the region number into account. This patch introduces a new type called `RegionBranchPoint`, replacing all uses of `std::optional<unsigned>` in the interface. It can be implicitly constructed from a region or a `RegionSuccessor`, can be compared with a region to check whether the branch point is branching from the parent, adds `isParent` to check whether we are coming from a parent op and adds `RegionSuccessor::parent` as a descriptive way to indicate branching from the parent. Differential Revision: https://reviews.llvm.org/D159116
2023-08-11[MLIR][analysis] Fix call op handling in sparse backward dataflowSrishti Srivastava
Currently, data in `AbstractSparseBackwardDataFlowAnalysis` is considered to flow one-to-one, in order, from the operands of an op implementing `CallOpInterface` to the arguments of the function it is calling. This understanding of the data flow is inaccurate. The operands of such an op that forward to the function arguments are obtained using a method provided by `CallOpInterface` called `getArgOperands()`. This commit fixes this bug by using `getArgOperands()` instead of `getOperands()` to get the mapping from operands to function arguments because not all operands necessarily forward to the function arguments and even if they do, they don't necessarily have to be in the order in which they appear in the op. The operands that don't get forwarded are handled by the newly introduced `visitCallOperand()` function, which works analogous to the `visitBranchOperand()` function. This fix is also propagated to liveness analysis that earlier relied on this incorrect implementation of the sparse backward dataflow analysis framework and corrects some incorrect assumptions made in it. Extra cleanup: Improved a comment and removed an unnecessary code line. Signed-off-by: Srishti Srivastava <srishtisrivastava.ai@gmail.com> Reviewed By: matthiaskramm, jcai19 Differential Revision: https://reviews.llvm.org/D157261
2023-08-10[mlir] Fix verifier of `RegionBranchOpInterface`Markus Böck
The verifier incorrectly passed the region number of the predecessor region instead of the successor region to `getSuccessorOperands`. This went unnoticed since all upstream `RegionBranchTerminatorOpInterface` implementations did not make use of the `index` parameter. Adding an assert to e.g. `scf.condition` to make sure the index is valid or adding a region terminator that passes different operands to different successors immediately causes the verifier to fail as it suddenly gets incorrect types. This patch fixes the implementation to correctly pass the successor region index. Differential Revision: https://reviews.llvm.org/D157507
2023-08-10[mlir] Revamp `RegionBranchOpInterface` successor mechanismMarkus Böck
The `RegionBranchOpInterface` had a few fundamental issues caused by the API design of `getSuccessorRegions`. It always required passing values for the `operands` parameter. This is problematic as the operands parameter actually changes meaning depending on which predecessor `index` is referring to. If coming from a region, you'd have to find a `RegionBranchTerminatorOpInterface` in that region, get its operand count, and then create a `SmallVector` of that size. This is not only inconvenient, but also error-prone, which has lead to a bug in the implementation of a previously existing `getSuccessorRegions` overload. Additionally, this made the method dual-use, trying to serve two different use-cases: 1) Trying to determine possible control flow edges between regions and 2) Trying to determine the region being branched to based on constant operands. This patch fixes these issues by changing the interface methods and adding new ones: * The `operands` argument of `getSuccessorRegions` has been removed. The method is now only responsible for returning possible control flow edges between regions. * An optional `getEntrySuccessorRegions` method has been added. This is used to determine which regions are branched to from the parent op based on constant operands of the parent op. By default, it calls `getSuccessorRegions`. This is analogous to `getSuccessorForOperands` from `BranchOpInterface`. * Add `getSuccessorRegions` to `RegionBranchTerminatorOpInterface`. This is used to get the possible successors of the terminator based on constant operands. By default, it calls the containing `RegionBranchOpInterface`s `getSuccessorRegions` method. * `getSuccessorEntryOperands` was renamed to `getEntrySuccessorOperands` for consistency. Differential Revision: https://reviews.llvm.org/D157506
2023-08-02[mlir] Add getArgOperandsMutable method to CallOpInterfaceMartin Erhart
Add a method to the CallOpInterface to get a mutable operand range over the function arguments. This allows to add, remove, or change the type of call arguments in a generic manner without having to assume that the argument operand range is at the end of the operand list, or having to type switch on all supported concrete operation kinds. Alternatively, a new OpInterface could be added which inherits from CallOpInterface and appends it with the mutable variants of the base interface. There will be two users of this new function in the beginning: (1) A few passes in the Arc dialect in CIRCT already use a downstream implementation of the alternative case mentioned above: https://github.com/llvm/circt/blob/main/include/circt/Dialect/Arc/ArcInterfaces.td#L15 (2) The BufferDeallocation pass will be modified to be able to pass ownership of memrefs to called private functions if the caller does not need the memref anymore by appending the function argument list with a boolean value per memref, thus enabling earlier deallocation of the memref which can lead to lower peak memory usage. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D156675
2023-07-31[NFCI][mlir][Tests] Rename identifiers minor/major to avoid clashes with ↵Roger Ferrer Ibanez
system headers Identifiers major and minor are often already taken in POSIX systems due to their presence in <sys/types.h> as part of the makedev library function. This causes compilation failures on FreeBSD and Linux systems with glibc <2.28. This change renames the identifiers to major_/minor_. Differential Revision: https://reviews.llvm.org/D156683
2023-07-28Add support for versioning properties in MLIR bytecodeMatteo Franciolini
[mlir] Add support for custom readProperties/writeProperties methods. Currently, operations that opt-in to adopt properties will see auto-generated readProperties/writeProperties methods to emit and parse bytecode. If a dialects opts in to use `usePropertiesForAttributes`, those definitions will be generated for the current definition of the op without the possibility to handle attribute versioning. The patch adds the capability for an operation to define its own read/write methods for the encoding of properties so that versioned operations can handle upgrading properties encodings. In addition to this, the patch adds an example showing versioning on NamedProperties through the dialect version API exposed by the reader. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D155340
2023-07-27[mlir] somewhat decompose TestDialect.cppAlex Zinenko
TestDialect.cpp along with the ODS-generated files amounts to around 100k LoC and takes a significant amount of time to compile. Factor out the test ops related to testing the sytnax and assembly format, which are a relatively large and well delimited group, into a separate set of files. Also factor out dialect interfaces into a separate file. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D155947
2023-07-21[mlir] allow dense dataflow to customize call and region operationsAlex Zinenko
Initial implementations of dense dataflow analyses feature special cases for operations that have region- or call-based control flow by leveraging the corresponding interfaces. This is not necessarily sufficient as these operations may influence the dataflow state by themselves as well we through the control flow. For example, `linalg.generic` and similar operations have region-based control flow and their proper memory effects, so any memory-related analyses such as last-writer require processing `linalg.generic` directly instead of, or in addition to, the region-based flow. Provide hooks to customize the processing of operations with region- cand call-based contol flow in forward and backward dense dataflow analysis. These hooks are trigerred when control flow is transferred between the "main" operation, i.e. the call or the region owner, and another region. Such an apporach allows the analyses to update the lattice before and/or after the regions. In the `linalg.generic` example, the reads from memory are interpreted as happening before the body region and the writes to memory are interpreted as happening after the body region. Using these hooks in generic analysis may require introducing additional interfaces, but for now assume that the specific analysis have spceial cases for the (rare) operaitons with call- and region-based control flow that need additional processing. Reviewed By: Mogball, phisiart Differential Revision: https://reviews.llvm.org/D155757
2023-07-20[ODS] Use Adaptor Trait for Shaped Type InferenceAmanda Tang
Author inferReturnTypeComponents methods with the Op Adaptor by using the InferShapedTypeOpAdaptor. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D155243
2023-07-18[ODS] Use Adaptor Traits for Type InferenceAmanda Tang
Author inferReturnTypes methods with the Op Adaptor by using the InferTypeOpAdaptor. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D155115
2023-07-17[mlir][ODS] Add support for passing properties to `ref` in `custom`Markus Böck
This is essentially a follow up to https://reviews.llvm.org/D155072 This adds support for also passing properties as `ref` parameter to `custom`. This requires the property to have been bound previously and will error otherwise. This makes it possible for an implementation of `custom` to take previously parsed data into account, creating nice context-dependent grammars :-) Differential Revision: https://reviews.llvm.org/D155297
2023-07-13[mlir][ODS] Add support for passing properties to `custom`Markus Böck
Printing and parsing properties of ops is currently only possible through the `prop-dict` attribute. This forces a specific place that the property is printed at and is generally not very flexible. This patch adds support for passing properties to the `custom` directive, making it possible to incorporate them with more complex syntax. This makes it possible to parse and print them without generic syntax and without the use of `prop-dict`. Differential Revision: https://reviews.llvm.org/D155072
2023-07-10[MLIR][Test] Avoid buffer overflow for `test.verifiers`rikhuijzer
Fixes buffer overflows which occurred anytime a "test.verifiers" op was used. Fixes #61378, fixes #61379, fixes #61381. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D154792
2023-07-04[mlir][TestDialect] Fix invalid custom op printersRahul Kayaith
This fixes a few custom printers which were printing IR that couldn't be round-tripped. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D150080
2023-05-26[MLIR] Add native Bytecode support for propertiesMehdi Amini
This is adding a new interface (`BytecodeOpInterface`) to allow operations to opt-in skipping conversion to attribute and serializing properties to native bytecode. The scheme relies on a new section where properties are stored in sequence { size, serialize_properties }, ... The operations are storing the index of a properties, a table of offset is built when loading the properties section the first time. This is a re-commit of 837d1ce0dc which conflicted with another patch upgrading the bytecode and the collision wasn't properly resolved before. Differential Revision: https://reviews.llvm.org/D151065
2023-05-25Revert "[MLIR] Add native Bytecode support for properties"Mehdi Amini
This reverts commit ca5a12fd69d4acf70c08f797cbffd714dd548348 and follow-up fixes: df34c288c428eb4b867c8075def48b3d1727d60b 07dc906883af660780cf6d0cc1044f7e74dab83e ab80ad0095083fda062c23ac90df84c40b4332c8 837d1ce0dc8eec5b17255291b3462e6296cb369b The first commit was incomplete and broken, I'll prepare a new version later, in the meantime pull this work out of tree.
2023-05-25[MLIR] Add native Bytecode support for propertiesMehdi Amini
This is adding a new interface (`BytecodeOpInterface`) to allow operations to opt-in skipping conversion to attribute and serializing properties to native bytecode. The scheme relies on a new section where properties are stored in sequence { size, serialize_properties }, ... The operations are storing the index of a properties, a table of offset is built when loading the properties section the first time. Back-deployment to version prior to 4 are relying on getAttrDictionnary() which we intend to deprecate and remove: that is putting a de-factor end-of-support horizon for supporting deployments to version older than 4. Differential Revision: https://reviews.llvm.org/D151065
2023-05-12[mlir] Move casting calls from methods 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. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. 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 first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-05-11[mlir][bytecode] Fix dialect version parsing.Jacques Pienaar
We were querying the wrong EncReader along some paths that resulted in failures depending on if one encountered an Attribute from an unloaded dialect before encountering an operation from that dialect. Also fix error where we were able to emit "custom" form for an attribute without custom form in TestDialect. Differential Revision: https://reviews.llvm.org/D150260
2023-05-01Introduce MLIR Op PropertiesMehdi Amini
This new features enabled to dedicate custom storage inline within operations. This storage can be used as an alternative to attributes to store data that is specific to an operation. Attribute can also be stored inside the properties storage if desired, but any kind of data can be present as well. This offers a way to store and mutate data without uniquing in the Context like Attribute. See the OpPropertiesTest.cpp for an example where a struct with a std::vector<> is attached to an operation and mutated in-place: struct TestProperties { int a = -1; float b = -1.; std::vector<int64_t> array = {-33}; }; More complex scheme (including reference-counting) are also possible. The only constraint to enable storing a C++ object as "properties" on an operation is to implement three functions: - convert from the candidate object to an Attribute - convert from the Attribute to the candidate object - hash the object Optional the parsing and printing can also be customized with 2 extra functions. A new options is introduced to ODS to allow dialects to specify: let usePropertiesForAttributes = 1; When set to true, the inherent attributes for all the ops in this dialect will be using properties instead of being stored alongside discardable attributes. The TestDialect showcases this feature. Another change is that we introduce new APIs on the Operation class to access separately the inherent attributes from the discardable ones. We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`, and other similar method which don't make the distinction explicit, leading to an entirely separate namespace for discardable attributes. Recommit d572cd1b067f after fixing python bindings build. Differential Revision: https://reviews.llvm.org/D141742
2023-05-01Revert "Introduce MLIR Op Properties"Mehdi Amini
This reverts commit d572cd1b067f1177a981a4711bf2e501eaa8117b. Some bots are broken and investigation is needed before relanding.
2023-05-01Introduce MLIR Op PropertiesMehdi Amini
This new features enabled to dedicate custom storage inline within operations. This storage can be used as an alternative to attributes to store data that is specific to an operation. Attribute can also be stored inside the properties storage if desired, but any kind of data can be present as well. This offers a way to store and mutate data without uniquing in the Context like Attribute. See the OpPropertiesTest.cpp for an example where a struct with a std::vector<> is attached to an operation and mutated in-place: struct TestProperties { int a = -1; float b = -1.; std::vector<int64_t> array = {-33}; }; More complex scheme (including reference-counting) are also possible. The only constraint to enable storing a C++ object as "properties" on an operation is to implement three functions: - convert from the candidate object to an Attribute - convert from the Attribute to the candidate object - hash the object Optional the parsing and printing can also be customized with 2 extra functions. A new options is introduced to ODS to allow dialects to specify: let usePropertiesForAttributes = 1; When set to true, the inherent attributes for all the ops in this dialect will be using properties instead of being stored alongside discardable attributes. The TestDialect showcases this feature. Another change is that we introduce new APIs on the Operation class to access separately the inherent attributes from the discardable ones. We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`, and other similar method which don't make the distinction explicit, leading to an entirely separate namespace for discardable attributes. Differential Revision: https://reviews.llvm.org/D141742
2023-04-11[mlir] Make the inliner arg/res handlers more concise.Tobias Gysi
The revision ensures the newly introduced argument and result handlers cannot be used for type conversion. Instead use the existing materializeCallConversion hook to perform type conversions. Reviewed By: Dinistro Differential Revision: https://reviews.llvm.org/D147605