Commit Graph

6624 Commits

Author SHA1 Message Date
Lei Zhang 5b7619c90b [mlir] Fix scf.for single iteration canonicalization check
We should be check whether lb + step >= ub to determine
whether this is a single iteration. Previously we were
checking lb + lb >= ub.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D95440
2021-02-02 18:30:50 -05:00
Diego Caballero cf5c517c05 [mlir][Vector] Add lowering to LLVM for vector.bitcast
Add the conversion pattern for vector.bitcast to lower it to
the LLVM Dialect.

Reviewed By: ThomasRaoux, aartbik

Differential Revision: https://reviews.llvm.org/D95579
2021-02-03 01:19:20 +02:00
Mehdi Amini 29fffff8d3 Revert "Fix namespace for MLIR Async Runtime"
This reverts commit b7d80058ff.

The mlir-windows buildbot is broken.
2021-02-02 20:54:16 +00:00
River Riddle ec10f06609 [mlir][Pattern] Create a new IRRewriter class to enable sharing code with pattern rewrites
This revision adds two new classes, RewriterBase and IRRewriter. RewriterBase is a new shared base class between IRRewriter and PatternRewriter. PatternRewriter will continue to be the base class used to perform rewrites within a rewrite pattern. IRRewriter on the other hand, is a new class that allows for tracking IR rewrites from outside of a rewrite pattern. In this revision all of the old API from PatternRewriter is moved to RewriterBase, but the distinction between IRRewriter and PatternRewriter is kept on the chance that a necessary API divergence happens in the future.

Currently if you want to have some utility that transforms a piece of IR and share it between pattern and non-pattern code, you have to duplicate it. This revision enables the creation of utilities that can be invoked from rewrite patterns and normal transformation code:

```c++
void someSharedUtility(RewriterBase &rewriter, ...) {
  // Some interesting IR mutation here.
}

// Some RewritePattern
LogicalResult MyPattern::matchAndRewrite(Operation *op, PatternRewriter &rewriter) {
  ...
  someSharedUtility(rewriter, ...);
  ...
}

// Some Pass
void MyPass::runOnOperation() {
  ...
  IRRewriter rewriter(...);
  someSharedUtility(rewriter, ...);
}
```

Differential Revision: https://reviews.llvm.org/D94638
2021-02-02 12:04:51 -08:00
Matthew Parkinson b7d80058ff Fix namespace for MLIR Async Runtime
The MLIR Async runtime uses different namespacing for the header file,
and the definitions of its C API. The header file places the extern "C"
functions inside namespace mlir::runtime, and the definitions are not
in a namespace. This causes issues in cl.exe. It treats the declaration
and definition as different, and thus does not apply dllexport to the
definition, which leads to the mlir_async_runtime.dll containing no
definitions, and the mlir_async_runtime.lib not being generated.

This patch moves the namespace to cover the definitions, and thus
generates the dll correctly on Windows with cl.exe.

This was tested with Visual Studio C++ 19.28.29336.

Differential Revision: https://reviews.llvm.org/D95386
2021-02-02 19:17:41 +00:00
Michał Górny 2aa1af9b1d [MLIR] [CMake] Support building MLIR standalone
Add the necessary bits to CMakeLists to make it possible to configure
MLIR against installed LLVM, and build it with minimal need for LLVM
source tree.  The latter is only necessary to run unittests, and if it
is missing then unittests are skipped with a warning.

This change includes the necessary changes to tests, in particular
adding some missing substitutions and defining missing variables
for lit.site.cfg.py substitution.

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D85464

Co-authored-by: Isuru Fernando <isuruf@gmail.com>
2021-02-02 13:10:21 -06:00
Christian Sigg 5b3881691f [mlir] Delay adding the __resume function
The __resume function trips up LLVM's 'X86 DAG->DAG Instruction Selection' unless optimizations are disabled.

