89 Commits

Author SHA1 Message Date
Krzysztof Drewniak
d7c53a91c2
[mlir] Decouple enum generation from attributes, adding EnumInfo and EnumCase (#132148)
This commit pulls apart the inherent attribute dependence of classes
like EnumAttrInfo and EnumAttrCase, factoring them out into simpler
EnumCase and EnumInfo variants. This allows specifying the cases of an
enum without needing to make the cases, or the EnumInfo itself, a
subclass of SignlessIntegerAttrBase.

The existing classes are retained as subclasses of the new ones, both
for backwards compatibility and to allow attribute-specific information.

In addition, the new BitEnum class changes its default printer/parser
behavior: cases when multiple keywords appear, like having both nuw and
nsw in overflow flags, will no longer be quoted by the operator<<, and
the FieldParser instance will now expect multiple keywords. All
instances of BitEnumAttr retain the old behavior.
2025-03-27 19:40:06 -05:00
Krzysztof Drewniak
263ec7221e
[mlir][NFC] Move and rename EnumAttrCase, EnumAttr C++ classes (#132650)
This moves the EnumAttrCase and EnumAttr classes from Attribute.h/.cpp
to a new EnumInfo.h/cpp and renames them to EnumCase and EnumInfo,
respectively.

This doesn't change any of the tablegen files or any user-facing aspects
of the enum attribute generation system, just reorganizes code in order
to make main PR (#132148) shorter.
2025-03-26 20:26:14 -05:00
Kazu Hirata
26d513d197
[TableGen] Migrate away from PointerUnion::{is,get} (NFC) (#122569)
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>
2025-01-11 00:17:40 -08:00
Rahul Joshi
659192b184
[NFC][MLIR][TableGen] Eliminate llvm:: for commonly used types (#112456)
Eliminate `llvm::` namespace qualifier for commonly used types in MLIR
TableGen backends to reduce code clutter.
2024-10-18 14:26:57 -07: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
d256b9e88b
[TableGen] Change DefInit::Def to a const Record pointer (#110747)
This change undoes a const_cast<> introduced in an earlier change to
help transition to const pointers. It 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 09:48:26 -07:00
Kazu Hirata
5e1e6a689c
[TableGen] Avoid repeated hash lookups (NFC) (#107429) 2024-09-05 11:58:03 -07:00
Mehdi Amini
1f97219a90 Apply clang-tidy fixes for performance-move-const-arg in Pattern.cpp (NFC) 2024-02-15 16:02:40 -08:00
Logan Chien
08d7377b67 [mlir] Enable DRR variadic operand matching
This commit enables DRR rewriter to match a fixed number of sub-operands
as a variadic operand.

Differential Review: https://reviews.llvm.org/D157359
2023-08-28 14:11:32 -07: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
Mehdi Amini
2d8f793b32 Revert "[mlir] Add a postprocessing parameter in Pattern"
This reverts commit 02596693fac55f550e85620f5184547c80c8f930.
This reverts commit 3c5b4dabdc06dd380391ac965b16961610c0db77.

The build is broken:

mlir/test/lib/Dialect/Test/TestOps.td:988:7: error: Value specified for template argument 'Pat:supplemental_results' is of type dag; expected type list<dag>: (addBenefit 10)
def : Pat<(OpD $input), (OpF $input), [], (addBenefit 10)>;
      ^
2023-08-15 15:50:29 -07:00
Jian Cai
02596693fa [mlir] Add a postprocessing parameter in Pattern
This adds a parameter SupplementalPatterns in tablegen class Pattern for
postprocessing code. For example, this can be used to ensure ops are
placed in the correct device by copying the atttributes that decide
devicement placement in Tensorflow dialect to prevent performance
regression.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D157032
2023-08-15 14:08:31 -07:00
Chia-hung Duan
32032cbf25 [mlir][tblgen] Fix emitting wrong index for either directive.
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D149152
2023-05-03 13:07:45 +00:00
Fangrui Song
3cfe412e4c [TableGen] llvm::Optional => std::optional 2022-12-06 07:21:02 +00:00
Benjamin Kramer
9fa59e7643 [mlir] Use C++17 structured bindings instead of std::tie where applicable. NFCI 2022-08-09 13:34:17 +02:00
Kazu Hirata
ae002f8bca Use isa instead of dyn_cast (NFC) 2022-07-25 23:00:58 -07:00
Kazu Hirata
064a08cd95 Don't use Optional::hasValue (NFC) 2022-06-20 20:05:16 -07:00
Markus Böck
7b196f1b09 [mlir][Rewrite] Add support for using an operation with no results as location
Prior to this patch, using an operation without any results as the location would result in the generation of invalid C++ code. It'd try to format using the result values, which would would end up being an empty string for an operation without any.
This patch fixes that issue by instead using getValueAndRangeUse which handles both ranges as well as the case for an op without any results.

Differential Revision: https://reviews.llvm.org/D118885
2022-02-03 15:08:09 +01:00
Markus Böck
8652fc8453 [mlir][NFC] Fully qualify a default C++ string in Pattern.cpp 2022-02-03 11:50:37 +01:00
Mehdi Amini
1fc096af1e Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC)
Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D116250
2022-01-02 01:45:18 +00:00
Mehdi Amini
e5639b3fa4 Fix more clang-tidy cleanups in mlir/ (NFC) 2021-12-22 20:53:11 +00:00
Mehdi Amini
02b6fb218e Fix clang-tidy issues in mlir/ (NFC)
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D115956
2021-12-20 20:25:01 +00:00
Chia-hung Duan
2d99c815d7 [mlir-tblgen] Support either in Tablegen DRR.
Add a new directive `either` to specify the operands can be matched in either order

Reviewed By: jpienaar, Mogball

Differential Revision: https://reviews.llvm.org/D110666
2021-11-08 23:16:03 +00:00
rdzhabarov
fb3d83acaf [mlir] Fix redundant return in the void method.
clang-tidy, fix redundant return statement at the end of the void method.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D111251
2021-10-06 18:45:30 +00:00
Chia-hung Duan
bb2506061b [mlir-tblgen] Add DagNode StaticMatcher.
Some patterns may share the common DAG structures. Generate a static
function to do the match logic to reduce the binary size.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D105797
2021-09-20 23:37:42 +00:00
Mogball
cb8c30d35d [DRR] Explicit Return Types in Rewrites
Adds a new rewrite directive returnType that can be added at the end of an op's
argument list to explicitly specify return types.

```
(OpX $v0, $v1, (returnType "$_builder.getI32Type()"))
```

Pass in a bound value to copy its return type, or pass a native code call to
dynamically create new types.

```
(OpX $v0, $v1, (returnType $v0, (NativeCodeCall<"..."> $v1)))
```

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D109472
2021-09-15 14:25:29 -07:00
Chia-hung Duan
d7314b3c09 [mlir-tblgen] Support binding multi-results of NativeCodeCall
We are able to bind NativeCodeCall result as binding operation. To make
table-gen have better understanding in the form of helper function,
we need to specify the number of return values in the NativeCodeCall
template. A VoidNativeCodeCall is added for void case.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D102160
2021-07-21 11:23:22 +08:00
Chia-hung Duan
b4001ae885 [mlir-tblgen] Fix failed matching when binds same operand of an op in different depth
For example, we will generate incorrect code for the pattern,

def : Pat<((FooOp (FooOp, $a, $b), $b)), (...)>;

We didn't allow $b to be bond twice with same operand of same op.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D105677
2021-07-20 15:43:09 +08:00
Chia-hung Duan
34b5482b33 Support NativeCodeCall binding in rewrite pattern.
We are able to bind the result from native function while rewriting
pattern. In matching pattern, if we want to get some values back, we can
do that by passing parameter as return value placeholder. Besides, add
the semantic of '$_self' in NativeCodeCall while matching, it'll be the
operation that defines certain operand.

Differential Revision: https://reviews.llvm.org/D100746
2021-05-10 09:29:27 +08:00
Paul C. Anagnostopoulos
415fab6f67 [TableGen] Eliminate the 'code' type
Update the documentation.

Rework various backends that relied on the code type.

Differential Revision: https://reviews.llvm.org/D92269
2020-12-03 10:19:11 -05:00
Rob Suderman
ad1fe3963f [MLIR] Fix gcc5 in D89161
Missing .str() makes gcc5 unable to infer the template to use.

Differential Revision: https://reviews.llvm.org/D89516
2020-10-15 17:03:06 -07:00
Rob Suderman
2bf423b021 [mlir] RewriterGen NativeCodeCall matcher with ConstantOp matcher
Added an underlying matcher for generic constant ops. This
included a rewriter of RewriterGen to make variable use more
clear.

Differential Revision: https://reviews.llvm.org/D89161
2020-10-15 16:32:20 -07:00
rdzhabarov
008c0ea6a4 [DDR] Introduce implicit equality check for the source pattern operands with the same name.
This CL allows user to specify the same name for the operands in the source pattern which implicitly enforces equality on operands with the same name.
E.g., Pat<(OpA $a, $b, $a) ... > would create a matching rule for checking equality for the first and the last operands. Equality of the operands is enforced at any depth, e.g., OpA ($a, $b, OpB($a, $c, OpC ($a))).

Example usage: Pat<(Reshape $arg0, (Shape $arg0)), (replaceWithValue $arg0)>

Note, this feature only covers operands but not attributes.
Current use cases are based on the operand equality and explicitly add the constraint into the pattern. Attribute equality will be worked out on the different CL.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D89254
2020-10-14 11:05:13 -07:00
Mehdi Amini
0b793c4be0 Revert "[DDR] Introduce implicit equality check for the source pattern operands with the same name."
This reverts commit 7271c1bcb96051bcd227d3fa6071a620fe238850.

This broke the gcc-5 build:

/usr/include/c++/5/ext/new_allocator.h:120:4: error: no matching function for call to 'std::pair<const std::__cxx11::basic_string<char>, mlir::tblgen::SymbolInfoMap::SymbolInfo>::pair(llvm::StringRef&, mlir::tblgen::SymbolInfoMap::SymbolInfo)'
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
In file included from /usr/include/c++/5/utility:70:0,
                 from llvm/include/llvm/Support/type_traits.h:18,
                 from llvm/include/llvm/Support/Casting.h:18,
                 from mlir/include/mlir/Support/LLVM.h:24,
                 from mlir/include/mlir/TableGen/Pattern.h:17,
                 from mlir/lib/TableGen/Pattern.cpp:14:
/usr/include/c++/5/bits/stl_pair.h:206:9: note: candidate: template<class ... _Args1, long unsigned int ..._Indexes1, class ... _Args2, long unsigned int ..._Indexes2> std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>)
         pair(tuple<_Args1...>&, tuple<_Args2...>&,
         ^
2020-10-14 00:37:10 +00:00
rdzhabarov
7271c1bcb9 [DDR] Introduce implicit equality check for the source pattern operands with the same name.
This CL allows user to specify the same name for the operands in the source pattern which implicitly enforces equality on operands with the same name.
E.g., Pat<(OpA $a, $b, $a) ... > would create a matching rule for checking equality for the first and the last operands. Equality of the operands is enforced at any depth, e.g., OpA ($a, $b, OpB($a, $c, OpC ($a))).

Example usage: Pat<(Reshape $arg0, (Shape $arg0)), (replaceWithValue $arg0)>

Note, this feature only covers operands but not attributes.
Current use cases are based on the operand equality and explicitly add the constraint into the pattern. Attribute equality will be worked out on the different CL.

Differential Revision: https://reviews.llvm.org/D89254
2020-10-13 16:05:14 -07:00
Nicolas Vasilache
60cf8453d0 Revert "Revert "Give attributes C++ namespaces.""
This reverts commit df295fac6cd14977672b2874700572e0f77b77da.

Reactivates a spuriously rolled back change.
2020-10-12 08:23:54 +00:00
Nicolas Vasilache
df295fac6c Revert "Give attributes C++ namespaces."
This reverts commit 0a34492f36d77f043d371cc91f359b2d65e86475.

This change turned out to be very intrusive wrt some internal projects.
Reverting until this can be sorted out.
2020-10-09 19:41:41 +00:00
Federico Lebrón
0a34492f36 Give attributes C++ namespaces.
Reviewed By: mehdi_amini, jpienaar

Differential Revision: https://reviews.llvm.org/D89014
2020-10-09 05:36:27 +00:00
Rahul Joshi
12d16de538 [MLIR][NFC] Remove tblgen:: prefix in TableGen/*.cpp files
- Add "using namespace mlir::tblgen" in several of the TableGen/*.cpp files and
  eliminate the tblgen::prefix to reduce code clutter.

Differential Revision: https://reviews.llvm.org/D85800
2020-08-12 14:41:18 -07:00
Rahul Joshi
d891d738d9 [MLIR][NFC] Adopt variadic isa<>
Differential Revision: https://reviews.llvm.org/D82489
2020-06-24 17:02:44 -07:00
Lei Zhang
60f1d26366 Revert "[mlir][drr] NFC: avoid SmallVector when collecting substitution values"
This reverts commit 2f8b164ca220f8cd29d70c8359ed91e8fb8d9959, which
causes a breakage on Clang 5.
2020-04-24 15:33:03 -04:00
Lei Zhang
2f8b164ca2 [mlir][drr] NFC: avoid SmallVector when collecting substitution values
Now both Operation::operand_range and Operation::result_range have
.begin() and .end() for ranged-based for loop and we have
ValueRange for wrapping a single Value. We can remove the SmallVector
materialization!

Differential Revision: https://reviews.llvm.org/D78766
2020-04-24 09:36:47 -04:00
River Riddle
aba1acc89c [mlir][ODS] Add support for optional operands and results with a new Optional directive.
Summary: This revision adds support for specifying operands or results as "optional". This is a special case of variadic where the number of elements is either 0 or 1. Operands and results of this kind will have accessors generated using Value instead of the range types, making it more natural to interface with.

Differential Revision: https://reviews.llvm.org/D77863
2020-04-10 14:12:06 -07:00
Jacques Pienaar
d6b32e39ae [mlir][drr] Allow specifying string in location
Summary:
The string in the location is used to provide metadata for the fused location
or create a NamedLoc. This allows tagging individual locations to convey
additional rewrite information.

Differential Revision: https://reviews.llvm.org/D77840
2020-04-10 12:43:22 -07:00
Jacques Pienaar
3f7439b280 [mlir][DRR] Add location directive
Summary:
Add directive to indicate the location to give to op being created. This
directive is optional and if unused the location will still be the fused
location of all source operations.

Currently this directive only works with other op locations, reusing an
existing op location or a fusion of op locations. But doesn't yet support
supplying metadata for the FusedLoc.

Based off initial revision by antiagainst@ and effectively mirrors GlobalIsel
debug_locations directive.

Differential Revision: https://reviews.llvm.org/D77649
2020-04-07 13:38:25 -07:00
Mehdi Amini
b12a7c88f7 Fix MLIR build by adding missing header after cleanup in af450eab 2020-03-01 01:11:44 +00:00
Benjamin Kramer
adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Mehdi Amini
308571074c Mass update the MLIR license header to mention "Part of the LLVM project"
This is an artifact from merging MLIR into LLVM, the file headers are
now aligned with the rest of the project.
2020-01-26 03:58:30 +00:00