16520 Commits

Author SHA1 Message Date
Christian Sigg
092b6c5ee3 [mlir][nfc] Allow ops to have operands/attributes named context.
This is probably a bad idea, but it's only become a problem with properties and is easy to fix.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D159185
2023-09-05 09:24:20 +02:00
Markus Böck
b66219d735 [mlir] Fix infinite recursion in alias initializer
The alias initializer keeps a list of child indices around. When an alias is then marked as non-deferrable, all children are also marked non-deferrable.

This is currently done naively which leads to an infinite recursion if using mutable types or attributes containing a cycle.

This patch fixes this by adding an early return if the alias is already marked non-deferrable. Since this function is the only way to mark an alias as non-deferrable, it is guaranteed that if it is marked non-deferrable, all its children are as well, and it is not required to walk all the children.
This incidentally makes the non-deferrable marking also `O(n)` instead of `O(n^2)` (although not performance sensitive obviously).

Differential Revision: https://reviews.llvm.org/D158932
2023-08-31 08:54:24 +02:00
Matthias Springer
cc7e24c7a7 [mlir] Fix crash when adding nested dialect extensions
A dialect extension can add additional dialect extensions in its `apply` function. This used to crash when the vector of `extensions` was internally reallocated while it is being iterated over.

Differential Revision: https://reviews.llvm.org/D158838
2023-08-31 08:54:24 +02:00
Balaji V. Iyer
94f348b784 [mlir][math] Modify math.powf to handle negative bases.
Powf expansion currently returns NaN when the base is negative.
This is because taking natural log of a negative number gives
NaN. This patch will square the base and half the exponent, thereby
getting around the negative base problem.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D158797
2023-08-31 08:54:24 +02:00
Matthias Springer
ad5ed49a14 [mlir][memref] Fix crash in SubViewReturnTypeCanonicalizer
`SubViewReturnTypeCanonicalizer` is used by `OpWithOffsetSizesAndStridesConstantArgumentFolder`, which folds constant SSA value (dynamic) sizes into static sizes. The previous implementation crashed when a dynamic size was folded into a static `1` dimension, which was then mistaken as a rank reduction.

Differential Revision: https://reviews.llvm.org/D158721
2023-08-31 08:54:24 +02:00
Mehdi Amini
5e47fe1945 Fix ODS verifier emission for DerivedAttr when Properties are enabled
Differential Revision: https://reviews.llvm.org/D158679
2023-08-25 09:42:01 +02:00
Mehdi Amini
a95298a0ed Fix canonicalizer to copy the entire GreedyRewriteConfig instead of selected fields
It is surprising for the user that only some fields were honored.

Also make the FrozenRewritePatternSet a shared_ptr<const T>.

Fixes #64543

Differential Revision: https://reviews.llvm.org/D157469
2023-08-25 09:42:01 +02:00
Mehdi Amini
69946c8c9c Fix MSAN error: use of unitialized value when hashing the MLIR pass manager (NFC) 2023-08-25 09:42:01 +02:00
Mehdi Amini
c5f0c32da7 Fix MLIR pass manager initialization: hash the pass pipeline to detect when initialization is needed
The current logic hashes the context to detect registration changes and re-run
the pass initialization. However it wasn't checking for changes to the
pipeline, so a pass that would get added after a first run would not be
initialized during subsequent runs.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D158377
2023-08-25 09:42:01 +02:00
Mehdi Amini
0d8fd074b7 Fix some missing fully qualified namespaces in MLIR TableGen generator
Using properties would break when a dialect isn't in the mlir namespace
2023-08-25 09:42:01 +02:00
Mehdi Amini
67dca9da75 Fix MLIR build failure: error: no member named 'getValue' in 'mlir::OptionalParseResult'
Fix #63072
2023-08-25 09:42:01 +02:00
Mehdi Amini
5db0d770c7 Finish renaming getOperandSegmentSizeAttr() from operand_segment_sizes to operandSegmentSizes
This renaming started with the native ODS support for properties, this is completing it.