Only adding the __resume function when it's needed allows lowering through AsyncToLLVM and LLVM without '-O0' as long as the coroutine functionality is not used.

Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D95868
2021-02-02 20:02:54 +01:00
Vladislav Vinogradov 67dfe9c8d7 [mlir] Return new Operation from `Rewriter::replaceOpWithNewOp`
It will allow to perform additional manipulation with the newly created Operation.
For example, custom attributes propagation/changes.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D95525
2021-02-02 18:33:13 +00:00
Vladislav Vinogradov 9593584988 [mlir] Print more verbose message in case of type inference error
Include the types into the error message.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D95854
2021-02-02 18:27:30 +00:00
Vladislav Vinogradov 7cc7998497 [mlir] Allow to use constant lambda as callbacks for `TypeConverter`
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D95787
2021-02-02 18:26:45 +00:00
Vladislav Vinogradov d8c373815d [mlir][NFC] Add missing include guards to MlirOptMain.h
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95533
2021-02-02 18:26:09 +00:00
Vladislav Vinogradov f1bdf9fa9b [mlir][NFC] Use explicit `mlir` namespace in generated code
This makes the generated code independent from actual namespace of its users.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D95520
2021-02-02 18:24:43 +00:00
Lei Zhang a2e791e396 Revert "[mlir] Fix scf.for single iteration canonicalization check"
This reverts commit b2b35697dc.
It gotten accidentially landed before LGTM.
2021-02-02 11:13:39 -05:00
Lei Zhang e901188cf9 [mlir][spirv] Define sp.VectorShuffle
This patch adds basic op definition, parser/printer, and verifier.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D95825
2021-02-02 11:08:56 -05:00
Lei Zhang b2b35697dc [mlir] Fix scf.for single iteration canonicalization check
We should be check whether lb + step >= ub to determine
whether this is a single iteration. Previously we were
checking lb + lb >= ub.

Differential Revision: https://reviews.llvm.org/D95440
2021-02-02 11:08:56 -05:00
Lei Zhang b24e3cc542 [mlir] Put template specialization in the same namespace
This should address GCC 5 failure due to specialization of
runStrategy in different namespace.
2021-02-02 10:05:32 -05:00
Nicolas Vasilache 8fce22888b [mlir][Linalg] Fix and properly test CodegenStrategy API
Fix a bug that was introduced where calling the codegen strategy with actual concrete C++ Op types did not trigger the expected behavior.
Also introduce a test for the behavior that was missing.

Differential Revision: https://reviews.llvm.org/D95863
2021-02-02 13:01:12 +00:00
Benjamin Kramer 94f540cc7c [mlir][Linalg] Fix unused variable warning in Release builds. NFC. 2021-02-02 12:59:41 +01:00
Nicolas Vasilache 0a2a260aab [mlir][Linalg] Refactor Linalg vectorization for better reuse and extensibility.
This revision unifies Linalg vectorization and paves the way for vectorization of Linalg ops with mixed-precision operations.
The new algorithm traverses the ops in the linalg block in order and avoids recursion.
It uses a BlockAndValueMapping to keep track of vectorized operations.

The revision makes the following modifications but is otherwise NFC:
1. vector.transfer_read are created eagerly and may appear in a different order than the original order.
2. a more progressive vectorization to vector.contract results in only the multiply operation being converted to `vector.contract %a, %b, %zero`, where `%zero` is a
constant of the proper type. Later vector canonicalizations are assumed to rewrite vector.contract %a, %b, %zero + add to a proper accumulate form.

Differential revision: https://reviews.llvm.org/D95797
2021-02-02 11:31:09 +00:00
Alex Zinenko 0409eb2874 [mlir] Keep track of region signature conversions as argument replacements
In dialect conversion, signature conversions essentially perform block argument
replacement and are added to the general value remapping. However, the replaced
values were not tracked, so if a signature conversion was rolled back, the
construction of operand lists for the following patterns could have obtained
block arguments from the mapping and give them to the pattern leading to
use-after-free. Keep track of signature conversions similarly to normal block
argument replacement, and erase such replacements from the general mapping when
the conversion is rolled back.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D95688
2021-02-02 10:38:31 +01:00
Nicolas Vasilache 49c9c3a59e [mlir][Standard] Extend n-D vector lowering to LLVM to [s|z]exti ops.
[s|z]exti ops do not have the same operand and result type.
As a consequence, the lowering of the n-D vector form needs to be relaxed a bit.
This revision additionally performs a few NFC renamings of variables to make them more intuitive.

Differential Revision: https://reviews.llvm.org/D95760
2021-02-02 07:45:50 +00:00
natashaknk 21724ddcb7 [MLIR][TOSA] Comparison based elementwise operations for tosa-to-linalg
Comitted log, exp, maximum, minimum, comparison, ceil and floor conversions from TOSA to LinAlg. Support for signless integer and floating point.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D95839
2021-02-01 21:37:52 -08:00
MaheshRavishankar 342d4662e1 [mlir] Add custom directive hooks for printing mixed integer or value operands.
Add printer and parser hooks for a custom directive that allows
parsing and printing of idioms that can represent a list of values
each of which is either an integer or an SSA value. For example in

`subview %source[%offset_0, 1] [4, %size_1] [%stride_0, 3]`

