Commit Graph

11290 Commits

Author SHA1 Message Date
jfurtek c4caa90b15 [mlir][tblgen] Generate builders with inferred return types and unwrapped attributes
This diff causes mlir-tblgen to generate code for an additional builder for an
operation argument with a return type that can be inferred *AND* an attribute in
the argument list can be "unwrapped." (Previously, the unwrapped build function
was only generated for builders with explicit return types in separate or
aggregate form.) As an example, this builder might be used by code that creates
operations that implement the `SameOperandsAndResultType` interface. A test case
was created.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D124043
2022-04-25 19:00:44 +00:00
Jeremy Furtek a266a21000 [mlir][ods] Extend the EnumAttr tablegen class to support BitEnum attributes
This diff allows the EnumAttr class to be used for bit enum attributes (in
addition to previously supported integer enum attributes). While integer
and bit enum attributes share many common implementation aspects, parsing
bit enum values requires a separate implementation. This is accomplished
by creating empty parser and printer strings in the EnumAttrInfo record,
and having derived classes (specific to bit and integer enums) override with
an appropriate parser/printer string.

To support existing bit enums that may use a vertical bar separator, the
parser is modified to support the | token.

Tests were added for bit enums alongside integer enums.

Future diffs for fastmath attributes in the arithmetic dialect will use these
changes.

(resubmission of earlier abaondoned diff, updated to reflect subsequent changes
in the repository)

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D123880
2022-04-25 19:00:00 +00:00
jfurtek 4e5dee2f30 [mlir][ods] Add tablegen field for concise printing of BitEnum attributes
This diff introduces a tablegen field for bit enum attributes
(`printBitEnumPrimaryGroups`) to control printing when the enum uses "group"
cases. An example would be an implementation that uses a `fastmath` enum value
as an alias for individual fastmath flags. The proposed field would allow
printing of simply `fast` for the enum value, instead of the more verbose list
that would include `fast` as well as the individual flags (e.g. `reassoc,nnan,
ninf,nsz,arcp,contract,afn,fast`).

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123871
2022-04-25 18:48:35 +00:00
Markus Böck 12a2716953 [mlir][LLVM] Support opaque pointers in `llvm.mlir.addressof`
The verifier of llvm.mlir.addressof did not properly account for opaque pointers, that is, the pointer type not having an element type equal to the type of the referenced global or function. This patch fixes that by skipping the test for the element type if the pointer is opaque.

Differential Revision: https://reviews.llvm.org/D124333
2022-04-25 12:23:16 +02:00
Alex Zinenko 4c807f2f57 [mlir][vector] insert `alloca`s outside of loops
After https://reviews.llvm.org/D119743 added the `AutomaticAllocationScope`
trait to loop-like constructs, the vector transfer full/partial splitting pass
started inserting allocations for temporaries within the closest loop rather
than the closest function (or other allocation scope such as `async.execute`).
While this is correct as long as the lowered code takes care of automatic
deallocation at the end of each iteration of the loop, this interferes with
downstream optimizations that expect `alloca`s to be at the function level.
Step over loops when looking for the closest allocation scope in vector
transfer full/partial splitting pass thus restoring the original behavior.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D124366
2022-04-25 10:49:09 +02:00
Markus Böck 34312f1f0c [mlir][LLVM] Support opaque pointers in data layout entries
This is likely preferable to having it crash if one were to specify an opaque pointer type, and the actual element type is unused either way.

Differential Revision: https://reviews.llvm.org/D124334
2022-04-25 09:14:33 +02:00
Nick Kreeger 4620032ee3 Revert "[mlir][sparse] Expose SpareTensor passes as enums instead of opaque numbers for vectorization and parallelization options."
This reverts commit d59cf901cb.

Build fails on NVIDIA Sparse tests:
https://lab.llvm.org/buildbot/#/builders/61/builds/25447
2022-04-23 20:14:48 -05:00
Nick Kreeger d59cf901cb [mlir][sparse] Expose SpareTensor passes as enums instead of opaque numbers for vectorization and parallelization options.
The SparseTensor passes currently use opaque numbers for the CLI, despite using an enum internally. This patch exposes the enums instead of numbered items that are matched back to the enum.

Fixes GitHub issue #53389

Reviewed by: aartbik, mehdi_amini

Differential Revision: https://reviews.llvm.org/D123876
2022-04-23 19:16:57 -05:00
Matthias Springer 48b8edac1c [mlir][bufferize][NFC] Remove old references to Comprehensive Bufferize
Differential Revision: https://reviews.llvm.org/D124324
2022-04-23 18:01:05 +09:00
Matthias Springer 940a3f6b3d [mlir][bufferize][NFC] Clean up test cases
Run `one-shot-bufferize` instead of `linalg-comprehensive-module-bufferize` and move some test cases to their respective dialects.

Differential Revision: https://reviews.llvm.org/D124323
2022-04-23 18:00:55 +09:00
River Riddle eda6f907d2 [mlir][NFC] Shift a bunch of dialect includes from the .h to the .cpp
Now that dialect constructors are generated in the .cpp file, we can
drop all of the dependent dialect includes from the .h file.

Differential Revision: https://reviews.llvm.org/D124298
2022-04-23 01:09:29 -07:00
River Riddle f3ebf828dc [mlir] Generate Dialect constructors in .cpp instead of .h
By generating in the .h file, we were forcing dialects to include
a lot of additional header files because:

* Fields of the dialect, e.g. std::unique_ptr<>, were unable to use
  forward declarations.
* Dependent dialects are loaded in the constructor, requiring the
  full definition of each dependent dialect (which, depending on
  the file structure of the dialect, may include the operations).

By generating in the .cpp we get much faster builds, and also
better align with the rest of the code base.

Fixes #55044

Differential Revision: https://reviews.llvm.org/D124297
2022-04-23 00:44:54 -07:00
Markus Böck 8ed2bd1e74 [mlir][LLVM] Fix `DataLayoutTypeInterface` for opqaue pointers with non-default address space
As a fallback mechanism, if no entry was supplied for a given address space, the size or alignment for a pointer type with the default address space is returned instead.
This code currently crashes with opaque pointers, as it tries to construct a typed pointer type from the opaque pointer type, leading to a null pointer dereference when fetching the element type.

This patch fixes the issue by handling the opaque pointer cases explicitly.

Differential Revision: https://reviews.llvm.org/D124290
2022-04-23 00:10:31 +02:00
Markus Böck bab3d3778d [mlir][LLVM] Fix crash when using opaque pointers in function signatures
Using opaque pointers in function signatures leads to an attempt to recursively convert all types, including sub types in LLVM types. In the case of LLVM pointers, it may not have a subtype aka element type if it is opaque which would then lead to a null pointer dereference.

Differential Revision: https://reviews.llvm.org/D124291
2022-04-23 00:10:31 +02:00
Yi Zhang 1cddcfdc3c Fix CollapsedLayoutMap for dim size 1 case
This change fixes `CollapsedLayoutMap` for cases where the collapsed
dims are size 1. The cases where inner most dims are size 1 and
noncontiguous can be represented by the strided form and therefore can
be allowed. For such cases, the new stride should be of the next entry
in an association whose dimension is not size 1. If the next entry is
dynamic, it's not possible to decide which stride to use at compilation
time and the stride is set to dynamic.

Differential Revision: https://reviews.llvm.org/D124137
2022-04-22 17:48:24 -04:00
Alex Zinenko 40a8bd635b [mlir] use side effects in the Transform dialect
Currently, the sequence of Transform dialect operations only supports a single
use of each operand (verified by the `transform.sequence` operation). This was
originally motivated by the need to guard against accessing a payload IR
operation associated with a transform IR value after this operation has likely
been rewritten by a transformation. However, not all Transform dialect
operations rewrite payload IR, in particular the "navigation" operation such as
`transform.pdl_match` do not.

Introduce memory effects to the Transform dialect operations to describe their
effect on the payload IR and the mapping between payload IR opreations and
transform IR values. Use these effects to replace the single-use rule, allowing
repeated reads and disallowing use-after-free, where operations with the "free"
effect are considered to "consume" the transform IR value and rewrite the
corresponding payload IR operations). As an additional improvement, this
enables code motion transformation on the transform IR itself.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D124181
2022-04-22 23:29:11 +02:00
Okwan Kwon ee285faed2 [mlir] Do not bubble up extract slice when it is rank-reducing.
The bubble up logic was written by assuming the slice operation is
always a normal slice that outputs a tensor with the same rank.

Differential Revision: https://reviews.llvm.org/D124283
2022-04-22 12:21:47 -07:00
cpillmayer 3e8560f890 [MLIR] Add option to print users of an operation as comment in the printer
This allows printing the users of an operation as proposed in the git issue #53286.
To be able to refer to operations with no result, these operations are assigned an
ID in SSANameState.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D124048
2022-04-22 18:58:10 +00:00
Jacques Pienaar 9bae20b528 [mlir] Add shape.func
Add shape func op for use (primarily) in shape function_library op. Allows
setting default dialect for some simpler authoring. This is a minimal version
of the ops needed.

Differential Revision: https://reviews.llvm.org/D124055
2022-04-22 11:35:35 -07:00
Lei Zhang 6f28fd0bf7 [mlir][vector] Fold 1-element reduction into extract or arith ops
If there is only one single element in the vector, then we can
just extract the element to compute the final result.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D124129
2022-04-22 14:24:46 -04:00
Matthias Springer d6dab38ae4 [mlir][bufferize][NFC] Add function boundary bufferization flag to BufferizationOptions
This makes the API easier to use. Also allows us to check for incorrect API usage for easier debugging.

Differential Revision: https://reviews.llvm.org/D124265
2022-04-23 01:11:37 +09:00
Matthias Springer b0b19fae81 [mlir][bufferize][NFC] Rewrite op filter logic
The `hasFilter` field is not needed. Instead, the filter accepts ops by default if no ALLOW rule was specified.

Differential Revision: https://reviews.llvm.org/D124264
2022-04-23 00:25:24 +09:00
Lei Zhang fc760c0260 [mlir][vector] Fold cancelling vector.shape_cast(vector.broadcast)
vector.broadcast can inject all size one dimensions. If it's
followed by a vector.shape_cast to the original type, we can
cancel the op pair, like cancelling consecutive shape_cast ops.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D124094
2022-04-22 08:58:26 -04:00
Matthias Springer 494505f39f [mlir][bufferize][NFC] Move SCF test cases to SCF dialect
Differential Revision: https://reviews.llvm.org/D124249
2022-04-22 20:35:20 +09:00
Matthias Springer e07a7fd5c0 [mlir][bufferization] Move ModuleBufferization to bufferization dialect
* Move Module Bufferization to the bufferization dialect. The implementation is split into `OneShotModuleBufferize.cpp` and `FuncBufferizableOpInterfaceImpl.cpp`, so that the external model implementation can be easily moved to the func dialect in the future.
* Split and clean up test cases. A few test cases are still remaining in Linalg and will be updated separately.
* `linalg.inplaceable` is renamed to `bufferization.writable` to accurately reflect its current usage.
* Attributes and their verifiers are moved from the Linalg dialect to the Bufferization dialect.
* Expand documentation.
* Add a new flag to One-Shot Bufferize to allow for function boundary bufferization.