A mass automated textual rename seems safe for most codebases.
Drop also the ods prefix to keep the accessors the same as they were before
this change:
 properties.odsOperandSegmentSizes
reverts back to:
 properties.operandSegementSizes

The ODS prefix was creating divergence between all the places and make it harder to
be consistent.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D157173
2023-08-25 09:42:01 +02:00
Mehdi Amini
3ac2860217 [MLIR] Make the ConversionTarget const ref in the DialectConversion (NFC)
It isn't mutated during the conversion already, communicate this through the API.

Differential Revision: https://reviews.llvm.org/D157199
2023-08-10 09:06:20 +02:00
Mehdi Amini
600edc20b9 Clarify the invariant of the MLIR pass pipeline around Pass::initialize()
This method should not load new dialect or affect the context itself.

Differential Revision: https://reviews.llvm.org/D157198
2023-08-10 09:06:20 +02:00
Benjamin Maxwell
45ad84a742 [mlir][VectorOps] Fix folding of vector.extract from stretch vector.broadcast
Previously, foldExtractFromBroadcast() would incorrectly fold:

  func.func @extract_from_stretch_broadcast(%src: vector<3x1x2xf32>) -> f32 {
    %0 = vector.broadcast %src : vector<3x1x2xf32> to vector<3x4x2xf32>
    %1 = vector.extract %0[0, 2, 0] : vector<3x4x2xf32>
    return %1: f32
  }

to:

  func.func @extract_from_stretch_broadcast(%src: vector<3x1x2xf32>) -> f32 {
    %0 = vector.extract %src[0, 2, 0] : vector<3x1x2xf32>
    return %0: f32
  }

This was due to the wrong offset being used when zeroing the "dim-1"
broadcasted dims. It should use the difference in rank across the
broadcast as the starting offset, as the ranks after that are the ones
that could have been stretched.

Reviewed By: awarzynski, dcaballe

Differential Revision: https://reviews.llvm.org/D157003
2023-08-10 09:06:20 +02:00
Tobias Gysi
13a8302b2e [mlir] Store segment sizes in std::array
This revision uses std::array instead of normal c arrays to store the
operand and result segment sizes. This is a follow up to
https://reviews.llvm.org/D155919, which converted the operand and result
segment sizes to properties. Its use of c arrays triggered warnings in
downstream projects due to the direct comparison of c arrays. This
revision fixes the warnings using std::arrays that implement a
proper comparison operator, which compares the array elements rather
that the array pointers.

Note: it seems the comparison operator is effectively dead code for now.
It still seems useful to fix the warning and ensure the comparison works
as expected assume someone starts using it at some point in time.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D156888
2023-08-10 09:06:20 +02:00
Mehdi Amini
6dc155bc91 [MLIR][Bytecode] Add missing field initializer in constructor initializer list
Leaving this field unitialized could led to crashes when it'll diverge from the
IRNumbering phase.

Differential Revision: https://reviews.llvm.org/D156965
2023-08-10 09:06:20 +02:00
Valentin Clement
416411fde5 [mlir] Reduce warnings for bad assertion in generated code
When the operation has no attributes, the generated assertion is
always false and triggers lots of warnings in the build.

```
warning: comparison of unsigned expression < 0 is always false
```

Just return a StringAttr when there is no attribute.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D156819
2023-08-10 09:06:20 +02:00
Mogball
6e2cf38560 [mlir][llvm] Fix export of 64-bit integer function attributes
The `allocsize` attribute is weird because it packs two 32-bit values
into a 64-bit value. It also turns out that the passthrough attribute
exporter was using `int`, which is incorrectly handling 64-bit integers.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D156574
2023-08-10 09:06:20 +02:00
Nicolas Vasilache
2c5ed2da4f [mlir][gpu] NFC - Fail gracefully when type conversion fails instead of crashing 2023-08-10 09:06:20 +02:00
Thomas Raoux
3e62997c4c [mlir] Fix arith verifier for tensor with encoding
The verifier for some arith ops were not considering that ranked
tensor types can have encodings.

