summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [mlir] NFC: Remove Value::operator* and Value::operator-> now that Value is ↵River Riddle2020-01-111-81/+79
| | | | | | | | | | properly value-typed. Summary: These were temporary methods used to simplify the transition. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D72548
* Sprinkle some constexpr on default ctors so the compiler can diagnose unused ↵Benjamin Kramer2020-01-101-1/+0
| | | | instances. NFCI.
* [mlir][spirv] Add basic definitions for supporting availabilityLei Zhang2019-12-271-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | SPIR-V has a few mechanisms to control op availability: version, extension, and capabilities. These mechanisms are considered as different availability classes. This commit introduces basic definitions for modelling SPIR-V availability classes. Specifically, an `Availability` class is added to SPIRVBase.td, along with two subclasses: MinVersion and MaxVersion for versioning. SPV_Op is extended to take a list of `Availability`. Each `Availability` instance carries information for generating op interfaces for the corresponding availability class and also the concrete availability requirements. With the availability spec on ops, we can now auto-generate the op interfaces of all SPIR-V availability classes and also synthesize the op's implementations of these interfaces. The interface generation is done via new TableGen backends -gen-avail-interface-{decls|defs}. The op's implementation is done via -gen-spirv-avail-impls. Differential Revision: https://reviews.llvm.org/D71930
* NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.River Riddle2019-12-231-18/+17
| | | | | | ValuePtr was a temporary typedef during the transition to a value-typed Value. PiperOrigin-RevId: 286945714
* Adjust License.txt file to use the LLVM licenseMehdi Amini2019-12-231-13/+4
| | | | PiperOrigin-RevId: 286906740
* NFC: Introduce new ValuePtr/ValueRef typedefs to simplify the transition to ↵River Riddle2019-12-221-19/+20
| | | | | | | | | | Value being value-typed. This is an initial step to refactoring the representation of OpResult as proposed in: https://groups.google.com/a/tensorflow.org/g/mlir/c/XXzzKhqqF_0/m/v6bKb08WCgAJ This change will make it much simpler to incrementally transition all of the existing code to use value-typed semantics. PiperOrigin-RevId: 286844725
* NFC: Remove unnecessary 'llvm::' prefix from uses of llvm symbols declared ↵River Riddle2019-12-181-4/+4
| | | | | | | | in `mlir` namespace. Aside from being cleaner, this also makes the codebase more consistent. PiperOrigin-RevId: 286206974
* Add atomic operations to SPIR-V dialect.Mahesh Ravishankar2019-12-161-0/+65
| | | | | | | Some changes to the dialect generation script to allow specification of different base class to derive from in ODS. PiperOrigin-RevId: 285859230
* NFC: Cleanup the various Op::print methods.River Riddle2019-12-121-73/+43
| | | | | | This cleans up the implementation of the various operation print methods. This is done via a combination of code cleanup, adding new streaming methods to the printer(e.g. operand ranges), etc. PiperOrigin-RevId: 285285181
* More convenience build methods for SPIR-V ops.Mahesh Ravishankar2019-12-101-45/+75
| | | | | | | | | | | | Add some convenience build methods to SPIR-V ops and update the lowering to use these methods where possible. For SPIRV::CompositeExtractOp move the method to deduce type of element based on base and indices into a convenience function. Some additional functionality needed to handle differences between parsing and verification methods. PiperOrigin-RevId: 284794404
* [spirv] Add CompositeConstruct operation.Denis Khalikov2019-12-091-0/+67
| | | | | | | Closes tensorflow/mlir#308 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/308 from denis0x0D:sandbox/composite_construct 9ef7180f77f9374bcd05afc4f9e6c1d2d72d02b7 PiperOrigin-RevId: 284613617
* [spirv] Add spv.IAdd, spv.ISub, and spv.IMul foldersLei Zhang2019-12-091-5/+36
| | | | | | | The patterns to be folded away can be commonly generated during lowering to SPIR-V. PiperOrigin-RevId: 284604855
* Add lowering for module with gpu.kernel_module attribute.Mahesh Ravishankar2019-12-091-8/+41
| | | | | | | | | | | The existing GPU to SPIR-V lowering created a spv.module for every function with gpu.kernel attribute. A better approach is to lower the module that the function lives in (which has the attribute gpu.kernel_module) to a spv.module operation. This better captures the host-device separation modeled by GPU dialect and simplifies the lowering as well. PiperOrigin-RevId: 284574688
* Update the builder API to take ValueRange instead of ArrayRef<Value *>River Riddle2019-12-071-3/+2
| | | | | | This allows for users to provide operand_range and result_range in builder.create<> calls, instead of requiring an explicit copy into a separate data structure like SmallVector/std::vector. PiperOrigin-RevId: 284360710
* [spirv] Add CompositeInsertOp operationDenis Khalikov2019-12-051-21/+86
| | | | | | | | | | A CompositeInsertOp operation make a copy of a composite object, while modifying one part of it. Closes tensorflow/mlir#292 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/292 from denis0x0D:sandbox/composite_insert 2200962b9057bda53cd2f2866b461e2797196380 PiperOrigin-RevId: 284036551
* Add spv.AtomicCompareExchangeWeakLei Zhang2019-12-051-0/+77
| | | | PiperOrigin-RevId: 283997917
* [spirv] Add spv.GroupNonUniformBallotLei Zhang2019-12-031-0/+40
| | | | | | | | | This CL also did the following cleanup: - Moved the test for spv.SubgroupBallotKHR to its own file - Wrapped generated canonicalization patterns in anonymous namespace - Updated header comments in SPVOps.td PiperOrigin-RevId: 283650091
* [spirv] Add spv.SubgroupBallotKHROpLei Zhang2019-12-031-3/+24
| | | | PiperOrigin-RevId: 283522284
* [spirv] Check that operand of `spirv::CompositeExtractOp` is constant while ↵Denis Khalikov2019-11-281-0/+3
| | | | | | | | | folding. Closes tensorflow/mlir#281 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/281 from denis0x0D:sandbox/composite_ex_fold d02d73658bd1b9eaa515eb4e0aee34bc41d4252b PiperOrigin-RevId: 282971563
* [spirv] NFC: Add getZero() and getOne() static method to ConstantOpLei Zhang2019-11-271-0/+29
| | | | | | | Getting constant zero or one is very common so it merits a special handy method on spirv::ConstantOp itself. PiperOrigin-RevId: 282832572
* [spirv] Add folders for spv.IAdd and spv.IMulLei Zhang2019-11-271-0/+30
| | | | | | | | | Adding zero and multiplying one can be common when generating code for index calculation. This CL also sorted canonicalize.mlir to alphabetical order. PiperOrigin-RevId: 282828055
* Introduce attributes that specify the final ABI for a spirv::ModuleOp.Mahesh Ravishankar2019-11-251-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | To simplify the lowering into SPIR-V, while still respecting the ABI requirements of SPIR-V/Vulkan, split the process into two 1) While lowering a function to SPIR-V (when the function is an entry point function), allow specifying attributes on arguments and function itself that describe the ABI of the function. 2) Add a pass that materializes the ABI described in the function. Two attributes are needed. 1) Attribute on arguments of the entry point function that describe the descriptor_set, binding, storage class, etc, of the spv.globalVariable this argument will be replaced by 2) Attribute on function that specifies workgroup size, etc. (for now only workgroup size). Add the pass -spirv-lower-abi-attrs to materialize the ABI described by the attributes. This change makes the SPIRVBasicTypeConverter class unnecessary and is removed, further simplifying the SPIR-V lowering path. PiperOrigin-RevId: 282387587
* NFC: Wire up DRR settings for SPIR-V canonicalization patternsLei Zhang2019-11-231-57/+9
| | | | | | | | This CL added necessary files and settings for using DRR to write SPIR-V canonicalization patterns and also converted the patterns for spv.Bitcast and spv.LogicalNot. PiperOrigin-RevId: 282132786
* [spirv] Add a canonicalizer for `spirv::LogicalNotOp`.Denis Khalikov2019-11-221-0/+41
| | | | | | | | | | | | | | | | Add a canonicalizer for `spirv::LogicalNotOp`. Converts: * spv.LogicalNot(spv.IEqual(...)) -> spv.INotEqual(...) * spv.LogicalNot(spv.INotEqual(...)) -> spv.IEqual(...) * spv.LogicalNot(spv.LogicalEqual(...)) -> spv.LogicalNotEqual(...) * spv.LogicalNot(spv.LogicalNotEqual(...)) -> spv.LogicalEqual(...) Also moved the test for spv.IMul to arithemtic tests. Closes tensorflow/mlir#256 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/256 from denis0x0D:sandbox/canon_logical_not 76ab5787b2c777f948c8978db061d99e76453d44 PiperOrigin-RevId: 282012356
* Support SPIR-V constant op to take DenseElementsAttr as input.Hanhan Wang2019-11-181-7/+37
| | | | | | | | Iterates each element to build the array. This includes a little refactor to combine bool/int/float into a function, since they are similar. The only difference is calling different function in the end. PiperOrigin-RevId: 281210288
* [spirv] Add a canonicalizer for BitcastOp.Denis Khalikov2019-11-181-4/+33
| | | | | | | | | | Convert chained `spirv::BitcastOp` operations into one `spirv::BitcastOp` operation. Closes tensorflow/mlir#238 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/238 from denis0x0D:sandbox/canon_bitcast 4352ed4f81b959ec92f849c599e733b62a99c010 PiperOrigin-RevId: 281129234
* [spirv] Add bit opsDenis Khalikov2019-11-151-0/+86
| | | | | | | | | | | | | This CL added op definitions for a few bit operations: * OpBitFieldInsert * OpBitFieldSExtract * OpBitFieldUExtract Closes tensorflow/mlir#233 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/233 from denis0x0D:sandbox/bit_field_ops e7fd85b00d72d483d7992dc42b9cc4d673903455 PiperOrigin-RevId: 280691816
* Add support for OpPhi in loop header blockLei Zhang2019-11-121-0/+12
| | | | | | | | | | | | During deserialization, the loop header block will be moved into the spv.loop's region. If the loop header block has block arguments, we need to make sure it is correctly carried over to the block where the new spv.loop resides. During serialization, we need to make sure block arguments from the spv.loop's entry block are not silently dropped. PiperOrigin-RevId: 280021777
* Add support for nested symbol references.River Riddle2019-11-111-8/+9
| | | | | | | | | | | | | | | | | | This change allows for adding additional nested references to a SymbolRefAttr to allow for further resolving a symbol if that symbol also defines a SymbolTable. If a referenced symbol also defines a symbol table, a nested reference can be used to refer to a symbol within that table. Nested references are printed after the main reference in the following form: symbol-ref-attribute ::= symbol-ref-id (`::` symbol-ref-id)* Example: module @reference { func @nested_reference() } my_reference_op @reference::@nested_reference Given that SymbolRefAttr is now more general, the existing functionality centered around a single reference is moved to a derived class FlatSymbolRefAttr. Followup commits will add support to lookups, rauw, etc. for scoped references. PiperOrigin-RevId: 279860501
* [spirv] Add bit opsDenis Khalikov2019-11-081-0/+34
| | | | | | | | | | | | | | | | | | | This CL added op definitions for a few bit operations: * OpShiftLeftLogical * OpShiftRightArithmetic * OpShiftRightLogical * OpBitCount * OpBitReverse * OpNot Also moved the definition of spv.BitwiseAnd to follow the lexicographical order. Closes tensorflow/mlir#215 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/215 from denis0x0D:sandbox/bit_ops d9b0852b689ac6c4879a9740b1740a2357f44d24 PiperOrigin-RevId: 279350470
* Add (parse|print)OptionalAttrDictWithKeyword hooks to simplify parsing ↵River Riddle2019-11-051-17/+3
| | | | | | | | attribute dictionaries with regions. Many operations with regions add an additional 'attributes' prefix when printing the attribute dictionary to differentiate it from the region body. This leads to duplicated logic for detecting when to actually print the attribute dictionary. PiperOrigin-RevId: 278747681
* NFC: Rename parseOptionalAttributeDict -> parseOptionalAttrDict to match the ↵River Riddle2019-11-051-5/+5
| | | | | | name of the print method. PiperOrigin-RevId: 278696668
* [spirv] Add cast operationsDenis Khalikov2019-10-301-22/+34
| | | | | | | | | | | | | | | | | | | This CL added op definitions for a few cast operations: * OpConvertFToU * OpConvertFToS * OpConvertSToF * OpConvertUToF * OpUConvert * OpSConvert * OpFConvert Also moved the definition of spv.Bitcast to the new file. Closes tensorflow/mlir#208 and tensorflow/mlir#174 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/208 from denis0x0D:sandbox/cast_ops 79bc9b37398aafddee6cf6beb301807988fe67f9 PiperOrigin-RevId: 277587891
* Add a utility accessor 'has_single_element' for ranges.River Riddle2019-10-301-1/+1
| | | | | | This provides an easy way to check if a range has a single element. PiperOrigin-RevId: 277544647
* [spirv] Fix gen_spirv_dialect.py and add spv.UnreachableLei Zhang2019-10-301-0/+20
| | | | | | | | | This CL fixed gen_spirv_dialect.py to support nested delimiters when chunking existing ODS entries in .td files and to allow ops without correspondence in the spec. This is needed to pull in the definition of OpUnreachable. PiperOrigin-RevId: 277486465
* Add a convenient operation build method for spirv::SelectOpMahesh Ravishankar2019-10-281-0/+5
| | | | | | | | The SelectOp always has the same result type as its true/false value. Add a builder method that uses the operand type to get the result type. PiperOrigin-RevId: 277217978
* [spirv] AccessChainOp canonicalization.Denis Khalikov2019-10-241-3/+39
| | | | | | | | | | Combine chained `spirv::AccessChainOp` operations into one `spirv::AccessChainOp` operation. Closes tensorflow/mlir#198 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/198 from denis0x0D:sandbox/canon_access_chain 0cb87955a85511071143d62637ff939d0dabc2bd PiperOrigin-RevId: 276609345
* Fix minor spelling tweaks (NFC)Kazuaki Ishizaki2019-10-201-3/+3
| | | | | | Closes tensorflow/mlir#177 PiperOrigin-RevId: 275692653
* Use new eraseOp instead of replaceOp with empty valuesGeoffrey Martin-Noble2019-10-191-1/+1
| | | | PiperOrigin-RevId: 275631166
* NFC: Remove trivial builder get methods.River Riddle2019-10-171-1/+1
| | | | | | These don't add any value, and some are even more restrictive than the respective static 'get' method. PiperOrigin-RevId: 275391240
* [spirv] Add a canonicalization pattern for spv.selection.Denis Khalikov2019-10-171-0/+164
| | | | | | | | | | | Add a canonicalization pattern for spv.selection operation. Convert spv.selection operation to spv.Select based on simple pattern. Closes tensorflow/mlir#183 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/183 from denis0x0D:sandbox/canon_select 43d04d923272dd60b9da39f70bdbc51a5168db62 PiperOrigin-RevId: 275312748
* [spirv] Implement inliner interfaceLei Zhang2019-10-161-0/+9
| | | | | | | | | | | | | | We just need to implement a few interface hooks to DialectInlinerInterface and CallOpInterface to gain the benefits of an inliner. :) Right now only supports some trivial cases: * Inlining single block with spv.Return/spv.ReturnValue * Inlining multi block with spv.Return * Inlining spv.selection/spv.loop without return ops More advanced cases will require block argument and Phi support. PiperOrigin-RevId: 275151132
* [spirv] Add support for SpecId decoration on spv.specConstantLei Zhang2019-10-151-2/+20
| | | | | | | | The SpecId decoration is the handle for providing external specialization. Similar to descriptor set and binding on global variables, we directly bake it into assembly parsing and printing. PiperOrigin-RevId: 274893879
* Add support for parsing/printing non bare-identifier SymbolRefs.River Riddle2019-10-081-11/+15
| | | | | | The restriction that symbols can only have identifier names is arbitrary, and artificially limits the names that a symbol may have. This change adds support for parsing and printing symbols that don't fit in the 'bare-identifier' grammar by printing the reference in quotes, e.g. @"0_my_reference" can now be used as a symbol name. PiperOrigin-RevId: 273644768
* [spirv] Allow return ops to be in control flow opsLei Zhang2019-10-041-2/+2
| | | | | | | Use `getParentOfType<FunctionOp>()` instead of `cast<FuncOp>(getParentOp())` to avoid crash when return ops are used inside spv.selection/spv.loop. PiperOrigin-RevId: 273006041
* Add spv.Undef op to support OpUndef instruction in SPIR-V.Mahesh Ravishankar2019-10-041-0/+17
| | | | | | | | Adding support for OpUndef instruction. Updating the dialect generation script to fix a few bugs in the instruction spec generation. PiperOrigin-RevId: 272975685
* Add some utility builder functions for SPIR-V operations.Mahesh Ravishankar2019-10-041-10/+43
| | | | | | | | | | | Add builder functions for spv._address_of, spv.EntryPoint, spv.ExecutionMode and spv.Load to make it easier to create these operations. Fix a minor bug in printing of spv.EntryPoint Add a utility function to get the attribute name associated with a decoration. PiperOrigin-RevId: 272952846
* [spirv] Add support for spv.selectionLei Zhang2019-10-021-8/+104
| | | | | | | | | | | | | | | Similar to spv.loop, spv.selection is another op for modelling SPIR-V structured control flow. It covers both OpBranchConditional and OpSwitch with OpSelectionMerge. Instead of having a `spv.SelectionMerge` op to directly model selection merge instruction for indicating the merge target, we use regions to delimit the boundary of the selection: the merge target is the next op following the `spv.selection` op. This way it's easier to discover all blocks belonging to the selection and it plays nicer with the MLIR system. PiperOrigin-RevId: 272475006
* Add support for Logical Ops in SPIR-V dialectMahesh Ravishankar2019-09-301-10/+26
| | | | | | | | | | | | | | | | | | Add operations corresponding to OpLogicalAnd, OpLogicalNot, OpLogicalEqual, OpLogicalNotEqual and OpLogicalOr instructions in SPIR-V dialect. This needs changes to class hierarchy in SPIR-V TableGen files to split SPIRVLogicalOp into SPIRVLogicalUnaryOp and SPIRVLogicalBinaryOp. All derived classes of SPIRVLogicalOp are updated accordingly. Update the spirv dialect generation script to 1) Allow specifying base class to use for instruction spec generation and file name to generate the specification in separately. 2) Use the existing descriptions for operations. 3) Update define_inst.sh to also invoke define_opcode.sh to also define the corresponding SPIR-V instruction opcode enum. PiperOrigin-RevId: 272014876
* Add spv.Bitcast operation to SPIR-V dialectMahesh Ravishankar2019-09-251-0/+73
| | | | | | | | | Support the OpBitcast instruction of SPIR-V using the spv.Bitcast operation. The semantics implemented in the dialect differ from the SPIR-V spec in that the dialect does not allow conversion to/from pointer types from/to non-pointer types. PiperOrigin-RevId: 271255957
OpenPOWER on IntegriCloud