Differential Revision: https://reviews.llvm.org/D122229
2022-04-22 19:37:28 +09:00
Matthias Springer bd1d87e3d1 [mlir][bufferization][NFC] Remove layout post processing step
The layout postprocessing step was removed and is now part of the FuncOp bufferization. If the user specified a certain layout map for a tensor function arg, use that layout map directly when bufferizing the function signature. Previously, the bufferization used a generic layout map for every tensor function arg and then updated function signatures and CallOps in a separate step.

Differential Revision: https://reviews.llvm.org/D122228
2022-04-22 18:49:47 +09:00
Matthias Springer 70777d967f [mlir][bufferize][NFC] Move FuncOp bufferization to BufferizableOpInterface impl
FuncOps are now less special. They must still be analyzed + bufferized in a certain order, but they are now bufferized same as other ops that have a region: Bufferize the op first (`bufferize` interface method), then bufferize the region body with other bufferization patterns. In the case of FuncOps, the function signature is bufferized together with ReturnOps. Similar to how, e.g., scf.for ops are bufferized together with scf.yield ops.

This change is essentially a reimplementation of the FuncOp bufferization, but mostly NFC from a user's perspective (apart from error messages). This change is in preparation of moving the code to the bufferization dialect.

Differential Revision: https://reviews.llvm.org/D123214
2022-04-22 18:47:12 +09:00
Matthias Springer d820acdde1 [mlir][bufferize][NFC] Use custom walk instead of GreedyPatternRewriter
The bufferization driver was previously using a GreedyPatternRewriter. This was problematic because bufferization must traverse ops top-to-bottom. The GreedyPatternRewriter was previously configured via `useTopDownTraversal`, but this was a hack; this API was just meant for performance improvements and should not affect the result of the rewrite.

BEGIN_PUBLIC
No public commit message needed.
END_PUBLIC

Differential Revision: https://reviews.llvm.org/D123618
2022-04-22 18:23:09 +09:00
jacquesguan 9b32886e7e [mlir][Arithmetic] Use common constant fold function in RemSI and RemUI to cover splat.
This patch replaces current fold function with the common constant fold funtion in order to cover the situation of constant splat.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D124236
2022-04-22 09:20:18 +00:00
jacquesguan abc17a6751 [mlir][Arithmetic] Use matchPattern to simplify code.
This patch replaces some code with matchPattern and move them before the constant folder function in order to avoid redundant invoking.

Differential Revision: https://reviews.llvm.org/D124235
2022-04-22 08:42:51 +00:00
Adrian Kuegel a74e5a89b9 [mlir] Move isGuaranteedCollapsible to CollapseShapeOp (NFC).
It seems more natural than to have it as a static method of ExpandShapeOp.
Also fix a typo ("the the" -> "the").

Differential Revision: https://reviews.llvm.org/D124234
2022-04-22 10:31:25 +02:00
Will Dietz bb8c8751cf [MLIR] prefer /bin/sh over /bin/bash for simple test scripts
These scripts do not appear to require bash, and while /bin/sh
is not guaranteed either it's more commonly available.

Fixes tests on NixOS and in certain sandbox build environments.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D124205
2022-04-21 20:25:17 -05:00
Amy Zhuang 5bd4bcfc04 [mlir] Modify SuperVectorize to generate select op->combiner op
Insert the select op before the combiner op when vectorizing a
reduction loop that needs a mask, so the vectorized reduction loop
can pass isLoopParallel check and be transformed correctly in later
passes.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D124047
2022-04-21 17:09:13 -07:00
Mahesh Ravishankar 0c090dcc8a [mlir][Linalg] Deprecate legacy reshape + generic op folding patterns.
These patterns have been superceded by the fusion by collapsing patterns.

Differential Revision: https://reviews.llvm.org/D124145
2022-04-21 22:25:23 +00:00
Chris Lattner 31c8abc3f1 [AsmParser/Printer] Rework sourceloc support for function arguments.
When Location tracking support for block arguments was added, we
discussed various approaches to threading support for this through
function-like argument parsing.  At the time, we added a parallel array
of locations that could hold this.  It turns out that that approach was
verbose and error prone, roughly no one adopted it.

This patch takes a different approach, adding an optional source
locator to the UnresolvedOperand class.  This fits much more naturally
into the standard structure we use for representing locators, and gives
all the function like dialects locator support for free (e.g. see the
test adding an example for the LLVM dialect).

Differential Revision: https://reviews.llvm.org/D124188
2022-04-21 12:43:36 -07:00
Frederik Gossen 673e9828be [MLIR] Fix iteration counting in greedy pattern application
Previously, checking that a fix point is reached was counted as a full
iteration. As this "iteration" never changes the IR, this seems counter-
intuitive.

Differential Revision: https://reviews.llvm.org/D123641
2022-04-21 15:17:28 -04:00
Alex Zinenko 0edb262d91 [mlir] enable doc generation for the transform dialect 2022-04-21 18:52:08 +02:00
Fangrui Song ae46b3e01f Revert D121279 "[MLIR][GPU] Add canonicalizer for gpu.memcpy"
This reverts commit 12f55cac69.

Causes miscompile. Will follow up with a reproduce.
2022-04-21 08:55:13 -07:00
Alex Zinenko 30f22429d3 [mlir] Connect Transform dialect to PDL
This introduces a pair of ops to the Transform dialect that connect it to PDL
patterns. Transform dialect relies on PDL for matching the Payload IR ops that
are about to be transformed. For this purpose, it provides a container op for
patterns, a "pdl_match" op and transform interface implementations that call
into the pattern matching infrastructure.

To enable the caching of compiled patterns, this also provides the extension
mechanism for TransformState. Extensions allow one to store additional
information in the TransformState and thus communicate it between different
Transform dialect operations when they are applied. They can be added and
removed when applying transform ops. An extension containing a symbol table in
which the pattern names are resolved and a pattern compilation cache is
introduced as the first client.

Depends On D123664

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D124007
2022-04-21 16:23:10 +02:00
Markus Böck 850b2c6b3c [mlir] Fix `Region`s `takeBody` method if the region is not empty
The current implementation of takeBody first clears the Region, before then taking ownership of the blocks of the other regions. The issue here however, is that when clearing the region, it does not take into account references of operations to each other. In particular, blocks are deleted from front to back, and operations within a block are very likely to be deleted despite still having uses, causing an assertion to trigger [0].

This patch fixes that issue by simply calling dropAllReferences()before clearing the blocks.

[0] 9a8bb4bc63/mlir/lib/IR/Operation.cpp (L154)

Differential Revision: https://reviews.llvm.org/D123913
2022-04-21 15:32:59 +02:00
Markus Böck a41aaf166f [mlir] Make `Regions`s `cloneInto` multithread-readable
Prior to this patch, `cloneInto` would do a simple walk over the blocks and contained operations and clone and map them as it encounters them. As finishing touch it then remaps any successor and operands it has remapped during that process.

This is generally fine, but sadly leads to a lot of uses of both operations and blocks from the source region, in the cloned operations in the target region. Those uses lead to writes in the use-def list of the operations, making `cloneInto` never thread safe.

This patch reimplements `cloneInto` in three steps to avoid ever creating any extra uses on elements in the source region:
* It first creates the mapping of all blocks and block operands
* It then clones all operations to create the mapping of all operation results, but does not yet clone any regions or set the operands
* After all operation results have been mapped, it now sets the operations operands and clones their regions.

That way it is now possible to call `cloneInto` from multiple threads if the Region or Operation is isolated-from-above. This allows creating copies of  functions or to use `mlir::inlineCall` with the same source region from multiple threads. In the general case, the method is thread-safe if through cloning, no new uses of `Value`s from outside the cloned Operation/Region are created. This can be ensured by mapping any outside operands via the `BlockAndValueMapping` to `Value`s owned by the caller thread.

While I was at it, I also reworked the `clone` method of `Operation` a little bit and added a proper options class to avoid having a `cloneWithoutRegionsAndOperands` method, and be more extensible in the future. `cloneWithoutRegions` is now also a simple wrapper that calls `clone` with the proper options set. That way all the operation cloning code is now contained solely within `clone`.

Differential Revision: https://reviews.llvm.org/D123917
2022-04-21 13:43:00 +02:00
Uday Bondhugula f47a38f517 Add async dependencies support for gpu.launch op
Add async dependencies support for gpu.launch op: this allows specifying
a list of async tokens ("streams") as dependencies for the launch.

Update the GPU kernel outlining pass lowering to propagate async
dependencies from gpu.launch to gpu.launch_func op. Previously, a new
stream was being created and destroyed for a kernel launch. The async
deps support allows the kernel launch to be serialized on an existing
stream.

Differential Revision: https://reviews.llvm.org/D123499
2022-04-21 16:25:59 +05:30
Nimish Mishra 00c511b351 Added lowering support for atomic read and write constructs
This patch adds lowering support for atomic read and write constructs.
Also added is pointer modelling code to allow FIR pointer like types to
be inferred and converted while lowering.

Reviewed By: kiranchandramohan

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

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2022-04-21 12:19:13 +05:30
River Riddle 0fd3a1ce60 [mlir][NFC] Update remaining textual references of un-namespaced `func` operations
The special case parsing of operations in the `func` dialect is being removed, and
operations will require the dialect namespace prefix.
2022-04-20 22:17:31 -07:00
River Riddle cda6aa78f8 [mlir][NFC] Update textual references of `func` to `func.func` in Transform tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:30 -07:00
River Riddle a4936cb3e8 [mlir][NFC] Update textual references of `func` to `func.func` in Pass/Target tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:30 -07:00
River Riddle 63237cddc1 [mlir][NFC] Update textual references of `func` to `func.func` in tool/runner tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:30 -07:00
River Riddle 6a99d29022 [mlir][NFC] Update textual references of `func` to `func.func` in IR/Interface tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:30 -07:00
River Riddle 87db8e4439 [mlir][NFC] Update textual references of `func` to `func.func` in Integration tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:29 -07:00
River Riddle c48e3a13f3 [mlir][NFC] Update textual references of `func` to `func.func` in Tensor/Tosa/Vector tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:29 -07:00
River Riddle 2c7836ef15 [mlir][NFC] Update textual references of `func` to `func.func` in SPIRV tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:29 -07:00
River Riddle fb35cd3baf [mlir][NFC] Update textual references of `func` to `func.func` in SparseTensor tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:29 -07:00
River Riddle 0254b0bcf0 [mlir][NFC] Update textual references of `func` to `func.func` in LLVM/Math/MemRef/NVGPU/OpenACC/OpenMP/Quant/SCF/Shape tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:28 -07:00
River Riddle 92d38adb83 [mlir][NFC] Update textual references of `func` to `func.func` in Linalg tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:28 -07:00
River Riddle 412b8850f6 [mlir][NFC] Update textual references of `func` to `func.func` in Bufferization/Complex/EmitC/CF/Func/GPU tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:28 -07:00
River Riddle 5e7dea225b [mlir][NFC] Update textual references of `func` to `func.func` in AMX/Arithmetic/ArmSVE/Async tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:28 -07:00
River Riddle 227ed2f448 [mlir][NFC] Update textual references of `func` to `func.func` in Affine/ tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:27 -07:00
River Riddle 3028bf740e [mlir][NFC] Update textual references of `func` to `func.func` in Conversion/ tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:27 -07:00
River Riddle ccaabff131 [mlir][NFC] Update textual references of `func` to `func.func` in Analysis/ tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:27 -07:00
River Riddle 8ae83bb8be [mlir][NFC] Update textual references of `func` to `func.func` in ODS documentation
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:26 -07:00
River Riddle 2310ced874 [mlir][NFC] Update textual references of `func` to `func.func` in examples+python scripts
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:26 -07:00
Shraiysh Vaishay 88bb2521b0 [mlir][OpenMP] Add checks and tests for hint clause and fix empty hint
This patch handles empty hint value for critical and atomic constructs.