Differential Revision: https://reviews.llvm.org/D156557
2023-08-10 09:06:20 +02:00
Alexis Engelke
6664b6e980 [mlir][LLVMIR] Fix identified structs with same name
Different identified struct types may have the same name ("").
Previously, these were deduplicated based on their name, which caused
an assertion failure when nesting identified structs:

    %0 = type { %1 }
    %1 = type { i8 }
    declare void @fn(%0)

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D156531
2023-08-10 09:06:20 +02:00
River Riddle
fc209e4158 [mlir-lsp] Guard writing output to JSONTransport with mutex
This allows for users of the lsp transport libraries to process replies
in parallel, without overlapping/clobbering the output.

Differential Revision: https://reviews.llvm.org/D156295
2023-08-10 09:06:20 +02:00
River Riddle
685bcc1d73 [mlir:bytecode] Only visit the all regions path if the op has regions
Zero region operations return true for both isBeforeAllRegions and
isAfterAllRegions when using WalkStage. The bytecode walk only
expects region holding operations in the after regions path, so
guard against that.
2023-08-10 09:06:20 +02:00
River Riddle
99b39d7df6 [mlir:bytecode] Support lazy loading dynamically isolated regions
We currently only support lazy loading for regions that
statically implement the IsolatedFromAbove trait, but that
limits the amount of operations that can be lazily loaded. This review
lifts that restriction by computing which operations have isolated
regions when numbering, allowing any operation to be lazily loaded
as long as it doesn't use values defined above.

Differential Revision: https://reviews.llvm.org/D156199
2023-08-10 09:06:20 +02:00
River Riddle
45a4a1371b [mlir:bytecode] Fix bytecode lazy loading for ops with multiple regions
We currently encode each region as a separate section, but
the reader expects all of the regions to be in the same section.
This updates the writer to match the behavior that the reader
expects.

Differential Revision: https://reviews.llvm.org/D156198
2023-08-10 09:06:20 +02:00
Mehdi Amini
6b3e6a9db7 Add release notes for MLIR
Differential Revision: https://reviews.llvm.org/D156253
2023-08-10 09:06:20 +02:00
Oleg Shyshkov
a50e3a66b9 [mlir] Fix assembly format parser generator after 9ea6b30ac20f8223fb6aeae853e5c73691850a8d. 2023-08-10 09:06:20 +02:00
Jakub Kuderski
f71f8c923a [mlir][spirv] Do not introduce vector<1xT> in UnifyAliasedResource
1-element vectors are not valid in SPIR-V and fail `Bitcast` op verification.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D156207
2023-08-10 09:06:20 +02:00
Fangrui Song
cd2570ae9c [Support] Remove llvm::is_trivially_{copy/move}_constructible
This restores D132311, which was reverted in
29c841ce93e087fa4e0c5f3abae94edd460bc24a (Sep 2022) due to certain files
not buildable with GCC 7.3.0. The previous attempt was reverted by
6cd9608fb37ca2418fb44b57ec955bb5efe10689 (Dec 2020).

This time, GCC 7.3.0 has existing build errors for a long time due to
structured bindings for many files, e.g.

```
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:9098:13: error: cannot decompose class type ‘std::pair<llvm::Value*, const llvm::SCEV*>’: both it and it
s base class ‘std::pair<llvm::Value*, const llvm::SCEV*>’ have non-static data members
   for (auto [_, Stride] : Legal->getLAI()->getSymbolicStrides()) {
             ^~~~~~~~~~~
```

... and also some `error: duplicate initialization of` instances due to llvm/Transforms/IPO/Attributor.h.

---

GCC 7.5.0 has a bug that, without this change, certain `SmallVector` with a `std::pair` element type like `SmallVector<std::pair<Instruction * const, Info>, 0> X;` lead to spurious

```
/tmp/opt/gcc-7.5.0/include/c++/7.5.0/type_traits:878:48: error: constructor required before non-static data member for ‘...’ has been parsed
```

Switching to std::is_trivially_{copy/move}_constructible fixes the error.

