Commit Graph

23658 Commits

Author SHA1 Message Date
Will Froom
4b1d5b8d4f [MLIR] Fix pipelineInitializationKey never being correctly updated (#150948)
Prior to this change `pipelineInitializationKey` would never be updated
so `initialize` would always be called even if the pipeline didn't
change
2025-07-28 15:47:12 +01:00
Anchu Rajendran S
9d642b0ec8 [flang][MLIR][OpenMP][llvm]Atomic Control Support (#150860) 2025-07-28 05:46:10 -07:00
Yuvaraj Venkatesh
9c606ae0c0 [MLIR][TOSA] Update IfOp print/parse to support ranked condition tens… (#149791)
…or and optional block arguments

This change extends the TOSA `cond_if` operation's print and parse logic
to handle the following:

- The condition operand may now have any rank, as long as the total
number of elements sums to 1.

  %1 = tosa.cond_if %0 : tensor<1x1x1xi1> -> tensor<4xf32>

- The `then` and `else` regions can now include optional block
arguments. The updated IR syntax reflects this:

%1 = tosa.cond_if %0 (%arg2 = %arg0, %arg3 = %arg1) : tensor<i1>
(tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>

- Removed parentheses around single result types in the printed
representation, aligning with the `AsmPrinter` conventions.

Co-authored-by: Luke Hutton <luke.hutton@arm.com>
2025-07-28 10:44:21 +01:00
Yi-Chi Lee
fdd7f9c61b [mlir][tosa] Allow scalar int8 tensors to be unranked (#150731)
This PR fixes #150519
2025-07-28 10:03:35 +01:00
lonely eagle
2adbf9e92b [mlir][memref] Support test-compose-subview dynamic size (#146881)
Supports the case where the sizes of the subview op is dynamic.When
there are more for loops in the tile algorithm, multiple subviews are
performed and test-compose-subview does not work when the size operand
of the subview ops is dynamic value.
2025-07-28 16:58:45 +08:00
Oleksandr "Alex" Zinenko
d532d58974 [mlir] Nominate MLIR Egress category maintainers (#149487)
This is a nomination for the maintainers of the egress category within
MLIR as proposed in
https://discourse.llvm.org/t/mlir-project-maintainers/87189. As agreed
in the Project Council meeting on July 17, we are proceeding with
category nominations without waiting for lead maintainers to be
nominated.
2025-07-28 10:41:52 +02:00
Oleksandr "Alex" Zinenko
ac4c13d0d8 [mlir] Nominate Tensor Compiler maintainers (#149488)
This is a nomination for the maintainers of the tensor compiler category
within MLIR as proposed in
https://discourse.llvm.org/t/mlir-project-maintainers/87189. As agreed
in the Project Council meeting on July 17, we are proceeding with
category nominations without waiting for lead maintainers to be
nominated.
2025-07-28 10:01:29 +02:00
Andrzej Warzyński
f529c0b56f [mlir][linalg][nfc] Clean-up leftover code post #149156 (#150602)
In https://github.com/llvm/llvm-project/pull/149156, I ensured that we
no longer generate spurious `tensor.empty` ops when vectorizing
`linalg.unpack`.

This follow-up removes leftover code that is now redundant but was
missed in the original PR.
2025-07-28 09:00:19 +01:00
Oleksandr "Alex" Zinenko
a87fb3b60f [mlir] Nominate MLIR Core category maintainers (#149485)
This is a nomination for the maintainers of the core category within
MLIR as proposed in
https://discourse.llvm.org/t/mlir-project-maintainers/87189. As agreed
in the Project Council meeting on July 17, we are proceeding with
category nominations without waiting for lead maintainers to be
nominated.
2025-07-28 09:49:35 +02:00
Mehdi Amini
9e5f9ff82f [MLIR] Fix release build: reference to NDEBUG guarded function (NFC)
With LDBG(), the code isn't guarded in release mode, even if the optimizer
will remove it because there is a `if (false)` statement. We need the
function declaration to be there at minima.
2025-07-27 13:24:54 -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
Mehdi Amini
865dd278a9 [MLIR] Remove overly verbose Debug for TypeID checks (NFC) (#150751)
These are spammy and mostly uninteresting during debugging.
2025-07-27 20:21:03 +02:00
Mehdi Amini
5983d7db7d Migrate more of DataFlow framework to LDBG (NFC) (#150752) 2025-07-27 20:20:54 +02:00
Mehdi Amini
c28dfa1341 [MLIR] Update Inliner.cpp to use LDBG() for logging (NFC) (#150762) 2025-07-27 20:20:47 +02:00
Mehdi Amini
789fcef805 [MLIR] Migrate some "transform dialect" source to use the standard LDBG macro (NFC) (#150695) 2025-07-27 20:19:23 +02:00
Abid Qadeer
7d7f3819e0 Revert "[OMPIRBuilder] Don't use invalid debug loc in reduction functions." (#150832)
Reverts llvm/llvm-project#147950

I noticed some fails in the reduction tests with clang after this
change. I need to understand the failures better. Reverting this for
now.
2025-07-27 16:43:28 +01:00
Matthias Springer
c639475974 [mlir][Transforms] Dialect Conversion: Fix folder implementation (#150775)
Operation folders can do two things:

1. Modify IR (in-place op modification). Failing to legalize an in-place
folded operation does not trigger an immediate rollback. This happens
only if the driver decides to try a different lowering path, requiring
it to roll back a bunch of modifications, including the application of
the folder.
2. Create new IR (constant op materialization of a folded attribute).
Failing to legalize a newly created constant op triggers an immediate
rollback.

In-place op modifications should be guarded by
`startOpModification`/`finalizeOpModification` because they are no
different from other in-place op modifications. (They just happen
outside of a pattern, but that does not mean that we should not track
those changes; we are tracking everything else.) This commit adds those
two function calls.

This commit also moves the `rewriter.replaceOp(op, replacementValues);`
function call before the loop nest that legalizes the newly created
constant ops (and therefore `replacementValues`). Conceptually, the
folded op must be replaced before attempting to legalize the constants
because the constant ops may themselves be replaced as part of their own
legalization process. The previous implementation happened to work in
the current conversion driver, but is incompatible with the One-Shot
Dialect Conversion driver, which expects to see the most recent IR at
all time.

From an end-user perspective, this commit should be NFC. A common
folder-rollback pattern that is exercised by multiple tests cases: A
`memref.dim` is folded to `arith.constant`, but `arith.constant` is not
marked as legal as per the conversion target, triggering a rollback.

Note: Folding is generally unsafe in a dialect conversion (see #92683),
but that's a different issue. (In a One-Shot Dialect Conversion, it will
no longer be unsafe.)
2025-07-27 12:01:01 +02:00
Matthias Springer
a7c9563995 [mlir][IR] Set insertion point when erasing an operation (#146955)
Erasing the operation to which the current insertion point is set,
leaves the insertion point in an invalid state. This commit resets the
insertion point to the following operation.

Also adjust the insertion point when inlining a block.
2025-07-27 10:27:27 +02:00
Kazu Hirata
ea6106b2e2 [mlir] Fix a warning
This patch fixes:

  mlir/lib/Transforms/Utils/DialectConversion.cpp:1686:14: error:
  unused variable 'newParentOp' [-Werror,-Wunused-variable]
2025-07-27 00:59:41 -07:00
Matthias Springer
292fd903bf [mlir][test] Turn test-legalize-mode into a pass option (#150767)
The `test-legalize-mode` option is used only by the
`test-legalize-patterns` pass.
2025-07-26 17:19:14 +02:00
Matthias Springer
0c804270d1 [mlir][Transforms][NFC] Dialect Conversion: Improve insert callbacks (#150753)
This commit makes some minor NFC-style improvements to the
`notifyBlockInserted` and `notifyOperationInserted` implementations:

* Rename some variables.
* Add more comments and document the fact the current mechanism has a
bug when running in "rollback allowed" mode.
* Move some code from the `notify...` functions into the constructor of
the respective `IRRewrite` objects. This is in preparation of the
One-Shot Dialect Conversion refactoring. The moved pieces of code are
not needed in "no rollback" mode and properly encapsulated inside of
`IRRewrite`, which is also not needed in "no rollback" mode.
* Slightly improve `-debug` output.
2025-07-26 16:29:56 +02:00
Matthias Springer
08e101e274 [mlir][Transforms] Dialect Conversion: check for "failure" after modification (#150748)
Add a new "expensive check" when running with `allowPatternRollback =
false`: returning "failure" after modifying IR is no longer allowed.
This check detects a few more API violations in addition to the check
`undoRewrites`. The latter check will be removed soon. (Because the
One-Shot Dialect Conversion will no longer maintain the stack of IR
rewrites.)

Also fix a build error when expensive checks are enabled.
2025-07-26 16:28:00 +02:00
Mehdi Amini
70e0f31747 [MLIR] Remove unused DBGS macro (NFC) 2025-07-26 06:35:40 -07:00
Matthias Springer
5ec6ac882c [mlir][Transforms][NFC] Dialect Conversion: Move lookup functions (#150743)
Add `lookupOrDefault` / `lookupOrNull` wrappers to
`ConversionPatternRewriterImpl` and call those wrappers throughout the
code base.

This commit is in preparation of the One-Shot Dialect Conversion
refactoring. In future, the implementation will bypass the `mapping`
when rollback is disabled. The switch will be made in those wrapper
functions.
2025-07-26 11:07:21 +02:00
Matthias Springer
cccde9b2b1 [mlir][SCF] Do not access erased operation in scf.while lowering (#150741)
Do not access the erased `scf.while` operation in the lowering pattern.
That won't work anymore in a One-Shot Dialect Conversion and triggers a
use-after-free sanitizer error.

After the One-Shot Dialect Conversion refactoring, a
`ConversionPatternRewriter` will behave more like a normal
`PatternRewriter`.
2025-07-26 11:07:06 +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
Aiden Grossman
676314a85f [MLIR] Remove uses of %T from lit tests (#150725)
%T has been deprecated for about seven years and is to be avoided given
it does not use a unique dir per test. Remove it from lit tests in MLIR
with the eventual goal to be removing support within llvm-lit.

This patch just reuses %t.o given it is deleted in between sections of
the test.
2025-07-25 17:49:30 -07:00
Mehdi Amini
6f0f79842a [MLIR] Remove unused DBGS macro (NFC) 2025-07-25 16:49:21 -07:00
Maksim Levental
9e7834cadf [mlir][NFC] update mlir/lib create APIs (35/n) (#150708)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 16:47:57 -07:00
Mehdi Amini
9e09c4dd52 [MLIR] Fix release build: the definition for the FULL_LDBG macro was incorrect 2025-07-25 14:12:51 -07:00
Benoit Jacob
04a44fef1f [MLIR] Fix release build: FULL_LDBG macro was incorrect when NDEBUG is defined (#150698)
DEBUGLOG_WITH_STREAM_AND_TYPE is an internal implementation detail of
LDBG in DebugLog.h. When NDEBUG is defined,
DEBUGLOG_WITH_STREAM_AND_TYPE is not defined at all.

Signed-off-by: Benoit Jacob <jacob.benoit.1@gmail.com>
2025-07-25 22:52:45 +02:00
Fabian Mora
34a08cb89c [mlir][LLVM] Remove llvm deps from the LLVM dialect (#150692)
This patch removes spurious includes of `llvm/IR` files, and unnecessary
link components in the LLVM dialect.

The only major dependencies still coming from LLVM are
`llvm::DataLayout`, which is used by `verifyDataLayoutString` and some
`dwarf` symbols in some attributes. Both of them should likely be
removed in the future.

Finally, I also removed one constructor from `LLVM::AssumeOp` that used
[OperandBundleDefT](https://llvm.org/doxygen/classllvm_1_1OperandBundleDefT.html)
without good reason and introduced a header unnecessarily.
2025-07-25 16:51:47 -04: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
Maksim Levental
c090ed53fb [mlir][NFC] update mlir/Dialect create APIs (33/n) (#150659)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 16:13:55 -04:00
Mehdi Amini
2f8c926d6e [MLIR] Migrate PatternLoggingListener to the standard LDBG output (#150686) 2025-07-25 21:51:07 +02:00
Mehdi Amini
f26db3f3ec [MLIR] Add a OpWithFlags class that acts as a "stream modifier" to customize Operation streaming (#150636) 2025-07-25 20:58:14 +02:00
Maksim Levental
fcbcfe44cf [mlir][NFC] update mlir/Dialect create APIs (32/n) (#150657)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 13:50:15 -05:00
Han-Chung Wang
0844812b2e Revert "[mlir][linalg] Restrict linalg.pack to not have artificial padding." (#150675)
Reverts llvm/llvm-project#150522 because it breaks
`Integration/Dialect/Linalg/CPU/pack-unpack-mmt4d.mlir`.

https://lab.llvm.org/buildbot/#/builders/116/builds/16097
2025-07-25 11:27:41 -07:00
Han-Chung Wang
773e158c64 [mlir][linalg] Restrict linalg.pack to not have artificial padding. (#150522)
The revision restrict the `linalg.pack` op to not have artificial
padding semantics. E.g., the below is valid without the change, and it
becomes invalid with the change.

```mlir
func.func @foo(%src: tensor<9xf32>) -> tensor<100x8xf32> {
  %cst = arith.constant 0.000000e+00 : f32
  %dest = tensor.empty() : tensor<100x8xf32>
  %pack = linalg.pack %src
    padding_value(%cst : f32)
    inner_dims_pos = [0]
    inner_tiles = [8] into %dest
    : tensor<9xf32> -> tensor<100x8xf32>
  return %pack : tensor<100x8xf32>
}
```

IMO, it is a misuse if we use pack ops with artificial padding sizes
because the intention of the pack op is to relayout the source based on
target intrinsics, etc. The output shape is expected to be
`tensor<2x8xf32>`. If people need extra padding sizes, they can create a
new pad op followed by the pack op.

This also makes consumer tiling much easier because the consumer fusion
does not support artificial padding sizes. It is very hard to make it
work without using ad-hoc patterns because the tiling sizes are about
source, which implies that you don't have a core_id/thread_id to write
padding values to the whole tile.

People may have a question how why pad tiling implementation works. The
answer is that it creates an `if-else` branch to handle the case. In my
experience, it is very struggle in transformation because most of the
time people only need one side of the branch given that the tile sizes
are usually greater than padding sizes. However, the implementation is
conservatively correct in terms of semantics. Given that the
introduction of `pack` op is to serve the relayout needs better, having
the restriction makes sense to me.

Removed tests:
-
`no_bubble_up_pack_extending_dimension_through_expand_cannot_reassociate`
from `data-layout-propagation.mlir`: it is a dup test to
`bubble_up_pack_non_expanded_dims_through_expand` after we fix the
shape.
- `fuse_pack_consumer_with_untiled_extra_padding` from
`tile-and-fuse-consumer.mlir`: it was created for artificial padding in
the consumer fusion implementation.

The other changes in lit tests are just fixing the shape.

---------

Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-07-25 11:06:17 -07:00
Mehdi Amini
ce535c8700 [MLIR] Add missing includes to NVVM/Target.cpp (fix build) (#150637)
Depending on the CMake configuration, these missing headers triggers a
compilation error.
2025-07-25 19:54:46 +02:00
Maksim Levental
258daf5395 [mlir][NFC] update mlir create APIs (34/n) (#150660)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 12:36:54 -05:00
Maksim Levental
c610b24493 [mlir][NFC] update mlir/Dialect create APIs (27/n) (#150638)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 11:48:32 -05:00
Maksim Levental
b58ad3650f [mlir][NFC] update mlir/Dialect create APIs (30/n) (#150643)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 11:48:17 -05:00
Maksim Levental
258d04c810 [mlir][NFC] update mlir/Dialect create APIs (28/n) (#150641)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 11:48:00 -05:00
Maksim Levental
a6bf40d1c6 [mlir][NFC] update mlir/Dialect create APIs (29/n) (#150642)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-25 11:47:44 -05:00
Jaden Angella
af1ca08ddb [mlir][EmitC]Remove the Unused Option in the wrap-emitc-func-in-class Pass (#150577)
This patch removes the option `namedAttribute` which is not used in this
pass.
2025-07-25 09:30:55 -07:00
Jacques Pienaar
07967d4af8 [mlir] Switch to new LDBG macro (#150616)
Change local variants to use new central one.
2025-07-25 18:22:46 +02:00
Frank Schlimbach
b2d4963ee9 [NFC][mlir][mesh,shard] Fixing misnomers in mesh dialect, renaming 'mesh' dialect to 'shard' (#150177)
Dialect to 'shard' (discourse 87053)
  - dialect name mesh -> shard
  - (device) mesh -> (device) grid
  - spmdize -> partition

A lot of diffs, but simple renames only.

@tkarna @yaochengji
2025-07-25 16:53:08 +02:00
Maksim Levental
21774489f0 [mlir][python] fix PyDenseResourceElementsAttribute finalizer (#150561)
This PR melds https://github.com/llvm/llvm-project/pull/150137 and
https://github.com/llvm/llvm-project/pull/149414 *and* partially reverts
https://github.com/llvm/llvm-project/pull/124832.

The summary is the `PyDenseResourceElementsAttribute` finalizer/deleter
has/had two problems

1. wasn't threadsafe (can be called from a different thread than that
which currently holds the GIL)
2. can be called while the interpreter is "not initialized"

https://github.com/llvm/llvm-project/pull/124832 for some reason decides
to re-initialize the interpreter to avoid case 2 and runs afoul of the
fact that `Py_IsInitialized` can be false during the finalization of the
interpreter itself (e.g., at the end of a script).

I don't know why this decision was made (I missed the PR) but I believe
we should never be calling
[Py_Initialize](https://docs.python.org/3/c-api/init.html#c.Py_Initialize):

> In an application \*\*\*\***embedding Python**\*\*\*\*, this should be
called before using any other Python/C API functions

**but we aren't embedding Python**!

So therefore we will only be in case 2 when the interpreter is being
finalized and in that case we should just leak the buffer.

Note,
[lldb](548ca9e976/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (L81-L93))
does a similar sort of thing for its finalizers.

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
Co-authored-by: Max Manainen <maximmanainen@gmail.com>

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
Co-authored-by: Max Manainen <maximmanainen@gmail.com>
2025-07-25 08:05:30 -04:00