each of the list (which represents offset, size and strides) is a mix
of either statically know integer values or dynamically computed SSA
values. Since this is used in many places adding a custom directive to
parse/print this idiom allows using assembly format on operations
which use this idiom.

Differential Revision: https://reviews.llvm.org/D95773
2021-02-01 19:03:49 -08:00
Weiwei Li 35f746c17f [mlir][spirv] Add support for OpImageType
Support OpImageType in SPIRV Dialect.

This change doesn't support operand AccessQualifier since
it is optinal and only enables under Kernel capability.

co-authored-by: Alan Liu <alanliu.yf@gmail.com>

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D95580
2021-02-01 16:44:31 -05:00
Mehdi Amini 32ef6d89f4 Avoid string comparisons on the fast path of MLIR Identifier lookup (NFC)
Differential Revision: https://reviews.llvm.org/D95770
2021-02-01 21:05:07 +00:00
Lei Zhang 75347ba1fa Revert "[mlir][spirv] Add support for OpImageType"
This reverts commit 21f1462106.
2021-02-01 15:02:34 -05:00
Lei Zhang 21f1462106 [mlir][spirv] Add support for OpImageType
Support OpImageType in SPIRV Dialect.

This change doesn't support operand AccessQualifier since
it is optinal and only enables under Kernel capability.

co-authored-by: Alan Liu <alanliu.yf@gmail.com>

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D95580
2021-02-01 15:01:31 -05:00
Hanhan Wang b3f611bfe7 [mlir][Linalg] Replace SimplePad with PadTensor in hoist-padding
This is the last revision to migrate using SimplePadOp to PadTensorOp, and the
SimplePadOp is removed in the patch. Update a bit in SliceAnalysis because the
PadTensorOp takes a region different from SimplePadOp. This is not covered by
LinalgOp because it is not a structured op.

Also, remove a duplicated comment from cpp file, which is already described in a
header file. And update the pseudo-mlir in the comment.

This is as same as D95615 but fixing one dep in CMakeLists.txt