This also adds checks and tests for hint clause on atomic constructs.

Reviewed By: peixin, kiranchandramohan, NimishMishra

Differential Revision: https://reviews.llvm.org/D123186
2022-04-21 07:31:03 +05:30
Mehdi Amini 02eac667ed Improve invalid-ir-print-after-failure.mlir to show the effects of -mlir-print-assume-verified (NFC) 2022-04-20 20:40:41 +00:00
Matthias Springer 8544523dcb [mlir][tensor] Promote extract(from_elements(...)) to folding pattern
Differential Revision: https://reviews.llvm.org/D123617
2022-04-20 23:47:42 +09:00
gysit 407b351da2 [mlir][linalg] Add ods-gen helper to simplify the build methods.
Add a helper used to implement the build methods generated by ods-gen. The change reduces code size and compilation time since all structured op builders use the same build method. The change reduces the LinalgOps.cpp compilation time from 10.2s to 9.8s (debug build).

Depends On D123987

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D124003
2022-04-20 13:14:38 +00:00
gysit 17721b6915 [mlir][linalg] Avoid template methods for parsing and printing.
The revision avoids template methods for parsing and printing that are replicated for every named operation. Instead, the new methods take a regionBuilder argument. The revision reduces the compile time of LinalgOps.cpp from 11.2 to 10.2 seconds (debug build).

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D123987
2022-04-20 13:06:31 +00:00
Uday Bondhugula d7565de6cc [MLIR] NFC. Drop trailing white space in GPU async ops print
NFC. Drop trailing end of line white space in GPU async ops' printer
whenever the list of async deps is empty.

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D123754
2022-04-20 17:56:53 +05:30
Uday Bondhugula d423fc3724 Add RegionBranchOpInterface on affine.for op
Add RegionBranchOpInterface on affine.for op so that transforms relying
on RegionBranchOpInterface can support affine.for. E.g.:
buffer-deallocation pass.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D123568
2022-04-20 17:46:07 +05:30
Matthias Springer 9235e597a4 [mlir][bufferize] Fix missing copies when writing to a buffer in a loop
Writes into tensors that are definied outside of a repetitive region, but with the write happening inside of the repetitive region were previously not considered conflicts. This was incorrect.

E.g.:
```
%0 = ... : tensor<?xf32>
scf.for ... {
  "reading_op"(%0) : tensor<?xf32>
  %1 = "writing_op"(%0) : tensor<?xf32> -> tensor<?xf32>
  ...
}
```

In the above example, "writing_op" should be out-of-place.

This commit fixes the bufferization for any op that declares its repetitive semantics via RegionBranchOpInterface.
2022-04-20 18:51:06 +09:00
Ingo Müller 1fe1f913c5 [mlir][docs] Add missing parentheses in example code on walkers.
`getFunction` was missing parentheses.

Reviewed By: ftynse, mehdi_amini

Differential Revision: https://reviews.llvm.org/D123999
2022-04-20 09:43:41 +00:00
jacquesguan 61baf2ffa7 [mlir][Vector] Add check of supported reduction kind for ScanOp.
This patch adds check of supported reduction kind for ScanOp to avoid using and/or/xor for floating point type.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123977
2022-04-20 02:42:19 +00:00
jacquesguan 590a38920f [mlir][LLVMIR] Add vector predication type cast intrinsic ops.
This patch adds vector predication type cast intrinsic ops.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123996
2022-04-20 02:11:14 +00:00
Mehdi Amini 8608ed1441 Apply clang-tidy fixes for llvm-twine-local in OpenMPToLLVMIRTranslation.cpp (NFC) 2022-04-20 00:39:10 +00:00
John Demme 6b0bed7ea5 [MLIR] [Python] Add a method to clear live operations map
Introduce a method on PyMlirContext (and plumb it through to Python) to
invalidate all of the operations in the live operations map and clear
it. Since Python has no notion of private data, an end-developer could
reach into some 3rd party API which uses the MLIR Python API (that is
behaving correctly with regard to holding references) and grab a
reference to an MLIR Python Operation, preventing it from being
deconstructed out of the live operations map. This allows the API
developer to clear the map when it calls C++ code which could delete
operations, protecting itself from its users.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123895
2022-04-19 15:14:09 -07:00
Krzysztof Drewniak ddc2eb0ada [mlir] Adds getUpperBound() to LoopLikeInterface.
getUpperBound is analogous to getLowerBound(), except for the upper
bound, and is used in range analysis.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D124020
2022-04-19 19:56:44 +00:00
Alex Zinenko 0eb403ad1b [mlir][transform] Introduce transform.sequence op
Sequence is an important transform combination primitive that just indicates
transform ops being applied in a row. The simplest version requires fails
immediately if any transformation in the sequence fails. Introducing this
operation allows one to start placing transform IR within other IR.

Depends On D123135

Reviewed By: Mogball, rriddle

Differential Revision: https://reviews.llvm.org/D123664
2022-04-19 21:41:02 +02:00
Ashay Rane 25c218be36 [MLIR] Add function to create BFloat16 array attribute
This patch adds a new function `mlirDenseElementsAttrBFloat16Get()`,
which accepts the shaped type, the number of BFloat16 values, and a
pointer to an array of BFloat16 values, each of which is a `uint16_t`
value.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D123981
2022-04-19 19:27:06 +00:00
Mehdi Amini 83892d76f4 Print custom assembly on pass failure by default
The printer is now resilient to invalid IR and will already automatically
fallback to the generic form on invalid IR. Using the generic printer on
pass failure was a conservative option before the printer was made
failsafe.

Reviewed By: lattner, rriddle, jpienaar, bondhugula

Differential Revision: https://reviews.llvm.org/D123915
2022-04-19 17:29:08 +00:00
Mehdi Amini 2d6335421f Apply clang-tidy fixes for llvm-qualified-auto in OpenMPToLLVMIRTranslation.cpp (NFC) 2022-04-19 17:20:57 +00:00
Mehdi Amini f9735be7e2 Apply clang-tidy fixes for performance-unnecessary-value-param in ControlFlowInterfaces.cpp (NFC) 2022-04-19 17:20:57 +00:00
Arnab Dutta 12f55cac69 [MLIR][GPU] Add canonicalizer for gpu.memcpy
Fold away gpu.memcpy op when only uses of dest are
the memcpy op in question, its allocation and deallocation
ops.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D121279
2022-04-19 17:54:00 +05:30
Marius Brehler 2ba865903d [mlir][emitc] Add test for invalid type
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D123503
2022-04-19 11:03:56 +02:00
Matthias Springer a3005a406e [mlir][interfaces] Fix infinite loop in insideMutuallyExclusiveRegions
This function was missing a termination condition.
2022-04-19 16:28:52 +09:00
Mehdi Amini 4e01184ad5 Apply clang-tidy fixes for performance-unnecessary-value-param in JitRunner.cpp (NFC) 2022-04-19 07:23:12 +00:00
Mehdi Amini 722a3a58e2 Apply clang-tidy fixes for performance-for-range-copy in MemRefOps.cpp (NFC) 2022-04-19 07:23:12 +00:00
Matthias Springer 0f4ba02db3 [mlir][interfaces] Add helpers for detecting recursive regions
Add helper functions to check if an op may be executed multiple times based on RegionBranchOpInterface.

Differential Revision: https://reviews.llvm.org/D123789
2022-04-19 16:13:32 +09:00
Michael Kruse 2d92ee97f1 Reapply "[OpenMP] Refactor OMPScheduleType enum."
This reverts commit af0285122f.

The test "libomp::loop_dispatch.c" on builder
openmp-gcc-x86_64-linux-debian fails from time-to-time.
See #54969. This patch is unrelated.
2022-04-18 21:56:47 -05:00
Mehdi Amini 1881d6fc80 Apply clang-tidy fixes for performance-unnecessary-copy-initialization in MathOps.cpp (NFC) 2022-04-19 00:47:58 +00:00
Mehdi Amini 6120bd4703 Apply clang-tidy fixes for performance-for-range-copy in ElementwiseOpFusion.cpp (NFC) 2022-04-19 00:47:58 +00:00
Groverkss 15650b320b [MLIR][Presburger] Remove inheritence in MultiAffineFunction
This patch removes inheritence of MultiAffineFunction from IntegerPolyhedron
and instead makes IntegerPolyhedron as a member.

This patch removes virtualization in MultiAffineFunction and also removes
unnecessary functions inherited from IntegerPolyhedron.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123921
2022-04-19 01:25:13 +05:30
Michael Kruse af0285122f Revert "[OpenMP] Refactor OMPScheduleType enum."
This reverts commit 9ec501da76.

It may have caused the openmp-gcc-x86_64-linux-debian buildbot to fail.
https://lab.llvm.org/buildbot/#/builders/4/builds/20377
2022-04-18 14:38:31 -05:00
Michael Kruse 9ec501da76 [OpenMP] Refactor OMPScheduleType enum.
The OMPScheduleType enum stores the constants from libomp's internal sched_type in kmp.h and are used by several kmp API functions. The enum values have an internal structure, namely each scheduling algorithm (e.g.) exists in four variants: unordered, orderend, normerge unordered, and nomerge ordered.

This patch (basically a followup to D114940) splits the "ordered" and "nomerge" bits into separate flags, as was already done for the "monotonic" and "nonmonotonic", so we can apply bit flags operations on them. It also now contains all possible combinations according to kmp's sched_type. Deriving of the OMPScheduleType enum from clause parameters has been moved form MLIR's OpenMPToLLVMIRTranslation.cpp to OpenMPIRBuilder to make available for clang as well. Since the primary purpose of the flag is the binary interface to libomp, it has been made more private to LLVMFrontend. The primary interface for generating worksharing-loop using OpenMPIRBuilder code becomes `applyWorkshareLoop` which derives the OMPScheduleType automatically and calls the appropriate emitter function.

While this is mostly a NFC refactor, it still applies the following functional changes:
 * The logic from OpenMPToLLVMIRTranslation to derive the OMPScheduleType also applies to clang. Most notably, it now applies the nonmonotonic flag for non-static schedules by default.
 * In OpenMPToLLVMIRTranslation, the nonmonotonic default flag was previously not applied if the simd modifier was used. I assume this was a bug, since the effect was due to `loop.schedule_modifier()` returning `mlir::omp::ScheduleModifier::none` instead of `llvm::Optional::None`.
 * In OpenMPToLLVMIRTranslation, the nonmonotonic default flag was set even if ordered was specified, in breach to what the comment before citing the OpenMP specification says. I assume this was an oversight.

The ordered flag with parameter was not considered in this patch. Changes will need to be made (e.g. adding/modifying function parameters) when support for it is added. The lengthy names of the enum values can be discussed, for the moment this is avoiding reusing previously existing enum value names such as `StaticChunked` to avoid confusion.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D123403
2022-04-18 14:03:17 -05:00
River Riddle 58ceae9561 [mlir:NFC] Remove the forward declaration of FuncOp in the mlir namespace
FuncOp has been moved to the `func` namespace for a little over a month, the
using directive can be dropped now.
2022-04-18 12:01:55 -07:00
Mehdi Amini b968c59050 Improve terminator doc in MLIR LangRef
Reviewed By: rriddle, bondhugula

