Commit Graph

127 Commits

Author SHA1 Message Date
Quinn Dawkins
ff96267b42 [mlir][vector] Add folder for bitcast of integer splat constants
This is a similar to the existing folder for f16 to f32 added with
D96041 but instead for integer types where destination bits > source bits.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D142922
2023-01-30 23:40:42 -05:00
Lei Zhang
d3ddbe153e [mlir][vector] Clarify vector.contract promotion behavior
This commit updates vector.contract documentation to clarify
the promotion behavior if operands and the result have different
bitwidths. It also adds a check to disable signed/unsigned integer
types and only allow signless integers.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D142915
2023-01-31 00:08:26 +00:00
Diego Caballero
4626bd0b91 [mlir][vector] Disable folding for masked reductions
Reductions can't be folded into plain arith ops until we can mask
those arith ops.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D141645
2023-01-19 23:06:53 +00:00
Matthias Springer
e5f711623a [mlir][vector] Limit vector.mask op to single vector result
Multiple vector results require multiple masks and passthru values.

Depends On: D141683

Differential Revision: https://reviews.llvm.org/D141786
2023-01-18 15:55:13 +01:00
Thomas Raoux
b015fccbe5 [mlir][vector] Fix extract op canonicalization for 0d vector
Fix ExtractOpFromBroadcast when the broadcast source is a 0d vector.

Differential Revision: https://reviews.llvm.org/D141735
2023-01-17 17:25:51 +00:00
Thomas Raoux
6dc9725471 [mlir][vector] Fix lowering of permutation maps for transfer_write op
The lowering of transfer write permutation maps didn't match the op definition:
93ccccb00d/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td (L1476)

Fix the lowering and add a case to the integration test in
order to enforce the correct semantic.

Differential Revision: https://reviews.llvm.org/D141801
2023-01-17 17:04:04 +00:00
Frank (Fang) Gao
688d6507c7 [mlir][vector] Add scalable vectors support to OuterProductOp
This will probably be the first in a series of patches that tries to
enable code generation for ARM SME (extension of SVE).

Since SME's core operation is the outer product instruction, I figured
that it would probably be a good idea to enable the outer product
operation to properly accept and generate scalable vectors.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D138718
2023-01-16 11:49:11 -05:00
Prabhdeep Singh Soni
3e38fdf686 Revert "[mlir][vector] Add scalable vectors support to OuterProductOp"
This reverts commit be4c5ad54c.

This patch did not include the test case.
2023-01-16 11:47:06 -05:00
Diego Caballero
afc3756e6c [mlir][vector] Masking support for reductions in Linalg vectorizer
This patch enables vectorization of reductions in Linalg vectorizer
using the vector.mask operation. It also introduces the logic to slice
and propagate the vector mask of a masked multi-reduction to their
respective lowering operations.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D141571
2023-01-13 20:45:04 +00:00
Matthias Springer
f94131a2a5 [mlir][vector] Support multiple result types in vector.mask
The verifier already had support for multiple result types, but the op definition assumed a single, optional result.

Differential Revision: https://reviews.llvm.org/D141683
2023-01-13 16:59:36 +01:00
Frank (Fang) Gao
be4c5ad54c [mlir][vector] Add scalable vectors support to OuterProductOp
This will probably be the first in a series of patches that tries to
enable code generation for ARM SME (extension of SVE).

Since SME's core operation is the outer product instruction, I figured
that it would probably be a good idea to enable the outer product
operation to properly accept and generate scalable vectors.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D138718
2023-01-13 10:54:18 -05:00
Jeff Niu
1b60f0d73c [mlir][ods] Generate inferReturnTypes for ops with TypesMatchWith
Ops that use TypesMatchWith to constrain result types for verification
and to infer result types during parser generation should also be able
to have the `inferReturnTypes` method auto generated. This patch
upgrades the logic for generating `inferReturnTypes` to handle the
TypesMatchWith trait by building a type inference graph where each edge
corresponds to "type of A can be inferred from type of B", supporting
transformers other than `"$_self"`.

Reviewed By: lattner, rriddle

Differential Revision: https://reviews.llvm.org/D141231
2023-01-12 13:26:12 -08:00
Jeff Niu
4d67b27817 [mlir] Add operations to BlockAndValueMapping and rename it to IRMapping
The patch adds operations to `BlockAndValueMapping` and renames it to `IRMapping`. When operations are cloned, old operations are mapped to the cloned operations. This allows mapping from an operation to a cloned operation. Example:

