Commit Graph

550 Commits

Author SHA1 Message Date
Kazu Hirata
51ddfd76dd [mlir] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp:947:13:
  error: variable 'distributedDim' set but not used
  [-Werror,-Wunused-but-set-variable]
2023-01-09 09:51:17 -08:00
Matthias Springer
1523b72946 [mlir][vector] Distribute vector.insert op
In case the distributed dim of the dest vector is also a dim of the src vector, each lane inserts a smaller part of the source vector. Otherwise, one lane inserts the entire src vector and the other lanes do nothing.

Differential Revision: https://reviews.llvm.org/D137953
2023-01-09 16:50:28 +01:00
Matthias Springer
73ce971c63 [mlir][vector] Distribute vector.insertelement op
In case of a distribution, only one lane inserts the scalar value. In case of a broadcast, every lane inserts the scalar.

Differential Revision: https://reviews.llvm.org/D137929
2023-01-09 16:41:08 +01:00
Matthias Springer
9085f00b4d [mlir][vector] Support vector.extract distribution of >1D vectors
Ops such as `%1 = vector.extract %0[2] : vector<5x96xf32>`.

Distribute the source vector, then extract. In case of a 1d extract, rewrite to vector.extractelement.

Differential Revision: https://reviews.llvm.org/D137646
2023-01-09 16:39:50 +01:00
Thomas Raoux
f41abcda5e [mlir][vector] Relax restriction on reduction distribution
Relax unnecessary restriction when distribution a vector.reduce op.
All the float and integer types can be supported by user's lambda.

Differential Revision: https://reviews.llvm.org/D141094
2023-01-06 16:20:17 +00:00
jacquesguan
490c77e46d [mlir][vector] Fix typo, NFC.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D140681
2022-12-28 11:46:45 +08:00
Thomas Raoux
1a0453eb44 [mlir][vector] Fix bug in extractOp folding
We were missing to check for transpose when folding.
Also add a new file to test folding independently of
canonicalization as canonicalization was hiding the bug.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D140533
2022-12-22 14:51:02 -08:00
Matthias Springer
41e731f2a4 [mlir][vector] Add additional scalar vector transfer foldings
* Rewrite vector.transfer_write of vectors with 1 element to
  memref.store
* Rewrite vector.extract(vector.transfer_read) to memref.load

Differential Revision: https://reviews.llvm.org/D140391
2022-12-22 14:43:48 +01:00
Matthias Springer
d0766c0861 [mlir][vector] Fold vector.extractelement(vector.broadcast)
Differential Revision: https://reviews.llvm.org/D140394
2022-12-22 10:34:58 +01:00
Matthias Springer
2ec98ffbf1 [mlir][vector] Add scalar vector xfer to memref patterns
These patterns devectorize scalar transfers such as vector<f32> or vector<1xf32>.

Differential Revision: https://reviews.llvm.org/D140215
2022-12-19 10:27:49 +01:00
Fangrui Song
cbb0981388 [mlir] llvm::Optional::value => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.
2022-12-17 19:07:38 +00:00
Ramkumar Ramachandra
22426110c5 mlir/tblgen: use std::optional in generation
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch changes the way mlir-tblgen generates .inc
files, and modifies tests and documentation appropriately. It is a "no
compromises" patch, and doesn't leave the user with an unpleasant mix of
llvm::Optional and std::optional.

