178 Commits

Author SHA1 Message Date
Erik Davis
a66d8f62e6
[mlir][doc] fixup code block (#153977)
This fixes a small typo in the toy tutorial. A code block was not
correctly terminated, causing it to run into the subsequent block.
2025-08-17 13:01:05 +02:00
Diego Caballero
33465bb2bb
[mlir][Vector] Remove vector.extractelement and vector.insertelement ops (#149603)
This PR removes `vector.extractelement` and `vector.insertelement` ops
from the code base in favor of the `vector.extract` and `vector.insert`
counterparts.

See RFC:
https://discourse.llvm.org/t/rfc-psa-remove-vector-extractelement-and-vector-insertelement-ops-in-favor-of-vector-extract-and-vector-insert-ops
2025-07-28 11:01:14 -07:00
Matthias Springer
f4c05be544
[mlir][toy] Update dialect conversion example (#150826)
The Toy tutorial used outdated API. Update the example to:

* Use the `OpAdaptor` in all places.
* Do not mix `RewritePattern` and `ConversionPattern`. This cannot
always be done safely and should not be advertised in the example code.
2025-07-27 21:57:43 +02:00
Mehdi Amini
03dc2a41f3
[MLIR] Update MLIR tutorial to use LDBG() macro (#150763) 2025-07-27 20:21:18 +02:00
lonely eagle
1a4f0d6115
[mlir][doc] Fix transform dialect tutorial ch3 (#150456)
Fixed some bugs in documentation. Add CallOpInterfaceHandle to the
arguments of ChangeCallTargetOp, after doing so the section described in
the documentation works correctly, Otherwise the following code reports
an error.
```
// Cast to our new type.
 %casted = transform.cast %call : !transform.any_op to !transform.my.call_op_interface
// Using our new operation.
 transform.my.change_call_target %casted, "microkernel" : !transform.my.call_op_interface
```
2025-07-26 09:21:35 +08:00
Maksim Levental
284a5c2c0b
[mlir][NFC] update mlir/examples create APIs (31/n) (#150652)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 16:14:16 -04:00
Mehdi Amini
a608b0c7ca [MLIR] Improve tutorial to make it clear that walk() is visiting the root op (NFC) 2025-07-24 11:17:30 -07:00
lonely eagle
4c70195634
[mlir][transform] Fix ch2 and additional documentation (#148407)
Fixed error code in example.In addition to this, the content in the documentation has been improved by adding links to the code repository.
2025-07-18 20:28:43 +08:00
lonely eagle
efa30f496f
[mlir][transform] Fix transform dialect tutorial chapter 1 (#147983)
In the transform dialect tutorial chapter 1, there were some errors that
prevented the example from running. This PR fixes them.

---------

Co-authored-by: Renato Golin <rengolin@systemcall.eu>
2025-07-14 20:45:58 +08:00
Renato Golin
6daf2b956d
[MLIR][Linalg] Remove elemwise_unary and elemwise_binary (#147082)
RFC:
https://discourse.llvm.org/t/rfc-deprecate-linalg-elemwise-unary-and-elemwise-binary/87144

Remove the two operations and fix the tests by:
* Cleaning simple operation tests of the old ops
* Changing `linalg.elemwise_{u|bi}nary` with `linalg.{exp|add}` on
transform tests
* Changing some of the tests with `linalg.elementwise` instead, to
broaden test coverage
* Surgically removing the `elemwise_*` part in the Python tests
* Update MLIR transform examples (text and tests) with
`linalg.elementwise` instead

Nothing else changed.
2025-07-07 12:33:55 +01:00
Michael Maitland
7454098a9e
[mlir][Value] Add getNumUses, hasNUses, and hasNUsesOrMore to Value (#142084)
We already have hasOneUse. Like llvm::Value we provide helper methods to
query the number of uses of a Value. Add unittests for Value, because
that was missing.

---------

Co-authored-by: Michael Maitland <michaelmaitland@meta.com>
2025-05-30 00:39:45 -04:00
Joshua James Venter
d0fbfa6d97
[mlir] Explain required attrs for CallOpInterface in Toy (NFC) (#141018)
Following #123176.

Signed-off-by: Joshua James Venter <venter.joshua@gmail.com>
2025-05-22 11:54:45 +02:00
yanming
63ad1492dc [mlir][NFC] Fix the MLIR example format to conform to SSA form. 2025-05-13 18:08:14 +08:00
Jakub Kuderski
0078cf79ad
[mlir] Remove deprecated cast member functions (#135556)
These have been deprecated for over two years now in favor of free
functions.

See the relevant discourse thread:

https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443
and the deprecation notice: https://mlir.llvm.org/deprecation/.
2025-04-14 09:08:34 -04:00
Matthias Springer
a21cfca320
[mlir][IR] Deprecate match and rewrite functions (#130031)
Deprecate the `match` and `rewrite` functions. They mainly exist for
historic reasons. This PR also updates all remaining uses of in the MLIR
codebase.

This is addressing a
[comment](https://github.com/llvm/llvm-project/pull/129861#pullrequestreview-2662696084)
on an earlier PR.

Note for LLVM integration: `SplitMatchAndRewrite` will be deleted soon,
update your patterns to use `matchAndRewrite` instead of separate
`match` / `rewrite`.

---------

Co-authored-by: Jakub Kuderski <jakub@nod-labs.com>
2025-03-07 08:43:01 +01:00
AidinT
03ad7edbb6
[mlir][doc][tutorials] Remove docs and code discrepancies (#125422)
Toy tutorial [chapter 4](https://mlir.llvm.org/docs/Tutorials/Toy/Ch-4/)
contains many discrepancies between snippets and code in `example`
directory.
This is a fix for the documentation.
2025-02-04 10:45:46 -07:00
Vishakh Prakash
9d0fa42fbb
[mlir] Update Ch-2.md (#121379)
line 265 in the file llvm-project/mlir/docs/Tutorials/Toy/Ch-2.md 

changed mlir::OpTraits to mlir::OpTrait
2025-01-06 09:44:05 +08:00
csstormq
6b8edc9f79
[mlir] Fix disagreement between document and test(NFC) (#109257) 2024-09-20 09:25:57 +08:00
Jeremy Kun
7f1968625a
Add a tutorial on mlir-opt (#96105)
This tutorial gives an introduction to the `mlir-opt` tool, focusing on
how to run basic passes with and without options, run pass pipelines
from the CLI, and point out particularly useful flags.

---------

Co-authored-by: Jeremy Kun <j2kun@users.noreply.github.com>
Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2024-08-01 16:49:01 -07:00
Ramkumar Ramachandra
db791b278a
mlir/LogicalResult: move into llvm (#97309)
This patch is part of a project to move the Presburger library into
LLVM.
2024-07-02 10:42:33 +01:00
Matthias Springer
becc238f77
[mlir][docs] Fix mistakes in data flow analysis code example (#97286) 2024-07-01 18:59:58 +02:00
Mehdi Amini
fd92735933 [MLIR][Doc] Fix NamedAttribute API in code sample (NFC) 2024-04-24 10:28:30 -07:00
Oleksandr "Alex" Zinenko
e8b31fb39d
[mlir] fix latex formulas in the tutorial 2024-04-22 14:49:28 +02:00
mlevesquedion
73fa6685c4
Fix a few broken links (#87098)
References to headings need to be preceded with a slash. Also,
references to headings on the same page do not need to contain the name
of the document (omitting the document name means if the name changes
the links will still be valid).

I double checked the links by building [the
website](https://github.com/llvm/mlir-www):

```shell
./mlir-www-helper.sh --install-docs ../llvm-project website
cd website && hugo serve
```
2024-04-05 09:52:53 +02:00
Oleksandr "Alex" Zinenko
5a9bdd85ee
[mlir] split transform interfaces into a separate library (#85221)
Transform interfaces are implemented, direction or via extensions, in
libraries belonging to multiple other dialects. Those dialects don't
need to depend on the non-interface part of the transform dialect, which
includes the growing number of ops and transitive dependency footprint.

Split out the interfaces into a separate library. This in turn requires
flipping the dependency from the interface on the dialect that has crept
in because both co-existed in one library. The interface shouldn't
depend on the transform dialect either.

As a consequence of splitting, the capability of the interpreter to
automatically walk the payload IR to identify payload ops of a certain
kind based on the type used for the entry point symbol argument is
disabled. This is a good move by itself as it simplifies the interpreter
logic. This functionality can be trivially replaced by a
`transform.structured.match` operation.
2024-03-20 22:15:17 +01:00
Kohei Yamaguchi
0c13a896df
[mlir][docs] Fix broken docs (#82308)
- Fixed OpenACC's spec link format
- Add missed `OpenACCPasses.md` into Passes.md
- Add missed `MyExtensionCh4.md` into Ch4.md of tutorial of transform
2024-02-21 10:11:22 +01:00
mlevesquedion
a90a09fa2e
[mlir][docs] Fix broken links to traits documentation (#82131)
It seems the `Traits.md` file was turned into `Traits/_index.md` in
https://reviews.llvm.org/D153291, causing links to `Traits.md` to no
longer work (instead, `Traits` needs to be used).
2024-02-17 13:51:36 -08:00
Oleksandr "Alex" Zinenko
b33b91a217
[mlir] update transform dialect tutorials (#81199)
Use the "main" transform-interpreter pass instead of the test pass.
This, along with the previously introduced debug extension, now allow
tutorials to no longer depend on test passes and extensions.
2024-02-09 17:35:14 +01:00
Oleksandr "Alex" Zinenko
2798b72ae7
[mlir] introduce debug transform dialect extension (#77595)
Introduce a new extension for simple print-debugging of the transform
dialect scripts. The initial version of this extension consists of two
ops that are printing the payload objects associated with transform
dialect values. Similar ops were already available in the test extenion
and several downstream projects, and were extensively used for testing.
2024-01-12 13:24:02 +01:00
Oleksandr "Alex" Zinenko
4cb2ef4fe3
[mlir] add a chapter on matchers to the transform dialect tutorial (#76725)
These operations has been available for a while, but were not described
in the tutorial. Add a new chapter on using and defining match
operations.
2024-01-09 13:19:41 +01:00
Andrzej Warzyński
ca5d34ec71
[mlir][TD] Fix the order of return handles (#76929)
Replace (in tests and docs):

    %forall, %tiled = transform.structured.tile_using_forall

with (updated order of return handles):

    %tiled, %forall = transform.structured.tile_using_forall

Similar change is applied to (in the TD tutorial):

    transform.structured.fuse_into_containing_op

This update makes sure that the tests/documentation are consistent with
the Op specifications. Follow-up for #67320 which updated the order of
the return handles for `tile_using_forall`.
2024-01-04 12:54:16 +00:00
Andrzej Warzyński
f8c034140b
[mlir][docs] Update TD tutorial - Ch0 (#76858)
Updates `generic` as `linalg.generic` (for consistency and to avoid
ambiguity) and a few other fixes.
2024-01-04 09:48:44 +01:00
Andrzej Warzyński
39298b09ec
[mlir][docs] Capitalize "Transform" in "transform dialect" (#76840)
A mix of "Transform dialect" and "transform dialect" is used ATM. This
patch capitalizes the outstanding instances of "transform".
2024-01-03 21:33:11 +00:00
Mehdi Amini
26a0b27736
Make MLIR Value more consistent in terms of const "correctness" (NFC) (#72765)
MLIR can't really be const-correct (it would need a `ConstValue` class
alongside the `Value` class really, like `ArrayRef` and
`MutableArrayRef`). This is however making is more consistent: method
that are directly modifying the Value shouldn't be marked const.
2023-11-20 20:52:15 -08:00
Oleksandr "Alex" Zinenko
aab795a8dc
[mlir] run buffer deallocation in transform tutorial (#67978)
Buffer deallocation pipeline previously was incorrect when applied to
functions. It has since been fixed. Make sure it is exercised in the
tutorial to avoid leaking allocations.
2023-10-02 16:08:11 +02:00
Oleksandr "Alex" Zinenko
96ff0255f2
[mlir] cleanup of structured.tile* transform ops (#67320)
Rename and restructure tiling-related transform ops from the structured
extension to be more homogeneous. In particular, all ops now follow a
consistent naming scheme:

 - `transform.structured.tile_using_for`;
 - `transform.structured.tile_using_forall`;
 - `transform.structured.tile_reduction_using_for`;
 - `transform.structured.tile_reduction_using_forall`.

This drops the "_op" naming artifact from `tile_to_forall_op` that
shouldn't have been included in the first place, consistently specifies
the name of the control flow op to be produced for loops (instead of
`tile_reduction_using_scf` since `scf.forall` also belongs to `scf`),
and opts for the `using` connector to avoid ambiguity.

The loops produced by tiling are now systematically placed as *trailing*
results of the transform op. While this required changing 3 out of 4 ops
(except for `tile_using_for`), this is the only choice that makes sense
when producing multiple `scf.for` ops that can be associated with a
variadic number of handles. This choice is also most consistent with
*other* transform ops from the structured extension, in particular with
fusion ops, that produce the structured op as the leading result and the
loop as the trailing result.
2023-09-26 09:14:29 +02:00
Oleksandr "Alex" Zinenko
6841eff107
[mlir] add transform tutorial chapter for Halide conv mapping (#66386)
This chapter demonstrates how one can replicate Halide DSL
transformations using transform dialect operations transforming payload
expressed using Linalg. This was a part of the live tutorial presented
at EuroLLVM 2023.
2023-09-25 09:47:48 +02:00
Martin Erhart
34a35a8b24 [mlir] Move FunctionInterfaces to Interfaces directory and inherit from CallableOpInterface
Functions are always callable operations and thus every operation
implementing the `FunctionOpInterface` also implements the
`CallableOpInterface`. The only exception was the FuncOp in the toy
example. To make implementation of the `FunctionOpInterface` easier,
this commit lets `FunctionOpInterface` inherit from
`CallableOpInterface` and merges some of their methods. More precisely,
the `CallableOpInterface` has methods to get the argument and result
attributes and a method to get the result types of the callable region.
These methods are always implemented the same way as their analogues in
`FunctionOpInterface` and thus this commit moves all the argument and
result attribute handling methods to the callable interface as well as
the methods to get the argument and result types. The
`FuntionOpInterface` then does not have to declare them as well, but
just inherits them from the `CallableOpInterface`.
Adding the inheritance relation also required to move the
`FunctionOpInterface` from the IR directory to the Interfaces directory
since IR should not depend on Interfaces.

Reviewed By: jpienaar, springerm

Differential Revision: https://reviews.llvm.org/D157988
2023-08-31 11:28:23 +00:00
Jie Fu
5577493734 [mlir] Update mlir/docs/Tutorials/UnderstandingTheIRStructure.md (NFC) 2023-08-11 16:09:38 +08:00
Ingo Müller
b7d462a729 [mlir][transform][tutorial] Fix typo in inline code snippet. (NFC)
Reviewed By: ingomueller-net

Differential Revision: https://reviews.llvm.org/D154828
2023-07-10 10:38:33 +00:00
Ingo Müller
278a8efb7f [mlir][transform][tutorial] Make snippets of Ch1 run.
The snippets had several problems including mismatching argument names,
stray or missing symbols, and missing updates to changes in transform
ops. I also rewrapped those comments in the snippets that I touchted
that exceeded 80 characters.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D154817
2023-07-10 10:15:14 +00:00
Ingo Müller
5b341c89b7 [mlir][doc][transform] Fix link to documentation in tutorial. (NFC)
Reviewed By: ingomueller-net

Differential Revision: https://reviews.llvm.org/D154724
2023-07-07 16:08:00 +00:00
Kohei Yamaguchi
4921ff5b92 [mlir][doc] Fix broken docs
- Fix include paths for Transform Dialect Tutorial
- Add math dialect's pass into Pass.md
- Remove a include path of Quant dialect from Pass.md

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D153944
2023-06-28 08:34:50 +00:00
Kai Sasaki
f763270b53
[mlir] Replace HTML escaped character 2023-06-24 02:43:40 +00:00
Matthias Springer
c63d2b2c71 [mlir][transform] Add TransformRewriter
All `apply` functions now have a `TransformRewriter &` parameter. This rewriter should be used to modify the IR. It has a `TrackingListener` attached and updates the internal handle-payload mappings based on rewrites.

Implementations no longer need to create their own `TrackingListener` and `IRRewriter`. Error checking is integrated into `applyTransform`. Tracking listener errors are reported only for ops with the `ReportTrackingListenerFailuresOpTrait` trait attached, allowing for a gradual migration. Furthermore, errors can be silenced with an op attribute.

Additional API will be added to `TransformRewriter` in subsequent revisions. This revision just adds an "empty" `TransformRewriter` class and updates all `apply` implementations.

Differential Revision: https://reviews.llvm.org/D152427
2023-06-20 10:49:59 +02:00
Andrey Portnoy
444bb1f1bb [mlir][Toy] Remove unnecessary transpose from chapter 1 example
The call to 'multiply_transpose' in the initialization of the variable 'f' was
intended to have a shape mismatch. However the variable 'a' has shape <2, 3> and
the variable 'c' has shape <3, 2>, so the arguments 'transpose(a)' and 'c' have
in fact compatible shapes (<3, 2> both), the opposite of what is wanted here.
This commit removes the transpose so that arguments 'a' and 'c' have
incompatible shapes <2, 3> and <3, 2>, respectively.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D151897
2023-06-06 11:23:35 -07:00
Alex Zinenko
d8c18e422b [mlir] fix documentation includes 2023-05-31 08:58:42 +00:00
Alex Zinenko
68ae0d7803 [mlir] add initial chapters of the transform dialect tutorial
The transform dialect has been around for a while and is sufficiently
stable at this point. Add the first three chapters of the tutorial
describing its usage and extension.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D151491
2023-05-30 15:26:58 +00:00
Whitney Tsang
a2ab6a5e2b [mlir][CallOpInterface] Add setCalleeFromCallable method
Currently `CallOpInterface` has a method `getCallableForCallee` to have a consistent way to get the callee from an operation with `CallOpInterface`, but missing a consistent way to set a callee for an operation with `CallOpInterface`.

A set callee method is useful for transformations that operate on `CallOpInterface`, and change the callee, e.g., a pass that specialize function, which clone the callee, and change the `CallOpInterface`'s callee to the cloned version. Without such method, transformation would need to understand the implementation for every operations with `CallOpInterface`, and have a type switch to handle them.

This review adds a method to set callee for operation with `CallOpInterface`.

Reviewed By: gysit, zero9178o

Differential Revision: https://reviews.llvm.org/D149763
2023-05-08 06:07:10 -07:00
Matthias Springer
4c48f016ef [mlir][Affine][NFC] Wrap dialect in "affine" namespace
This cleanup aligns the affine dialect with all the other dialects.

Differential Revision: https://reviews.llvm.org/D148687
2023-04-20 11:19:21 +09:00