Commit Graph

10801 Commits

Author SHA1 Message Date
Groverkss bab2a4f2fb [MLIR][Presburger] Use PresburgerSpace in SetCoalescer
This patch changes the implementation of SetCoalescer to use PresburgerSpace
instead of reimplementing parts of PresburgerSpace.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122984
2022-04-03 04:06:47 +05:30
Groverkss 1483fb33b3 [MLIR][Presburger][NFC] Rename getCompatibleSpace to getSpaceWithoutLocals
Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122973
2022-04-02 23:39:57 +05:30
Groverkss 86f255360c [MLIR][Presburger] Make constructors from PresburgerSpace explicit
This patch makes constructors of IntegerRelation, IntegerPolyhedron,
PresburgerRelation, PresburgerSet from PresburgerSpace explicit. This
prevents bugs like:

```
void fun(IntegerRelation a, IntegerRelation b) {
  IntegerPolyhedron c = a.intersect(b);
}
```

Here, `a.intersect(b)` will return `IntegerRelation`, which will be implicitly
converted to `PresburgerSpace` and will use the `PresburgerSpace` constructor
for IntegerPolyhedron. Leading to loss of any constraints in the intersection
of `a` and `b`. After this patch, this will give a compile error.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122972
2022-04-02 18:14:38 +05:30
Arjun P fbeb0db54f [MLIR][Presburger] LexSimplex: support is{Redundant,Separate}Inequality
Add integer-exact checks for inequalities being separate and redundant in LexSimplex.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122921
2022-04-02 12:31:17 +01:00
Arjun P 698484549a [MLIR][Presburger] Make the SimplexBase constructor protected
This is not supposed to be instantiated directly anyway.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122923
2022-04-02 12:30:23 +01:00
River Riddle 0d8df98035 [mlir] Allow for using OpPassManager in pass options
This significantly simplifies the boilerplate necessary for passes
to define nested pass pipelines.

Differential Revision: https://reviews.llvm.org/D122880
2022-04-02 00:45:11 -07:00
River Riddle 6edef13569 [mlir:PassOption] Rework ListOption parsing and add support for std::vector/SmallVector options
ListOption currently uses llvm:🆑:list under the hood, but the usages
of ListOption are generally a tad different from llvm:🆑:list. This
commit codifies this by making ListOption implicitly comma separated,
and removes the explicit flag set for all of the current list options.
The new parsing for comma separation of ListOption also adds in support
for skipping over delimited sub-ranges (i.e. {}, [], (), "", ''). This
more easily supports nested options that use those as part of the
format, and this constraint (balanced delimiters) is already codified
in the syntax of pass pipelines.

See https://discourse.llvm.org/t/list-of-lists-pass-option/5950 for
related discussion

Differential Revision: https://reviews.llvm.org/D122879
2022-04-02 00:45:11 -07:00
jacquesguan bc37077947 [mlir][Vector] Add constant folder for extractelement.
This revision adds constant folder for vector.extractelement.

Differential Revision: https://reviews.llvm.org/D122886
2022-04-02 11:10:42 +08:00
jacquesguan 262823612d [mlir][Vector] Add constant folder for insertelement.
This revision adds constant folder for vector.insertelement.

