Commit Graph

8946 Commits

Author SHA1 Message Date
Benjamin Kramer 48a1a993fb [mlir] Fall back to posix_memalign for aligned_alloc on MacOS
aligned_alloc was added in MacOS 10.15, some users want to support older
versions. The runtime functions makes this easy, so just put in a call
to posix_memalign, which provides the same functionality.
2022-07-26 11:29:37 +02:00
Kazu Hirata ae002f8bca Use isa instead of dyn_cast (NFC) 2022-07-25 23:00:58 -07:00
Kazu Hirata 2789c4f51c [mlir] Use value_or (NFC) 2022-07-25 23:00:56 -07:00
jacquesguan 78015047b2 [mlir][Math] Add constant folder for Exp2Op.
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-26 08:48:48 +08:00
Jacques Pienaar 13bc82b587 [mlir] SCCP add missing pessimistic setting
When this was updated in D127139 the update in-place case was no longer
marked as pessimistic. Add back in.

Differential Revision: https://reviews.llvm.org/D130453
2022-07-25 17:41:17 -07:00
River Riddle c35a4f5804 [mlir][Parser] Fix memory leak when failing to parse a forward declared block
This commit fixes a failure edge case where we accidentally drop forward
declared blocks in the error case. This allows for running the
invalid.mlir test in asan mode now.

Fixes #51387

Differential Revision: https://reviews.llvm.org/D130132
2022-07-25 17:29:49 -07:00
River Riddle c60b897d22 [mlir] Refactor the Parser library in preparation for an MLIR binary format
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-25 16:33:01 -07:00
lipracer de7ff8d66f [mlir][NFC] Remove TypeRange's constructors that cause ambiguity
ArrayRef<Value> can implicit convert to ValueRange,when we call TypeRange(SmallVector<Value>) is ambiguity.
TypeRange(ValueRange values)
TypeRange(ArrayRef<Value> values)

Reviewed By: rriddle, Mogball

Differential Revision: https://reviews.llvm.org/D129475
2022-07-25 15:38:05 -06:00
lipracer 10a4f03335 Split class ValueRange to a new file
When we apply parent patch : https://reviews.llvm.org/D129475
The prompt I get with the clang compiler is: ValueRange is imcomplete type,ValueRange is a forward declaration in the file TypeRange.h, and the file OperationSupport.h already includes the file TypeRange.h.The class TypeRange and the class ValueRange depend on each other.

Reviewed By: rriddle, Mogball

Differential Revision: https://reviews.llvm.org/D130332
2022-07-25 15:33:21 -06:00
Kiran Chandramohan 7bb1151ba2 [Flang][OpenMP] Initial support for integer reduction in worksharing-loop
Lower the Flang parse-tree containing OpenMP reductions to the OpenMP
dialect. The OpenMP dialect models reductions with,
1) A reduction declaration operation that specifies how to initialize, combine,
and atomically combine private reduction variables.
2) The OpenMP operation (like wsloop) that supports reductions has an array of
reduction accumulator variables (operands) and an array attribute of the same
size that points to the reduction declaration to be used for the reduction
accumulation.
3) The OpenMP reduction operation that takes a value and an accumulator.
This operation replaces the original reduction operation in the source.

(1) is implemented by the `createReductionDecl` in OpenMP.cpp,
(2) is implemented while creating the OpenMP operation,
(3) is implemented by the `genOpenMPReduction` function in OpenMP.cpp, and
called from Bridge.cpp. The implementation of (3) is not very robust.

NOTE 1: The patch currently supports only reductions for integer type addition.
NOTE 2: Only supports reduction in the worksharing loop.
NOTE 3: Does not generate atomic combination region.
NOTE 4: Other options for creating the reduction operation include
a) having the reduction operation as a construct containing an assignment
and then handling it appropriately in the Bridge.
b) we can modify `genAssignment` or `genFIR(AssignmentStmt)` in the Bridge to
handle OpenMP reduction but so far we have tried not to mix OpenMP
and non-OpenMP code and this will break that.
I will try (b) in a separate patch.
NOTE 5: OpenMP dialect gained support for reduction with the patches:
D105358, D107343. See https://discourse.llvm.org/t/rfc-openmp-reduction-support/3367
for more details.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D130077

