Commit Graph

536 Commits

Author SHA1 Message Date
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
stanley-nod
d2061530dc [mlir][vector] Modify constraint and interface for warp reduce on f16 and i8
Quantization method is crucial and ubiqutous in accelerating machine
learning workloads. Most of these methods uses f16 and i8 types.

This patch relaxes the type contraints on warp reduce distribution to
allow these types. Furthermore, this patch also changed the interface
and moved the initial reduction of data to a single thread into the
distributedReductionFn, this gives flexibility for developers to control
how they are obtaining the initial lane value, which might differ based
on the input types. (i.e to shuffle 32-width type, we need to reduce f16
to 2xf16 types rather than a single element).

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D137691
2022-11-09 11:52:17 -08:00
Oleg Shyshkov
41280908e4 Revert "[mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface."
Breaks linalg python tests. Would need to also update python/mlir/dialects/linalg/opdsl.

This reverts commit b809d73973.
2022-11-09 15:59:54 +01:00
Oleg Shyshkov
b809d73973 [mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface.
[RFC: EnumAttr for iterator types in Linalg](https://discourse.llvm.org/t/rfc-enumattr-for-iterator-types-in-linalg/64535)

This affect touches and probably breaks most of the code that creates `linalg.generic`. A fix would be to replace calls to `getParallelIteratorTypeName/getReductionIteratorTypeName` with `mlir::utils::IteratorType::parallel/reduction` and types from `StringRef` to `mlir::utils::IteratorType`.

Due to limitations of tablegen, shared C++ definition of IteratorType enum lives in StructuredOpsUtils.td, but each dialect should have it's own EnumAttr wrapper. To avoid conflict, all enums in a dialect are put into a separate file with a separate tablegen rule.

Test dialect td files are refactored a bit.

Printed format of `linalg.generic` temporarily remains unchanged to avoid breaking code and tests in the same change.

Differential Revision: https://reviews.llvm.org/D137658
2022-11-09 15:47:29 +01: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
Adrian Kuegel
abe2738b7b [mlir] Apply two ClangTidy findings.
- argument name 'isLastOutput' in comment does not match parameter name
  'hasOutput'.
- override is redundant since the function is already declared 'final'.
2022-11-07 09:24:32 +01:00
Thomas Raoux
91f62f0e35 [mlir][vector] Fix distribution of scf.for with value coming from above
When a value used in the forOp is defined outside the region but within
the parent warpOp we need to return and distribute the value to pass it
to new operations created within the loop.
Also simplify the lambda interface.

Differential Revision: https://reviews.llvm.org/D137146
2022-11-02 04:15:18 +00:00
Fangrui Song
22a4b336a6 [mlir][arith] Fix -Wunused-but-set-variable 2022-10-27 23:58:22 +00:00
Diego Caballero
c3e09036e8 [mlir][Vector] Introduce the vector.mask operation lowering
This patch introduces the lowering for xfer ops masked with `vector.mask`.
Vector reductions are not lowered yet because new LLVM intrinsics are needed
in the LLVM dialect.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D136741
2022-10-27 22:54:20 +00: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
Matthias Springer
bf531f28f5 [mlir][vector][bufferize] Implement DestinationStyleOpInterface on TransferWriteOp
This simplifies the BufferizableOpInterface implementation of vector.transfer_write.

Differential Revision: https://reviews.llvm.org/D136348
2022-10-27 11:02:19 +02: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
Alex Zinenko
4b6447e220 [mlir] stopgap for incorrect vector.contract lowering
`vector.contract` is being lowered to the default mul/add contraction
regardless if of the kind indicated. Stop the lowering completely in
this case until the correct one can be implemented.

Reviewed By: springerm, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D136079
2022-10-17 14:49:34 +00:00
Thomas Raoux
1757164eed [mlir][vector] Add distribution for extract from 0d vector
Differential Revision: https://reviews.llvm.org/D135994
2022-10-14 23:06:42 +00: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