Differential Revision: https://reviews.llvm.org/D123886
2022-04-18 18:43:30 +00:00
Mehdi Amini 21b251624b Apply clang-tidy fixes for readability-identifier-naming in GPUDialect.cpp (NFC) 2022-04-18 18:15:30 +00:00
Mehdi Amini c817628b67 Apply clang-tidy fixes for readability-simplify-boolean-expr in TypeConverter.cpp (NFC) 2022-04-18 18:15:30 +00:00
Jacques Pienaar f4085c57dd [mlir] Fix two AttributeParser aborts
Reproducers that resulted in triggering the following asserts

mlir::NamedAttribute::NamedAttribute(mlir::StringAttr, mlir::Attribute)
mlir/lib/IR/Attributes.cpp:29:3
consumeToken
mlir/lib/Parser/Parser.h:126

Differential Revision: https://reviews.llvm.org/D122240
2022-04-18 09:30:35 -07:00
Groverkss 4ffd0b6fde [MLIR][Presburger] Make IntegerRelation::mergeLocalIds not delete duplicates
This patch modifies mergeLocalIds to not delete duplicate local ids in
`this` relation. This allows the ordering of the final local ids for `this`
to be determined more easily, which is generally required when other objects
refer to these local ids.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D123866
2022-04-18 10:15:35 +05:30
jacquesguan 5479044bfc [mlir][Vector] Fold transpose splat to splat with transposed type.
This revision folds transpose splat to a new splat with the transposed vector type. For a splat, there is no need to actually do transpose for it, it would be more effective to just build a new splat as the result.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123765
2022-04-18 03:00:17 +00:00
Chris Lattner cac19f4141 [LogicalResult.h] Move ParseResult to the bottom of file and fix comment, NFC.
This was review feedback that I missed in the phab review:
https://reviews.llvm.org/D123760
2022-04-17 15:34:26 -07:00
Chris Lattner 81b2dc548b [Support] Move ParseResult from OpDefinition.h to LogicalResult.h
This class is a helper for 'parser-like' use cases of LogicalResult
where the implicit conversion to bool is tolerable.  It is used by the
operation asmparsers, but is more generic functionality that is closely
aligned with LogicalResult.  Hoist it up to LogicalResult.h to make it
more accessible.  This is part of Issue #54884

Differential Revision: https://reviews.llvm.org/D123760
2022-04-17 15:18:33 -07:00
Mehdi Amini d98481a1e7 Revert "[MLIR] Provide a way to print ops in custom form on pass failure"
This reverts commit daabcf5f04.

This patch still had on-going discussion that should be closed before
committing.
2022-04-17 18:55:09 +00:00
Uday Bondhugula daabcf5f04 [MLIR] Provide a way to print ops in custom form on pass failure
The generic form of the op is too verbose and in some cases not
readable. On pass failure, ops have been so far printed in generic form
to provide a (stronger) guarantee that the IR print succeeds. However,
in a large number of pass failure cases, the IR is still valid and
the custom printers for the ops will succeed. In fact, readability is
highly desirable post pass failure. This revision provides an option to
print ops in their custom/pretty-printed form on IR failure -- this
option is unsafe and there is no guarantee it will succeed. It's
disabled by default and can be turned on only if needed.

Differential Revision: https://reviews.llvm.org/D123893
2022-04-17 20:10:40 +05:30
Jacques Pienaar bdabe505f4 [mlir][docs] Add missing directory separator 2022-04-16 21:59:18 -07:00
Valentin Clement bd514967aa
[mlir][CSE] Add ability to remove commutative operations
This patch takes advantage of the Commutative trait on operation
to remove identical commutative operations where the operands are swapped.

The second operation below can be removed since `arith.addi` is commutative.
```
%1 = arith.addi %a, %b : i32
%2 = arith.addi %b, %a : i32
```

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123492
2022-04-16 21:09:47 +02:00
Mehdi Amini 709868707c Apply clang-tidy fixes for readability-identifier-naming in OpFormatGen.cpp (NFC) 2022-04-16 06:36:12 +00:00
Mehdi Amini cdbd9c9bab Apply clang-tidy fixes for llvm-qualified-auto in OpFormatGen.cpp (NFC) 2022-04-16 06:36:11 +00:00
River Riddle 0f304ef017 [mlir] Add asserts when changing various MLIRContext configurations
This helps to prevent tsan failures when users inadvertantly mutate the
context in a non-safe way.

Differential Revision: https://reviews.llvm.org/D112021
2022-04-15 21:49:03 -07:00
Mogball b1d3faab7a [NFC] fix cmake build 2022-04-16 00:56:38 +00:00
Mehdi Amini 94244bda9d Apply clang-tidy fixes for readability-identifier-naming in mlir-parser-fuzzer.cpp (NFC) 2022-04-16 00:44:51 +00:00
Mehdi Amini fc9e440942 Apply clang-tidy fixes for readability-identifier-naming in DummyParserFuzzer.cpp (NFC) 2022-04-16 00:44:51 +00:00
Mogball fa26c7ff4b [mlir] Refactor LICM into a utility
LICM is refactored into a utility that is application on any region. The implementation is moved to Transform/Utils.
2022-04-16 00:37:07 +00:00
Stella Stamenova 353f0a8e43 Revert "[mlir] Refactor LICM into a utility"
This reverts commit 3131f80824.

This commit broke the Windows mlir bot:
https://lab.llvm.org/buildbot/#/builders/13/builds/19745
2022-04-15 17:09:16 -07:00
Mogball 3131f80824 [mlir] Refactor LICM into a utility
LICM is refactored into a utility that is application on any region. The implementation is moved to Transform/Utils.
2022-04-15 22:07:01 +00:00
River Riddle ac860240ad [mlir][NFC] Cleanup the TestClone pass
Fix variable naming convention and cleanup a clang-tidy warning.
2022-04-15 12:57:07 -07:00
River Riddle 31c88660ab [mlir] Remove the use of FilterTypes for template metaprogramming
This technique results in an explosion in compile time, resulting from a
huge number of std::tuple/concat instatiations. This technique is replaced
by simpler metaprogramming and results in a signficant reduction in
compile time. A local debug/asan build saw a 4x speed up in the processing
of ArithmeticOps.h.inc, and given the nature of this change every dialect
should see similar reductions in compile time.

Differential Revision: https://reviews.llvm.org/D123360
2022-04-15 12:57:07 -07:00
Arjun P ef8b2a7cea [MLIR][Presburger] addSymbolicCut: fix the integral symbols heuristic to match the docs
Previously this checked if the entire symbolic numerator was divisible by the
denominator, which is never the case when this function is called. Fixed this to
check only the non-const coefficients in the numerator, which was what was
intended and documented.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123592
2022-04-15 20:34:06 +01:00
Thomas Raoux b4bcef05b7 [mlir][vector] Fix bug in extractFromBroadcast folding
extract was incorrectly folded when the source was coming from a
broadcast that was both adding new rank and broadcasting the inner
dimension.

Differential Revision: https://reviews.llvm.org/D123867
2022-04-15 19:21:45 +00:00
Arjun P 69c1a35488 [MLIR][Presburger][Simplex] moveRowUnknownToColumn: support the row sample value being zero
When the sample value is zero, everything is the same except that failure to
pivot does not imply emptiness. So, leave it to the user to mark as empty if
necessary, if they know the sample value is strictly negative. This is needed
for an upcoming symbolic lexmin heuristic.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123604
2022-04-15 20:15:21 +01:00
William S. Moses 0df963e817 [MLIR][ClonePass] Attempt fix for anonymous pass name 2022-04-15 15:14:20 -04:00
rdzhabarov 3ef4099a61 [mlir] Fix BUILD issues and dependencies.
Differential Revision: https://reviews.llvm.org/D123868
2022-04-15 19:05:02 +00:00
William S. Moses 9a8bb4bc63 [NFC] Update comments 2022-04-15 14:33:13 -04:00
Mogball 3430ae1e7b [mlir] Update LICM to support Graph Regions
Changes the algorithm of LICM to support graph regions (no guarantee of topologically sorted order). Also fixes an issue where ops with recursive side effects and regions would not be hoisted if any nested ops used operands that were defined within the nested region.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D122465
2022-04-15 17:30:27 +00:00
William S. Moses ed499ddcda [MLIR] Fix operation clone
Operation clone is currently faulty.

Suppose you have a block like as follows:

```
(%x0 : i32) {
   %x1 = f(%x0)
   return %x1
}
```

The test case we have is that we want to "unroll" this, in which we want to change this to compute `f(f(x0))` instead of just `f(x0)`. We do so by making a copy of the body at the end of the block and set the uses of the argument in the copy operations with the value returned from the original block.
This is implemented as follows:
1) map to the block arguments to the returned value (`map[x0] = x1`).
2) clone the body

Now for this small example, this works as intended and we get the following.

```
(%x0 : i32) {
   %x1 = f(%x0)
   %x2 = f(%x1)
   return %x2
}
```

This is because the current logic to clone `x1 = f(x0)` first looks up the arguments in the map (which finds `x0` maps to `x1` from the initialization), and then sets the map of the result to the cloned result (`map[x1] = x2`).

However, this fails if `x0` is not an argument to the op, but instead used inside the region, like below.

```
(%x0 : i32) {
   %x1 = f() {
      yield %x0
   }
   return %x1
}
```

This is because cloning an op currently first looks up the args (none), sets the map of the result (`map[%x1] = %x2`), and then clones the regions. This results in the following, which is clearly illegal:

```
(%x0 : i32) {
   %x1 = f() {
      yield %x0
   }
   %x2 = f() {
      yield %x2
   }
   return %x2
}
```

Diving deeper, this is partially due to the ordering (how this PR fixes it), as well as how region cloning works. Namely it will first clone with the mapping, and then it will remap all operands. Since the ordering above now has a map of `x0 -> x1` and `x1 -> x2`, we end up with the incorrect behavior here.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122531
2022-04-15 13:09:13 -04:00
jfurtek bed8212157 [mlir][ods][NFC] Move enum attribute definitions from OpBase.td to EnumAttr.td
This diff moves `EnumAttr` tablegen definitions (specifically, `IntEnumAttr` and
`BitEnumAttr`-related classes) from `OpBase.td` to `EnumAttr.td`. No
functionality is changed.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123551
2022-04-15 16:51:14 +00:00
Alex Zinenko 6c5ae8e974 [mlir] Support opaque types in LLVM IR -> MLIR translation
LLVM IR is moving towards adoption of opaque pointer types. These require extra
information to be passed when constructing some operations, in particular GEP
and Alloca. Adapt the builders of said operations and modify the translation
code to handle both opaque and non-opaque pointers.

This incidentally adds the translation for Alloca alignment and fixes the translation
of struct-related GEP indices that must be constant.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D123792
2022-04-15 17:51:31 +02:00
Lei Zhang 4db65e279b [mlir][vector] Reorder elementwise(transpose)
Similar to the existing pattern for reodering cast(transpose),
this makes transpose following transpose and increases the chance
of embedding the transposition inside contraction op. Actually
cast ops are just special instances of elementwise ops.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123596
2022-04-15 09:05:35 -04:00
Mehdi Amini 4197475eb0 Apply clang-tidy fixes for readability-identifier-naming in TestTypes.cpp (NFC) 2022-04-15 08:01:04 +00:00
Mehdi Amini 7a80912dd8 Apply clang-tidy fixes for modernize-use-default-member-init in ControlFlowSinkUtils.cpp (NFC) 2022-04-15 08:01:04 +00:00
Chia-hung Duan 5232c5c5d4 [mlir] Fix verification order of nested ops.
In order to increase parallism, certain ops with regions and have the
IsIsolatedFromAbove trait will have their verification delayed. That
means the region verifier may access the invalid ops and may lead to a
crash.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D122771
2022-04-15 04:41:10 +00:00
Thomas Raoux 59058c441a [mlir][vector] Add operations used for Vector distribution
Add vector op warp_execute_on_lane_0 that will be used to do incremental
vector distribution in order to target warp level vector programming for
architectures with GPU-like SIMT programming model.
The idea behing the op is discussed further on discourse:
https://discourse.llvm.org/t/vector-vector-distribution-large-vector-to-small-vector/1983/23

