summaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen/Operator.cpp
AgeCommit message (Collapse)Author
2025-09-10[mlir][tblgen] Fix bug when mixing props and InferTypes (#157367)Fabian Mora
This patch fixes a bug occurring when properties are mixed with any of the InferType traits, causing tblgen to crash. A simple reproducer is: ``` def _TypeInferredPropOp : NS_Op<"type_inferred_prop_op_with_properties", [ AllTypesMatch<["value", "result"]> ]> { let arguments = (ins Property<"unsigned">:$prop, AnyType:$value); let results = (outs AnyType:$result); let hasCustomAssemblyFormat = 1; } ``` The issue occurs because of the call: ``` op.getArgToOperandOrAttribute(infer.getIndex()); ``` To understand better the issue, consider: ``` attrOrOperandMapping = [Operand0] arguments = [Prop0, Operand0] ``` In this case, `infer.getIndex()` will return `1` for `Operand0`, but `getArgToOperandOrAttribute` expects `0`, causing the discrepancy that causes the crash. The fix is to change `attrOrOperandMapping` to also include props.
2025-07-02[mlir] Remove unused includes (NFC) (#146709)Kazu Hirata
2025-06-18[mlir][Vector] Add `vector.to_elements` op (#141457)Diego Caballero
This PR introduces the `vector.to_elements` op, which decomposes a vector into its scalar elements. This operation is symmetrical to the existing `vector.from_elements`. Examples: ``` // Decompose a 0-D vector. %0 = vector.to_elements %v0 : vector<f32> // %0 = %v0[0] // Decompose a 1-D vector. %0:2 = vector.to_elements %v1 : vector<2xf32> // %0#0 = %v1[0] // %0#1 = %v1[1] // Decompose a 2-D. %0:6 = vector.to_elements %v2 : vector<2x3xf32> // %0#0 = %v2[0, 0] // %0#1 = %v2[0, 1] // %0#2 = %v2[0, 2] // %0#3 = %v2[1, 0] // %0#4 = %v2[1, 1] // %0#5 = %v2[1, 2] ``` This op is aimed at reducing code size when modeling "structured" vector extractions and simplifying canonicalizations of large sequences of `vector.extract` and `vector.insert` ops into `vector.shuffle` and other sophisticated ops that can re-arrange vector elements.
2025-05-19[LLVM][TableGen] Rename `ListInit::getValues()` to `getElements()` (#140289)Rahul Joshi
Rename `ListInit::getValues()` to `getElements()` to better match with other `ListInit` members like `getElement`. Keep `getValues()` for existing downstream code but mark it deprecated.
2025-01-13[MLIR][TableGen] Use arg index in InferredResultType constructor. (#122717)Philipp Schilk
Trying to constrain two results to be of the same type using `AllTypesMatch` would cause `mlir-tablgen` to crash on this assertion[1]. Example: ```tblgen def OpL5 : NS_Op<"op_with_same_but_unconstraint_results", [AllTypesMatch<["result_a", "result_b"]>]> { let results = (outs AnyType:$result_a, AnyType:$result_b); } ``` This is because there was a small bug when constructing the `inferences` graph from these constraints: The sources should be specified by the combined arg/result index (in other words, with results negative) not with the result index. [1] https://github.com/llvm/llvm-project/blob/99612a3a18e0c40aac9c52b68e67b106f97ed4fa/mlir/lib/TableGen/Operator.cpp#L526
2025-01-11[TableGen] Migrate away from PointerUnion::{is,get} (NFC) (#122569)Kazu Hirata
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-10-18[NFC][MLIR][TableGen] Eliminate `llvm::` for commonly used types (#112456)Rahul Joshi
Eliminate `llvm::` namespace qualifier for commonly used types in MLIR TableGen backends to reduce code clutter.
2024-10-16[MLIR][TableGen] Use const pointers for various `Init` objects (#112562)Rahul Joshi
This reverts commit 0eed3055511381436ee69d1caf64a4af47f8d65c and applies additional fixes in `verifyArgument` in OmpOpGen.cpp for gcc-7 bot failures
2024-10-16Revert "[MLIR][TableGen] Use const pointers for various `Init` objects" ↵Mehdi Amini
(#112506) Reverts llvm/llvm-project#112316 Bots are failing.
2024-10-14[MLIR][TableGen] Use const pointers for various `Init` objects (#112316)Rahul Joshi
Use const pointers for various `Init` objects. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-02[TableGen] Change `DefInit::Def` to a const Record pointer (#110747)Rahul Joshi
This change undoes a const_cast<> introduced in an earlier change to help transition to const pointers. It is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-08-21[mlir] [tablegen] Make `hasSummary` and `hasDescription` useful (#105531)Alex Rice
The `hasSummary` and `hasDescription` functions are currently useless as they check if the corresponding `summary` and `description` are present. However, these values are set to a default value of `""`, and so these functions always return true. This PR changes these functions to check if the summary and description are just whitespace, which is presumably closer to their original intent. @math-fehr @zero9178
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-05-26[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. 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 patch updates all remaining uses of the deprecated functionality in mlir/. This was done with clang-tidy as described below and further modifications to GPUBase.td and OpenMPOpsInterfaces.td. 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: 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. ``` 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 ``` Differential Revision: https://reviews.llvm.org/D151542
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-03-15[ADT][mlir][NFCI] Do not use non-const lvalue-refs with enumerateJakub Kuderski
Replace references to enumerate results with either result_pairs (reference wrapper type) or structured bindings. I did not use structured bindings everywhere as it wasn't clear to me it would improve readability. This is in preparation to the switch to zip semantics which won't support non-const lvalue reference to elements: https://reviews.llvm.org/D144503. I chose to use values instead of const lvalue-refs because MLIR is biased towards avoiding `const` local variables. This won't degrade performance because currently `result_pair` is cheap to copy (size_t + iterator), and in the future, the enumerator iterator dereference will return temporaries anyway. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D146006
2023-03-14[mlir] Use Use *{Set,Map}::contains (NFC)Kazu Hirata
2023-01-18[mlir] Add support for interface inheritanceRiver Riddle
This allows for interfaces to define a set of "base classes", which are interfaces whose methods/extra class decls/etc. should be inherited by the derived interface. This more easily enables combining interfaces and their dependencies, without lots of awkard casting. Additional implicit conversion operators also greatly simplify the conversion process. One other aspect of this "inheritance" is that we also implicitly add the base interfaces to the attr/op/type. The user can still add them manually if desired, but this should help remove some of the boiler plate when an interface has dependencies. See https://discourse.llvm.org/t/interface-inheritance-and-dependencies-interface-method-visibility-interface-composition Differential Revision: https://reviews.llvm.org/D140198
2023-01-14[mlir][tblgen] Fix undefined behaviour found by MSVC debug iteratorsMarkus Böck
Incrementing past the end iterator of any container in C++ is immediate undefined behaviour. This is guaranteed to occur in the loop condition due to the expression cur = earlyIncIt++, which when earlyIncIt is the end iterator (aka we just did the last iteration of the loop), will do an increment on the end iterator. To fix this, the patch refactors the loop to a more conventional loop using iterators, with the only difference being that the increment happens through the erase operation, which conveniently returns an iterator to the element after the erased element. Thanks to that guarantee there is also no need to use std::list over std::vector. I also opted to reduce the inner loop find_if, because I felt splitting the "search" and the effects of if it was successful made the code (subjectively) nicer, and also avoided having to add an extra "bool erased" to the outer loop body. Differential Revision: https://reviews.llvm.org/D141758
2023-01-12[mlir][ods] Generate inferReturnTypes for ops with TypesMatchWithJeff Niu
Ops that use TypesMatchWith to constrain result types for verification and to infer result types during parser generation should also be able to have the `inferReturnTypes` method auto generated. This patch upgrades the logic for generating `inferReturnTypes` to handle the TypesMatchWith trait by building a type inference graph where each edge corresponds to "type of A can be inferred from type of B", supporting transformers other than `"$_self"`. Reviewed By: lattner, rriddle Differential Revision: https://reviews.llvm.org/D141231
2023-01-11[mlir] Add a new fold API using Generic AdaptorsMarkus Böck
This is part of the RFC for a better fold API: https://discourse.llvm.org/t/rfc-a-better-fold-api-using-more-generic-adaptors/67374 This patch implements the required foldHook changes and the TableGen machinery for generating `fold` method signatures using `FoldAdaptor` for ops, based on the value of `useFoldAPI` of the dialect. It may be one of 2 values, with convenient named constants to create a quasi enum. The new `fold` method will then be generated if `kEmitFoldAdaptorFolder` is used. Since the new `FoldAdaptor` approach is strictly better than the old signature, part of this patch updates the documentation and all example to encourage use of the new `fold` signature. Included are also tests exercising the new API, ensuring proper construction of the `FoldAdaptor` and proper generation by TableGen. Differential Revision: https://reviews.llvm.org/D140886
2023-01-11[mlir][tblgen] Generate generic adaptors for OpsMarkus Böck
This is part of the RFC for a better fold API: https://discourse.llvm.org/t/rfc-a-better-fold-api-using-more-generic-adaptors/67374 This patch implements the generation of generic adaptors through TableGen. These are essentially a generalization of Adaptors, as implemented previously, but instead of indexing into a `mlir::ValueRange`, they may index into any container, regardless of the element type. This allows the use of the convenient getter methods of Adaptors to be reused on ranges that are the result of some kind of mapping functions of an ops operands. In the case of the fold API in the RFC, this would be `ArrayRef<Attribute>`, which is a mapping of the operands to their possibly-constant values. Implementation wise, some special care was taken to not cause a compile time regression, nor to break any kind of source compatibility. For that purpose, the current adaptor class was split into three: * A generic adaptor base class, within the detail namespace as it is an implementation detail, which implements all APIs independent of the range type used for the operands. This is all the attribute and region related code. Since it is not templated, its implementation does not have to be inline and can be put into the cpp source file * The actual generic adaptor, which has a template parameter for the range that should be indexed into for retrieving operands. It implements all the getters for operands, as they are dependent on the range type. It publicly inherits from the generic adaptor base class * A class named as adaptors have been named so far, inheriting from the generic adaptor class with `mlir::ValueRange` as range to index into. It implements the rest of the API, specific to `mlir::ValueRange` adaptors, which have previously been part of the adaptor. This boils down to a constructor from the Op type as well as the verify function. The last class having the exact same API surface and name as Adaptors did previously leads to full source compatibility. Differential Revision: https://reviews.llvm.org/D140660
2022-12-08[mlir][ods] Generate remover methods with camelcaseJeff Niu
The remove*Attr methods were not being generated with the correct camelcase method. Depends on D139470 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D139471
2022-12-02[mlir] Remove support for non-prefixed accessorsRiver Riddle
This finishes off a year long pursuit to LLVMify the generated operation accessors, prefixing them with get/set. Support for any other accessor naming is fully removed after this commit. https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629 Differential Revision: https://reviews.llvm.org/D136727
2022-09-06[mlir] Flip default value of emitAccessorPrefix to kEmitAccessorPrefix_PrefixedRiver Riddle
Most dialects have already flipped to prefixed, and the intention to switch has been telegraphed for a while. Differential Revision: https://reviews.llvm.org/D133179
2022-06-20[mlir] Don't use Optional::hasValue (NFC)Kazu Hirata
2022-04-28[mlir] Attach InferTypeOpInterface on SameOperandsAndResultType operations ↵River Riddle
when possible This allows for inferring the result types of operations in certain situations by using the type of an operand. This commit allowed for automatically supporting type inference for many more operations with no additional effort, e.g. nearly all Arithmetic operations now support result type inferrence with no additional changes. Differential Revision: https://reviews.llvm.org/D124581
2022-04-28[mlir:ODS] Support using attributes in AllTypesMatch to automatically add ↵River Riddle
InferTypeOpInterface This allows for using attribute types in result type inference for use with InferTypeOpInterface. This was a TODO before, but it isn't much additional work to properly support this. After this commit, arith::ConstantOp can now have its InferTypeOpInterface implementation automatically generated. Differential Revision: https://reviews.llvm.org/D124580
2022-02-18[mlir][ODS] Infer return types if the operands are variadic but the results ↵Benjamin Kramer
are not Clean up code that worked around this limitation. Differential Revision: https://reviews.llvm.org/D120119
2022-02-15[mlir][ods] Allow type attribute/operand for 0 result ops prefixedJacques Pienaar
Without results, there is no getType injected and so generating one in prefixed form doesn't result in any failures during C++ compilation. Differential Revision: https://reviews.llvm.org/D119871
2022-02-02[mlir] Support verification order (1/3)Chia-hung Duan
This CL supports adding dependency between traits verifiers and the dependency will be checked statically. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D115135
2022-01-31Remove OpTrait, AttrTrait and TypeTraitSanjoy Das
- Remove the `{Op,Attr,Type}Trait` TableGen classes and replace with `Trait` - Rename `OpTraitList` to `TraitList` and use it in a few places The bulk of this change is a mechanical s/OpTrait/Trait/ throughout the codebase. Reviewed By: rriddle, jpienaar, herhut Differential Revision: https://reviews.llvm.org/D118543
2022-01-26[mlir][NFC] Add a using for llvm::SMLoc/llvm::SMRange to LLVM.hRiver Riddle
These are used pervasively during parsing. Differential Revision: https://reviews.llvm.org/D118291
2022-01-18Use reference for large object passed by value at the moment in MLIR ↵Mehdi Amini
TableGen (NFC) Also make the ODS Operator class have const iterator, and use const references for existing API taking Operator by reference. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D117516
2022-01-06[mlir][ods] ODS ops get an `extraClassDefinition`Mogball
Extra definitions are placed in the generated source file for each op class. The substitution `$cppClass` is replaced by the op's C++ class name. This is useful when declaring but not defining methods in TableGen base classes: ``` class BaseOp<string mnemonic> : Op<MyDialect, mnemonic, [DeclareOpInterfaceMethods<SomeInterface>] { let extraClassDeclaration = [{ // ZOp is declared at at the bottom of the file and is incomplete here ZOp getParent(); }]; let extraClassDefinition = [{ int $cppClass::someInterfaceMethod() { return someUtilityFunction(*this); } ZOp $cppClass::getParent() { return dyn_cast<ZOp>(this->getParentOp()); } }]; } ``` Certain things may prevent defining these functions inline, in the declaration. In this example, `ZOp` in the same dialect is incomplete at the function declaration because ops classes are declared in alphabetical order. Alternatively, functions may be too big to be desired as inlined, or they may require dependencies that create cyclic includes, or they may be calling a templated utility function that one may not want to expose in a header. If the functions are not inlined, then inheriting from the base class N times means that each function will need to be defined N times. With `extraClassDefinitions`, they only need to be defined once. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D115783
2021-12-20Fix clang-tidy issues in mlir/ (NFC)Mehdi Amini
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D115956
2021-10-26[mlir] Fix missing prefix for region accessor on OpAdaptorJacques Pienaar
Also flip op-decl-and-defs test to _Prefixed to test more.
2021-10-24[mlir] Switch arith, llvm, std & shape dialects to accessors prefixed both form.Jacques Pienaar
Following https://llvm.discourse.group/t/psa-ods-generated-accessors-will-change-to-have-a-get-prefix-update-you-apis/4476, this follows flipping these dialects to _Both prefixed form. This changes the accessors to have a prefix. This was possibly mostly without breaking breaking changes if the existing convenience methods were used. (https://github.com/jpienaar/llvm-project/blob/main/clang-tools-extra/clang-tidy/misc/AddGetterCheck.cpp was used to migrate the callers post flipping, using the output from Operator.cpp) Differential Revision: https://reviews.llvm.org/D112383
2021-10-20[mlir] Expand prefixing to OpFormatGenJacques Pienaar
Follow up to also use the prefixed emitters in OpFormatGen (moved getGetterName(s) and getSetterName(s) to Operator as that is most convenient usage wise even though it just depends on Dialect). Prefix accessors in Test dialect and follow up on missed changes in OpDefinitionsGen. Differential Revision: https://reviews.llvm.org/D112118
2021-09-13Add sanity check in MLIR ODS to catch case where an ↵Mehdi Amini
arguments/results/regions/successors names overlap This is making a tablegen crash with a more friendly error. Differential Revision: https://reviews.llvm.org/D109474
2021-08-23[mlir] Add support for VariadicOfVariadic operandsRiver Riddle
This revision adds native ODS support for VariadicOfVariadic operand groups. An example of this is the SwitchOp, which has a variadic number of nested operand ranges for each of the case statements, where the number of case statements is variadic. Builtin ODS support allows for generating proper accessors for the nested operand ranges, builder support, and declarative format support. VariadicOfVariadic operands are supported by providing a segment attribute to use to store the operand groups, mapping similarly to the AttrSizedOperand trait (but with a user defined attribute name). `build` methods for VariadicOfVariadic operand expect inputs of the form `ArrayRef<ValueRange>`. Accessors for the variadic ranges return a new `OperandRangeRange` type, which represents a contiguous range of `OperandRange`. In the declarative assembly format, VariadicOfVariadic operands and types are by default formatted as a comma delimited list of value lists: `(<value>, <value>), (), (<value>)`. Differential Revision: https://reviews.llvm.org/D107774
2021-07-20[mlir][ods] Add nested OpTraitJacques Pienaar
Allows for grouping OpTraits with list of OpTrait to make it easier to group OpTraits together without needing to use list concats (e.g., enable using `[Traits, ..., UsefulGroupOfTraits, Others, ...]` instead of `[Traits, ...] # UsefulGroupOfTraits # [Others, ...]`). Flatten in construction of Operation. This recurses here as the expectation is that these aren't expected to be deeply nested (most likely only 1 level of nesting). Differential Revision: https://reviews.llvm.org/D106223
2021-05-11[mlir][ODS]: Add per-op cppNamespace.Sean Silva
This is useful for dialects that have logical subparts. Differential Revision: https://reviews.llvm.org/D102200
2021-04-15[mlir] Add support for adding attribute+type traits/interfaces to tablegen defsRiver Riddle
This matches the current support provided to operations, and allows attaching traits, interfaces, and using the DeclareInterfaceMethods utility. This was missed when attribute/type generation was first added. Differential Revision: https://reviews.llvm.org/D100233
2021-01-11[mlir][ODS] Add a C++ abstraction for OpBuildersRiver Riddle
This removes the need for OpDefinitionsGen to use raw tablegen API, and will also simplify adding builders to TypeDefs as well. Differential Revision: https://reviews.llvm.org/D94273
2020-12-03[TableGen] Eliminate the 'code' typePaul C. Anagnostopoulos
Update the documentation. Rework various backends that relied on the code type. Differential Revision: https://reviews.llvm.org/D92269
2020-11-17[mlir] Add basic support for attributes in ODS-generated Python bindingsAlex Zinenko
In ODS, attributes of an operation can be provided as a part of the "arguments" field, together with operands. Such attributes are accepted by the op builder and have accessors generated. Implement similar functionality for ODS-generated op-specific Python bindings: the `__init__` method now accepts arguments together with operands, in the same order as in the ODS `arguments` field; the instance properties are introduced to OpView classes to access the attributes. This initial implementation accepts and returns instances of the corresponding attribute class, and not the underlying values since the mapping scheme of the value types between C++, C and Python is not yet clear. Default-valued attributes are not supported as that would require Python to be able to parse C++ literals. Since attributes in ODS are tightely related to the actual C++ type system, provide a separate Tablegen file with the mapping between ODS storage type for attributes (typically, the underlying C++ attribute class), and the corresponding class name. So far, this might look unnecessary since all names match exactly, but this is not necessarily the cases for non-standard, out-of-tree attributes, which may also be placed in non-default namespaces or Python modules. This also allows out-of-tree users to generate Python bindings without having to modify the bindings generator itself. Storage type was preferred over the Tablegen "def" of the attribute class because ODS essentially encodes attribute _constraints_ rather than classes, e.g. there may be many Tablegen "def"s in the ODS that correspond to the same attribute type with additional constraints The presence of the explicit mapping requires the change in the .td file structure: instead of just calling the bindings generator directly on the main ODS file of the dialect, it becomes necessary to create a new file that includes the main ODS file of the dialect and provides the mapping for attribute types. Arguably, this approach offers better separability of the Python bindings in the build system as the main dialect no longer needs to know that it is being processed by the bindings generator. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D91542
2020-09-26Common code preparation for tblgen-types patchJohn Demme
Cleanup and add methods which https://reviews.llvm.org/D86904 requires. Breaking up to lower review load. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D88267