(cherry picked from commit 6a684dbc4433a33e5f94fb15c9e378a2408021e0)
2023-07-27 15:29:23 +02:00
Simon Pilgrim
3d83912c0c Revert rGfae7b98c221b5b28797f7b56b656b6b819d99f27 "[Support] Change SetVector's default template parameter to SmallVector<*, 0>"
This is failing on Windows MSVC builds:
llvm\unittests\Support\ThreadPool.cpp(380): error C2440: 'return': cannot convert from 'Vector' to 'std::vector<llvm::BitVector,std::allocator<llvm::BitVector>>'
        with
        [
            Vector=llvm::SmallVector<llvm::BitVector,0>
        ]
2023-07-25 10:22:08 +01:00
Cullen Rhodes
ca9a3354d0 [mlir][ArmSME] Add tile load op and extend tile store tile size support
This extends the existing 'arm_sme.tile_store' op to support all tile
sizes and adds a new op 'arm_sme.tile_load', as well as lowerings from
vector -> custom ops and custom ops -> intrinsics. Currently there's no
lowering for i128.

Depends on D154867

Reviewed By: awarzynski, dcaballe

Differential Revision: https://reviews.llvm.org/D155306
2023-07-25 08:28:36 +00:00
Fangrui Song
fae7b98c22 [Support] Change SetVector's default template parameter to SmallVector<*, 0>
Similar to D156016 for MapVector.
2023-07-25 00:39:17 -07:00
Fangrui Song
fb2a971c01 [Support] Change MapVector's default template parameter to SmallVector<*, 0>
SmallVector<*, 0> is often a better replacement for std::vector :
both the object size and the code size are smaller.
(SmallMapVector uses SmallVector as well, but it is not common.)

clang size decreases by 0.0226%.
instructions:u decreases 0.037% when compiling a sqlite3 amalgram.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D156016
2023-07-24 22:04:03 -07:00
Fangrui Song
480d7a3aff [mlir-tblgen] Fix IWYU
Right now std::vector is instantiated with an incomplete element type,
which is ok but best to avoid.
2023-07-24 21:50:29 -07:00
Kevin Gleason
998003eaf7 [mlir] Fix for MSVC bool splat issue encountered.
When building MLIR using bazel on windows with MSVC2019, bool splats
were being created incorrectly:

```
dense<[true,true,true,true]> : tensor<4xi1>
-(parse with mlir-opt)-> dense<[true, false, false, false]> : tensor<4xi1>
```

Appears that a Windows bazel build produces a corrupt DenseIntOrFPElementsAttr.
Unable to repro using MSVC and cmake.

Issue first discovered here:
https://github.com/google/jax/issues/16394

Added test point for reproduction:

```
$ bazel test @llvm-project//mlir/unittests:ir_tests --test_arg=--gtest_filter=DenseSplatTest.BoolSplatSmall
```

Differential Revision: https://reviews.llvm.org/D155745
2023-07-24 20:45:43 -07:00
Mehdi Amini
794f74e257 Fix MLIR test pass crash
The pass tried to fold in reverse-post-order, but it cause an issue
when a parent is folded before the chilren as they will still be
present in the worklist.
Use reverse-preorder instead here.

Fixes #64089
2023-07-24 19:54:56 -07:00
Mehdi Amini
9ea6b30ac2 Update ODS variadic segments "magic" attributes to use native Properties
The operand_segment_sizes and result_segment_sizes Attributes are now inlined
in the operation as native propertie. We continue to support building an
Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the
property from an attribute with `setAttr("operand_segment_sizes", attr)`.

A new bytecode version is introduced to support backward compatibility and
backdeployments.