Differential Revision: https://reviews.llvm.org/D122721
2022-04-02 10:20:19 +08:00
Jacques Pienaar ad38f409f9 [mlir] Switch debugString helper to << operator
Supports more cases.
2022-04-01 16:33:35 -07:00
Lei Zhang a480d75fe4 [mlir][vector] Fold transpose(broadcast(<scalar>))
For such cases, the transpose op can be elided.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D122903
2022-04-01 14:51:36 -04:00
wren romano 63bdcaf92a [mlir][sparse] Moving `delete coo` into codegen instead of runtime library
Prior to this change there were a number of places where the allocation and deallocation of SparseTensorCOO objects were not cleanly paired, leading to inconsistencies regarding whether each function released its tensor/coo arguments or not, as well as making it easy to run afoul of memory leaks, use-after-free, or double-free errors.  This change cleans up the codegen vs runtime boundary to resolve those issues.  Now, the only time the runtime library frees an object is either (a) because it's a function explicitly designed to do so, or (b) because the allocated object is entirely local to the function and would be a memory leak if not released.  Thus, now the codegen takes complete responsibility for releasing any objects it caused to be allocated.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122435
2022-04-01 11:08:52 -07:00
Lei Zhang 57b101bdec [mlir][vector] Handle scalars in extract_strided_slice(broadcast)
For such cases we cannot generate extract_strided_slice ops.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D122902
2022-04-01 12:07:47 -04:00
Lei Zhang 533ec929f6 [mlir][spirv] Add pattern to lower math.copysign
This follows the logic:
https://git.musl-libc.org/cgit/musl/tree/src/math/copysignf.c

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D122910
2022-04-01 12:06:47 -04:00
Matthias Springer 73c0333dee [mlir][tensor][bufferize] Support 0-d collapse_shape with offset
Differential Revision: https://reviews.llvm.org/D122901
2022-04-01 22:30:37 +09:00
Groverkss de70ff10e4 [MLIR][Presburger][NFC] Use "disjunct" to refer to disjuncts in PresburgerRelation
This patch modifies the name "integerRelations" and "relation" to refer to the
disjuncts in PresburgerRelation to "disjunct(s)".  This is done to be
consistent with the rest of the interface.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122892
2022-04-01 17:38:30 +05:30
Arjun P 31cb99959f [MLIR][Presburger] subtract: fix bug when an input set has duplicate divisions
Previously, when an input set had a duplicate division, the duplicates might
be removed by a call to mergeLocalIds due to being detected as being duplicate
for the first time. The subtraction implementation cannot handle existing
locals being removed, so this would lead to unexpected behaviour. Resolve this
by removing all the duplicates up front.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122826
2022-04-01 12:38:45 +01:00
Arjun P acb378e21c [MLIR][Presburger] Factor out some functionality from LexSimplex into a LexSimplexBase
LexSimplex cannot be made to support symbols for symbolic lexmin; this requires
a second class. In preparation for upstreaming support for symbolic lexmin,
keep the part of LexSimplex that are specific to non-symbolic lexmin in LexSimplex
and move the parts that are required to a common class LexSimplexBase for both to
inherit from.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122828
2022-04-01 11:54:26 +01:00
Groverkss a5a598be44 [MLIR][Presburger] Use PresburgerSpace in constructors
This patch modifies IntegerPolyhedron, IntegerRelation, PresburgerRelation,
PresburgerSet, PWMAFunction, constructors to take PresburgerSpace instead of
dimensions. This allows information present in PresburgerSpace to be carried
better and allows for a general interface.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122842
2022-04-01 15:07:26 +05:30
Peixin-Qiao 3e7415a0ff [OMPIRBuilder] Support ordered clause specified without parameter
This patch supports ordered clause specified without parameter in
worksharing-loop directive in the OpenMPIRBuilder and lowering MLIR to
LLVM IR.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D114940
2022-04-01 16:17:29 +08:00
Mehdi Amini 83e3c6a717 Fix MLIR test pass
Inadvertently removed `populateWithGenerated` while testing native
patterns.
2022-04-01 06:37:18 +00:00
Mehdi Amini 43f0d5f934 Add a test case for `applyPatternsAndFoldGreedily` to support the revert of 59bbc7a08
This shows that pushing constant to the right in a commutative op leads
to `applyPatternsAndFoldGreedily` to converge without applying all the
patterns.

Differential Revision: https://reviews.llvm.org/D122870
2022-04-01 06:17:07 +00:00
Mehdi Amini ba43d6f85c Revert "[GreedPatternRewriter] Preprocess constants while building worklist when not processing top down"
This reverts commit 59bbc7a085.

This exposes an issue breaking the contract of
`applyPatternsAndFoldGreedily` where we "converge" without applying
remaining patterns.
2022-04-01 06:16:55 +00:00
River Riddle 59bbc7a085 [GreedPatternRewriter] Preprocess constants while building worklist when not processing top down
This avoids accidentally reversing the order of constants during successive
application, e.g. when running the canonicalizer. This helps reduce the number
of iterations, and also avoids unnecessary changes to input IR.

Fixes #51892

Differential Revision: https://reviews.llvm.org/D122692
2022-03-31 12:08:55 -07:00
Alex Zinenko 3a4ada6991 Revert "Added an empty __init__.py file to the MLIR Python bindings"
This reverts commit b50893db52.