Co-authored-by: Peixin-Qiao <qiaopeixin@huawei.com>
2022-07-25 18:47:07 +00:00
Christopher Bate 894641e974 Revert "[mlir][Arithmetic] Add `arith.delinearize_index` operation"
This reverts commit 535b507ba5.
2022-07-25 11:52:05 -06:00
Benoit Jacob f4ac950957 Generalize the vector transfer flattening patterns (dyn shapes).
Differential Revision: https://reviews.llvm.org/D130284
2022-07-25 15:59:08 +00:00
Alex Zinenko 9c1d133c3a [mlir] move _mlir_alloc and friends to CRunnerUtils
These functions don't depend on the C++ runtime and therefore belong to
CRunnerUtils. Clean up the macros on the way as `_MSC_VER` indicates the
compiler, not the platform, which is indicated by `_WIN32` and will be
present when, e.g., compiling with minGW.

Reviewed By: rdzhabarov

Differential Revision: https://reviews.llvm.org/D130025
2022-07-25 15:52:53 +02:00
Michele Scuttari a8601f11fb [MLIR] Generic 'malloc', 'aligned_alloc' and 'free' functions
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 15:52:51 +02:00
Matthias Springer 1defec8730 [mlir][tensor][bufferize][NFC] Remove duplicate code
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 12:34:16 +02:00
Matthias Springer 664ffa46bb [mlir][tensor][bufferize] Fix deallocation of GenerateOp/FromElementsOp
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 12:25:06 +02:00
Alex Zinenko 333ee218ce [mlir] Transform dialect: separate dependent and generated dialects
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 09:59:53 +00:00
Matthias Springer 5f5f71e737 [mlir][tensor][bufferize] Load dependent dialects
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 11:36:10 +02:00
Adrian Kuegel 07628a94e8 [mlir] Apply ClangTidyPerformance findings (NFC) 2022-07-25 10:50:04 +02:00
jacquesguan 9e241c70f7 [mlir][Math] Add constant folder for ExpOp.
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 16:26:48 +08:00
Marius Hillenbrand 1ef32e7828 [mlir][Arithmetic] Fix printing larger integer attributes in arith.const
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-25 08:37:51 +05:30
Kazu Hirata 9e88cbcc40 Use any_of (NFC) 2022-07-24 14:48:11 -07:00
Kazu Hirata 87d627b623 Remove redundant string initialization (NFC)
Identified with readability-redundant-string-init.
2022-07-24 12:27:11 -07:00
Kazu Hirata c730f9a164 Convert for_each to range-based for loops (NFC) 2022-07-23 12:17:27 -07:00
Dmitri Gribenko aba43035bd Use llvm::sort instead of std::sort where possible
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-23 15:19:05 +02:00
Kazu Hirata 380a1b204c Use callables directly in any_of, count_if, etc (NFC) 2022-07-23 00:28:31 -07:00
Kazu Hirata 33c18fbc19 [mlir] Use value instead of getValue (NFC) 2022-07-22 23:33:46 -07:00
Kazu Hirata 6fa6901bf0 Use has_value instead of hasValue (NFC) 2022-07-22 23:04:38 -07:00
rkayaith 65aedd338c [mlir][python] Fix issue in diagnostic note initialization
Previously the elements of the notes tuple would be invalid objects when
accessed from a diagnostic handler, resulting in a segfault when used.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D129943
2022-07-22 16:56:14 -04:00
Christopher Bate 535b507ba5 [mlir][Arithmetic] Add `arith.delinearize_index` operation
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 11:20:41 -06:00
Thomas Raoux 9f6ba4be26 [mlir][vector] Extend transfer_write to read propagation
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 17:11:06 +00:00
Jacques Pienaar 13448db06a [mlir][tosa] Flip accessors used to prefixed form (NFC)
Follow up from dialect flip, just flipping accessors. Both forms still
generated.
2022-07-22 09:56:08 -07:00
Jeff Niu edfc4bb9b9 [mlir][ods] Remove warning in `AttrOrTypeDef`
This warning was added because using attribute or type assembly formats
with `skipDefaultBuilders` set could cause compilation errors, since the
required builder prototype may not necessarily be generated and would
need to be checked by hand. This patch removes the warning because a
warning that the generated C++ "might" not compile is not particularly
useful. Attempting to address the TODO (i.e. detect whether a builder of
the correct prototype is provided) would be fragile since it would not
be possible to account for implicit conversions, etc.

