summaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen/Operator.cpp
AgeCommit message (Collapse)Author
2020-09-14Make namespace handling uniform across dialect backends.Federico Lebrón
Now backends spell out which namespace they want to be in, instead of relying on clients #including them inside already-opened namespaces. This also means that cppNamespaces should be fully qualified, and there's no implicit "::mlir::" prepended to them anymore. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D86811
2020-08-12[MLIR][NFC] Remove tblgen:: prefix in TableGen/*.cpp filesRahul Joshi
- Add "using namespace mlir::tblgen" in several of the TableGen/*.cpp files and eliminate the tblgen::prefix to reduce code clutter. Differential Revision: https://reviews.llvm.org/D85800
2020-08-10[MLIR][TableGen] Fix ambiguous build methods when inferring result types.Rahul Joshi
- Fix ODS framework to suppress build methods that infer result types and are ambiguous with collective variants. This applies to operations with a single variadic inputs whose result types can be inferred. - Extended OpBuildGenTest to test these kinds of ops. Differential Revision: https://reviews.llvm.org/D85060
2020-07-12[mlir][ODS] Add support for specifying the namespace of an interface.River Riddle
The namespace can be specified using the `cppNamespace` field. This matches the functionality already present on dialects, enums, etc. This fixes problems with using interfaces on operations in a different namespace than the interface was defined in. Differential Revision: https://reviews.llvm.org/D83604
2020-06-29[ods] Update Operator to record Arg->[Attr|Operand]Index mappingJacques Pienaar
Also fixed bug in type inferface generator to address bug where operands and attributes are interleaved. Differential Revision: https://reviews.llvm.org/D82819
2020-06-24[MLIR][NFC] Adopt variadic isa<>Rahul Joshi
Differential Revision: https://reviews.llvm.org/D82489
2020-06-15[mlir] Remove OperandAdaptorJacques Pienaar
Use ::Adaptor alias instead uniformly. Makes the naming more consistent as adaptor can refer to attributes now too. Differential Revision: https://reviews.llvm.org/D81789
2020-06-03Fix build: TableGen uses `is<T>` instead of `isa<T>` as predicateMehdi Amini
2020-06-03Replace dyn_cast<>() with isa<>() when the result isn't used (NFC)Mehdi Amini
Fixed warning reported by some GCC version.
2020-05-28[mlir] Use ValueRange instead of ArrayRef<Value>Jacques Pienaar
This allows constructing operand adaptor from existing op (useful for commonalizing verification as I want to do in a follow up). I also add ability to use member initializers for the generated adaptor constructors for convenience. Differential Revision: https://reviews.llvm.org/D80667
2020-05-27[mlir] Add simple generator for return typesJacques Pienaar
Take advantage of equality constrains to generate the type inference interface. This is used for equality and trivially built types. The type inference method is only generated when no type inference trait is specified already. This reorders verification that changes some test error messages. Differential Revision: https://reviews.llvm.org/D80484
2020-04-26[mlir] Optimize operand storage such that all operations can have resizable ↵River Riddle
operand lists This revision refactors the structure of the operand storage such that there is no additional memory cost for resizable operand lists until it is required. This is done by using two different internal representations for the operand storage: * One using trailing operands * One using a dynamically allocated std::vector<OpOperand> This allows for removing the resizable operand list bit, and will free up APIs from needing to workaround non-resizable operand lists. Differential Revision: https://reviews.llvm.org/D78875
2020-04-16[mlir] ODS: support operations with resizable operand listsAlex Zinenko
MLIR supports operations with resizable operand lists, but this property must be indicated during the construction of such operations. It can be done programmatically by calling a function on OperationState. Introduce an ODS-internal trait `ResizableOperandList` to indicate such operations are use it when generating the bodies of various `build` functions as well as the `parse` function when the declarative assembly format is used. Differential Revision: https://reviews.llvm.org/D78292
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-04-05[mlir][ODS] Add support for variadic regions.River Riddle
Summary: This revision adds support for marking the last region as variadic in the ODS region list with the VariadicRegion directive. Differential Revision: https://reviews.llvm.org/D77455
2020-03-24[mlir] Revamp operation documentation generationRiver Riddle
Summary: This revisions performs several cleanups to the generated dialect documentation: * Standardizes format of attributes/operands/results sections * Splits out operation/type/dialect documentation generation to allow for composing generated and hand-written documentation * Add section for declarative assembly syntax and successors * General cleanup Differential Revision: https://reviews.llvm.org/D76573
2020-03-06[mlir][SideEffects] Enable specifying side effects directly on the ↵River Riddle
arguments/results of an operation. Summary: New classes are added to ODS to enable specifying additional information on the arguments and results of an operation. These classes, `Arg` and `Res` allow for adding a description and a set of 'decorators' along with the constraint. This enables specifying the side effects of an operation directly on the arguments and results themselves. Example: ``` def LoadOp : Std_Op<"load"> { let arguments = (ins Arg<AnyMemRef, "the MemRef to load from", [MemRead]>:$memref, Variadic<Index>:$indices); } ``` Differential Revision: https://reviews.llvm.org/D74440
2020-03-01Fix MLIR build by adding missing header after cleanup in af450eabMehdi Amini
2020-02-21[mlir][ODS] Add support for specifying the successors of an operation.River Riddle
This revision add support in ODS for specifying the successors of an operation. Successors are specified via the `successors` list: ``` let successors = (successor AnySuccessor:$target, AnySuccessor:$otherTarget); ``` Differential Revision: https://reviews.llvm.org/D74783
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
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-12-19Unique trait list during ODS Operator trait constructionJacques Pienaar
Concatting lists in TableGen is easy, creating unique lists less so. There is no reason for duplicated op traits so we could throw an error instead but duplicates could occur due to concatting different list of traits in ODS (e.g., for convenience reasons), so just dedup them during Operator trait construction instead. PiperOrigin-RevId: 286488423
2019-11-25Add support for AttrSizedOperandSegments/AttrSizedResultSegmentsLei Zhang
Certain operations can have multiple variadic operands and their size relationship is not always known statically. For such cases, we need a per-op-instance specification to divide the operands into logical groups or segments. This can be modeled by attributes. This CL introduces C++ trait AttrSizedOperandSegments for operands and AttrSizedResultSegments for results. The C++ trait just guarantees such size attribute has the correct type (1D vector) and values (non-negative), etc. It serves as the basis for ODS sugaring that with ODS argument declarations we can further verify the number of elements match the number of ODS-declared operands and we can generate handy getter methods. PiperOrigin-RevId: 282467075
2019-11-21Add support for using the ODS result names as the Asm result names for ↵River Riddle
multi-result operations. This changes changes the OpDefinitionsGen to automatically add the OpAsmOpInterface for operations with multiple result groups using the provided ODS names. We currently just limit the generation to multi-result ops as most single result operations don't have an interesting name(result/output/etc.). An example is shown below: // The following operation: def MyOp : ... { let results = (outs AnyType:$first, Variadic<AnyType>:$middle, AnyType); } // May now be printed as: %first, %middle:2, %0 = "my.op" ... PiperOrigin-RevId: 281834156
2019-11-14[ODS] Fix operation argument population to avoid crashLei Zhang
The `Operator` class keeps an `arguments` field, which contains pointers to `operands` and `attributes` elements. Thus it must be populated after `operands` and `attributes` are finalized so to have stable pointers. SmallVector may re-allocate when still having new elements added, which will invalidate pointers. PiperOrigin-RevId: 280466896
2019-10-21[DRR] Allow interleaved operands and attributesLei Zhang
Previously DRR assumes attributes to appear after operands. This was the previous requirements on ODS, but that has changed some time ago. Fix DRR to also support interleaved operands and attributes. PiperOrigin-RevId: 275983485
2019-07-30Remove dead code.Jacques Pienaar
PiperOrigin-RevId: 260585594
2019-07-19Automatically generate (de)serialization methods for SPIR-V opsMahesh Ravishankar
For ops in SPIR-V dialect that are a direct mirror of SPIR-V operations, the serialization/deserialization methods can be automatically generated from the Op specification. To enable this an 'autogenSerialization' field is added to SPV_Ops. When set to non-zero, this will enable the automatic (de)serialization function generation Also adding tests that verify the spv.Load, spv.Store and spv.Variable ops are serialized and deserialized correctly. To fully support these tests also add serialization and deserialization of float types and spv.ptr types PiperOrigin-RevId: 258684764
2019-07-05ODS: provide a flag to skip generation of default build methodsAlex Zinenko
Some operations need to override the default behavior of builders, in particular region-holding operations such as affine.for or tf.graph want to inject default terminators into the region upon construction, which default builders won't do. Provide a flag that disables the generation of default builders so that the custom builders could use the same function signatures. This is an intentionally low-level and heavy-weight feature that requires the entire builder to be implemented, and it should be used sparingly. Injecting code into the end of a default builder would depend on the naming scheme of the default builder arguments that is not visible in the ODS. Checking that the signature of a custom builder conflicts with that of a default builder to prevent emission would require teaching ODG to differentiate between types and (optional) argument names in the generated C++ code. If this flag ends up being used a lot, we should consider adding traits that inject specific code into the default builder. PiperOrigin-RevId: 256640069
2019-06-19Print proper message saying variadic ops are not supported in RewriterGenLei Zhang
Support for ops with variadic operands/results will come later; but right now a proper message helps to avoid deciphering confusing error messages later in the compilation stage. PiperOrigin-RevId: 254071820
2019-06-09[ODS] Support variadic operand/result verificationLei Zhang
This CL enables verification code generation for variadic operands and results. In verify(), we use fallback getter methods to access all the dynamic values belonging to one static variadic operand/result to reuse the value range calculation there. PiperOrigin-RevId: 252288219
2019-06-09[ODG] Add iterators for results in OperatorLei Zhang
PiperOrigin-RevId: 251417085
2019-06-03Introduce OpOperandAdaptors and emit them from ODSAlex Zinenko
When manipulating generic operations, such as in dialect conversion / rewriting, it is often necessary to view a list of Values as operands to an operation without creating the operation itself. The absence of such view makes dialect conversion patterns, among others, to use magic numbers to obtain specific operands from a list of rewritten values when converting an operation. Introduce XOpOperandAdaptor classes that wrap an ArrayRef<Value *> and provide accessor functions identical to those available in XOp. This makes it possible for conversions to use these adaptors to address the operands with names rather than rely on their position in the list. The adaptors are generated from ODS together with the actual operation definitions. This is another step towards making dialect conversion patterns specific for a given operation. Illustrate the approach on conversion patterns in the standard to LLVM dialect conversion. PiperOrigin-RevId: 251232899
2019-06-01 [ODS] Support region names and constraintsLei Zhang
Similar to arguments and results, now we require region definition in ops to be specified as a DAG expression with the 'region' operator. This way we can specify the constraints for each region and optionally give the region a name. Two kinds of region constraints are added, one allowing any region, and the other requires a certain number of blocks. -- PiperOrigin-RevId: 250790211
2019-06-01 [ODS] Support numRegions in Op definitionLei Zhang
-- PiperOrigin-RevId: 250282024
2019-05-20 [ODS] Allow dialect to specify C++ namespacesLei Zhang
Previously we force the C++ namespaces to be `NS` if `SomeOp` is defined as `NS_SomeOp`. This is too rigid as it does not support nested namespaces well. This CL adds a "namespace" field into the Dialect class to allow flexible namespaces. -- PiperOrigin-RevId: 249064981
2019-05-06 Add extraClassDeclaration field for ops.Jacques Pienaar
Simple mechanism to allow specifying arbitrary function declarations. The modelling will not cover all cases so allow a means for users to declare a method function that they will define in their C++ files. The goal is to allow full C++ flexibility as the goal is to cover cases not modelled. -- PiperOrigin-RevId: 245889819
2019-05-06 Add Dialect in op definition to capture prefix and documentation.Jacques Pienaar
Enables specifying the documentation for dialect along with defining the ops of the dialect. The doc generator will be expanded in follow up to emit the documentation in the autogenerated files. This is precursor to allowing common base for all ops in a dialect. All the dialect documentation is super sparse and just added as placeholder. I was tempted (and started) to move ConstantOp to be generated too, but this will be easier post adding extra_methods, so deferring until then. -- PiperOrigin-RevId: 245759984
2019-05-06 [TableGen] Support multiple variadic operands/resultsLei Zhang
Certain ops can have multiple variadic operands/results, e.g., `tf.DynamicStitch`. Even if an op has only one variadic operand/result, it is not necessarily the very last one, e.g., `tf.RaggedGather`. This CL enhances TableGen subsystem to be able to represent such cases. In order to deduce the operand/result value range for each variadic operand, currently we only support variadic operands/results all of the same size. So two new traits, `SameVariadicOperandSize` and `SameVariadicResultSize` are introduced. -- PiperOrigin-RevId: 245310628
2019-04-18 [TableGen] Fix support for ops whose names have a leading underscoreLei Zhang
TensorFlow ops have the convention to use leading underscore to denote internal ops. -- PiperOrigin-RevId: 243627723
2019-04-05 [TableGen] Rework verifier generation and error messagesLei Zhang
Previously we bundle the existence check and the MLIR attribute kind check in one call. Further constraints (like element bitwidth) have to be split into following checks. That is not a nice separation given that we have more checks for constraints. Instead, this CL changes to generate a local variable for every attribute, check its existence first, then check the constraints. Creating a local variable for each attribute also avoids querying it multiple times using the raw getAttr() API. This is a win for both performance the readability of the generated code. This CL also changed the error message to be more greppable by delimiting the error message from constraints with boilerplate part with colon. -- PiperOrigin-RevId: 241906132
2019-03-29Add a trait to set the result type by attributeFeng Liu
Before this CL, the result type of the pattern match results need to be as same as the first operand type, operand broadcast type or a generic tensor type. This CL adds a new trait to set the result type by attribute. For example, the TFL_ConstOp can use this to set the output type to its value attribute. PiperOrigin-RevId: 240441249
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-29TableGen: allow mixing attributes and operands in the Arguments DAG of Op ↵Alex Zinenko
definition The existing implementation of the Op definition generator assumes and relies on the fact that native Op Attributes appear after its value-based operands in the Arguments list. Furthermore, the same order is used in the generated `build` function for the operation. This is not desirable for some operations with mandatory attributes that would want the attribute to appear upfront for better consistency with their textual representation, for example `cmpi` would prefer the `predicate` attribute to be foremost in the argument list. Introduce support for using attributes and operands in the Arguments DAG in no particular order. This is achieved by maintaining a list of Arguments that point to either the value or the attribute and are used to generate the `build` method. PiperOrigin-RevId: 237002921
2019-03-29[TableGen] Use ArrayRef instead of SmallVectorImpl for suitable methodLei Zhang
PiperOrigin-RevId: 235577399
2019-03-29Create OpTrait base class & allow operation predicate OpTraits.Jacques Pienaar
* Introduce a OpTrait class in C++ to wrap the TableGen definition; * Introduce PredOpTrait and rename previous usage of OpTrait to NativeOpTrait; * PredOpTrait allows specifying a trait of the operation by way of predicate on the operation. This will be used in future to create reusable set of trait building blocks in the definition of operations. E.g., indicating whether to operands have the same type and allowing locally documenting op requirements by trait composition. - Some of these building blocks could later evolve into known fixed set as LLVMs backends do, but that can be considered with more data. * Use the modelling to address one verify TODO in a very local manner. This subsumes the current custom verify specification which will be removed in a separate mechanical CL. PiperOrigin-RevId: 234827169
2019-03-29[TableGen] Support using Variadic<Type> in resultsLei Zhang
This CL extended TableGen Operator class to provide accessors for information on op results. In OpDefinitionGen, added checks to make sure only the last result can be variadic, and adjusted traits and builders generation to consider variadic results. PiperOrigin-RevId: 234596124