Differential Revision: https://reviews.llvm.org/D123703
2022-04-15 03:47:52 +00:00
Jacques Pienaar 35bd41916b [mlir] Add assert to fail with more info (NFC)
This would have assert before during tensor type construction with
opaque error, assert and fail earlier now.
2022-04-14 19:54:12 -07:00
jacquesguan 3d79c52f31 [mlir][LLVMIR] Add more vector predication intrinsic ops.
This revision adds vector predication select, merge and load/store intrinsic ops.

Differential Revision: https://reviews.llvm.org/D123477
2022-04-15 02:13:42 +00:00
Mehdi Amini ffdba713f5 Fix MLIR website generation 2022-04-15 01:28:30 +00:00
Thomas Raoux 894a591cf6 [mlir][nvgpu] Move mma.sync and ldmatrix in nvgpu dialect
Move gpu operation mma.sync and ldmatrix in nvgpu as they are specific
to nvidia target.

Differential Revision: https://reviews.llvm.org/D123824
2022-04-14 23:44:52 +00:00
Mehdi Amini 72e2b4e7a7 Apply clang-tidy fixes for modernize-use-default-member-init in PDLLServer.cpp (NFC) 2022-04-14 22:59:14 +00:00
Mehdi Amini db6796dfa8 Apply clang-tidy fixes for modernize-use-default-member-init in SparseTensorUtils.cpp (NFC) 2022-04-14 22:59:14 +00:00
Bixia Zheng cb6f8d77a2 [mlir][sparse][taco] Use the SparseCompiler from python/tools.
Copy the implementation of SparseCompiler from python/tools to taco/tools until we have a common place to install it. Modify TACO to use this SparseCompiler for compilation and jitting.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D123696
2022-04-14 15:17:18 -07:00
Thomas Raoux 4c564940a1 [mlir][nvgpu] Add NVGPU dialect (architectural specific gpu dialect)
This introduce a new dialect for vendro specific ptx operations. This
also adds the first operation ldmatrix as an example. More operations
will be added in follow up patches.
This new dialect is meant to be a bridge between GPU and Vector
dialectis and NVVM dialect.

This is based on the RFC proposed here:
https://discourse.llvm.org/t/rfc-add-nv-gpu-dialect-hw-specific-extension-of-gpu-dialect-for-nvidia-gpus/61466/8

Differential Revision: https://reviews.llvm.org/D123266
2022-04-14 16:33:46 +00:00
Alex Zinenko e5a5e00825 [mlir] fix compiler warnings
-Wsign-compare and -Wunsued-value in the recently introduced code.
2022-04-14 15:26:50 +02:00
Lei Zhang e54236dfb5 [mlir][vector] Cast away leading one dims for insert ops
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123621
2022-04-14 08:57:32 -04:00
Lei Zhang bc408afbfe [mlir][vector] Fold splat constant transpose
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123595
2022-04-14 08:51:25 -04:00
Alex Zinenko d064c4801c [mlir] Introduce Transform dialect
This dialect provides operations that can be used to control transformation of
the IR using a different portion of the IR. It refers to the IR being
transformed as payload IR, and to the IR guiding the transformation as
transform IR.

The main use case for this dialect is orchestrating fine-grain transformations
on individual operations or sets thereof. For example, it may involve finding
loop-like operations with specific properties (e.g., large size) in the payload
IR, applying loop tiling to those and only those operations, and then applying
loop unrolling to the inner loops produced by the previous transformations. As
such, it is not intended as a replacement for the pass infrastructure, nor for
the pattern rewriting infrastructure. In the most common case, the transform IR
will be processed and applied to payload IR by a pass. Transformations
expressed by the transform dialect may be implemented using the pattern
infrastructure or any other relevant MLIR component.

This dialect is designed to be extensible, that is, clients of this dialect are
allowed to inject additional operations into this dialect using the newly
introduced in this patch `TransformDialectExtension` mechanism. This allows the
dialect to avoid a dependency on the implementation of the transformation as
well as to avoid introducing dialect-specific transform dialects.

See https://discourse.llvm.org/t/rfc-interfaces-and-dialects-for-precise-ir-transformation-control/60927.

Reviewed By: nicolasvasilache, Mogball, rriddle

Differential Revision: https://reviews.llvm.org/D123135
2022-04-14 13:48:45 +02:00
Alex Zinenko 09141f1adf [mlir] Split intrinsics out of LLVMOps.td
Move the operations that correspond to LLVM IR intrinsics in a separate .td
file. This makes it easier to maintain the intrinsics and decreases the compile
time of LLVMDialect.cpp by ~25%.

Depends On D123310

Reviewed By: wsmoses, jacquesguan

Differential Revision: https://reviews.llvm.org/D123315
2022-04-14 13:23:31 +02:00
Alex Zinenko 2366a43b3c [mlir] initial support for opaque pointers in the LLVM dialect
LLVM IR has introduced and is moving forward with the concept of opaque
pointers, i.e. pointer types that are not carrying around the pointee type.
Instead, memory-related operations indicate the type of the data being accessed
through the opaque pointer. Introduce the initial support for opaque pointers
in the LLVM dialect:

  - `LLVMPointerType` to support omitting the element type;
  - alloca/load/store/gep to support opaque pointers in their operands and
    results; this requires alloca and gep to store the element type as an
    attribute;
  - memory-related intrinsics to support opaque pointers in their operands;
  - translation to LLVM IR for the ops above is no longer using methods
    deprecated in LLVM API due to the introduction of opaque pointers.

Unlike LLVM IR, MLIR can afford to support both opaque and non-opaque pointers
at the same time and simplify the transition. Translation to LLVM IR of MLIR
that involves opaque pointers requires the LLVMContext to be configured to
always use opaque pointers.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D123310
2022-04-14 13:23:29 +02:00
Mehdi Amini 35f48edb91 Apply clang-tidy fixes for llvm-qualified-auto in VectorTransforms.cpp (NFC) 2022-04-14 09:42:37 +00:00
Mehdi Amini 2d06420879 Apply clang-tidy fixes for performance-for-range-copy in SCF.cpp (NFC) 2022-04-14 09:42:36 +00:00
Uday Bondhugula 3766ca75f8 [MLIR] Fix missing return statement warning in PatternMatch.h
Fix missing return statement warning in PatternMatch.h. NFC.

```
mlir/include/mlir/IR/PatternMatch.h:983:3: warning: no return statement in
function returning non-void [-Wreturn-type]
```

Differential Revision: https://reviews.llvm.org/D123756
2022-04-14 13:03:21 +05:30
Arnab Dutta 392d55c1e2 [MLIR][GPU] Add canonicalization patterns for folding simple gpu.wait ops.
* Fold away redundant %t = gpu.wait async + gpu.wait [%t] pairs.

* Fold away %t = gpu.wait async ... ops when %t has no uses.

* Fold away gpu.wait [] ops.

* In case of %t1 = gpu.wait async [%t0], replace all uses of %t1
  with %t0.

Differential Revision: https://reviews.llvm.org/D121878
2022-04-14 12:30:55 +05:30
Stella Laurenzo 61352a580a [mlir] Introduce ml_program dialect.
Differential Revision: https://reviews.llvm.org/D120203
2022-04-13 21:38:14 -07:00
Stella Laurenzo 4f7585195d [NFC] Generically resolve body in FunctionOpInterface verifyBody.
Since the actual implementation class can arbitrarily shadow parts of the FunctionOpInterface exported API, access the body generically instead of via the use of the interface being defined.

Fixes https://github.com/llvm/llvm-project/issues/54807

Differential Revision: https://reviews.llvm.org/D123757
2022-04-13 20:58:19 -07:00
Arjun P 094ad0667c [MLIR][Presburger] change some `push_back`s to `emplace_back`s 2022-04-14 04:27:21 +01:00
Arjun P ef95a6e827 [MLIR][Presburger] change some post-increments/decrements to pre-increments/decrements 2022-04-14 04:26:29 +01:00
Okwan Kwon 18a01527ea [mlir] Fix a typo to load lsp-mode correctly.
Differential Revision: https://reviews.llvm.org/D123745
2022-04-14 00:04:40 +00:00
Mehdi Amini 93b23c8439 Apply clang-tidy fixes for llvm-else-after-return in SCF.cpp (NFC) 2022-04-13 23:14:44 +00:00
Mehdi Amini f19e90bc1f Apply clang-tidy fixes for readability-identifier-naming in OpenMPDialect.cpp (NFC) 2022-04-13 23:14:44 +00:00
Christopher Bate 77d2c815f5 [MLIR][GPU] Add GPU ops nvvm.mma.sync, nvvm.mma.ldmatrix, lane_id
This change adds three new operations to the GPU dialect: gpu.mma.sync,
gpu.mma.ldmatrix, and gpu.lane_id. The former two are meant to target
the lower level nvvm.mma.sync and nvvm.ldmatrix instructions, respectively.
Lowerings are added for the new GPU operations for conversion to
NVVM.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123647
2022-04-13 22:50:07 +00:00
Thomas Raoux 5b1b7108c8 [mlir][vector] Add unrolling pattern for TransposeOp
Support unrolling for vector.transpose following the same interface as
other vector unrolling ops.