A non-trivial change has been made to ControlFlowInterfaces to split one
constructor into two, relating to a build failure on Windows.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D138934
2022-12-17 11:13:26 +01:00
jacquesguan
0017dc2d0f [mlir][Vector] Use llvm::zip to avoid assertion failed.
This patch fixes the issue https://github.com/llvm/llvm-project/issues/59455.
We could omit the un-changed dimensions in offsets and sizes, so llvm::zip_equal would fail in this case.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D139815
2022-12-14 10:26:54 +08:00
Diego Caballero
72fd36448d [mlir][Vector] Initial masking support in Linalg vectorizer
This patch introduces the initial bits to support vector masking
using the `vector.mask` operation. Vectorization changes should be
NFC for non-masked cases. We can't test masked cases directly until
we extend the Transform dialect to support masking.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D137690
2022-12-13 01:33:06 +00:00
Kazu Hirata
192d9dd731 [mlir] Use std::nullopt instead of None in comments (NFC)
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-04 19:58:32 -08:00
Kazu Hirata
70c73d1b72 [mlir] Use std::nullopt instead of None in comments (NFC)
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-04 17:23:50 -08:00
Kazu Hirata
1a36588ec6 [mlir] Use std::nullopt instead of None (NFC)
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-12-03 18:50:27 -08:00
River Riddle
b74192b7ae [mlir] Remove support for non-prefixed accessors
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-12-02 13:32:36 -08:00
Nicolas Vasilache
495acf98da [mlir][Linalg] NFC - Purge OpBuilder uses in favor of RewriterBase in places unrelated to op definitions
RewriterBase is the proper builder to use so one can listen to IR modifications (i.e. not just creation).

Differential Revision: https://reviews.llvm.org/D137922
2022-12-02 08:06:29 -08:00
Jakub Kuderski
459ad97221 [mlir][vector] Reapply remaining cleanups from D139022. NFC.
It appears that structured bindings in function templates require extra
`template` keyword sparkled before `.cast<T>()` calls.
2022-11-30 18:52:54 -05:00
Jakub Kuderski
ce0946d0b0 [mlir][vector] Attempt to please gcc 9. NFC.
This is a post-commit fix to D139022.
2022-11-30 17:39:28 -05:00
Jakub Kuderski
dab9938faa Reapply "[mlir][vector] Clean up use of llvm::zip in VectorOps.cpp"
This reverts commit 0689edd687.

Reapply D139022 without `enumerate` over `zip` to fix build errors on
gcc 9.4.
2022-11-30 17:31:14 -05:00
Jakub Kuderski
0689edd687 Revert "[mlir][vector] Clean up use of llvm::zip in VectorOps.cpp"
This reverts commit f22a573b2b.

There's a buildbot that report compilation errors:
https://lab.llvm.org/buildbot/#/builders/199/builds/13507.
2022-11-30 17:23:18 -05:00
Jakub Kuderski
f22a573b2b [mlir][vector] Clean up use of llvm::zip in VectorOps.cpp
- Use `zip_equal` where iteratees are supposted to have equal lenght.
- Use `zip_first` where the first iteratee is supposed to be the
  shortest.
- Use `llvm::enumerate` instead of calculating index manually.
- Use structured bindings to unpack tuples where appropriate.
- Fix a bug in a comparison in `intersectsWhereNonNegative`.

Both `zip_first` (after D138858) and `zip_equal` (introduced in D138865)
assert interatee lengths, which allows us to more precisely convey
whether we want to iterate over the common prefix (`zip`), or expect all
lengths to be the same (`zip_equal`).

Reviewed By: dcaballe, antiagainst

Differential Revision: https://reviews.llvm.org/D139022
2022-11-30 17:13:04 -05:00
Kazu Hirata
d258021c08 [mlir] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Vector/IR/VectorOps.cpp:1751:13: error: unused
  function 'allBitsSet' [-Werror,-Wunused-function]
2022-11-30 08:57:07 -08:00
Jakub Kuderski
43ead4ecd1 [mlir][vector] Use zip_equal instead of size assertions. NFC. 2022-11-30 11:06:17 -05:00
Nicolas Vasilache
de13eeda11 [mlir][Vector] Add a Broadcast::createBroadcastOp helper
This helper handles non trivial cases of broadcast + optional transpose creation
that should not leak to the outside world.

Differential Revision: https://reviews.llvm.org/D139003
2022-11-30 05:32:14 -08:00
Diego Caballero
eb7e2998d1 Reland "[mlir][Vector] Re-define masking semantics in vector.transfer ops""
This relands commit 847b5f82a4.