In general, ODS should not be emitting warnings in cases like these.

Reviewed By: rriddle, wrengr

Differential Revision: https://reviews.llvm.org/D130102
2022-07-22 08:29:23 -07:00
Jacques Pienaar 1b7feac2a6 [mlir][tosa] Split canonicalization and folders out of TosaOps.
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 07:20:25 -07:00
Kiran Chandramohan 4ee9f3d59e [MLIR,OpenMP] : Add Conversion pattern for Critical Op
The Conversion pattern enables conversion of Critical Op with block
arguments.

Fixes https://github.com/llvm/llvm-project/issues/56629

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D130343
2022-07-22 12:57:48 +00:00
Matthias Springer 32c6e0815a [mlir][linalg] Add attribute matcher to structured.match transform op
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 13:55:12 +02:00
Matthias Springer bc882ed21f [mlir][linalg][transform] Add fuse_into_containing op
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 13:55:04 +02:00
Ivan Butygin 917e4519bc [mlir][arith] cmpi: move constant to the right side
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 12:39:17 +02:00
Ivan Butygin f46744bd2a [mlir][linalg] Fix FoldTensorCastConsumerOp invalid folding
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-22 11:39:12 +02:00
Kazu Hirata 70257fab68 Use any_of (NFC) 2022-07-22 01:05:17 -07:00
Uday Bondhugula fd156f5d4a [MLIR] Add affine.if canonicalization to compose in affine.apply ops
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-22 09:56:24 +05:30
Jacques Pienaar a1ec0d8bdc [mlir] Flip dialects to _Prefixed
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 12:03:07 -07:00
Jakub Kuderski 52b630da02 [mlir][spirv] Rename spv.GLSL ops to spv.GL. NFC.
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 13:03:30 -04:00
Christopher Bate 297ba167de [mlir][linalg] Add tile_size option to `structured.tile_to_foreach_thread_op`
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 10:32:01 -06:00
Alex Zinenko ee168fb90e [mlir][python] Fix issues with block argument slices
The type extraction helper function for block argument and op result
list objects was ignoring the slice entirely. So was the slice addition.
Both are caused by a misleading naming convention to implement slices
via CRTP. Make the convention more explicit and hide the helper
functions so users have harder time calling them directly.

Closes #56540.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D130271
2022-07-21 14:41:12 +00:00
Nicolas Vasilache 1f77f01c65 [mlir][Linalg] Add a Transform dialect NavigationOp op to match a list of 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 07:11:42 -07:00
Ivan Butygin d4217e6cc8 [mlir][memref] Missing type conversion in memref.reshape llvm lowering
Shape can be memref of index type, so memref::LoadOp result need to be converted into llvm type.

Differential Revision: https://reviews.llvm.org/D129965
2022-07-21 11:15:35 +02:00
lorenzo chelini 2ed7c3fd84 [MLIR][SCF] Enable better bufferization for `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 10:14:26 +02:00
lorenzo chelini 7f1c03171d Revert "[RFC][MLIR][SCF] Enable better bufferization for `TileConsumerAndFuseProducersUsingSCFForOp`"
This reverts commit 9e65850305.
2022-07-21 09:40:30 +02:00
lorenzo chelini 9e65850305 [RFC][MLIR][SCF] Enable better bufferization for `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 08:56:50 +02:00