Different from D95671, the fix was applied to run target.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D95785
2021-02-01 11:38:43 -08:00
xgupta 94fac81fcc [Branch-Rename] Fix some links
According to the [[ https://foundation.llvm.org/docs/branch-rename/ | status of branch rename ]], the master branch of the LLVM repository is removed on 28 Jan 2021.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95766
2021-02-01 16:43:21 +05:30
Tres Popp 2790cbedd0 Revert "[mlir][Linalg] Replace SimplePad with PadTensor in hoist-padding"
This reverts commit d9b953d84b.

This commit resulted in build bot failures and the author is away from a
computer, so I am reverting on their behalf until they have a chance to
look into this.
2021-02-01 09:43:55 +01:00
Christian Sigg a4b7d52f3a [mlir] Fix missing null termination in cuLinkAddData argument.
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D95679
2021-02-01 09:32:50 +01:00
Hanhan Wang d9b953d84b [mlir][Linalg] Replace SimplePad with PadTensor in hoist-padding
This is the last revision to migrate using SimplePadOp to PadTensorOp, and the
SimplePadOp is removed in the patch. Update a bit in SliceAnalysis because the
PadTensorOp takes a region different from SimplePadOp. This is not covered by
LinalgOp because it is not a structured op.

Also, remove a duplicated comment from cpp file, which is already described in a
header file. And update the pseudo-mlir in the comment.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D95671
2021-02-01 00:02:37 -08:00
Jacques Pienaar 2eb5f34542 Fix omitted kw in type alias printer
* Fixing missing `type` keyword in alias print
* Add test for large tuple type alias & rerun output to verify printed
form can be parsed (which caught the above).
2021-01-31 14:06:58 -08:00
Matthias Springer 5ec59f021c [mlir][AVX512] Fix result type of vp2intersect
The result values of vp2intersect are vectors of bits, i.e.,
vector<8xi1> or vector<16xi8> (instead of i8 or i16).

Differential Revision: https://reviews.llvm.org/D95678
2021-01-31 12:03:46 +09:00
Jacques Pienaar 4d9336923e Use type alias for large tuples
Tuples can occupy quite a lot of space, instead of printing out tuple type
everywhere, just use the type alias if larger (arbitrarily chose a bound for
now).

Differential Revision: https://reviews.llvm.org/D95707
2021-01-29 17:42:23 -08:00
karimnosseir 0af2527536 Update ElementsAttr::isValidIndex to handle ElementsAttr with a scalar. Scalar will have rank 0.
Update ElementsAttr::isValidIndex to handle ElementsAttr with a scalar. Scalar will have rank 0.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D95663
2021-01-29 16:56:00 -08:00
Alexander Belyaev 8d7cbcf582 [mlir] Preserve lexicographic order after loop collapsing.
Currently, for a scf.parallel (i,j,k) after the loop collapsing to 1D is done, the
IVs would be traversed as for an scf.parallel(k,j,i).

Differential Revision: https://reviews.llvm.org/D95693
2021-01-29 21:32:36 +01:00
Christopher Tetreault d3e8b9fdc0 Revert "[CMake] Actually require python 3.6 or greater"
There are builders that do not have python 3.6. Revert until this situation can be rectified

This reverts commit 0703b0753c.
2021-01-29 12:03:32 -08:00
Christopher Tetreault 0703b0753c [CMake] Actually require python 3.6 or greater
Previously, CMake would find any version of Python3. However, the project
claims to require 3.6 or greater, and 3.6 features are being used.

Reviewed By: yln

Differential Revision: https://reviews.llvm.org/D95635
2021-01-29 11:47:21 -08:00
Jordan Rupprecht 010b176cde [mlir][docs] Fix typo: even -> event 2021-01-29 09:16:35 -08:00
Christian Sigg 27924b1263 [mlir] Remove mlir_c_runner_utils_static.
The library is not actually static when BUILD_SHARED_LIBS is on, and tests need to explicitly load it already. Also, the shared objects it was linked to did not use any symbols from it and it was therefore never linked to it.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D95612
2021-01-29 15:04:48 +01:00
Tres Popp 0c5e4a25ee [mlir] Prevent segfault in Tensor canonicalization
This segfault could occur from out of bounds accesses when simplifying
tensor.extract with a constant index and a tensor created by
tensor.from_elements.

This IR is not necesarilly invalid as it might conditionally be
never executed.

Differential Revision: https://reviews.llvm.org/D95535
2021-01-29 10:57:58 +01:00
Mehdi Amini e9dc94291e Introduce a new DialectIdentifier structure, extending Identifier with a Dialect information
This class is looking up a dialect prefix on the identifier on initialization
and keeping a pointer to the Dialect when found.

The NamedAttribute key is now a DialectIdentifier.

Reviewed By: rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D95418
2021-01-29 00:05:36 +00:00
Richard Smith dfe26d5f44 [mlir][Linalg] Fix SFINAE check to actually check the value.
No internal functionality change intended, but this fixes out-of-tree
uses.
2021-01-28 15:15:46 -08:00
MaheshRavishankar 98835e3d98 [mlir][Linalg] Enable TileAndFusePattern to work with tensors.
Differential Revision: https://reviews.llvm.org/D94531
2021-01-28 14:13:01 -08:00
Hanhan Wang 2c7cc5fd20 Revert "[mlir][Linalg] Replace SimplePad with PadTensor in hoist-padding"
This reverts commit 1e790b745d.

Differential Revision: https://reviews.llvm.org/D95636
2021-01-28 11:25:02 -08:00
Hanhan Wang 1e790b745d [mlir][Linalg] Replace SimplePad with PadTensor in hoist-padding
This is the last revision to migrate using SimplePadOp to PadTensorOp, and the
SimplePadOp is removed in the patch. Update a bit in SliceAnalysis because the
PadTensorOp takes a region different from SimplePadOp. This is not covered by
LinalgOp because it is not a structured op.

Also, remove a duplicated comment from cpp file, which is already described in a
header file. And update the pseudo-mlir in the comment.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D95615
2021-01-28 11:09:57 -08:00
Jacques Pienaar acaf85f700 Add convenience function for checking arrays of shapes compatible.
Expand existing one to handle the common case for verifying compatible
is existing and inferred. This considers arrays equivalent if they they
have the same size and pairwise compatible elements.
2021-01-28 10:47:08 -08:00
Aart Bik 8af0ccf5a4 [sparse][mlir] give all sparse kernels an explicit "output" tensor
Rationale:
Providing an output tensor, even if one is not used as input to
the kernel provides the right pattern for using lingalg sparse
kernels (in contrast with reusing a tensor just to provide the shape).
This prepares proper bufferization that will follow.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D95587
2021-01-28 10:41:17 -08:00
Alex Zinenko d6be277347 [mlir] turn complex-to-llvm into a partial conversion
It is no longer necessary to also convert other "standard" ops along with the
complex dialect: the element types are now built-in integers or floating point
types, and the top-level cast between complex and struct is automatically
inserted and removed in progressive lowering.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D95625
2021-01-28 19:14:01 +01:00