Differential Revision: https://reviews.llvm.org/D155919
2023-07-24 18:16:58 -07:00
Mehdi Amini
c8bcc48af6 Cleanup CMake dependencies from unnecessary libraries in mlir/test/lib/Dialect/GPU/CMakeLists.txt (NFC) 2023-07-24 17:58:25 -07:00
Mehdi Amini
07102909c2 Revert "[mlir][gpu][transforms] Only depend on ExecutionEngine if MLIR_ENABLE_CUDA_RUNNER is true"
This reverts commit 68b7d3fffd7e8ebc40fdcb0acdcf2e88a93ea5c3.
The mlir-nvidia bot is broken.
2023-07-24 17:21:37 -07:00
Nicolas Vasilache
68b7d3fffd [mlir][gpu][transforms] Only depend on ExecutionEngine if MLIR_ENABLE_CUDA_RUNNER is true
This fixes a compilation bug where we would try to depend on ExecutionEngine but it wasn't actually built.
2023-07-25 01:26:03 +02:00
Nicolas Vasilache
90ecfa2a40 [mlir][linalg] NFC - Move some utils in preparation for revamping mapping of scf.forall 2023-07-25 01:19:57 +02:00
Ivan Butygin
8568921d43 [mlir][spirv] Convert ub.poison to spirv.undef
SPIR-V doesn't have poison, but poison can be converted to undef.

Differential Revision: https://reviews.llvm.org/D156163
2023-07-25 00:23:09 +02:00
Mehdi Amini
a7cd64c9f1 Revert "Update ODS variadic segments "magic" attributes to use native Properties"
This reverts commit 20b93abca6516bbb23689c3777536fea04e46e14.

One python test is broken, WIP.
2023-07-24 12:27:42 -07:00
Mehdi Amini
20b93abca6 Update ODS variadic segments "magic" attributes to use native Properties
The operand_segment_sizes and result_segment_sizes Attributes are now inlined
in the operation as native propertie. We continue to support building an
Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the
property from an attribute with `setAttr("operand_segment_sizes", attr)`.

A new bytecode version is introduced to support backward compatibility and
backdeployments.

Differential Revision: https://reviews.llvm.org/D155919
2023-07-24 11:37:57 -07:00
Mehdi Amini
5e8a1164f2 Revert "[mlir][gpu] Fallback to JIT compilation" "[mlir][gpu] Increase default SM version from 35 to 50" and "[mlir][gpu] Improving Cubin Serialization with ptxas Compiler"
This reverts commit 2e0e00ed841951e358a85a871647be9b3a622f51
and reverts commit a6eb40692c795a9cc29266779ceca2e304141114
and reverts commit 585cbe3f639783bf0307b47504acbd205f135310.

15 tests are broken on the mlir-nvidia buildbot:

'cuModuleLoadData(&module, data)' failed with 'CUDA_ERROR_INVALID_SOURCE'
'cuModuleGetFunction(&function, module, name)' failed with 'CUDA_ERROR_INVALID_HANDLE'
'cuLaunchKernel(function, gridX, gridY, gridZ, blockX, blockY, blockZ, smem, stream, params, extra)' failed with 'CUDA_ERROR_INVALID_HANDLE'
'cuModuleUnload(module)' failed with 'CUDA_ERROR_INVALID_HANDLE'
2023-07-24 10:23:15 -07:00
Ivan Butygin
0f446adf67 [mlir] Convert ub.poison to llvm.poison
Differential Revision: https://reviews.llvm.org/D155945
2023-07-24 18:40:12 +02:00
Lorenzo Chelini
0736200de4 [MLIR][Linalg] Move AggregatedOpInterface in linalg namespace (NFC)
For now, the interface is specific to linalg only.

Reviewed By: qcolombet

Differential Revision: https://reviews.llvm.org/D156091
2023-07-24 16:22:39 +02:00
Quinn Dawkins
80aed2ea45 [mlir][Transform] Allow printing inside matchers
Enables printf style debugging of matchers through `transform.print`
within the body of a matcher.

Differential Revision: https://reviews.llvm.org/D156078
2023-07-24 10:00:23 -04:00
Guray Ozen
a6eb40692c [mlir][gpu] Increase default SM version from 35 to 50
Current SM version is 35 but it is deprecated long time ago. D155563 introduced ptxas compilations, using sm_35 causes failures in builtbot. This change increase default SM version to 50.

Differential Revision: https://reviews.llvm.org/D156098
2023-07-24 15:11:30 +02:00