267 Commits

Author SHA1 Message Date
Maksim Levental
1cec5fffd8
[mlir] implement -verify-diagnostics=only-expected (#135131)
This PR implements `verify-diagnostics=only-expected` which is a "best
effort" verification - i.e., `unexpected`s and `near-misses` will not be
considered failures. The purpose is to enable narrowly scoped checking
of verification remarks (just as we have for lit where only a subset of
lines get `CHECK`ed).
2025-04-10 18:50:00 -04:00
Christopher McGirr
ae3faea1f2
[MLIR][mlir-opt] move action debugger hook flag (#134842)
Currently if a developer uses the flag `--mlir-enable-debugger-hook` the
debugger hook is not actually enabled. It seems the DebugConfig and the
MainMLIROptConfig are not connected.

To fix this we can move the `enableDebuggerHook` CL Option to the
DebugConfigCLOptions struct so that it can get registered and enabled
along with the other debugger flags. AFAICS there are no other uses of
the flag so this should be safe.

This also adds a small LIT test to check that the hook is enabled by
checking the std::cerr output for the log message.
2025-04-08 16:54:11 +02:00
Han-Chung Wang
66b0b0466b
[MLIR][NFC] Fix incomplete boundary comments. (#133516)
I observed that we have the boundary comments in the codebase like:

```
//===----------------------------------------------------------------------===//
// ...
//===----------------------------------------------------------------------===//
```

I also observed that there are incomplete boundary comments. The
revision is generated by a script that completes the boundary comments.

```
//===----------------------------------------------------------------------===//
// ...

...
```

Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-03-31 09:29:54 -07:00
Kazu Hirata
d66af9c69b
[mlir] Use SetVector::insert_range (NFC) (#133595) 2025-03-29 14:27:10 -07:00
Matthias Springer
6c867e27a7
[mlir] Use getSingleElement/hasSingleElement in various places (#131460)
This is a code cleanup. Update a few places in MLIR that should use
`hasSingleElement`/`getSingleElement`.

Note: `hasSingleElement` is faster than `.getSize() == 1` when it is
used with linked lists etc.

Depends on #131508.
2025-03-17 07:43:18 +01:00
Nikolay Panchenko
3ac5d8da61
[mlir-lsp] Abstract input and output of the JSONTransport (#129320)
The patch abstracts sending and receiving json messages of
`JSONTransport` to allow custom implementation of them. For example, one
concrete implementation can use pipes without a need to convert file
descriptor to a `FILE` object.
2025-03-14 12:31:28 -04:00
Kazu Hirata
4f4e2abb1a
[mlir] Migrate away from PointerUnion::{is,get} (NFC) (#122591)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2025-01-11 13:16:43 -08:00
Jie Fu
c8b15157d7 [mlir-opt] Fix -Wcovered-switch-default in MlirOptMain.cpp (NFC)
/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:262:7:
error: default label in switch which covers all enumeration values [-Werror,-Wcovered-switch-default]
      default:
      ^
1 error generated.
2024-11-28 11:22:28 +08:00
sfzhu93
1f422dc399
[MLIR][mlir-opt] add support for disabling diagnostics (#117669)
This PR adds a command line argument `--mlir-disable-diagnostic` for
disabling diagnostic information for mlir-opt.
When debugging with mlir-opt, some developers would like to disable the
diagnostic information and focus specifically on the dumped IR. For
example, https://github.com/triton-lang/triton/pull/5250
2024-11-27 18:51:18 -08:00
Thomas Peters
aa81c28cd5
[MLIR][mlir-opt] Add option to turn off verifier on parsing (#116287)
Sometimes, a developer may not wish to wait for the verifier
(imagine they did not follow the verifier guidelines and chased use-def
chains), or may wish to disable it.

Add a command-line option,
`--mlir-very-unsafe-disable-verifier-on-parsing`, which turns off the
verifier on parsing.

------

This implements the discussion from
https://discourse.llvm.org/t/optionally-turn-off-verifier-during-parsing/82805
2024-11-15 00:23:45 +01:00
Rahul Joshi
e768b076e3
[MLIR][TableGen] Use const pointers for various Init objects (#112562)
This reverts commit 0eed3055511381436ee69d1caf64a4af47f8d65c and applies
additional fixes in `verifyArgument` in OmpOpGen.cpp for gcc-7 bot
failures
2024-10-16 11:46:38 -07:00
Mehdi Amini
0eed305551
Revert "[MLIR][TableGen] Use const pointers for various Init objects" (#112506)
Reverts llvm/llvm-project#112316

Bots are failing.
2024-10-16 11:09:17 +02:00
Rahul Joshi
1ae9fe5ea0
[MLIR][TableGen] Use const pointers for various Init objects (#112316)
Use const pointers for various `Init` objects. This is a part of effort
to have better const correctness in TableGen backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-14 23:48:12 -07:00
Rahul Joshi
65e69f7436
[NFC][TableGen] Change Record::getSuperClasses to use const Record* (#110845)
Change `Record::getSuperClasses` to return a const pointer to the
superclass records.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-02 13:24:46 -07:00
Rahul Joshi
429819f223
[NFC][MLIR][TableGen] Eliminate llvm:: for common types in LSP Server (#110867) 2024-10-02 10:12:42 -07:00
Rahul Joshi
a86e966a20
[TableGen] Change TableGenMain to use const RecordKeeper (#110578)
Change TableGenMain's `MainFn` argument to be a function that accepts a
const reference to RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-01 06:51:07 -07:00
JOE1994
095b41c6ee [mlir] Reland 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0 with update (NFC)
Excluded updates to mlir/lib/AsmParser/Parser.cpp ,
which caused LIT failure "FAIL: MLIR::completion.test" on multiple buildbots.
2024-09-15 22:45:28 -04:00
JOE1994
61ff1cb452 Revert "[mlir] Nits on uses of llvm::raw_string_ostream (NFC)"
This reverts commit 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0.

"FAIL: MLIR::completion.test" on multiple buildbots.
2024-09-15 22:09:11 -04:00
JOE1994
5a6e52d6ef [mlir] Nits on uses of llvm::raw_string_ostream (NFC)
* Strip calls to raw_string_ostream::flush(), which is essentially a no-op
* Strip unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-09-15 21:33:42 -04:00
Rahul Joshi
b60c6cbc0b
[MLIR][TableGen] Migrate MLIR backends to use const RecordKeeper (#107505)
- Migrate MLIR backends to use a const RecordKeeper reference.
2024-09-07 15:13:19 -07:00
Lily Brown
e40c5b42fe
[lsp] Fix format string in Reply (#107480)
PR #105745 requires that `formatv` calls have the correct number of
arguments. This call to `Logger::info` was incorrect.
2024-09-06 10:42:02 +01:00
Matthias Springer
35f55f53df
[mlir][ODS] Consistent cppType / cppClassName usage (#102657)
Make sure that the usage of `cppType` and `cppClassName` of type and
attribute definitions/constraints is consistent in TableGen.

- `cppClassName`: The C++ class name of the type or attribute.
- `cppType`: The fully qualified C++ class name: C++ namespace and C++
class name.

Basically, we should always use the fully qualified C++ class name for
parameter types, return types or template arguments.

Also some minor cleanups.

Fixes #57279.
2024-08-09 21:53:13 +02:00
Natan-GabrielTiutiuIntel
5e6d5c01e0
[mlir] Add --list-passes option to mlir-opt (#100420)
Currently, the only way to see the passes that were registered is by
calling “mlir-opt --help”. However, for compilers with 500+ passes, the
help message becomes too long and sometimes hard to understand. In this
PR I add a new "--list-passes" option to mlir-opt, which can be used for
printing only the registered passes, a feature that would be extremely
useful.
2024-08-06 20:00:51 +02: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
Kazu Hirata
b7b337fb91
[mlir] Use llvm::unique (NFC) (#96415) 2024-06-24 11:54:02 -07:00
Nikita Popov
0aea1f2f21 [mlir] Add missing ManagedStatic.h includes (NFC) 2024-06-21 16:13:41 +02:00
Kazu Hirata
e411c88b72
Use StringRef::find_first_of(char), etc (NFC) (#92841) 2024-05-20 22:55:24 -07:00
Théo Degioanni
f6ae8e6381
[mlir][irdl] Fix missing verifier in irdl.parametric (#92700)
The parametric op was not checking the symbol it points to is a type or
attribute. This PR also fixes a small bug where an invalid IRDL file
would not end processing in mlir-opt. I also improved the error messages
for the already handled irdl.base invalid symbols.
2024-05-20 12:52:07 +01:00
Walter Erquinigo
d90159add4
[LSP] Use std::string for storing the Reply method (#92464)
This was using a StringRef, which is very unsafe because the method name
might just get disposed due to the async nature of the response.
This was causing weird characters being printed in the output logs.
2024-05-17 12:32:59 -04:00
Lily Brown
878c141adc
[mlir-lsp] Add DiagnosticTag from LSP spec (#91396)
Adds the [DiagnosticTag][diagtag] LSP construct to the LSP support
headers. I also added a unit test file to validate that the `tags` array
is omitted entirely if it's empty.

The LSP spec requires that `Diagnostic::tags` be an array; in order to
conform to that I used `std::vector`, as `SmallVector` doesn't have JSON
decoding support (you can encode it to JSON, but not decode it from
JSON).

[diagtag]:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#diagnosticTag
2024-05-08 15:07:37 -04:00
Peiming Liu
d2353695f8
[mlir][NFC] update code to use mlir::dyn_cast/cast/isa (#90633)
Fix compiler warning caused by using deprecated interface
(https://github.com/llvm/llvm-project/pull/90413)
2024-04-30 11:14:11 -07:00
Brian Gesiak
e24a7bbf45
[mlir-lsp] Support outgoing requests (#90078)
Add support for outgoing requests to `lsp::MessageHandler`. Much like
`MessageHandler::outgoingNotification`, this allows for the message
handler to send outgoing messages via its JSON transport, but in this
case, those messages are requests, not notifications.

Requests receive responses (also referred to as "replies" in
`MLIRLspServerSupportLib`). These were previously unsupported, and
`lsp::MessageHandler` would log an error each time it processed a JSON
message that appeared to be a response (something with an "id" field,
but no "method" field). However, the `outgoingRequest` method now
handles response callbacks: an outgoing request with a given ID is set
up such that a callback function is invoked when a response with that ID
is received.
2024-04-29 18:43:08 -04:00
Brian Gesiak
b811ad6f34
[mlir-lsp] Un-revert unit test additions (#90232)
This reverts the revert commit 6844c2feae93dd4251, which was comprised
of the following commits:

1. f3f6f22dfcced - [mlir-lsp] Initialize `Reply::method` member (#89857)
2. 37e13d4924841 - [mlir-lsp] Log invalid notification params (#89856)
3. ba1b52e6e764a - [mlir-lsp] Add `outgoingNotification` unit test
4. 84bc21f910173 - [mlir-lsp] Add transport unit tests (#89855)

Of these, (4) specifically caused issues in Windows pre-merge buildbots,
in the `TransportTest.MethodNotFound` unit test that it added. The
failure was caused by a statement that asserted that opening a file
stream on a newly created temporary file did not result in an error, but
this assert failed on Windows.

This patch adds additional error logging for failures, to make it
clearer what went wrong when failures occur. This patch also addresses
the Windows failure by ensuring temporary files are created in the
system temporary directory.
2024-04-29 10:54:31 -04:00
Mehdi Amini
6844c2feae Revert 4 last "[mlir-lsp]" commits: pre-merge bot is broken
This reverts commits:
- f3f6f22dfcced21116710a477c78e0739c942139.
- 37e13d4924841bd84edb8c67c667d6d2a6c2bc63.
- ba1b52e6e764ad637822f0b63d144eca6e5d5627.
- 84bc21f9101730af611a0175d89ae2056d5f41a7.
2024-04-25 19:21:39 -07:00
Brian Gesiak
a8c88de0df
Revert "[mlir-lsp] Rename OutgoingNotification (NFC) (#90076)"
This reverts commit b77416ea156acdec. While that seemed like an
appropriate rename at the time, further review on pull request #90078
makes it unnecessary. This revert changes the name back.
2024-04-25 21:59:22 -04:00
Brian Gesiak
b77416ea15
[mlir-lsp] Rename OutgoingNotification (NFC) (#90076)
Rename `OutgoingNotification` to `OutgoingMessage`, since the same
callback function type will be used in a future commit to represent
outgoing requests, in addition to outgoing notifications.
2024-04-25 15:39:55 -04:00
Brian Gesiak
f3f6f22dfc
[mlir-lsp] Initialize Reply::method member (#89857)
When debug level logging is enabled (by adding a call to
`Logger::setLogLevel(Logger::Level::Debug)`), the
`TransportInputTest.RequestWithInvalidParams` unit test logs:

```
[18:35:00.565] --> reply:(92)
```

The format string for this log statement is `"--> reply:{0}({1})"`,
where `{0}` is the original request's method name (that is, the method
name of the request being replied to), and `{1}` is the request ID.
However, because the `Reply` class never initializes its `method`
member, `{0}` is always empty. Initializing it results in the (nicer)
log error below:

```
I[18:35:00.565] --> reply:invalid-params-request(92)
```

Because this is only ever logged for now, its not possible to add a test
case for this. Future patches will rely on `method` being initialized,
however, and will add test cases for this path.
2024-04-24 15:44:07 -04:00
Benjamin Kramer
daa350c199 [mlir] Work around MSVC bug
MSVC fails to parse this construct, leading to
MlirTranslateMain.cpp(70): error C2065: 'inputSplitMarker': undeclared identifier

Just switching to brace init works around the issue
2024-03-17 14:05:41 +01:00
Mehdi Amini
2a547f0f6c [MLIR] Fix mlir-opt --show-dialects to not require any input (as documented) 2024-03-14 22:55:25 -07:00
Ingo Müller
516ccce7fa
[mlir] Make the split markers of splitAndProcessBuffer configurable. (#84765)
This allows to define custom splitters, which is interesting for
non-MLIR inputs and outputs to `mlir-translate`. For example, one may
use `; -----` as a splitter of `.ll` files. The splitters are now passed
as arguments into `splitAndProcessBuffer`, the input splitter defaulting
to the previous default (`// -----`) and the output splitter defaulting
to the empty string, which also corresponds to the previous default. The
behavior of the input split marker should not change at all; however,
outputs now have one new line *more* than before if there is no splitter
(old: `insertMarkerInOutput = false`, new: `outputSplitMarker = ""`) and
one new line *less* if there is one. The value of the input splitter is
exposed as a command line options of `mlir-translate` and other tools as
an optional value to the previously existing flag `-split-input-file`,
which defaults to the default splitter if not specified; the value of
the output splitter is exposed with the new `-output-split-marker`,
which default to the empty string in `mlir-translate` and the default
splitter in the other tools. In short, the previous usage or omission of
the flags should result in previous behavior (modulo the new lines
mentioned before).
2024-03-14 13:55:50 +01:00
Matthias Gehre
780a20984b
[PDLL]: Fix crash when negation doesn't apply to native constraint (#84331)
Fixes that
```
Pattern {
  let tuple = (attr<"3 : i34">);
  not tuple.0;
  erase _;
}
```
would crash the PDLL parser because it expected a native constraint
after `not`.
2024-03-08 08:27:46 +01:00
Mehdi Amini
6594f428de
Split the llvm::ThreadPool into an abstract base class and an implementation (#82094)
This decouples the public API used to enqueue tasks and wait for
completion from the actual implementation, and opens up the possibility
for clients to set their own thread pool implementation for the pool.

https://discourse.llvm.org/t/construct-threadpool-from-vector-of-existing-threads/76883
2024-03-02 19:10:50 -08:00
Matthias Gehre
8ec28af8ea Reapply "[mlir][PDL] Add support for native constraints with results (#82760)"
with a small stack-use-after-scope fix in getConstraintPredicates()

This reverts commit c80e6edba4a9593f0587e27fa0ac825ebe174afd.
2024-03-02 20:57:30 +01:00
Matthias Gehre
c80e6edba4 Revert "[mlir][PDL] Add support for native constraints with results (#82760)"
Due to buildbot failure https://lab.llvm.org/buildbot/#/builders/88/builds/72130

This reverts commit dca32a3b594b3c91f9766a9312b5d82534910fa1.
2024-03-01 07:44:30 +01:00
Matthias Gehre
dca32a3b59
[mlir][PDL] Add support for native constraints with results (#82760)
From https://reviews.llvm.org/D153245

This adds support for native PDL (and PDLL) C++ constraints to return
results.

This is useful for situations where a pattern checks for certain
constraints of multiple interdependent attributes and computes a new
attribute value based on them. Currently, for such an example it is
required to escape to C++ during matching to perform the check and after
a successful match again escape to native C++ to perform the computation
during the rewriting part of the pattern. With this work we can do the
computation in C++ during matching and use the result in the rewriting
part of the pattern. Effectively this enables a choice in the trade-off
of memory consumption during matching vs recomputation of values.

This is an example of a situation where this is useful: We have two
operations with certain attributes that have interdependent constraints.
For instance `attr_foo: one_of [0, 2, 4, 8], attr_bar: one_of [0, 2, 4,
8]` and `attr_foo == attr_bar`. The pattern should only match if all
conditions are true. The new operation should be created with a new
attribute which is computed from the two matched attributes e.g.
`attr_baz = attr_foo * attr_bar`. For the check we already escape to
native C++ and have all values at hand so it makes sense to directly
compute the new attribute value as well:

```
Constraint checkAndCompute(attr0: Attr, attr1: Attr) -> Attr;

Pattern example with benefit(1) {
    let foo = op<test.foo>() {attr = attr_foo : Attr};
    let bar = op<test.bar>(foo) {attr = attr_bar : Attr};
    let attr_baz = checkAndCompute(attr_foo, attr_bar);
    rewrite bar with {
        let baz = op<test.baz> {attr=attr_baz};
        replace bar with baz;
    };
}
```
To achieve this the following notable changes were necessary:
PDLL:
- Remove check in PDLL parser that prevented native constraints from
returning results

PDL:
- Change PDL definition of pdl.apply_native_constraint to allow variadic
results

PDL_interp:
- Change PDL_interp definition of pdl_interp.apply_constraint to allow
variadic results

PDLToPDLInterp Pass:
The input to the pass is an arbitrary number of PDL patterns. The pass
collects the predicates that are required to match all of the pdl
patterns and establishes an ordering that allows creation of a single
efficient matcher function to match all of them. Values that are matched
and possibly used in the rewriting part of a pattern are represented as
positions. This allows fusion and thus reusing a single position for
multiple matching patterns. Accordingly, we introduce
ConstraintPosition, which records the type and index of the result of
the constraint. The problem is for the corresponding value to be used in
the rewriting part of a pattern it has to be an input to the
pdl_interp.record_match operation, which is generated early during the
pass such that its surrounding block can be referred to by branching
operations. In consequence the value has to be materialized after the
original pdl.apply_native_constraint has been deleted but before we get
the chance to generate the corresponding pdl_interp.apply_constraint
operation. We solve this by emitting a placeholder value when a
ConstraintPosition is evaluated. These placeholder values (due to fusion
there may be multiple for one constraint result) are replaced later when
the actual pdl_interp.apply_constraint operation is created.

Changes since the phabricator review:
- Addressed all comments
- In particular, removed registerConstraintFunctionWithResults and
instead changed registerConstraintFunction so that contraint functions
always have results (empty by default)
- Thus we don't need to reuse `rewriteFunctions` to store constraint
functions with results anymore, and can instead use
`constraintFunctions`
- Perform a stable sort of ConstraintQuestion, so that
ConstraintQuestion appear before other ConstraintQuestion that use their
results.
- Don't create placeholders for pdl_interp::ApplyConstraintOp. Instead
generate the `pdl_interp::ApplyConstraintOp` before generating the
successor block.
- Fixed a test failure in the pdl python bindings


Original code by @martin-luecke

Co-authored-by: martin-luecke <martinpaul.luecke@amd.com>
2024-03-01 07:29:49 +01:00
Matteo Franciolini
ce4da0c4ee
Enables textual IR roundtripping through --verifyRoundtrip (#82946)
The patch enables roundtrip to textual file when running
`--verifyRoundtrip`. The verification is successful if both textual and
bytecode formats can roundtrip successfully.
2024-02-25 20:34:56 -08:00
Mehdi Amini
eb3409dc77 Apply clang-tidy fixes for readability-identifier-naming in PassPlugin.cpp (NFC) 2024-02-16 18:07:11 -08:00
Mehdi Amini
2545cac52e Apply clang-tidy fixes for llvm-include-order in Parser.cpp (NFC) 2024-02-16 18:07:10 -08:00
Mehdi Amini
820e438e70 Apply clang-tidy fixes for readability-identifier-naming in MlirOptMain.cpp (NFC) 2024-02-16 18:07:10 -08:00
Kazu Hirata
abaa79b25d [mlir] Use StringRef::ltrim (NFC) 2024-01-08 21:49:32 -08:00