Commit Graph

537 Commits

Author SHA1 Message Date
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
Mehdi Amini
ec6da06522 Apply clang-tidy fixes for misc-include-cleaner in MLIR examples 2023-10-25 22:27:30 -07:00
Mehdi Amini
904c5b484e Apply clang-tidy fixes for misc-include-cleaner in AST.cpp (NFC) 2023-10-22 14:24:18 -07:00
Mehdi Amini
d2d93a3365 Apply clang-tidy fixes for misc-include-cleaner in AST.cpp (NFC) 2023-10-22 14:23:50 -07:00
Mehdi Amini
f58eabc60e Apply clang-tidy fixes for misc-include-cleaner in MLIRGen.cpp (NFC) 2023-10-22 14:23:50 -07:00
Mehdi Amini
cd71a2c5fa Apply clang-tidy fixes for misc-include-cleaner in Dialect.cpp (NFC) 2023-10-22 14:23:49 -07:00
Mehdi Amini
2f20e0ee73 Apply clang-tidy fixes for misc-include-cleaner in toyc.cpp (NFC) 2023-10-22 14:23:49 -07:00
Jacques Pienaar
ce8b8b1639
[mlir][minimal-opt] Fix typo 2023-10-22 10:03:15 -07:00
Mehdi Amini
6db6e7e72e Apply clang-tidy fixes for llvm-qualified-auto in LowerToLLVM.cpp (NFC) 2023-10-21 17:31:37 -07:00
Mehdi Amini
c8f09c19b9 Apply clang-tidy fixes for llvm-qualified-auto in LowerToLLVM.cpp (NFC) 2023-10-21 17:31:37 -07:00
Mehdi Amini
1a12acd6b1 Apply clang-tidy fixes for misc-include-cleaner in standalone-translate.cpp (NFC) 2023-10-20 00:58:28 -07:00
Mehdi Amini
d8214f5143 Apply clang-tidy fixes for misc-include-cleaner in standalone-plugin.cpp (NFC) 2023-10-20 00:58:28 -07:00
Mehdi Amini
655b678197 Apply clang-tidy fixes for misc-include-cleaner in standalone-opt.cpp (NFC) 2023-10-20 00:58:28 -07:00
Mehdi Amini
83fd5d805c Apply clang-tidy fixes for misc-unused-alias-decls in StandaloneExtension.cpp (NFC) 2023-10-20 00:58:27 -07:00
Mehdi Amini
4b65b289e1 Apply clang-tidy fixes for misc-include-cleaner in StandalonePasses.cpp (NFC) 2023-10-20 00:58:27 -07:00
Mehdi Amini
a06f0e33eb Apply clang-tidy fixes for misc-include-cleaner in StandaloneOps.cpp (NFC) 2023-10-20 00:58:27 -07:00
Mehdi Amini
e59f76e9f5 Apply clang-tidy fixes for misc-include-cleaner in mlir-cat.cpp (NFC) 2023-10-20 00:58:27 -07:00
Christian Ulmann
484668c759
Reland "[MLIR][LLVM] Change addressof builders to use opaque pointers" (#69292)
This relands fbde19a664, which was broken due to incorrect GEP element type creation.

This commit changes the builders of the `llvm.mlir.addressof` operations
to no longer produce typed pointers.

As a consequence, a GPU to NVVM pattern had to be updated, that still
relied on typed pointers.
2023-10-17 11:33:45 +02:00
Christian Ulmann
9397e5f581 Revert "[MLIR][LLVM] Change addressof builders to use opaque pointers (#69215)"
This reverts commit fbde19a664 due to
breaking integration tests.
2023-10-17 06:31:48 +00:00
Christian Ulmann
fbde19a664
[MLIR][LLVM] Change addressof builders to use opaque pointers (#69215)
This commit changes the builders of the `llvm.mlir.addressof` operations
to no longer produce typed pointers.

As a consequence, a GPU to NVVM pattern and the toy example LLVM lowerings had to be updated, as they still relied on typed pointers.
2023-10-17 07:55:00 +02:00
Ivan R. Ivanov
26eb4285b5
[MLIR][LLVM] Add vararg support in LLVM::CallOp and InvokeOp (#67274)
In order to support indirect vararg calls, we need to have information about the
callee type - this patch adds a `callee_type` attribute that holds that.

The attribute is required for vararg calls, else, it is optional and the callee
type is inferred by the operands and results of the operation if not present.

The syntax for non-vararg calls remains the same, whereas for vararg calls, it
is changed to this:

```
llvm.call %p(%arg0, %arg0) vararg(!llvm.func<void (i32, ...)>) : !llvm.ptr, (i32, i32) -> ()
llvm.call @s(%arg0, %arg0) vararg(!llvm.func<void (i32, ...)>) : (i32, i32) -> ()
```
2023-09-28 08:26:45 +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
Mehdi Amini
863c346209 [MLIR] Switch the default for usePropertiesForAttributes (NFC)
This is adopting properties as storage for attribute by default.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158581
2023-08-28 20:25:03 -07:00
Mehdi Amini
57f03baf90 Revert "[MLIR] Switch the default for usePropertiesForAttributes (NFC)"
This reverts commit ef3ab3de97.

The revision hasn't actually been approved yet!
2023-08-27 16:30:44 -07:00
Mehdi Amini
ef3ab3de97 [MLIR] Switch the default for usePropertiesForAttributes (NFC)
This is adopting properties as storage for attribute by default.
2023-08-27 16:14:31 -07:00
Nicolas Vasilache
7c4e8c6a27 [mlir] Disentangle dialect and extension registrations.
This revision avoids the registration of dialect extensions in Pass::getDependentDialects.

Such registration of extensions can be dangerous because `DialectRegistry::isSubsetOf` is
always guaranteed to return false for extensions (i.e. there is no mechanism to track
whether a lambda is already in the list of already registered extensions).
When the context is already in a multi-threaded mode, this is guaranteed to assert.

Arguably a more structured registration mechanism for extensions with a unique ExtensionID
could be envisioned in the future.

In the process of cleaning this up, multiple usage inconsistencies surfaced around the
registration of translation extensions that this revision also cleans up.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D157703
2023-08-22 00:40:09 +00:00
Jian Cai
d22965f0d6 Reland "[mlir] Add a postprocessing parameter in Pattern"
This fixed a test failure that caused the rollback of the original
commit. Verified with ninja check-mlir.
2023-08-15 19:21:27 -07:00
Jie Fu
64e86d8a7e [mlir] Update mlir/examples/standalone/README.md (NFC) 2023-08-11 14:13:09 +08:00
Martin Erhart
d790a217a7 [mlir] Add getArgOperandsMutable method to CallOpInterface
Add a method to the CallOpInterface to get a mutable operand range over
the function arguments.  This allows to add, remove, or change the type
of call arguments in a generic manner without having to assume that the
argument operand range is at the end of the operand list, or having to
type switch on all supported concrete operation kinds.

Alternatively, a new OpInterface could be added which inherits from
CallOpInterface and appends it with the mutable variants of the base
interface.

There will be two users of this new function in the beginning:
(1) A few passes in the Arc dialect in CIRCT already use a downstream
implementation of the alternative case mentioned above: https://github.com/llvm/circt/blob/main/include/circt/Dialect/Arc/ArcInterfaces.td#L15
(2) The BufferDeallocation pass will be modified to be able to pass
ownership of memrefs to called private functions if the caller does not
need the memref anymore by appending the function argument list with a
boolean value per memref, thus enabling earlier deallocation of the
memref which can lead to lower peak memory usage.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D156675
2023-08-02 08:08:18 +00:00
Mehdi Amini
9f366db2c8 Fix typo in README for the MLIR minimal examples (NFC) 2023-07-31 13:09:18 -07:00
Mehdi Amini
d1edc7feb4 Add more numbers about MLIR binary sizes with the example binaries (NFC) 2023-07-26 16:13:14 -07:00
Mehdi Amini
e7f8b45953 Add an MLIR example of some mimimal example of MLIR setup
These may serve as example and showcase of the MLIR binary footprint.

Right now a release build of these tools on a linux machine shows:

- mlir-cat: 2MB
  This includes the Core IR, the textual parser/printer, the support for
  bytecode.
- mlir-minimal-opt: 3MB
  This adds all the tooling for an mlir-opt tool: the pass infrastructure
  and all the instrumentation associated with it.
- mlir-miminal-opt-canonicalize: 4.8MB
  This add the canonicalizer pass, which pulls in all the pattern/rewrite
  machinery, including the PDL compiler and intepreter.

Differential Revision: https://reviews.llvm.org/D156218
2023-07-25 11:38:19 -07:00
Rahul Kayaith
67a910bbff [mlir][python] Remove PythonAttr mapping functionality
This functionality has been replaced by TypeCasters (see D151840)

depends on D154468

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D154469
2023-07-18 12:21:28 -04:00
Alex Zinenko
e2b19ef6ac [mlir] mark libraries in mlir/examples as such
LLVM build system separates between `add_llvm_example_library` and
`add_llvm_library`, which is presumably used to package examples
separately from the regular library. Introduce a similar approach to
building example libraries in MLIR and use it for the transform dialect
tutorial.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D153265
2023-06-20 13:02:42 +02: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
Alex Zinenko
f17b137f77 [mlir] don't install tutorial libraries
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D153055
2023-06-16 18:32:08 +02:00
River Riddle
a5ef51d786 [mlir] Add support for "promised" interfaces
Promised interfaces allow for a dialect to "promise" the implementation of an interface, i.e.
declare that it supports an interface, but have the interface defined in an extension in a library
separate from the dialect itself. A promised interface is powerful in that it alerts the user when
the interface is attempted to be used (e.g. via cast/dyn_cast/etc.) and the implementation has
not yet been provided. This makes the system much more robust against misconfiguration,
and ensures that we do not lose the benefit we currently have of defining the interface in
the dialect library.

Differential Revision: https://reviews.llvm.org/D120368
2023-06-09 11:30:13 -07:00
Oleksandr "Alex" Zinenko
2bca6925a8
Fix link in transform example README.md 2023-05-31 11:39:26 +02:00
Alex Zinenko
d8c18e422b [mlir] fix documentation includes 2023-05-31 08:58:42 +00:00
Alex Zinenko
7cdb875d4d [mlir] silence msvc warning 2023-05-30 15:59:19 +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
Mark de Wever
cbaa3597aa Reland "[CMake] Bumps minimum version to 3.20.0.
This reverts commit d763c6e5e2.

Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719
This patch fixes the Windows build.

d763c6e5e2 reverted the reviews

D144509 [CMake] Bumps minimum version to 3.20.0.

This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

D150532 [OpenMP] Compile assembly files as ASM, not C

Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.

Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.

Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.

D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump

The build uses other mechanism to select the runtime.

Fixes #62719

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D151344
2023-05-27 12:51:21 +02:00
Mehdi Amini
660f714e26 [MLIR] Add native Bytecode support for properties
This is adding a new interface (`BytecodeOpInterface`) to allow operations to
opt-in skipping conversion to attribute and serializing properties to native
bytecode.

The scheme relies on a new section where properties are stored in sequence

  { size, serialize_properties }, ...

The operations are storing the index of a properties, a table of offset is
built when loading the properties section the first time.

This is a re-commit of 837d1ce0dc which conflicted with another patch upgrading
the bytecode and the collision wasn't properly resolved before.

Differential Revision: https://reviews.llvm.org/D151065
2023-05-26 17:45:01 -07:00
Tres Popp
68f58812e3 [mlir] Move casting calls from methods to function calls
The MLIR classes Type/Attribute/Operation/Op/Value support
cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast
functionality in addition to defining methods with the same name.
This change begins the migration of uses of the method to the
corresponding function call as has been decided as more consistent.

Note that there still exist classes that only define methods directly,
such as AffineExpr, and this does not include work currently to support
a functional cast/isa call.

Context:
- https://mlir.llvm.org/deprecation/ at "Use the free function variants
  for dyn_cast/cast/isa/…"
- Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443

Implementation:
This patch updates all remaining uses of the deprecated functionality in
mlir/. This was done with clang-tidy as described below and further
modifications to GPUBase.td and OpenMPOpsInterfaces.td.

Steps are described per line, as comments are removed by git:
0. Retrieve the change from the following to build clang-tidy with an
   additional check:
   main...tpopp:llvm-project:tidy-cast-check
1. Build clang-tidy
2. Run clang-tidy over your entire codebase while disabling all checks
   and enabling the one relevant one. Run on all header files also.
3. Delete .inc files that were also modified, so the next build rebuilds
   them to a pure state.

```
ninja -C $BUILD_DIR clang-tidy

run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\
               -header-filter=mlir/ mlir/* -fix

rm -rf $BUILD_DIR/tools/mlir/**/*.inc
```

Differential Revision: https://reviews.llvm.org/D151542
2023-05-26 10:29:55 +02:00
Tobias Hieta
f9008e6366
[NFC][Py Reformat] Reformat python files in mlir subdir
This is an ongoing series of commits that are reformatting our
Python code.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Differential Revision: https://reviews.llvm.org/D150782
2023-05-26 08:05:40 +02:00
Mehdi Amini
bb9a0c736b Revert "[MLIR] Add native Bytecode support for properties"
This reverts commit ca5a12fd69
and follow-up fixes:

df34c288c4
07dc906883
ab80ad0095
837d1ce0dc

The first commit was incomplete and broken, I'll prepare a new version
later, in the meantime pull this work out of tree.
2023-05-25 21:02:31 -07:00
Mehdi Amini
837d1ce0dc [MLIR] Add native Bytecode support for properties
This is adding a new interface (`BytecodeOpInterface`) to allow operations to
opt-in skipping conversion to attribute and serializing properties to native
bytecode.

The scheme relies on a new section where properties are stored in sequence

  { size, serialize_properties }, ...

The operations are storing the index of a properties, a table of offset is
built when loading the properties section the first time.

Back-deployment to version prior to 4 are relying on getAttrDictionnary() which
we intend to deprecate and remove: that is putting a de-factor end-of-support
horizon for supporting deployments to version older than 4.

Differential Revision: https://reviews.llvm.org/D151065
2023-05-25 15:15:47 -07:00
Nico Weber
d763c6e5e2 Revert "Reland "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit 65429b9af6.

Broke several projects, see https://reviews.llvm.org/D144509#4347562 onwards.

Also reverts follow-up commit "[OpenMP] Compile assembly files as ASM, not C"

This reverts commit 4072c8aee4.

Also reverts fix attempt  "[cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump"

This reverts commit 7d47dac5f8.
2023-05-17 10:53:33 -04:00
Mark de Wever
65429b9af6 Reland "[CMake] Bumps minimum version to 3.20.0."
The owner of the last two failing buildbots updated CMake.

This reverts commit e8e8707b4a.
2023-05-13 11:42:25 +02:00
Tres Popp
5c8ce6d576 [mlir] Move casting method calls to function calls
The MLIR classes Type/Attribute/Operation/Op/Value support
cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast
functionality in addition to defining methods with the same name.
This change continues the migration of uses of the method to the
corresponding function call as has been decided as more consistent.

This commit attempts to update all occurrences of the casts in .td
files, although it is likely that a couple were missed.

Context:
- https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…"
- Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443

Implementation:
Unfortunatley, this was not automated, but was handled by mindlessly
going to next occurrences of patterns, selecting the piece of code to
be moved into the function call, and running a vim macro over the span
of around 4 hours.

Differential Revision: https://reviews.llvm.org/D150199
2023-05-12 11:17:27 +02:00