Differential Revision: https://reviews.llvm.org/D123688
2022-04-13 19:44:16 +00:00
Mogball 60e34f8ddd [mlir][ods] Remove StrEnumAttr
StrEnumAttr has been deprecated in favour of EnumAttr, a solution based on AttrDef (https://reviews.llvm.org/D115181). This patch removes StrEnumAttr, along with all the custom ODS logic required to handle it.

See https://discourse.llvm.org/t/psa-stop-using-strenumattr-do-use-enumattr/5710 on how to transition to EnumAttr. In short,

```
// Before
def MyEnumAttr : StrEnumAttr<"MyEnum", "", [
  StrEnumAttrCase<"A">,
  StrEnumAttrCase<"B">
]>;

// After (pick an integer enum of your choice)
def MyEnum : I32EnumAttr<"MyEnum", "", [
  I32EnumAttrCase<"A", 0>,
  I32EnumAttrCase<"B", 1>
]> {
  // Don't generate a C++ class! We want to use the AttrDef
  let genSpecializedAttr = 0;
}
// Define the AttrDef
def MyEnum : EnumAttr<MyDialect, MyEnum, "my_enum">;
```

Reviewed By: rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D120834
2022-04-13 17:49:02 +00:00
Jacques Pienaar 5a236e69f2 [mlir][pdll] Include string in PDLLServer.h 2022-04-13 10:31:06 -07:00
Jacques Pienaar a9d7598ef8 [mlir][pdll] Rename extra dir flag
Not sure why this is overlapping, need to repro locally, but just rename
to something more explicit instead.
2022-04-13 10:00:10 -07:00
Jacques Pienaar aa9da11f5d [mlir][pdll] Add extra-dirs for LSP includes.
Enable specifying additional include directories to search. This is
consistent with what one can do with clangd (although there it is more
general compilation options) and Python LSP. We would in general expect
these to be provided by compilation database equivalent.

Differential Revision: https://reviews.llvm.org/D123474
2022-04-13 09:41:45 -07:00
Marius Brehler f71f105901 [mlir][docs] Fix broken links 2022-04-13 16:18:20 +02:00
Adrian Kuegel bd941c83f5 [mlir][Tensor] Fix wrong comment (NFC) 2022-04-13 14:30:55 +02:00
Shraiysh Vaishay f0ba32d666 [mlir][LLVM-IR] Added support for global variable attributes
This patch adds thread_local to llvm.mlir.global and adds translation for dso_local and addr_space to and from LLVM IR.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D123412
2022-04-13 08:31:01 +05:30
jacquesguan 605fc89a61 [mlir][Arithmetic] Add common constant folder function for type cast ops.
This revision replaces current type cast constant folder with a new common type cast constant folder function template.
It will cover all former folder and support fold the constant splat and vector.

Differential Revision: https://reviews.llvm.org/D123489
2022-04-13 02:11:59 +00:00
Aart Bik 28063a281b [mlir][sparse] refactored python setup of sparse compiler
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D123419
2022-04-12 11:58:41 -07:00
Mahesh Ravishankar b40e901333 [mlir][Linalg] Allow collapsing subset of the reassociations when fusing by collapsing.
This change generalizes the fusion of `tensor.expand_shape` ->
`linalg.generic` op by collapsing to handle cases where only a subset
of the reassociations specified in the `tensor.expand_shape` are valid
to be collapsed.
The method that does the collapsing is refactored to allow it to be a
generic utility when required.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D123153
2022-04-12 18:56:32 +00:00
Shraiysh Vaishay b18e82186f [mlir][OpenMP] Added omp.task
This patch adds tasking construct according to Section 2.10.1 of OpenMP 5.0

Reviewed By: peixin, kiranchandramohan, abidmalikwaterloo

Differential Revision: https://reviews.llvm.org/D123575
2022-04-12 23:55:47 +05:30
Groverkss 20aedb148b [MLIR][Presburger] Remove inheritance from PresburgerSpace in IntegerRelation, PresburgerRelation and PWMAFunction
This patch removes inheritence from PresburgerSpace in IntegerRelation and
instead makes it a member of these classes.

This is required for three reasons:
  - It prevents implicit casting to PresburgerSpace.
  - Not all functions of PresburgerSpace need to be exposed by the deriving classes.
  - IntegerRelation and IntegerPolyhedron are defined in a PresburgerSpace. It
    makes more sense for the space to be a member instead of them inheriting from
    a space.

Reviewed By: arjunp, ftynse

Differential Revision: https://reviews.llvm.org/D123585
2022-04-12 22:48:52 +05:30
Arjun P 0ac213667d [MLIR][Presburger] normalizeDiv: add assert that denom > 0 2022-04-12 13:06:53 +01:00
jacquesguan 83bd4fe2e8 [mlir][Math] Replace some constant folder functions with common folder functions.
Differential Revision: https://reviews.llvm.org/D123485
2022-04-12 11:34:47 +00:00
Arjun P 4aeb2a57f4 [MLIR][Presburger][Simplex] addSymbolicCut: don't add symbol div if denom is 1
This is unncessary, so we remove it as an optimization.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123540
2022-04-12 12:27:27 +01:00
Andrzej Warzynski fb16ed258c [mlir] Prefix pass manager options with `mlir-`
With this change, there's going to be a clear distinction between LLVM
and MLIR pass maanger options (e.g. `-mlir-print-after-all` vs
`-print-after-all`). This change is desirable from the point of view of
projects that depend on both LLVM and MLIR, e.g. Flang.

For consistency, all pass manager options in MLIR are prefixed with
`mlir-`, even options that don't have equivalents in LLVM .

Differential Revision: https://reviews.llvm.org/D123495
2022-04-12 09:32:44 +00:00
Matthias Springer fa087b4352 [mlir][scf][bufferize][NFC] Lookup buffer using helper function
Lookup iter_arg buffers using `lookupBuffer` instead of always creating a new `ToMemrefOp`. Also cast all yielded buffers (if necessary), regardless of whether they are an equivalent buffer or a new allocation.

Note: This should have been part of D123369.

Differential Revision: https://reviews.llvm.org/D123383
2022-04-12 18:09:30 +09:00
Mehdi Amini eeef40a6cd Apply clang-tidy fixes for performance-unnecessary-value-param in LLVMDialect.cpp (NFC) 2022-04-12 07:47:04 +00:00
Mehdi Amini e188ad8bf0 Apply clang-tidy fixes for performance-unnecessary-value-param in SplitReduction.cpp (NFC) 2022-04-12 07:47:04 +00:00
Mehdi Amini 30846d2916 Guard copy of std::function to llvm::function_ref (fix crash)
This is a footgun: assigning a null std::function to a function_ref
does not yield a null function_ref...
2022-04-12 07:44:04 +00:00
Mehdi Amini 07db69effe Use std::function instead of function_ref in MLIR JitRunner
This fixes an ASAN failure.
2022-04-12 07:28:19 +00:00
Mehdi Amini 6b7e6ea489 Revert "Fix CUDA runtime wrapper for GPU mem alloc/free to async"
This reverts commit b4117fede2.
This broke one of the MLIR bot, a test is failing.
2022-04-12 06:50:27 +00:00
Mehdi Amini 3c9e09036c Apply clang-tidy fixes for readability-identifier-naming in LinalgOps.cpp (NFC) 2022-04-12 05:30:01 +00:00
Mehdi Amini 47286e17ed Apply clang-tidy fixes for performance-for-range-copy in LinalgOps.cpp (NFC) 2022-04-12 05:30:01 +00:00
Mehdi Amini 0149a437e2 Apply clang-tidy fixes for llvm-qualified-auto in LinalgOps.cpp (NFC) 2022-04-12 04:39:58 +00:00
Mehdi Amini bf62a4b9c5 Apply clang-tidy fixes for performance-move-const-arg in ArithmeticOps.cpp (NFC) 2022-04-12 04:39:57 +00:00
Uday Bondhugula 56245cc18c [MLIR] NFC. Address clang-tidy warning in AffineOps.cpp
NFC. Address clang-tidy warning in AffineOps.cpp.
2022-04-12 09:58:29 +05:30
Uday Bondhugula b4117fede2 Fix CUDA runtime wrapper for GPU mem alloc/free to async
Switch CUDA runtime wrapper for GPU mem alloc/free to async. The
semantics of the GPU dialect ops (gpu.alloc/dealloc) and the wrappers it
lowered to (gpu-to-llvm) was for the async versions -- however, this was
being incorrectly mapped to cuMemAlloc/cuMemFree instead of
cuMemAllocAsync/cuMemFreeAsync.

Reviewed By: csigg

Differential Revision: https://reviews.llvm.org/D123482
2022-04-12 09:04:02 +05:30
Peixin-Qiao 139c5b8a96 [MLIR][OpenMP] Add support for threadprivate directive
This supports the threadprivate directive in OpenMP dialect following
the OpenMP 5.1 [2.21.2] standard. Also lowering to LLVM IR using OpenMP
IRBduiler.

Reviewed By: kiranchandramohan, shraiysh, arnamoy10

Differential Revision: https://reviews.llvm.org/D123350
2022-04-12 10:15:15 +08:00
jacquesguan 920527f4b5 [mlir][NFC] Remove some redundant code.
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123487
2022-04-12 02:10:04 +00:00
Eugene Zhulenev b35b9e307f [mlir] Add msan memory unpoisoning macros to mlir ExecutionEngine
Adding annotations on as-needed bases, currently only for memrefCopy, but in general all C API functions that take pointers to memory allocated/initialized inside the jit-compiled code must be annotated, to be able to run with msan.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123557
2022-04-11 18:58:28 -07:00
Arthur Eubanks 7ccd026cf2 Reland [mlir] Remove uses of LLVM's legacy pass manager
Use the new pass manager.

This also removes the ability to run arbitrary sets of passes. Not sure if this functionality is used, but it doesn't seem to be tested.

No need to initialize passes outside of constructing the PassBuilder with the new pass manager.

Reland: Fixed custom calls to `-lower-matrix-intrinsics` in integration tests by replacing them with `-O0 -enable-matrix`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123425
2022-04-11 16:53:32 -07:00
Arthur Eubanks c3efb75061 Revert "[mlir] Remove uses of LLVM's legacy pass manager"
This reverts commit b0f7f6f78d.

Causes test failures: https://lab.llvm.org/buildbot#builders/61/builds/24879
2022-04-11 16:45:19 -07:00
Mahesh Ravishankar 2291705d2b [mlir][Linalg] Split `populateElementwiseOpsFusionPatterns`.
The method to add elementwise ops fusion patterns pulls in many other
patterns by default. The patterns to pull in along with the
elementwise op fusion should be upto the caller. Split the method to
pull in just the elementwise ops fusion pattern. Other cleanup changes
include
- Move the pattern for constant folding of generic ops (currently only
  constant folds transpose) into a separate file, cause it is not
  related to fusion
- Drop the uber LinalgElementwiseFusionOptions. With the
  populateElementwiseOpsFusionPatterns being split, this has no
  utility now.
- Drop defaults for the control function.
- Fusion of splat constants with generic ops doesnt need a control
  function. It is always good to do.

Differential Revision: https://reviews.llvm.org/D123236
2022-04-11 23:37:23 +00:00
Arthur Eubanks b0f7f6f78d [mlir] Remove uses of LLVM's legacy pass manager
Use the new pass manager.

This also removes the ability to run arbitrary sets of passes. Not sure if this functionality is used, but it doesn't seem to be tested.

No need to initialize passes outside of constructing the PassBuilder with the new pass manager.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123425
2022-04-11 16:18:45 -07:00
Mehdi Amini f74569b37c Apply clang-tidy fixes for llvm-qualified-auto in AffineOps.cpp (NFC) 2022-04-11 23:14:47 +00:00
Mehdi Amini ceefc26145 Apply clang-tidy fixes for llvm-qualified-auto in ConvertShapeConstraints.cpp (NFC) 2022-04-11 23:14:46 +00:00
River Riddle e93ba84262 [mlir-vscode] Don't emit errors if the user didn't set the server path
This avoids emitting errors in situations where the user doesn't have a server
setup, and doesn't mean to (e.g. when they merely want syntax highlighting).

Differential Revision: https://reviews.llvm.org/D123240
2022-04-11 15:41:19 -07:00
River Riddle 4a6f5d73a4 [mlir-vscode] Refactor server creation to be lazy
We currently proactively create language clients for every workspace folder,
and every language. This makes startup time more costly, and also emits errors
for missing language servers in contexts that the user currently isn't in. For example,
if a user opens a .mlir file we don't want to emit errors about .pdll files. We also don't
want to emit errors for missing servers in workspace folders that don't even utilize
MLIR.

This commit refactors client creation to lazy-load when a document that requires the
server is opened.

Differential Revision: https://reviews.llvm.org/D123184
2022-04-11 15:41:19 -07:00
River Riddle 3c7e467406 [mlir-vscode] Fix processing of files not within the workspace
In a previous commit we added proper support for separate configurations
per workspace folder, but that effectively broke support for processing out-of-workspace
files. Given how useful this is (e.g. when iterating on a test case in /tmp), this
commit refactors server creation to support this again. We support this case using
a "fallback" server that specifically handles files not within the workspace. This uses
the configuration settings for the current workspace itself (not the specific folder).

Differential Revision: https://reviews.llvm.org/D123183
2022-04-11 15:41:19 -07:00
River Riddle 73c4f9d4d3 [mlir:docs] Add proper documentation for defining dialects
We don't actually have any documentation today for how to
declaratively define a dialect. This commit rectifies that and properly
documents how to define a Dialect in tablegen, and details all of
the possible fields.

Differential Revision: https://reviews.llvm.org/D123258
2022-04-11 15:05:57 -07:00
River Riddle a19fe7b640 [mlir] Split dialect definition constructs out of OpBase into DialectBase
OpBase is currently extremely overbloated with constructs. This
commit continues the current process of cleaning this up, by splitting
out dialect definition constructs. This maps the ODS side more closely
to the C++ side.

Differential Revision: https://reviews.llvm.org/D123257
2022-04-11 15:05:57 -07:00
Arjun P aafb428237 [MLIR][Presburger][Simplex] symbolic lexmin: add some normalization heuristics
Normalize some of the division and inequality expressions used,
which can improve performance. Also deduplicate some of the
normalization functionality throughout the Presburger library.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123314
2022-04-11 20:46:30 +01:00
Arjun P a2b212bafc [MLIR][Presburger] subtract: fix bug in the non-recursive implementation
When making the subtract implementation non-recursive, tail calls were
implemented by incrementing the level but not pushing a frame, and returning
was implemented as returning to the level corresponding to the number of frames in the stack.

This is incorrect, as there could be a case where we tail-recurse at `level`,
and then recurse at `level + 1`, pushing a frame. However, because the previous
frame was missing, this new frame would be interpreted as corresponding to
`level` and not `level + 1`. Fix this by removing the special handling of tail
calls and just doing them as normal recursion, as this is the simplest correct
implementation and handling them specifically would be a premature optimization.

The impact of this bug is only on performance as this can only lead to
unnecessary subtractions of the same disjuncts multiples times. As subtraction
is idempotent, and rationally empty disjuncts are always discarded, this
does not affect the output, so this patch does not include a regression test.
(This also does not affect termination.)

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123327
2022-04-11 20:45:29 +01:00
Mogball 15a65594c1 [mlir][ods] ODS-level Attribute Optimizations
This patch contains several ODS-level optimizations to attribute getters and getting.

1. OpAdaptors, when provided a DictionaryAttr, will instantiate an OperationName so that adaptor attribute getters can used cached identifiers.
2. Verifiers will take advantage of attributes stored in sorted order to get all required (non-optional, non-default valued, and non-derived) attributes in one pass over the attribute dictionary and verify that they are present.
3. ODS-generated attribute getters will use "subrange" lookup. Because the attributes are stored in sorted order and ODS knows which attributes are required, the number of required attributes less than and greater than each attribute can be computed. When searching for an attribute, the ends of the search range can be dropped.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D122430
2022-04-11 18:34:07 +00:00
Groverkss 8fc0e89d0b [MLIR][Presburger] Make PWMAFunction inheritence from space private
This patch makes inheritence from PresburgerSpace for PWMAFunction private.

The reasoning for this patch is to prevent implicit conversion to
PresburgerSpace from PWMAFunction and to not expose all functions exposed by
PresburgerSpace in PWMAFunction.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D123076
2022-04-11 20:01:38 +05:30
gysit 973dbe20f6 [mlir][tensor] Add pattern to fold ExtractSliceOp, PadOp chains.
The pattern folds chains of tensor::ExtractSliceOp, tensor::PadOp pairs if they pad different dimensions. Repeated tiling and padding of the tiled dimensions may introduce such chains. This canonicalization pattern folds these chains to a single tensor::ExtractSliceOp, tensor::PadOp pair that pads all dimensions at once, which simplifies vectorization and bufferization.

Example:
```mlir
   %0 = tensor.extract_slice %input[16, 0] [%sz0, 64] [1, 1]
       : tensor<64x64xf32> to tensor<?x64xf32>
   %1 = tensor.pad %0 low[0, 0] high[%pw0, 0] { ...
     } : tensor<?x64xf32> to tensor<8x64xf32>
   %2 = tensor.extract_slice %1[0, 4] [8, %sz1] [1, 1]
        : tensor<8x64xf32> to tensor<8x?xf32>
   %res = tensor.pad %2 nofold low[0, 0] high[0, %pw1] { ...
     } : tensor<8x?xf32> to tensor<8x4xf32>
```
folds into:
 ```mlir
   %0 = tensor.extract_slice %input[16, 4] [%sz0, %sz1] [1, 1]
        : tensor<64x64xf32> to tensor<?x?xf32>
   %res = tensor.pad %0 nofold low[0, 0] high[%pw0, %pw1] { ...
     } : tensor<?x?xf32> to tensor<8x4xf32>
 ```

Reviewed By: nicolasvasilache, hanchung

Differential Revision: https://reviews.llvm.org/D122722
2022-04-11 14:28:59 +00:00
Christian Sigg a0e1c13cae Remove deprecated `parseSourceFile/String()` overloads.
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123490
2022-04-11 14:11:08 +02:00
Marius Brehler 4f185fccc7 [mlir][emitc][nfc] Replace !emitc.opaque pointers
Replaces `!emitc.opaque` types used to express pointers with
`!emitc.ptr` types.
2022-04-11 11:56:03 +00:00
gysit 39b9336474 [mlir][vector] Swap ExtractSliceOp(TransferWriteOp).
Rewrite tensor::ExtractSliceOp(vector::TransferWriteOp) to vector::TransferWriteOp(tensor::ExtractSliceOp) if the full slice is overwritten and inserted into another tensor. After this rewrite, the operations bufferize in-place since all of them work on the same %iter_arg slice.

For example:
```mlir
  %0 = vector.transfer_write %vec, %init_tensor[%c0, %c0]
       : vector<8x16xf32>, tensor<8x16xf32>
  %1 = tensor.extract_slice %0[0, 0] [%sz0, %sz1] [1, 1]
       : tensor<8x16xf32> to tensor<?x?xf32>
  %r = tensor.insert_slice %1 into %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<?x?xf32> into tensor<27x37xf32>
```
folds to
```mlir
  %0 = tensor.extract_slice %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<27x37xf32> to tensor<?x?xf32>
  %1 = vector.transfer_write %vec, %0[%c0, %c0]
       : vector<8x16xf32>, tensor<?x?xf32>
  %r = tensor.insert_slice %1 into %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<?x?xf32> into tensor<27x37xf32>

Reviewed By: nicolasvasilache, hanchung

Differential Revision: https://reviews.llvm.org/D123190
2022-04-11 10:28:53 +00:00
gysit b24b56165a [mlir][vector] Update transfer read/write doc (NFC).
Clarify the in_bounds attribute is specified for the vector dimensions.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D123188
2022-04-11 10:06:41 +00:00
wren romano 8d8b566f0c [mlir][sparse] Moving <P,I,V>-invariant parts of SparseTensorStorage to base
This reorganization helps to clean up the changes needed for D122060.

Work towards fixing: https://github.com/llvm/llvm-project/issues/51652

Depends On D122625

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122928
2022-04-08 11:44:17 -07:00
Benjamin Kramer 175265ef80 Fix another g++ incompatibility. Same issue as 932f27dc1f. 2022-04-08 15:53:23 +02:00
Vivek Khandelwal b20719dc7d [mlir][Linalg] Add pooling_nchw_sum op.
This commit adds pooling_nchw_sum as a yaml op.

Reviewed By: cathyzhyi, gysit

Differential Revision: https://reviews.llvm.org/D123013
2022-04-08 17:57:47 +05:30
Benjamin Kramer 932f27dc1f Disambiguate conversion cast for GCC
GCC 9 has problems with this.

mlir/include/mlir/IR/OperationSupport.h: In member function ‘mlir::Value mlir::MutableOperandRange::operator[](unsigned int) const’:
mlir/include/mlir/IR/OperationSupport.h:912:43: error: call of overloaded ‘OperandRange(const mlir::MutableOperandRange&)’ is ambiguous
  912 |     return static_cast<OperandRange>(*this)[index];
      |
mlir/include/mlir/IR/OperationSupport.h:789:21: note: candidate: mlir::OperandRange::OperandRange(const llvm::iterator_range<llvm::detail::indexed_accessor_
range_base<mlir::OperandRange, mlir::OpOperand*, mlir::Value, mlir::Value, mlir::Value>::iterator>&)
   using RangeBaseT::RangeBaseT;
                     ^~~~~~~~~~
mlir/include/mlir/IR/OperationSupport.h:786:7: note: candidate: constexpr mlir::OperandRange::OperandRange(const mlir::OperandRange&)
 class OperandRange final : public llvm::detail::indexed_accessor_range_base<
       ^~~~~~~~~~~~
mlir/include/mlir/IR/OperationSupport.h:786:7: note: candidate: constexpr mlir::OperandRange::OperandRange(mlir::OperandRange&&)
2022-04-08 12:55:09 +02:00
Matthias Springer d7a9bf9143 [mlir][tensor] Fix verifier and bufferization of collapse_shape
Insert a buffer copy unless the dims are guaranteed to be collapsible. In the verifier, accept collapses unless they are guaranteed to be non-collapsible.

Differential Revision: https://reviews.llvm.org/D123316
2022-04-08 18:20:40 +09:00
Matthias Springer d2608adf49 [mlir][bufferize] Do not insert useless casts for newly allocated buffers
Differential Revision: https://reviews.llvm.org/D123369
2022-04-08 18:12:02 +09:00
Matthias Springer 8b09141909 [mlir][arith][bufferize] Fix tensors with different layouts after bufferization
Insert a cast if the two tensors with identical layout (that are passed to `arith.select`) have different layout maps after bufferization.

Differential Revision: https://reviews.llvm.org/D123321
2022-04-08 18:11:10 +09:00
Benjamin Kramer 656f0b825c [spirv] Make header self-contained. NFC. 2022-04-08 10:54:58 +02:00
jacquesguan e79b7f501c [mlir][Vector] Fold extractelement splat.
This revision supports to fold vector.extractelement (splat X) -> X.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122960
2022-04-08 07:54:37 +00:00
jacquesguan 088d38890c [mlir][Arithmetic] Add constant folder for negf.
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123293
2022-04-08 07:36:29 +00:00
River Riddle 36d3efea15 [mlir][NFC] Drop a few unnecessary includes from Pass.h 2022-04-07 23:42:47 -07:00
Markus Böck 0c789db541 [mlir] Add support for operation-produced successor arguments in BranchOpInterface
This patch revamps the BranchOpInterface a bit and allows a proper implementation of what was previously `getMutableSuccessorOperands` for operations, which internally produce arguments to some of the block arguments. A motivating example for this would be an invoke op with a error handling path:
```
invoke %function(%0)
  label ^success ^error(%1 : i32)

^error(%e: !error, %arg0 : i32):
  ...
```
The advantages of this are that any users of `BranchOpInterface` can still argue over remaining block argument operands (such as `%1` in the example above), as well as make use of the modifying capabilities to add more operands, erase an operand etc.

The way this patch implements that functionality is via a new class called `SuccessorOperands`, which is now returned by `getSuccessorOperands`. It basically contains an `unsigned` denoting how many operator produced operands exist, as well as a `MutableOperandRange`, which are the usual forwarded operands we are used to. The produced operands are assumed to the first few block arguments, followed by the forwarded operands afterwards. The role of `SuccessorOperands` is to provide various utility functions to modify and query the successor arguments from a `BranchOpInterface`.

Differential Revision: https://reviews.llvm.org/D123062
2022-04-08 08:28:16 +02:00
Stella Laurenzo 497f87bb7b NFC: Silence unused function 'scaleAndAdd' in release build.
Differential Revision: https://reviews.llvm.org/D123354
2022-04-07 21:19:19 -07:00
jacquesguan 5bd7b0efd0 [mlir][LLVMIR] Add more vector predication intrinsic ops.
This revision adds float unary, ternary and float/integer reduction intrinsic ops.

Differential Revision: https://reviews.llvm.org/D123189
2022-04-08 03:16:37 +00:00
Jeremy Furtek 21949de62f [mlir] Width parameterization of BitEnum attributes
This diff contains:

- Parameterization of bit enum attributes in OpBase.td by bit width (e.g. 32
and 64). Previously, all enums were 32-bits. This brings enum functionality in
line with other integer attributes, and allows for bit enums greater than 32
bits.
- SPIRV and Vector dialects were updated to use bit enum attributes with an
  explicit bit width

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123095
2022-04-08 01:21:29 +00:00
Stella Laurenzo 145574fa2d NFC: Eliminate warning for unused type alias FnTraitsT in release builds.
Differential Revision: https://reviews.llvm.org/D123351
2022-04-07 18:11:11 -07:00
River Riddle af371f9f98 Reland [GreedPatternRewriter] Preprocess constants while building worklist when not processing top down
Reland Note: Adds a fix to properly mark a commutative operation as folded if we change the order
             of its operands. This was uncovered by the fact that we no longer re-process constants.

This avoids accidentally reversing the order of constants during successive
application, e.g. when running the canonicalizer. This helps reduce the number
of iterations, and also avoids unnecessary changes to input IR.

Fixes #51892

Differential Revision: https://reviews.llvm.org/D122692
2022-04-07 11:31:42 -07:00
Mogball 2f78b43f4b [mlir][ods] Fix builder gen for VariadicRegion with inferred types
Builders generated for ops with variadic regions and inferred return types were not being correctly generated (missing parameter).
2022-04-07 18:22:49 +00:00
natashaknk fac9f45e05 [tosa][mlir] Add dynamic width/height support for depthwise convolution in tosa-to-linalg
In addition, fixed a small bug with padding incorrectly inferring output shape for dynaic inputs in convolution

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D121872
2022-04-07 10:50:06 -07:00
Lei Zhang 7becf0f6cd [mlir][vector] Fold extract(broadcast) of same rank
This case is handled in neither the folding or canonicalization
patterns. The folding pattern cannot generate new broadcast ops,
so it should be handled by the canonicalization pattern.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123307
2022-04-07 12:59:54 -04:00
Alex Zinenko dbf35b71c7 [mlir] specify dialect names in doc generation
In several cases, a doc is being generated from a .td file that includes
files containing other dialects. Specify the dialect for which the
documentation is being generated explicitly.
2022-04-07 16:37:46 +02:00
Arjun P 00b293e83f [MLIR][Presburger] refactor subtraction to be non-recursive
Subtraction was previously implemented recursively. This refactors it to be
non-recursive to avoid issues with potential stack overflows.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123248
2022-04-07 15:20:19 +01:00
Priyansh Singh d356cdcf31 Fix grammar and punctuation across several docs; NFC 2022-04-07 07:11:11 -04:00
Lorenzo Chelini 573e48765d [MLIR] Standalone: Fix copy-and-paste typo (NFC)
Remove duplicate statements.
2022-04-07 11:22:21 +02:00
Valentin Clement 02da964350
[mlir][CSE] Remove duplicated operations with MemRead side-effect
This patch enhances the CSE pass to deal with simple cases of duplicated
operations with MemoryEffects.

It allows the CSE pass to remove safely duplicate operations with the
MemoryEffects::Read that have no other side-effecting operations in
between. Other MemoryEffects::Read operation are allowed.

The use case is pretty simple so far so we can build on top of it to add
more features.

This patch is also meant to avoid a dedicated CSE pass in FIR and was
brought together afetr discussion on https://reviews.llvm.org/D112711.
It does not currently cover the full range of use cases described in
https://reviews.llvm.org/D112711 but the idea is to gradually enhance
the MLIR CSE pass to handle common use cases that can be used by
other dialects.

This patch takes advantage of the new CSE capabilities in Fir.

Reviewed By: mehdi_amini, rriddle, schweitz

Differential Revision: https://reviews.llvm.org/D122801
2022-04-07 10:08:55 +02:00
River Riddle 5520e07f46 [mlir:Parser][NFC] Replace SSAUseInfo with OpAsmParser::UnresolvedOperand
These are functionally identical, and merging the two removes the number of
redundant conversions within the parser.
2022-04-06 18:25:08 -07:00
River Riddle ea64828a10 [mlir:PDL] Expand how native constraint/rewrite functions can be defined
This commit refactors the expected form of native constraint and rewrite
functions, and greatly reduces the necessary user complexity required when
defining a native function. Namely, this commit adds in automatic processing
of the necessary PDLValue glue code, and allows for users to define
constraint/rewrite functions using the C++ types that they actually want to
use.

As an example, lets see a simple example rewrite defined today:

```
static void rewriteFn(PatternRewriter &rewriter, PDLResultList &results,
                      ArrayRef<PDLValue> args) {
  ValueRange operandValues = args[0].cast<ValueRange>();
  TypeRange typeValues = args[1].cast<TypeRange>();
  ...
  // Create an operation at some point and pass it back to PDL.
  Operation *op = rewriter.create<SomeOp>(...);
  results.push_back(op);
}
```

After this commit, that same rewrite could be defined as:

```
static Operation *rewriteFn(PatternRewriter &rewriter ValueRange operandValues,
                            TypeRange typeValues) {
  ...
  // Create an operation at some point and pass it back to PDL.
  return rewriter.create<SomeOp>(...);
}
```

Differential Revision: https://reviews.llvm.org/D122086
2022-04-06 17:41:59 -07:00
Aart Bik 0b55f94d2b [mlir][sparse] replace stack-based access pattern with dyn-alloc
Rationale:
Allocating the temporary buffers for access pattern expansion on the stack
(using alloca) is a bit too agressive, since it easily runs out of stack space
for large enveloping tensor dimensions. This revision changes the dynamic
allocation of these buffers with explicit alloc/dealloc pairs.

Reviewed By: bixia, wrengr

Differential Revision: https://reviews.llvm.org/D123253
2022-04-06 17:10:43 -07:00
John Demme 8d8738f6fe [MLIR] Add block detach func to CAPI and use it in Python bindings
Adds `mlirBlockDetach` to the CAPI to remove a block from its parent
region. Use it in the Python bindings to implement
`Block.append_to(region)`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123165
2022-04-06 13:11:56 -07:00
Matthias Springer 7e6de86ff6 [mlir][bufferize][NFC] Remove caller map and ordered func list from FuncAnalysisState
These can be local variables. No need to store them in the struct.

Differential Revision: https://reviews.llvm.org/D123210
2022-04-07 00:49:24 +09:00
Matthias Springer cb186bc508 [mlir][bufferize][NFC] Rename ModuleAnalysisState to FuncAnalysisState
This is for consistency reasons. `*AnalysisState` always starts with the name of the dialect.

Differential Revision: https://reviews.llvm.org/D123209
2022-04-07 00:48:53 +09:00
Arjun P 1ba6043332 [MLIR][Presburger] Refactor subtraction in preparation for making it iterative
Refactor the operation of subtraction by
- removing the usage of SimplexRollbackScopeExit since this
  can't be used in the iterative version
- reducing the number of stack variables to make the
  iterative version easier to follow

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123156
2022-04-06 16:35:28 +01:00
Matthias Springer f4f1cf6c31 [mlir][bufferize] Better analysis for return values of CallOps
Support returning arbitrary tensors from functions. Even those that are
not equivalent. To that end, additional information is gathered during
the analysis phase. In particular, which function args are aliasing with
which return values.

Also fix bugs in the current implementation when returning equivalent
tensors. Various unit tests are added to ensure that we have better test
coverage.

Note: Returning non-equivalent tensors is only allowed when
allowReturnAllocs is enabled. This functionality is useful for unit
testing and compatibility with other bufferizations such as the sparse
compiler. This is also towards using ModuleBufferization as a
replacement for --func-bufferize.

Differential Revision: https://reviews.llvm.org/D119120
2022-04-06 23:54:32 +09:00
Matthias Springer cd7de446fd [mlir][bufferize] Simplify ModuleBufferization driver
* Bufferize FuncOp bodies and boundaries in the same loop. This is in preparation of moving FuncOp bufferization into an external model implementation.
* As a side effect, stop bufferization earlier if there was an error. (Do not continue bufferization, fewer error messages.)
* Run equivalence analysis of CallOps before the main analysis. This is needed so that equialvence info is propagated properly.

Differential Revision: https://reviews.llvm.org/D123208
2022-04-06 23:53:07 +09:00
Matthias Springer 5ab34492d6 [mlir][bufferize] Fix dropped return type in ModuleBufferization
Differential Revision: https://reviews.llvm.org/D123192
2022-04-06 23:48:15 +09:00
Alex Zinenko 82c18dd9ad [mlir] Fix DialectRegistry::addExtension compile error
It appears that the DialectRegistry::addExtension template was never
instantiated because it contains an obvious compilation error. Fix it.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D123199
2022-04-06 13:00:34 +02:00
Alexander Belyaev 747b10be95 Revert "Revert "[mlir] Rewrite canonicalization of collapse(expand) and expand(collapse).""
This reverts commit 96e9b6c9dc.
2022-04-06 12:18:30 +02:00
Matthias Springer 7a50560354 [mlir][bufferize][NFC] Clean up ModuleBufferizationState
* Store bbArg indices instead of BlockArguments, so that args can be changed during bufferizationn.
* Use type aliases for better readability.

Differential Revision: https://reviews.llvm.org/D123191
2022-04-06 18:32:53 +09:00
Nicolas Vasilache fc8f465a00 [mlir][MemRef] Allow transposed layouts in ExpandShapeOp.
https://reviews.llvm.org/D122641 introduced fixes to the ExpandShapeOp verifier
but also introduced an artificial layout limitation that prevents the consideration of transposed layouts.

This revision fixes the omissions and reimplements the logic using saturated arithmetic which is more
idiomatic and avoids leaking internal implementation details.

Tests cases are added for transposed layouts.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D122845
2022-04-06 04:19:30 -04:00
Argyrios Kyrtzidis 330268ba34 [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes
Returning `std::array<uint8_t, N>` is better ergonomics for the hashing functions usage, instead of a `StringRef`:

* When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural
* Returning `std::array<uint8_t, N>` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef`

As part of this patch also:

* Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes.
* Make `MD5Result` inherit from `std::array<uint8_t, 16>` which improves & simplifies its API.

Differential Revision: https://reviews.llvm.org/D123100
2022-04-05 21:38:06 -07:00
jacquesguan 2420d42925 [mlir][LLVMIR] Add vector predication binary intrinsic ops.
Differential Revision: https://reviews.llvm.org/D122971
2022-04-06 10:48:24 +08:00