Differential Revision: https://reviews.llvm.org/D138079
2022-11-29 03:36:54 +00:00
Diego Caballero
f6d90055fd [mlir][Vector] Remove 'lower-permutation-maps' option from VectorToSCF
This patch is part of a larger simplification effort of vector transfer
operations. It removes the flag `lower-permutation-maps` from
VectorToSCF conversion and enables the lowering of permutation maps
by default. This means that VectorToSCF will always lower permutation
maps to independent broadcast/transpose operations before lowering
vector operations to SCF.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D138742
2022-11-28 23:56:43 +00:00
Jakub Kuderski
f0fe38035c [mlir][vector] Add fold pattern to constant-fold InsertStridedSliceOp
Fold InsertStridedOp(ConstantOp into ConstantOp) -> ConstantOp.

This pattern comes with vector size threshold to make sure we do not
introduce too many large constants.

This help clean up code created by the Wide Integer Emulation pass.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D138739
2022-11-28 14:25:28 -05:00
Nicolas Vasilache
0650e1bcc0 [mlir][vector] Fix folding of vector.extract from vector.broadcast
This revision fixes a bug in the vector.extract folding that was missing
handling the "dim-1" broadcasting case in vector.broadcast.

Differential Revision: https://reviews.llvm.org/D138804
2022-11-28 07:17:31 -08:00
Jakub Kuderski
5d05d2966f [mlir][vector] Add fold pattern for InsertOp(Constant into Constant)
This pattern comes with vector size threshold to make sure we do not
introduce too many large constants.

This help clean up code created by the Wide Integer Emulation pass.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D138733
2022-11-25 23:01:29 -05:00
Jakub Kuderski
360f3b8db4 [mlir][vector] Update stale comment. NFC. 2022-11-25 14:48:31 -05:00
Jakub Kuderski
f795b20736 [mlir][vector] Update fold pattern name. NFC. 2022-11-25 14:44:37 -05:00
Jakub Kuderski
afba86709f [mlir][vector] Add fold for ExtractStridedSlice(non-splat ConstantOp)
This allows us to better canonicalize/clean-up code created by the Wide
Integer Emulation pass.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D138606
2022-11-25 13:42:56 -05:00
Jakub Kuderski
0e72d00d19 [mlir][vector] Constant fold sub-vector extraction
This generalizes the existing fold for `ExtractOp(non-splat constant)`
to work with vector results. The vector case is handled by extracting
the subrange of attribute array.

My main use it to clean up code generated by the Wide Integer Emulation
pass.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D138690
2022-11-25 13:39:45 -05:00
Nicolas Vasilache
6ff1233304 [mlir][Vector] Add a LowerVectorsOp to VectorTransformOps
This op significantly improves transfor dialect usage when using vector abstractions.
It also brings us closer to writing simple end-to-end unit tests that guard against subtle regressions in how patterns combine.

Differential Revision: https://reviews.llvm.org/D138723
2022-11-25 08:27:36 -08:00
Nicolas Vasilache
c4ce8a40fa [mlir][Vector] Vector transform skeleton
Differential Revision: https://reviews.llvm.org/D134722
2022-11-25 04:51:50 -08:00
Jakub Kuderski
51afca640c [mlir][vector] Simplify fold pattern for ExtractOp(constant). NFC.
Use helper functions. Reuse array element attributes.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D138609
2022-11-23 18:57:21 -05:00
Nicolas Vasilache
7a69a9d7ae [NFC][mlir] VectorUtils / IndexingUtils simplifications and cleanups
This revision refactors and cleans up a bunch of infra related to vector, shapes and indexing into more reusable APIs.

Differential Revision: https://reviews.llvm.org/D138501
2022-11-22 23:42:29 -08:00
Kazu Hirata
6ba4b62af8 Return None instead of Optional<T>() (NFC)
This patch replaces:

  return Optional<T>();

with:

  return None;

to make the migration from llvm::Optional to std::optional easier.
Specifically, I can deprecate None (in my source tree, that is) to
identify all the instances of None that should be replaced with
std::nullopt.

Note that "return None" far outnumbers "return Optional<T>();".  There
are more than 2000 instances of "return None" in our source tree.

