summaryrefslogtreecommitdiff
path: root/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
AgeCommit message (Collapse)Author
2025-10-10[MLIR][Vector] Remove vector.splat (#162167)James Newling
vector.splat has been deprecated (user: please use the very similar vector.broadcast instead) with the last PR landing about 6 weeks ago. The discourse discussion is at https://discourse.llvm.org/t/rfc-mlir-vector-deprecate-then-remove-vector-splat/87143/1 The last PR was #152230 This PR completely removes vector.splat. In addition to removing vector.splat from VectorOps.td, it - Updates the few remaining places where vector::SplatOp is created (now vector::BroadcastOp is created) - Removes temporary patterns where vector.splat is replaced by vector.broadcast The only place 'vector.splat' appears is now the files https://github.com/llvm/llvm-project/blob/main/mlir/utils/tree-sitter-mlir/test/corpus/op.txt and https://github.com/llvm/llvm-project/blob/main/mlir/utils/tree-sitter-mlir/dialect/vector.js --------- Signed-off-by: James Newling <james.newling@gmail.com>
2025-10-04[mlir][vector] Simplify rewrite pattern inheriting constructors. NFC. (#161966)Jakub Kuderski
Use the `Base` type alias from https://github.com/llvm/llvm-project/pull/158433.
2025-09-26[MLIR][TBLGen] Added compound assignment operator for any BitEnum (#160840)Alexandra Sidorova
## Details: - Added missing compound assignment operators `|=`, `&=`, `^=` to `mlir-tblgen` - Replaced the arithmetic operators with added assignment operators for `BitEnum` in the transformations - Updated related documentation ## Tickets: - Closes https://github.com/llvm/llvm-project/issues/158098
2025-09-18[mlir][spirv] Simplify inheriting constructor declarations. NFC. (#159681)Jakub Kuderski
Use the `Base` type alias from https://github.com/llvm/llvm-project/pull/158433.
2025-09-15[mlir][vector] Use `source` as the source argument name (#158258)Andrzej Warzyński
This patch updates the following ops to use `source` (instead of `vector`) as the name for their source argument: * `vector.extract` * `vector.scalable.extract` * `vector.extract_strided_slice` This change ensures naming consistency with the "builders" for these Ops that already use the name `source` rather than `vector`. It also addresses part of: * https://github.com/llvm/llvm-project/issues/131602 Specifically, it ensures that we use `source` and `dest` for read and write operations, respectively (as opposed to `vector` and `dest`).
2025-09-04[mlir][spirv][vector] Use adaptor.getElements() in FromElements lowering. ↵Han-Chung Wang
(#156972) Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-08-28[mlir][spirv] Propagate alignment requirements from vector to spirv (#155278)Erick Ochoa Lopez
Propagates the alignment attribute from `vector.{load,store}` to `spirv.{load,store}`. --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2025-07-28[mlir][Vector] Remove `vector.extractelement` and `vector.insertelement` ops ↵Diego Caballero
(#149603) This PR removes `vector.extractelement` and `vector.insertelement` ops from the code base in favor of the `vector.extract` and `vector.insert` counterparts. See RFC: https://discourse.llvm.org/t/rfc-psa-remove-vector-extractelement-and-vector-insertelement-ops-in-favor-of-vector-extract-and-vector-insert-ops
2025-07-22[mlir][NFC] update `Conversion` create APIs (7/n) (#149889)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-22[mlir][vector][spirv] Fix a crash in `VectorLoadOpConverter` (#149964)Longsheng Mou
This PR adds null check for `spirvVectorType` in VectorLoadOpConverter to prevent a crash. Fixes #149956.
2025-07-21[mlir][vector] Support direct broadcast conversion (LLVM & SPIRV) (#148027)James Newling
Add conversion for broadcast from scalar for LLVM and SPIRV. Also some miscellaneous replacements of vector.splat with vector.broadcast in VectorToGPU and ArithToAMDGPU. Part of deprecation of vector.splat RFC: https://discourse.llvm.org/t/rfc-mlir-vector-deprecate-then-remove-vector-splat/87143/4
2025-07-02[mlir][vector][spirv] Lower `vector.to_elements` to SPIR-V (#146618)Eric Feng
Implement `vector.to_elements` lowering to SPIR-V. Fixes: https://github.com/llvm/llvm-project/issues/145929
2025-04-07[mlir][vector] Standardise `valueToStore` Naming Across Vector Ops (NFC) ↵Andrzej Warzyński
(#134206) This change standardises the naming convention for the argument representing the value to store in various vector operations. Specifically, it ensures that all vector ops storing a value—whether into memory, a tensor, or another vector — use `valueToStore` for the corresponding argument name. Updated operations: * `vector.transfer_write`, `vector.insert`, `vector.scalable_insert`, `vector.insert_strided_slice`. For reference, here are operations that currently use `valueToStore`: * `vector.store` `vector.scatter`, `vector.compressstore`, `vector.maskedstore`. This change is non-functional (NFC) and does not affect the functionality of these operations. Implements #131602
2025-02-07[mlir][vector][spirv] Handle 1-element vector.{load|store} lowering. (#126294)Md Abdullah Shahneous Bari
Add support for single element vector{load|store} lowering to SPIR-V. Since, SPIR-V converts single element vector to scalars, it needs special attention for vector{load|store} lowering to spirv{load|store}.
2025-02-06[mlir][spirv] Fix some issues related to converting ub.poison to SPIR-V ↵Andrea Faulds
(#125905) This is a follow-up to 5df62bdc9be9c258c5ac45c8093b71e23777fa0e. That commit should not have needed to make the vector.insert and vector.extract conversions to SPIR-V directly handle the static poison index case, as there is a fold from those to ub.poison, and a conversion pattern from ub.poison to spirv.Undef, however: - The ub.poison fold result could not be materialized by the vector dialect (fixed as of d13940ee263ff50b7a71e21424913cc0266bf9d4). - The conversion pattern wasn't being populated in VectorToSPIRVPass, which is used by the tests. This commit changes this. - The ub.poison to spirv.Undef pattern rejected non-scalar types, which prevented its use for vector results. It is unclear why this restriction existed; a remark in D156163 said this was to avoid converting "user types", but it is not obvious why these shouldn't be permitted (the SPIR-V specification allows OpUndef for all types except OpTypeVoid). This commit removes this restriction. With these fixed, this commit removes the redundant static poison index handling, and updates the tests.
2025-02-05[mlir][spirv] Support poison index when converting vector.insert/extract ↵Andrea Faulds
(#125560) This modifies the conversion patterns so that, in the case where the index is known statically to be poison, the insertion/extraction is replaced by an arbitrary junk constant value, and in the dynamic case, the index is sanitized at runtime. This avoids triggering a UB in both cases. The dynamic case is definitely a pessimisation of the generated code, but the use of dynamic indexes is expected to be very rare and already slow on real-world GPU compilers ingesting SPIR-V, so the impact should be negligible. Resolves #124162.
2025-01-28[mlir][Vector] Add support for poison indices to `Extract/IndexOp` (#123488)Diego Caballero
Following up on #122188, this PR adds support for poison indices to `ExtractOp` and `InsertOp`. It also includes canonicalization patterns to turn extract/insert ops with poison indices into `ub.poison`.
2024-12-04[mlir][spirv][vector] Support converting vector.from_elements to SPIR-V ↵Andrea Faulds
(#118540) Closes #118098.
2024-11-06[mlir][VectorToSPIRV] Add conversion for vector.extract with dynamic indices ↵Kunwar Grover
(#114137)
2024-10-05[mlir][NFC] Mark type converter in `populate...` functions as `const` (#111250)Matthias Springer
This commit marks the type converter in `populate...` functions as `const`. This is useful for debugging. Patterns already take a `const` type converter. However, some `populate...` functions do not only add new patterns, but also add additional type conversion rules. That makes it difficult to find the place where a type conversion was added in the code base. With this change, all `populate...` functions that only populate pattern now have a `const` type converter. Programmers can then conclude from the function signature that these functions do not register any new type conversion rules. Also some minor cleanups around the 1:N dialect conversion infrastructure, which did not always pass the type converter as a `const` object internally.
2024-07-30[mlir][vector] Use `DenseI64ArrayAttr` for shuffle masks (#101163)Benjamin Maxwell
Follow on from #100997. This again removes from boilerplate conversions to/from IntegerAttr and int64_t (otherwise, this is a NFC).
2024-07-26[mlir][spirv] Support `vector.step` in vector to spirv conversion (#100651)Angel Zhang
Added a conversion pattern and LIT tests for lowering `vector.step` to SPIR-V. Fixes: #100602 --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2024-07-22[mlir][spirv] Fix bug for `vector.broadcast` op in `convert-vector-to-spirv` ↵Angel Zhang
pass (#99928) This PR addresses [!17976](https://github.com/iree-org/iree/issues/17976) by using converted `resultType` instead of the original result type obtained from `castOp.getResultVectorType`. A new LIT test is also included.
2024-07-14[mlir][spirv] Handle scalar shuffles in vector to spirv conversion (#98809)Jakub Kuderski
These may not get canonicalized before conversion to spirv and need to be handled during vector to spirv conversion. Because spirv does not support 1-element vectors, we can't emit `spirv.VectorShuffle` and need to lower this to `spirv.CompositeExtract`.
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-06-13[mlir][spirv] Implement SPIR-V lowering for `vector.deinterleave` (#95313)Angel Zhang
1. Added a conversion for `vector.deinterleave` to the `VectorToSPIRV` pass. 2. Added LIT tests for the new conversion. --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2024-05-28[mlir][Bazel] Followup to 57c10fa564af44a5b236bc642c540d715b04448cAdrian Kuegel
It removed the dependency from the wrong target. Also, we need to remove the header include to be able to remove the dependency from VectorToSPIRV.
2024-05-27[mlir][spirv] Add vector.interleave to spirv.VectorShuffle conversion (#93240)Angel Zhang
- Add `vector.interleave` to `spirv.VectorShuffle` conversion - Remove the `vector.interleave` to `vector.shuffle` conversion from `populateVectorToSPIRVPatterns` and CMake/Bazel dependencies --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2024-05-13[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enable in ↵Benoit Jacob
VectorToSPIRV (#92012) This is the second attempt at merging #91800, which bounced due to a linker error apparently caused by an undeclared dependency. `MLIRVectorToSPIRV` needed to depend on `MLIRVectorTransforms`. In fact that was a preexisting issue already flagged by the tool in https://discourse.llvm.org/t/ninja-can-now-check-for-missing-cmake-dependencies-on-generated-files/74344. Context: https://github.com/iree-org/iree/issues/17346. Test IREE integrate showing it's fixing the problem it's intended to fix, i.e. it allows IREE to drop its local revert of https://github.com/llvm/llvm-project/pull/89131: https://github.com/iree-org/iree/pull/17359 This is added to VectorToSPIRV because SPIRV doesn't currently handle `vector.interleave` (see motivating context above). This is limited to 1D, non-scalable vectors.
2024-05-13Revert "[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, ↵Benoit Jacob
enable in VectorToSPIRV" (#92006) Reverts llvm/llvm-project#91800 Reason: https://lab.llvm.org/buildbot/#/builders/268/builds/13935
2024-05-13[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enable in ↵Benoit Jacob
VectorToSPIRV (#91800) Context: https://github.com/iree-org/iree/issues/17346. Test IREE integrate showing it's fixing the problem it's intended to fix, i.e. it allows IREE to drop its local revert of https://github.com/llvm/llvm-project/pull/89131: https://github.com/iree-org/iree/pull/17359 This is added to VectorToSPIRV because SPIRV doesn't currently handle `vector.interleave` (see motivating context above). This is limited to 1D, non-scalable vectors.
2023-12-20[mlir][vector][gpu] Align minf/maxf reduction kind names with arith (#75901)Jakub Kuderski
This is to avoid confusion when dealing with reduction/combining kinds. For example, see a recent PR comment: https://github.com/llvm/llvm-project/pull/75846#discussion_r1430722175. Previously, they were picked to mostly mirror the names of the llvm vector reduction intrinsics: https://llvm.org/docs/LangRef.html#llvm-vector-reduce-fmin-intrinsic. In isolation, it was not clear if `<maxf>` has `arith.maxnumf` or `arith.maximumf` semantics. The new reduction kind names map 1:1 to arith ops, which makes it easier to tell/look up their semantics. Because both the vector and the gpu dialect depend on the arith dialect, it's more natural to align names with those in arith than with the lowering to llvm intrinsics. Issue: https://github.com/llvm/llvm-project/issues/72354
2023-11-27[mlir][spirv] Handle non-innerprod float vector add reductions (#73476)Jakub Kuderski
Instead of extracting all individual vector components and performing a scalar summation, use `spirv.Dot` with the original reduction operand and a vector constant of all ones.
2023-11-26[mlir][spirv] Add floating point dot product (#73466)Jakub Kuderski
Because `OpDot` does not require any extra capabilities or extensions, enable it by default in the vector to spirv conversion.
2023-11-24[mlir][spirv] Split codegen for float min/max reductions and others v2. ↵Jakub Kuderski
[NFC] (#73363) This is https://github.com/llvm/llvm-project/pull/69023 but with cleanups. Reduced complexity by avoiding CRTP and preprocessor defines in favor of free functions Original description by @unterumarmung: --- This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671. There are two types of min/max operations for floating-point numbers: `minf`/`maxf` and `minimumf`/`maximumf`. The code generation for these operations should differ from that of other vector reduction kinds. This difference arises because CL and GL operations for floating-point min and max do not have the same semantics when handling NaNs. Therefore, we must enforce the desired semantics with additional ops. ~~However, since the code generation for floating-point min/max operations shares the same functionality as extracting values for the vector, we have decided to refactor the existing code using the CRTP pattern.~~ This change does not alter the actual behavior of the code and is necessary for future fixes to the codegen for floating-point min/max operations. --------- Co-authored-by: Daniil Dudkin <unterumarmung@yandex.ru>
2023-11-24[mlir][vector][spirv] Lower vector.load and vector.store to SPIR-V (#71674)Kai Wang
Add patterns to lower vector.load to spirv.load and vector.store to spirv.store.
2023-09-22[mlir][Vector] Add support for Value indices to vector.extract/insertDiego Caballero
`vector.extract/insert` ops only support constant indices. This PR is extending them so that arbitrary values can be used instead. This work is part of the RFC: https://discourse.llvm.org/t/rfc-psa-remove-vector-extractelement-and-vector-insertelement-ops-in-favor-of-vector-extract-and-vector-insert-ops Differential Revision: https://reviews.llvm.org/D155034
2023-09-13[mlir][vector] Rename vector reductions: `maxf` → `maximumf`, `minf` → ↵Daniil Dudkin
`minimumf` This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671. Here, we are addressing task 2.1 from the plan, which involves renaming the vector reductions to align with the semantics of the corresponding LLVM intrinsics. Reviewed By: dcaballe Differential Revision: https://reviews.llvm.org/D158618
2023-07-31[mlir][spirv][vector] Fix vector shuffle conversion for scalar inputsJakub Kuderski
Handle both v0 and v1 operands that may be converted to SPIR-V scalars. Fixes: https://github.com/llvm/llvm-project/issues/64271 Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D156717
2023-07-31[mlir][vector] Use DenseI64ArrayAttr for ExtractOp/InsertOp positionsMatthias Springer
`DenseI64ArrayAttr` provides a better API than `I64ArrayAttr`. E.g., accessors returning `ArrayRef<int64_t>` (instead of `ArrayAttr`) are generated. Differential Revision: https://reviews.llvm.org/D156684
2023-06-26[mlir] Add pattern to handle trivial shape_cast in SPIR-VJerry Wu
Handle the trivial case of size-1 vector.shape_cast. Differential Revision: https://reviews.llvm.org/D153719
2023-05-26[mlir] Update cast/isa method calls to function callsTres Popp
This updates the rest (at implementation) of MLIR's use of cast/isa method calls where function calls are possible and automatic refactoring is not. These changes occured in .td files or in macros. 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
2023-05-15[mlir][spirv] Check type legality using converter for vectorsLei Zhang
This allows `index` vectors to be converted to SPIR-V. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D150616
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-04-19[mlir][IR] Remove ShapedType::getSizeInBitsMatthias Springer
This function returns incorrect values for memrefs and vectors due to "widening". Differential Revision: https://reviews.llvm.org/D148501
2023-04-18[mlir][spirv][vector] Enable vector3 when converting to dot productLei Zhang
It's common to see such cases for contraction from convolution with input channel as 3. Although we aren't utilizing all 4 lanes for dot product, it should still be better than performing the multiply and reduction separately. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D148642
2023-03-10[mlir][spirv][vector] Add pattern to convert reduction to SPIR-V dot prodJakub Kuderski
This converts a specific form of `vector.reduction` to SPIR-V integer dot product ops. Add a new test pass to excercise this outside of the main vector to spirv conversion pass. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D145760
2023-02-16[mlir][vector] NFC: Improve vector type accessor methodsLei Zhang
Plain `getVectorType()` can be quite confusing and error-prone given that, well, vector ops always work on vector types, and it can commonly involve both source and result vectors. So this commit makes various such accessor methods to be explicit w.r.t. source or result vectors. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D144159
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2022-12-29[mlir][spirv] Fail vector.bitcast conversion with different bitwidthLei Zhang
Depending on the target environment, we may need to emulate certain types, which can cause issue with bitcast. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D140437