aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect
AgeCommit message (Collapse)Author
2022-07-27[mlir][LLVM] Fix incorrect GEP fold with struct constantsMarkus Böck
The fold in it's current state only checks whether the amount of dynamic indices is 1. This does however not check for the presence of any struct indices, leading to an incorrect fold. This patch fixes that issue by checking that struct indices are 1, which in addition to the pre-existing check that dynamic indices are 1, guarantees that the single index is a dynamic one. Differential Revision: https://reviews.llvm.org/D129374
2022-07-27[mlir] more aggressive folding in tiling/fusion transformationsAlex Zinenko
Combine the recently added utilities for folded-by-construction affine operations with the attribute-based Range to enable more folding. This decreases the amount of emitted code but has little effect on test precisely because the tests are not checking for the spurious constants. The difference in the shape of affine maps comes from the internals of affine folding. Depends on D129633 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D130167
2022-07-27[mlir] Make ViewLikeInterface Range work with attributesAlex Zinenko
While most of methods in ViewLikeInterface accept an `OpFoldResult` for the offset/size/stride that may be static, represented as `Attribute`, or dynamic, represented as `Value`, the `Range` abstraction only accepted `Values`. This can often lead to known-constant offset/size/strides being materialized into constant operations and hinder further constant propagation without explicitly running the constant folding pass. This often leads to a more complicated than necessary addressing code being emitted. Switch `Range` to use `OpFoldResult`. Code that uses `Range` currently keeps materializing the constants to minimize the effect of this change on the IR. Further commits will make use of this. Reviewed By: nicolasvasilache, mravishankar Differential Revision: https://reviews.llvm.org/D129633
2022-07-27[mlir] Partially port splitting transform to TilingInterfaceAlex Zinenko
The structured op splitting transformation is conceptually similar to tiling in the sense that it decomposes the iteration space of the original op into several parts. Therefore, it is possible to implement it using the TilingInterface to operate on iteration spaces and their parts. However, the implementation also requires to pass updated input operands, which is not supported by the interface, so the implementation currently remains Linalg-specific. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D129564
2022-07-27[mlir] Apply ClangTidyPerformance findings (NFC)Adrian Kuegel
2022-07-26[mlir] Refactor SubElementInterface replace supportRiver Riddle
The current support was essentially the amount necessary to support replacing SymbolRefAttrs, but suffers from various deficiencies (both ergonomic and functional): * Replace crashes if unsupported This makes it really hard to use safely, given that you don't know if you are going to crash or not when using it. * Types aren't supported This seems like a simple missed addition when the attribute replacement support was originally added. * The ergonomics are weird It currently uses an index based replacement, which makes the implementations quite clunky. This commit refactors support to be a bit more ergonomic, and also adds support for types in the process. This was also a great oppurtunity to greatly simplify how replacement is done in the symbol table. Fixes #56355 Differential Revision: https://reviews.llvm.org/D130589
2022-07-26[mlir][transform] Add ForeachOp to transform dialectMatthias Springer
This op "unbatches" an op handle and executes the loop body for each payload op. Differential Revision: https://reviews.llvm.org/D130257
2022-07-26[mlir][Math] Add constant folder for Exp2Op.jacquesguan
This patch adds constant folder for Exp2Op which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130472
2022-07-25[mlir] Refactor the Parser library in preparation for an MLIR binary formatRiver Riddle
The current Parser library is solely focused on providing API for the textual MLIR format, but MLIR will soon also provide a binary format. This commit renames the current Parser library to AsmParser to better correspond to what the library is actually intended for. A new Parser library is added which will act as a unified parser interface between both text and binary formats. Most parser clients are unaffected, given that the unified interface is essentially the same as the current interface. Only clients that rely on utilizing the AsmParserState, or those that want to parse Attributes/Types need to be updated to point to the AsmParser library. Differential Revision: https://reviews.llvm.org/D129605
2022-07-25Revert "[mlir][Arithmetic] Add `arith.delinearize_index` operation"Christopher Bate
This reverts commit 535b507ba58e8b5f604d53ffc961be1456d229a7.
2022-07-25Generalize the vector transfer flattening patterns (dyn shapes).Benoit Jacob
Differential Revision: https://reviews.llvm.org/D130284
2022-07-25[MLIR] Generic 'malloc', 'aligned_alloc' and 'free' functionsMichele Scuttari
When converted to the LLVM dialect, the memref.alloc and memref.free operations were generating calls to hardcoded 'malloc' and 'free' functions. This didn't leave any freedom to users to provide their custom implementation. Those operations now convert into calls to '_mlir_alloc' and '_mlir_free' functions, which have also been implemented into the runtime support library as wrappers to 'malloc' and 'free'. The same has been done for the 'aligned_alloc' function. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D128791
2022-07-25[mlir][tensor][bufferize][NFC] Remove duplicate codeMatthias Springer
InsertSliceOp and ParallelInsertSliceOp are very similar and can share some of the bufferization analysis code. Differential Revision: https://reviews.llvm.org/D130465
2022-07-25[mlir][tensor][bufferize] Fix deallocation of GenerateOp/FromElementsOpMatthias Springer
Both ops allocate a buffer. There were cases in which the buffer was not deallocated. Differential Revision: https://reviews.llvm.org/D130469
2022-07-25[mlir] Transform dialect: separate dependent and generated dialectsAlex Zinenko
In the Transform dialect extensions, provide the separate mechanism to declare dependent dialects (the dialects the transform IR depends on) and the generated dialects (the dialects the payload IR may be transformed into). This allows the Transform dialect clients that are only constructing the transform IR to avoid loading the dialects relevant for the payload IR along with the Transform dialect itself, thus decreasing the build/link time. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D130289
2022-07-25[mlir][tensor][bufferize] Load dependent dialectsMatthias Springer
Load dialects that will be generated by the extension. (Except for BufferizationDialect and MemrefDialect which are loaded already.) Differential Revision: https://reviews.llvm.org/D130463
2022-07-25[mlir] Apply ClangTidyPerformance findings (NFC)Adrian Kuegel
2022-07-25[mlir][Math] Add constant folder for ExpOp.jacquesguan
This patch adds constant folder for ExpOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130318
2022-07-25[mlir][Arithmetic] Fix printing larger integer attributes in arith.constMarius Hillenbrand
For arith.constant operations of integer type, the operation generates result names that include the value of the constant (i.e., the IntegerAttr that defines the constant's value). That code currently assumes integer widths of 64 bits or less and hits an assert with wider constants or would create truncated and potentially ambiguous names when built with assertions disabled. To enable printing arith.constant ops for arbitrarily wide integer types, change to use the IntegerAttr's function getValue() when generating result names. Also, add a regression test. Reviewed By: bondhugula Differential Revision: https://reviews.llvm.org/D129930
2022-07-24Use any_of (NFC)Kazu Hirata
2022-07-23Convert for_each to range-based for loops (NFC)Kazu Hirata
2022-07-23Use llvm::sort instead of std::sort where possibleDmitri Gribenko
llvm::sort is beneficial even when we use the iterator-based overload, since it can optionally shuffle the elements (to detect non-determinism). However llvm::sort is not usable everywhere, for example, in compiler-rt. Reviewed By: nhaehnle Differential Revision: https://reviews.llvm.org/D130406
2022-07-23Use callables directly in any_of, count_if, etc (NFC)Kazu Hirata
2022-07-22[mlir] Use value instead of getValue (NFC)Kazu Hirata
2022-07-22Use has_value instead of hasValue (NFC)Kazu Hirata
2022-07-22[mlir][Arithmetic] Add `arith.delinearize_index` operationChristopher Bate
This change adds a new DelinearizeIndexOp to the `arith` dialect. The operation accepts an `index` type as well as a basis (array of index values) representing how the index should be decomposed into a multi-index. The decomposition obeys a canonical semantic that treats the final basis element as "fastest varying" and the first basis element as "slowest varying". A naive lowering of the operation using a sequence of `arith.divui` and `arith.remui` operations is also given. Differential Revision: https://reviews.llvm.org/D129697
2022-07-22[mlir][vector] Extend transfer_write to read propagationThomas Raoux
Folding of transfer_write into transfer_read is already supported but this requires the read and write to have the same permuation map. After linalg vectorization it is common to have different ppermuation map for write followed by read even though the cases could be propagated. This canonicalization handle cases where the permuation maps are different but the data read and written match and replace the transfer ops with broadcast and permuation Differential Revision: https://reviews.llvm.org/D130135
2022-07-22[mlir][tosa] Flip accessors used to prefixed form (NFC)Jacques Pienaar
Follow up from dialect flip, just flipping accessors. Both forms still generated.
2022-07-22[mlir][tosa] Split canonicalization and folders out of TosaOps.Jacques Pienaar
Scope ops file to ops. Used canonicalization as grouping for canonicalization patterns and folders (also considered OpTransforms but that felt too generic and the former two are used together). Reviewed By: silvas, rsuderman Differential Revision: https://reviews.llvm.org/D130297
2022-07-22[mlir][linalg] Add attribute matcher to structured.match transform opMatthias Springer
This is useful for building small test cases and will be utilized in a subsequent commit that adds a fusion example. Differential Revision: https://reviews.llvm.org/D130344
2022-07-22[mlir][linalg][transform] Add fuse_into_containing opMatthias Springer
This op fuses a given payload op into a given container op. Inside the container, all uses of the producer are replaced (fused) with the newly inserted op. If the producer is tileable and accessed via a tensor.extract_slice, the new op computes only the requested slice ("tile and fuse"). Otherwise, the entire tensor value is computed inside the container ("clone and fuse"). Differential Revision: https://reviews.llvm.org/D130244
2022-07-22[mlir][arith] cmpi: move constant to the right sideIvan Butygin
Convert arith.cmpi to the canonical form with constants on the right side to simplify further optimizations and open more opportunities for CSE. Differential Revision: https://reviews.llvm.org/D129929
2022-07-22[mlir][linalg] Fix FoldTensorCastConsumerOp invalid foldingIvan Butygin
CastOp can be in conditionally reachable region, in which case this folding will be invalid. Only conservatively fold ops in same block for now. Fixes https://github.com/llvm/llvm-project/issues/56557 Differential Revision: https://reviews.llvm.org/D130314
2022-07-22Use any_of (NFC)Kazu Hirata
2022-07-22[MLIR] Add affine.if canonicalization to compose in affine.apply opsUday Bondhugula
Add affine.if canonicalization to compose affine.apply ops into its set and operands. This eliminates affine.apply ops feeding into affine.if ops. Differential Revision: https://reviews.llvm.org/D130242
2022-07-21[mlir] Flip dialects to _PrefixedJacques Pienaar
At least two weeks passed since flipped to _Both. Made some additional NFC changes in .td files that were not converted earlier.
2022-07-21[mlir][spirv] Rename spv.GLSL ops to spv.GL. NFC.Jakub Kuderski
This is to improve consistency within the SPIR-V dialect and make these ops a bit shorter. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D130280
2022-07-21[mlir][linalg] Add tile_size option to `structured.tile_to_foreach_thread_op`Christopher Bate
This change modifies `structured.tile_to_foreach_thread_op` so that it accepts either `tile_sizes` or `num_threads` parameters. If `tile_sizes` are specified, then the number of threads required is derived the tile sizes rather than the other way around. In both cases, more aggressive folding of loop parameters is enabled during the transformation, allowing for the potential elimination of `affine.min` and `affine.max` operations in the static shape case when calculating the final adjusted tile size. Differential Revision: https://reviews.llvm.org/D130139
2022-07-21[mlir][Linalg] Add a Transform dialect NavigationOp op to match a list of ↵Nicolas Vasilache
ops or an interface. This operation is a NavigationOp that simplifies the writing of transform IR. Since there is no way of refering to an interface by name, the current implementation uses an EnumAttr and depends on the interfaces it supports. In the future, it would be worthwhile to remove this dependence and generalize. Differential Revision: https://reviews.llvm.org/D130267
2022-07-21[MLIR][SCF] Enable better bufferization for ↵lorenzo chelini
`TileConsumerAndFuseProducersUsingSCFForOp` Replace iterators of the outermost loop with region arguments of the innermost one. The changes avoid later `bufferization` passes to insert allocation within the body of the innermost loop. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D130083
2022-07-21Revert "[RFC][MLIR][SCF] Enable better bufferization for ↵lorenzo chelini
`TileConsumerAndFuseProducersUsingSCFForOp`" This reverts commit 9e6585030533e901a8c24dcb05b38d3f0d10331f.
2022-07-21[RFC][MLIR][SCF] Enable better bufferization for ↵lorenzo chelini
`TileConsumerAndFuseProducersUsingSCFForOp` Replace iterators of the outermost loop with region arguments of the innermost one. The changes avoid later `bufferization` passes to insert allocation within the body of the innermost loop. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D130083
2022-07-21[mlir][Linalg] Deprecate `tileAndFuseLinalgOps` method and associated patterns.Mahesh Ravishankar
The `tileAndFuseLinalgOps` is a legacy approach for tiling + fusion of Linalg operations. Since it was also intended to work on operations with buffer operands, this method had fairly complex logic to make sure tile and fuse was correct even with side-effecting linalg ops. While complex, it still wasnt robust enough. This patch deprecates this method and thereby deprecating the tiling + fusion method for ops with buffer semantics. Note that the core transformation to do fusion of a producer with a tiled consumer still exists. The deprecation here only removes methods that auto-magically tried to tile and fuse correctly in presence of side-effects. The `tileAndFuseLinalgOps` also works with operations with tensor semantics. There are at least two other ways the same functionality exists. 1) The `tileConsumerAndFuseProducers` method. This does a similar transformation, but using a slightly different logic to automatically figure out the legal tile + fuse code. Note that this is also to be deprecated soon. 2) The prefered way uses the `TilingInterface` for tile + fuse, and relies on the caller to set the tiling options correctly to ensure that the generated code is correct. As proof that (2) is equivalent to the functionality provided by `tileAndFuseLinalgOps`, relevant tests have been moved to use the interface, where the test driver sets the tile sizes appropriately to generate the expected code. Differential Revision: https://reviews.llvm.org/D129901
2022-07-21[mlir][Math] Add constant folder for LogOp.jacquesguan
This patch adds constant folder for LogOp which only supports single and double precision floating-point. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D130148
2022-07-20[mlir][Math] Add constant folder for Log1pOp.jacquesguan
This patch adds constant folder for Log1pOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D129979
2022-07-20[mlir][TilingInterface] Add support for interchange to tiling patterns that ↵Mahesh Ravishankar
use the `TilingInterface`. Differential Revision: https://reviews.llvm.org/D129956
2022-07-19[mlir] Flip LinAlg dialect to _BothJacques Pienaar
This one required more changes than ideal due to overlapping generated name with different return types. Changed getIndexingMaps to getIndexingMapsArray to move it out of the way/highlight that it returns (more expensively) a SmallVector and uses the prefixed name for the Attribute. Differential Revision: https://reviews.llvm.org/D129919
2022-07-19Don't combine if there would remain no true reduction dim.Benoit Jacob
Differential Revision: https://reviews.llvm.org/D130109
2022-07-19[mlir][Linalg] Add a TileToForeachThread transform.Nicolas Vasilache
This revision adds a new transformation to tile a TilingInterface `op` to a tiled `scf.foreach_thread`, applying tiling by `num_threads`. If non-empty, the `threadDimMapping` is added as an attribute to the resulting `scf.foreach_thread`. 0-tile sizes (i.e. tile by the full size of the data) are used to encode that a dimension is not tiled. Differential Revision: https://reviews.llvm.org/D129577
2022-07-19[mlir][bufferization][NFC] Move sparse_tensor.release to bufferization dialectMatthias Springer
This op used to belong to the sparse dialect, but there are use cases for dense bufferization as well. (E.g., when a tensor alloc is returned from a function and should be deallocated at the call site.) This change moves the op to the bufferization dialect, which now has an `alloc_tensor` and a `dealloc_tensor` op. Differential Revision: https://reviews.llvm.org/D129985