All of the instances in this patch come from functions that return
Optional<T> except Archive::findSym and ASTNodeImporter::import, where
we return Expected<Optional<T>>.  Note that we can construct
Expected<Optional<T>> from any parameter convertible to Optional<T>,
which None certainly is.

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

Differential Revision: https://reviews.llvm.org/D138464
2022-11-21 19:06:42 -08:00
Aliia Khasanova
399638f98c Merge kDynamicSize and kDynamicSentinel into one constant.
resolve conflicts

Differential Revision: https://reviews.llvm.org/D138282
2022-11-21 13:01:26 +00:00
Matthias Springer
2fea658a74 [mlir] GreedyPatternRewriter: Reprocess modified ops
Ops that were modifed in-place (`finalizeRootUpdate` was called) should be reprocessed by the GreedyPatternRewriter. This is currently not happening with `GreedyRewriteConfig::maxIterations = 1`.

Note: If your project goes into an infinite loop because of this change, you likely have one or multiple faulty patterns that modify the same operations in-place (`updateRootInplace`) indefinitely.

Differential Revision: https://reviews.llvm.org/D138038
2022-11-18 11:43:44 +01:00
Diego Caballero
847b5f82a4 Revert "[mlir][Vector] Re-define masking semantics in vector.transfer ops"
This reverts commit 6c59c5cd08.
2022-11-18 01:18:11 +00:00
Diego Caballero
6c59c5cd08 [mlir][Vector] Re-define masking semantics in vector.transfer ops
Masking hasn't been widely used in vector transfer ops and the semantics
of the mask operand were a bit loose. This patch states that the mask
operand in a vector transfer op is applied to the read/write part of the
operation and, therefore, its shape should match the shape of the
elements read/written from/into the memref/tensor regardless of any
permutation/broadcasting also applied by the transfer operation.

Reviewers: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D138079
2022-11-18 01:05:42 +00:00
Mahesh Ravishankar
fc367dfa67 [mlir] Remove Transforms/SideEffectUtils.h and move the methods into Interface/SideEffectInterfaces.h.
The methods in `SideEffectUtils.h` (and their implementations in
`SideEffectUtils.cpp`) seem to have similar intent to methods already
existing in `SideEffectInterfaces.h`. Move the decleration (and
implementation) from `SideEffectUtils.h` (and `SideEffectUtils.cpp`)
into `SideEffectInterfaces.h` (and `SideEffectInterface.cpp`).

Also drop the `SideEffectInterface::hasNoEffect` method in favor of
`mlir::isMemoryEffectFree` which actually recurses into the operation
instead of just relying on the `hasRecursiveMemoryEffectTrait`
exclusively.

Differential Revision: https://reviews.llvm.org/D137857
2022-11-15 20:07:35 +00:00
Oleg Shyshkov
e6598b053d Revert "Revert "[mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface.""
With python code fixed.

This reverts commit 41280908e4.
2022-11-11 10:54:08 +01:00
stanley-nod
dc26c03066 [mlir][vector] Add insertOp src shape check for BubbleUpBitCastForStridedSliceInsert
Not all shape of vectors can be casted into other types, we add a check
to not fold insertOp into bitcast if the shape does not support it.

Examples of unsupported shape castings are f16 vectors to f32 if the
shape is not multiple of 2s. or int8 to int32 if shapes are not multiple
of 4.

Reviewed By: antiagainst, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D137802
2022-11-10 16:41:59 -08:00
Matthias Springer
9d51b4e4e7 [mlir][vector] Support vector.extractelement distribution of 1D vectors
Ops such as `%1 = vector.extractelement %0[%pos : index] : vector<96xf32>`.

In case of an extract from a 1D vector, the source vector is distributed. The lane into which the requested position falls, extracts the element and shuffles it to all other lanes.

Differential Revision: https://reviews.llvm.org/D137336
2022-11-10 15:07:56 +01:00
Lei Zhang
39c80656fe [mlir][vector] Convert extract_strided_slice to extract & insert chain
This is useful for breaking down extract_strided_slice and potentially
cancel with other extract / insert ops before or after.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D137471
2022-11-09 19:42:07 -05:00