Post-commit review pointed out that adding this file will require the
entire Python tree (including out-of-tree projects) to come from the
same directory, which might be problematic in non-default installations.
Reverting pending further discussion.
2022-03-31 20:03:52 +02:00
Okwan Kwon 65bdeddb1e [mlir] Bubble up tensor.extract_slice above linalg operation
Bubble up extract_slice above Linalg operation.

A sequence of operations

    %0 = linalg.<op> ... arg0, arg1, ...
    %1 = tensor.extract_slice %0 ...

can be replaced with

    %0 = tensor.extract_slice %arg0
    %1 = tensor.extract_slice %arg1
    %2 = linalg.<op> ... %0, %1, ...

This results in the reduce computation of the linalg operation.

The implementation uses the tiling utility functions. One difference
from the tiling process is that we don't need to insert the checking
code for the out-of-bound accesses. The use of the slice itself
represents that the code writer is sure about the boundary condition.
To avoid adding the boundary condtion check code, `omitPartialTileCheck`
is introduced for the tiling utility functions.

Differential Revision: https://reviews.llvm.org/D122437
2022-03-31 16:48:38 +00:00
Groverkss 152e501d87 [MLIR][Presburger] Carry IdKind information in LinearTransform::applyTo
This patch fixes a bug in LinearTransform::applyTo where it did not carry the
IdKind information, and instead treated every id as IdKind::Domain.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122823
2022-03-31 20:42:50 +05:30
Arjun P 9615d717d1 [MLIR][Presburger] IntegerRelation::truncate: fix bug when truncating equalities
This was truncating inequalities instead of equalities.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122811
2022-03-31 15:16:30 +01:00
Arjun P d81fa76f3a [MLIR][Presburger] MultiAffineFunction:eliminateRedundantLocalId: fix bug where local offset was not considered
Previously, when updating the outputs matrix, the local offset was not being considered.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122812
2022-03-31 15:11:55 +01:00
Sergei Lebedev e1fdd8048c Fixed the type of context in type stubs for MLIR Python bindings
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122795
2022-03-31 14:28:10 +02:00
Sergei Lebedev b50893db52 Added an empty __init__.py file to the MLIR Python bindings
While not strictly required after PEP-420, it is better to have one, since not
all tooling supports implicit namespace packages.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122794
2022-03-31 11:57:31 +02:00
Sergei Lebedev 65b2f24c50 Fixed mypy type errors in MLIR Python type stubs
This commit fixes or disables all errors reported by

    python3 -m mypy -p mlir --show-error-codes

Note that unhashable types cannot be currently expressed in a way compatible
with typeshed. See https://github.com/python/typeshed/issues/6243 for details.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122790
2022-03-31 11:56:26 +02:00
Groverkss 8de84198ce [MLIR][Presburger] Remove forward declaration to PresburgerLocalSpace
This patch removes a forward declaration to PresburgerLocalSpace, a
class which does not exist anymore.
2022-03-31 14:28:27 +05:30
Matthias Springer 566975a252 [mlir][memref][NFC] Remove unused function
This fixes a compiler warning.
2022-03-31 17:16:03 +09:00
Matthias Springer 51df62388e [mlir][tensor] Fix bufferization of CollapseShapeOp / ExpandShapeOp
Infer a tighter MemRef type instead of always falling back to the most dynamic MemRef type. This is inefficient and caused op verification errors.

Differential Revision: https://reviews.llvm.org/D122649
2022-03-31 17:11:45 +09:00
Matthias Springer 86d118e7f2 [mlir][memref] Fix CollapseShapeOp verifier
Differential Revision: https://reviews.llvm.org/D122647
2022-03-31 17:08:16 +09:00
Matthias Springer 2bd7ee4566 [mlir][memref] Fix ExpandShapeOp verifier
* Complete rewrite of the verifier.
* CollapseShapeOp verifier will be updated in a subsequent commit.
* Update and expand op documentation.
* Add a new builder that infers the result type based on the source type, result shape and reassociation indices. In essence, only the result layout map is inferred.

Differential Revision: https://reviews.llvm.org/D122641
2022-03-31 17:05:52 +09:00
jacquesguan 01ad70fd1d [mlir][Vector] Fold ShuffleOp if result is identical to one of source vectors.
For example, we could do the following eliminations:
  fold vector.shuffle V1, V2, [0, 1, 2, 3] : <4xi32>, <2xi32> -> V1
  fold vector.shuffle V1, V2, [4, 5] : <4xi32>, <2xi32> -> V2

