summaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen/Type.cpp
AgeCommit message (Collapse)Author
2025-10-30[mlir] Simplify Default cases in type switches. NFC. (#165767)Jakub Kuderski
Use default values instead of lambdas when possible. `std::nullopt` and `nullptr` can be used now because of https://github.com/llvm/llvm-project/pull/165724.
2025-07-24[mlir] Remove unused includes (NFC) (#150476)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
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-08-09[mlir][ODS] Consistent `cppType` / `cppClassName` usage (#102657)Matthias Springer
Make sure that the usage of `cppType` and `cppClassName` of type and attribute definitions/constraints is consistent in TableGen. - `cppClassName`: The C++ class name of the type or attribute. - `cppType`: The fully qualified C++ class name: C++ namespace and C++ class name. Basically, we should always use the fully qualified C++ class name for parameter types, return types or template arguments. Also some minor cleanups. Fixes #57279.
2022-12-06[TableGen] llvm::Optional => std::optionalFangrui Song
2022-12-04[mlir] Use std::nullopt instead of None in comments (NFC)Kazu Hirata
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-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-06-02[mlir:PDLL] Add better support for providing Constraint/Pattern/Rewrite ↵River Riddle
documentation This commit enables providing long-form documentation more seamlessly to the LSP by revamping decl documentation. For ODS imported constructs, we now also import descriptions and attach them to decls when possible. For PDLL constructs, the LSP will now try to provide documentation by parsing the comments directly above the decls location within the source file. This commit also adds a new parser flag `enableDocumentation` that gates the import and attachment of ODS documentation, which is unnecessary in the normal build process (i.e. it should only be used/consumed by tools). Differential Revision: https://reviews.llvm.org/D124881
2021-11-12[mlir][ods] Unique attribute, successor, region constraintsMogball
With `-Os` turned on, results in 2-5% binary size reduction (depends on the original binary). Without it, the binary size is essentially unchanged. Depends on D113128 Differential Revision: https://reviews.llvm.org/D113331
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-01-06[mlir][ODS] Fix the use of cppClassName in Type constraints for TypeDefsRiver Riddle
This field is currently being used to mean "Fully resolved class name", which breaks the usage by TypeDefs. This revision prefixes the name with the dialect namespace when necessary. Differential Revision: https://reviews.llvm.org/D94192
2021-01-06[mlir][ODS] Rename several uses of 'description' to 'summary'River Riddle
Right now constraint/predicate traits/etc. use their "description" field as a one line human readable string. This breaks the current convention, by which a "description" may be multi-line. This revision renames the "description" field in these cases to "summary" which matches what the string is actually used as. This also unbreaks the use of TypeDefs(and eventually AttrDefs) in conjunction with existing type constraint facilities like `Optional`. Differential Revision: https://reviews.llvm.org/D94133
2020-12-26[ODS] Make the getType() method on a OneResult instruction return a specific ↵Chris Lattner
type. Implement Bug 46698, making ODS synthesize a getType() method that returns a specific C++ class for OneResult methods where we know that class. This eliminates a common source of casts in things like: myOp.getType().cast<FIRRTLType>().getPassive() because we know that myOp always returns a FIRRTLType. This also encourages op authors to type their results more tightly (which is also good for verification). I chose to implement this by splitting the OneResult trait into itself plus a OneTypedResult trait, given that many things are using `hasTrait<OneResult>` to conditionalize various logic. While this changes makes many many ops get more specific getType() results, it is generally drop-in compatible with the previous behavior because 'x.cast<T>()' is allowed when x is already known to be a T. The one exception to this is that we need declarations of the types used by ops, which is why a couple headers needed additional #includes. I updated a few things in tree to remove the now-redundant `.cast<>`'s, but there are probably many more than can be removed. Differential Revision: https://reviews.llvm.org/D93790
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-04-14[llvm][ADT] Move TypeSwitch class from MLIR to LLVMRiver Riddle
This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionality. Each `Case<T>` takes a callable to be invoked if the root value isa<T>, the callable is invoked with the result of dyn_cast<T>() as a parameter. Differential Revision: https://reviews.llvm.org/D78070
2020-04-10[mlir][ODS] Add support for optional operands and results with a new ↵River Riddle
Optional directive. Summary: This revision adds support for specifying operands or results as "optional". This is a special case of variadic where the number of elements is either 0 or 1. Operands and results of this kind will have accessors generated using Value instead of the range types, making it more natural to interface with. Differential Revision: https://reviews.llvm.org/D77863
2020-02-03[mlir][ODS] Refactor BuildableType to use $_builder as part of the formatRiver Riddle
Summary: Currently BuildableType is assumed to be preceded by a builder. This prevents constructing types that don't have a callable 'get' method with the builder. This revision reworks the format to be like attribute builders, i.e. by accepting $_builder within the format itself. Differential Revision: https://reviews.llvm.org/D73736
2020-01-30[mlir] Add initial support for parsing a declarative operation assembly formatRiver Riddle
Summary: This is the first revision in a series that adds support for declaratively specifying the asm format of an operation. This revision focuses solely on parsing the format. Future revisions will add support for generating the proper parser/printer, as well as transitioning the syntax definition of many existing operations. This was originally proposed here: https://llvm.discourse.group/t/rfc-declarative-op-assembly-format/340 Differential Revision: https://reviews.llvm.org/D73405
2020-01-26Mass update the MLIR license header to mention "Part of the LLVM project"Mehdi Amini
This is an artifact from merging MLIR into LLVM, the file headers are now aligned with the rest of the project.
2019-12-23Adjust License.txt file to use the LLVM licenseMehdi Amini
PiperOrigin-RevId: 286906740
2019-10-07Add DialectType and generate docs for dialect typesJacques Pienaar
Add new `typeDescription` (description was already used by base constraint class) field to type to allow writing longer descriptions about a type being defined. This allows for providing additional information/rationale for a defined type. This currently uses `description` as the heading/name for the type in the generated documentation. PiperOrigin-RevId: 273299332
2019-07-30Remove dead code.Jacques Pienaar
PiperOrigin-RevId: 260585594
2019-03-29[TableGen] Consolidate constraint related conceptsLei Zhang
Previously we have multiple mechanisms to specify op definition and match constraints: TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants are not added because there are so many distinct cases we need to model; essentially, they are all carrying a predicate. It's just an artifact of implementation. It's quite confusing for users to grasp these variants and choose among them. Instead, as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each dialect has the flexibility to define its own aliases if wanted. This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive from TypeConstraint and AttrConstraint, respectively. Comments are revised and examples are added to make it clear how to use constraints. PiperOrigin-RevId: 240125076
2019-03-29Change Value to NamedTypeConstraint and use TypeConstraint.Jacques Pienaar
Previously Value was a pair of name & Type, but for operands/result a TypeConstraint rather then a Type is specified. Update C++ side to match declarative side. PiperOrigin-RevId: 238984799
2019-03-29[TableGen] Model variadic operands using Variadic<Type>Lei Zhang
Previously, we were using the trait mechanism to specify that an op has variadic operands. That led a discrepancy between how we handle ops with deterministic number of operands. Besides, we have no way to specify the constraints and match against the variadic operands. This CL introduced Variadic<Type> as a way to solve the above issues. PiperOrigin-RevId: 232656104
2019-03-29[tablegen] Use tblgen:: classes for NamedAttribute and Operand fieldsLei Zhang
This is another step towards hiding raw TableGen API calls. PiperOrigin-RevId: 231580827
2019-03-29[doc] Generate more readable description for operandsLei Zhang
This CL mandated TypeConstraint and Type to provide descriptions and fixed various subclasses and definitions to provide so. The purpose is to enforce good documentation; using empty string as the default just invites oversight. PiperOrigin-RevId: 231579629
2019-03-29Define mAttr in terms of AttrConstraint.Jacques Pienaar
* Matching an attribute and specifying a attribute constraint is the same thing executionally, so represent it such. * Extract AttrConstraint helper to match TypeConstraint and use that where mAttr was previously used in RewriterGen. PiperOrigin-RevId: 231213580
2019-03-29TableGen: implement predicate tree and basic simplificationAlex Zinenko
A recent change in TableGen definitions allowed arbitrary AND/OR predicate compositions at the cost of removing known-true predicate simplification. Introduce a more advanced simplification mechanism instead. In particular, instead of folding predicate C++ expressions directly in TableGen, keep them as is and build a predicate tree in TableGen C++ library. The predicate expression-substitution mechanism, necessary to implement complex predicates for nested classes such as `ContainerType`, is replaced by a dedicated predicate. This predicate appears in the predicate tree and can be used for tree matching and separation. More specifically, subtrees defined below such predicate may be subject to different transformations than those that appear above. For example, a subtree known to be true above the substitution predicate is not necessarily true below it. Use the predicate tree structure to eliminate known-true and known-false predicates before code emission, as well as to collapse AND and OR predicates if their value can be deduced based on the value of one child. PiperOrigin-RevId: 229605997
2019-03-29TableGen: untie Attr from TypeAlex Zinenko
In TableGen definitions, the "Type" class has been used for types of things that can be stored in Attributes, but not necessarily present in the MLIR type system. As a consequence, records like "String" or "DerviedAttrBody" were of class "Type", which can be confusing. Furthermore, the "builderCall" field of the "Type" class serves only for attribute construction. Some TableGen "Type" subclasses that correspond to MLIR kinds of types do not have a canonical way of construction only from the data available in TableGen, e.g. MemRefType would require the list of affine maps. This leads to a conclusion that the entities that describe types of objects appearing in Attributes should be independent of "Type": they have some properties "Type"s don't and vice versa. Do not parameterize Tablegen "Attr" class by an instance of "Type". Instead, provide a "constBuilderCall" field that can be used to build an attribute from a constant value stored in TableGen instead of indirectly going through Attribute.Type.builderCall. Some attributes still don't have a "constBuilderCall" because they used to depend on types without a "builderCall". Drop definitions of class "Type" that don't correspond to MLIR Types. Provide infrastructure to define type-dependent attributes and string-backed attributes for convenience. PiperOrigin-RevId: 229570087
2019-03-29TableGen: extract TypeConstraints from TypeAlex Zinenko
MLIR has support for type-polymorphic instructions, i.e. instructions that may take arguments of different types. For example, standard arithmetic operands take scalars, vectors or tensors. In order to express such instructions in TableGen, we need to be able to verify that a type object satisfies certain constraints, but we don't need to construct an instance of this type. The existing TableGen definition of Type requires both. Extract out a TypeConstraint TableGen class to define restrictions on types. Define the Type TableGen class as a subclass of TypeConstraint for consistency. Accept records of the TypeConstraint class instead of the Type class as values in the Arguments class when defining operators. Replace the predicate logic TableGen class based on conjunctive normal form with the predicate logic classes allowing for abitrary combinations of predicates using Boolean operators (AND/OR/NOT). The combination is implemented using simple string rewriting of C++ expressions and, therefore, respects the short-circuit evaluation order. No logic simplification is performed at the TableGen level so all expressions must be valid C++. Maintaining CNF using TableGen only would have been complicated when one needed to introduce top-level disjunction. It is also unclear if it could lead to a significantly simpler emitted C++ code. In the future, we may replace inplace predicate string combination with a tree structure that can be simplified in TableGen's C++ driver. Combined, these changes allow one to express traits like ArgumentsAreFloatLike directly in TableGen instead of relying on C++ trait classes. PiperOrigin-RevId: 229398247
2019-03-29Put Operator and PredCNF into the tblgen namespaceLei Zhang
PiperOrigin-RevId: 228429130
2019-03-29Add tblgen::Type to wrap around TableGen Type defsLei Zhang
This CL added a tblgen::Type class to wrap around raw TableGen Record getValue*() calls on Type defs, which will provide a nicer API for handling TableGen Record. The PredCNF class is also updated to work together with tblgen::Type. PiperOrigin-RevId: 228429090