```
Operation *opWithRegion = ...
Operation *opInsideRegion = &opWithRegion->front().front();

IRMapping map
Operation *newOpWithRegion = opWithRegion->clone(map);
Operation *newOpInsideRegion = map.lookupOrNull(opInsideRegion);
```

Migration instructions:
All includes to `mlir/IR/BlockAndValueMapping.h` should be replaced with `mlir/IR/IRMapping.h`. All uses of `BlockAndValueMapping` need to be renamed to `IRMapping`.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D139665
2023-01-12 13:16:05 -08:00
Markus Böck
436ce713e3 [mlir][Vector][NFC] Migrate Vector dialect to the new fold API
See https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618 for context

Differential Revision: https://reviews.llvm.org/D141526
2023-01-12 09:52:14 +01:00
serge-sans-paille
984b800a03 Move from llvm::makeArrayRef to ArrayRef deduction guides - last part
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
2023-01-10 11:47:43 +01: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
d0766c0861 [mlir][vector] Fold vector.extractelement(vector.broadcast)
Differential Revision: https://reviews.llvm.org/D140394
2022-12-22 10:34:58 +01: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
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
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
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
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
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
Oleg Shyshkov
bada35390a [mlir][NFC] Remove unnecessary attr name getters from StructuredOpsUtils.h.
Those methods were added long time ago. Now we get the same methods generated by tablegen, so there is no need for duplicates.

Differential Revision: https://reviews.llvm.org/D137544
2022-11-07 14:40:56 +01:00
Diego Caballero
b1bc1a1ed6 [mlir][Vector] Introduce the MaskingOpInterface
This MaskingOpInterface provides masking cababilitites to those
operations that implement it. For only is only implemented by the `vector.mask`
operation and it's used to break the dependency between the Vector
dialect (where the `vector.mask` op lives) and operations implementing
the MaskableOpInterface.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D136734
2022-10-27 22:54:19 +00:00
Hanhan Wang
00767cb452 [mlir] Delete dup code and use unified methods.
The foldMemRefCast method is defined in memref namespace; the
foldTensorCast method is defined in tensor namespace. This revision
deletes the dup code and use the unified methods.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D136379
2022-10-21 16:51:44 -07:00
Mehdi Amini
f7cd3fc35e Apply clang-tidy fixes for performance-for-range-copy in VectorOps.cpp (NFC) 2022-10-13 21:49:19 +00:00
Diego Caballero
2d10f81d46 [mlir][Vector] Introduce 'vector.mask' operation and MaskableOpInterface
This patch introduces the `vector.mask` operation and the MaskableOpInterface
as described in https://discourse.llvm.org/t/rfc-vector-masking-representation-in-mlir/64964.
The `vector.mask` operation is used to predicate the execution of operations
implementing the MaskableOpInterface. This interface will be implemented by maskable
operations and provides information about its masking constraints and semantics.

For now, only vector transfer and reduction ops implement the MaskableOpInterface
for illustration and testing purposes.

Reviewed By: nicolasvasilache, rriddle

Differential Revision: https://reviews.llvm.org/D134939
2022-10-10 21:25:43 +00:00
Murali Vijayaraghavan
9c3d3eeb51 [mlir] vector.multi_reduction canonicalizes to vector.shape_cast (or
vector.extract, if the result is a scalar) only if all reduction
dimensions are of size 1.

Differential Revision: https://reviews.llvm.org/D135333
2022-10-06 00:11:31 +00:00
Murali Vijayaraghavan
617ca92bf1 Revert "Added canonicalization for vector.multi_reduction"
This reverts commit c16f3260a9.

There's a bug in the commit creates a scalar result with `ShapeCastOp`.
Reverting till that fix is done.
2022-10-05 21:43:51 +00:00
Murali Vijayaraghavan
c16f3260a9 Added canonicalization for vector.multi_reduction
If there are reductions only along unit dimensions, then they are folded

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D134996
2022-10-05 18:43:33 +00:00
Lei Zhang
9e8e4779a2 [mlir][vector] Fix double rank reducing folding bug
In https://reviews.llvm.org/D133883, we changed the
`FoldExtractSliceIntoTransferRead` pattern from requiring
full identity map to minor identity map. This effectively
allows rank reducing `vector.transfer_read` ops. However,
the logic for checking `tensor.extract_slice` rank reducing
still looks at the vector rank, which now could be smaller
than the `tensor.extract_slice`'s output tensor rank.
It ends up we can have incorrect index cacluation after
folding due to this double rank reducing behavior.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D134984
2022-09-30 16:50:48 -04:00