Differential Revision: https://reviews.llvm.org/D122706
2022-03-31 10:46:13 +08:00
Arjun P b97aa413d1 Revert "[MLIR][Presburger] LexSimplex::addEquality: add equalities as fixed columns"
This reverts commit 5630143af3. The
implementation in this commit was incorrect. Also, handling this representation
of equalities in the upcoming support for symbolic lexicographic minimization
makes that patch much more complex. It will be easier to review that without
this representaiton and then reintroduce the fixed column representation
later, hence the revert rather than a bug fix.
2022-03-30 23:26:05 +01:00
Nikita Popov 6ae13b74d6 [MLIR] Remove LLVMVectorType
While this claims to be the base class for fixed and scalable
vectors, this is no longer the case since D94405. In fact,
LLVMVectorType is not usable, since the methods it declares are
never defined. Remove this leftover.

Differential Revision: https://reviews.llvm.org/D122707
2022-03-30 10:57:42 +02:00
bzcheeseman 4fec44b0e6 [mlir] Allow Diagnostic/InFlightDiagnostic to convert to FailureOr.
Allow conversion of a diagnostic to FailureOr. This conversion only results
in `failure` because in the case where operator LogicalResult would return
success, the FailureOr constructor would assert.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D122596
2022-03-30 01:37:20 -07:00
Ingo Müller e124f73b52 [mlir][docs] Convert block comments to line comments.
The op documentation of the ops of the scf dialect used /**/ style block
comments which doesn't seem to exists (anymore?).

Reviewed By: nicolasvasilache, ingomueller-net

Differential Revision: https://reviews.llvm.org/D122565
2022-03-30 08:08:42 +00:00
Nikita Popov ea043ea183 [MLIR] Avoid some pointer element type accesses
Determine the element type from the MLIR LLVMPointerType, rather
than the LLVM PointerType.
2022-03-30 10:00:51 +02:00
Shraiysh Vaishay 4d1010909f [mlir][OpenMP] Fix memory leak by deleting unused value
Reviewed By: ftynse, rriddle

Differential Revision: https://reviews.llvm.org/D122633
2022-03-30 03:25:53 +05:30
Benjamin Kramer 35dab904c0 [linalg] When removing noop linalg.generics, check that inserting a cast is valid
linalg.generic can also take scalars instead of tensors, which
tensor.cast doesn't support. We don't have an easy way to cast between
scalars and tensors so just keep the linalg.generic in those cases.

Differential Revision: https://reviews.llvm.org/D122575
2022-03-29 23:05:54 +02:00
Arjun P ef6f7c4a60 [MLIR][Presburger] Simplify std::{all,any}_of -> llvm::{all,any}_of (NFC)
Also simplify [](const F &f){ return f.foo(); } -> std::mem_fn(&F::foo)
2022-03-29 18:04:45 +01:00
Mogball 610396e481 [mlir][ods] Allow null to be passed as default-valued attributes
Allow default-valued attributes to be passed as null to builders, which will not add the attribute if not present, so the default value will be returned by getters.
2022-03-29 16:55:00 +00:00
Ivan Butygin 6f79240430 [mlir][spirv] Mark SPV_UndefOp NoSideEffect
Differential Revision: https://reviews.llvm.org/D122561
2022-03-29 17:54:32 +03:00
Javier Setoain 7bc8ad5109 [mlir][vector][nfc] Rename index optimizations option
We are using "enable-index-optimizations" and "indexOptimizations" as
names for an optimization that consists of using i32 for indices within
a vector. For instance, when building a vector comparison for mask
generation. The name is confusing and suggests a scope beyond these
vector indices.  This change makes the function of the option explicit
in its name.

Differential Revision: https://reviews.llvm.org/D122415
2022-03-29 11:33:22 +01:00
Uday Bondhugula 6e56d049db [MLIR][NFC] Remove dead FlatAffineConstraints constructor
NFC. Remove dead FlatAffineConstraints constructor.

Differential Revision: https://reviews.llvm.org/D122638
2022-03-29 13:44:56 +05:30