36 Commits

Author SHA1 Message Date
Abhinav271828
562790f371
[MLIR][Presburger] Implement vertex enumeration and chamber decomposition for polytope generating function computation. (#78987)
We implement a function to compute the generating function corresponding
to a full-dimensional parametric polytope whose tangent cones are all
unimodular.
We fix a bug in unimodGenFunc to check the absolute value of the index.
We also implement Matrix<T>::negateMatrix() and Matrix<T>::scaleRow for
convenience.
2024-02-15 11:03:32 +05:30
Bharathi Ramana Joshi
66786a79d6
[MLIR][Presburger] Implement Matrix::moveColumns (#68362) 2024-01-13 18:51:26 +05:30
Abhinav271828
2dde029df8
[MLIR][Presburger] Implement computation of generating function for unimodular cones (#77235)
We implement a function that computes the generating function
corresponding to a unimodular cone.
The generating function for a polytope is obtained by summing these
generating functions over all tangent cones.
2024-01-11 01:28:36 +05:30
Adrian Kuegel
b238a0d989 [mlir] Apply ClangTidy findings.
- Remove redundant return
- Use .empty() instead of size() == 0.
2024-01-02 08:53:01 +00:00
Abhinav271828
e213af78b2
[MLIR][Presburger] Fix a bug with determinant of IntMatrix (#76622)
Fixed a bug where IntMatrix determinant() had a bug where it would try to assign to a null
pointer.
Added a test case that triggers this bug to avoid regressions.
2023-12-30 22:03:01 +02:00
Abhinav271828
cfd51fbadd
[MLIR][Presburger] Add LLL basis reduction (#75565)
Add a method for LLL basis reduction to the FracMatrix class.
This needs an abs() method for Fractions, which is added to Fraction.h.
2023-12-19 17:31:38 +01:00
Abhinav271828
84ab06ba2f
[MLIR][Presburger] Add Gram-Schmidt (#70843)
Implement Gram-Schmidt orthogonalisation for the FracMatrix class.
This requires dotProduct, which has been added as a util.
2023-12-13 08:28:47 +00:00
Mehdi Amini
2ee87cd610 [MLIR] Apply clang-tidy fixes for misc-include-cleaner in Presburger library (NFC) 2023-10-31 21:24:57 -07:00
Abhinav271828
f08fe1f1dd
[MLIR][Presburger] Implement matrix inverse (#67382)
Shift the `determinant()` function from LinearTransform to Matrix.
Implement a FracMatrix class, inheriting from Matrix<Fraction>, for inverses.
Implement inverse for FracMatrix and intInverse for IntMatrix.
Make Matrix internals protected instead of private so that Int/FracMatrix can access them.
2023-10-20 17:03:45 +01:00
Arjun P
7025ff6fa3 [MLIR][Presburger] clang-format and clang-tidy
Fix formatting issues mostly introduced in recent commits.
(This was possibly missed due to GitHub not having formatting checks at
the time, but it's unclear.)
2023-10-13 11:41:51 +01:00
Abhinav271828
c1b997464b
[MLIR][Presburger] Template Matrix to allow MPInt and Fraction; use IntMatrix for integer matrices (#66897)
Matrix has been templated to Matrix (for MPInt and Fraction) with
explicit instantiation for both these types.
IntMatrix, inheriting from Matrix<MPInt>, has been created to allow for
integer-only methods.
makeMatrix has been duplicated to makeIntMatrix and makeFracMatrix.

This was already landed previously but was reverted in
98c994c8e22d7f38cc04f56ee5cdeb337734414d due to build failure. This
fixes the failure.
2023-09-20 14:29:33 +01:00
Arjun P
98c994c8e2 Revert "[MLIR][Presburger] Template Matrix to allow MPInt and Fraction (#65272)"
This reverts commit efca035c6d28542ad6374cd8bf17ae7c72407ead.

Reverting due to windows build bot failure:
https://lab.llvm.org/buildbot/#/builders/13/builds/40242/steps/6/logs/stdio
2023-09-18 19:06:32 +01:00
Abhinav271828
efca035c6d
[MLIR][Presburger] Template Matrix to allow MPInt and Fraction (#65272)
The method implementations remain in the .cpp file; explicit instantiations have been added for these two types. 
makeMatrix has been duplicated to makeIntMatrix and makeFracMatrix.
2023-09-18 22:52:22 +05:30
Arjun P
057cae64eb [MLIR][Presburger] Matrix: hide expensive consistency check behind EXPENSIVE_CHECKS macro
This significantly improves performance of Release assert builds.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D143728
2023-02-14 15:28:44 +00:00
Groverkss
b696e25a7a [MLIR][Presburger] Add hermite normal form computation to Matrix
This patch adds hermite normal form computation to Matrix. Part of this algorithm
lived in LinearTransform, being used for compuing column echelon form. This
patch moves the implementation to Matrix::hermiteNormalForm and generalises it
to compute the hermite normal form.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D133510
2022-09-14 16:39:05 +01:00
Arjun P
6d6f6c4d3f [MLIR][Presburger] use arbitrary-precision arithmetic with MPInt instead of int64_t
Only the main Presburger library under the Presburger directory has been switched to use arbitrary precision. Users have been changed to just cast returned values back to int64_t or to use newly added convenience functions that perform the same cast internally.

The performance impact of this has been tested by checking test runtimes after copy-pasting 100 copies of each function. Affine/simplify-structures.mlir goes from 0.76s to 0.80s after this patch. Its performance sees no regression compared to its original performance at commit 18a06d4f3a7474d062d1fe7d405813ed2e40b4fc before a series of patches that I landed to offset the performance overhead of switching to arbitrary precision.

Affine/canonicalize.mlir and SCF/canonicalize.mlir show no noticable difference, staying at 2.02s and about 2.35s respectively.

Also, for Affine and SCF tests as a whole (no copy-pasting), the runtime remains about 0.09s on average before and after.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D129510
2022-09-14 15:47:41 +01:00
Groverkss
bb2226ac53 [MLIR][Presburger] Refactor MultiAffineFunction to be defined over universe
This patch refactors MAF to be defined over the universe in a given space
instead of being defined over a restricted domain.

The reasoning for this refactor is to store division representation for local
variables explicitly for the function outputs. This change is required for
unionLexMax/Min to support local variables which will be upstreamed after this
patch. Another reason for this refactor is to have a flattened form of
AffineMap as MultiAffineFunction.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D131864
2022-09-11 01:12:09 +01:00
Groverkss
479c4f648a [MLIR][Presburger] Refactor division representation to DivisionRepr
This patch refactors existing implementations of division representation storage
into a new class, DivisionRepr. This refactoring is done so that the common
division utilities can be shared in an upcoming patch.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D129146
2022-07-07 15:05:28 +01:00
Arjun P
ec145ba2a3 [MLIR][Presburger] Matrix: inline trivial accessors
This resolves a comment from https://reviews.llvm.org/D126708
that was previously missed.
2022-06-01 16:56:46 +01:00
Arjun P
d5e31cf38a [MLIR][Presburger] Move Matrix accessors inline
This gives a 1.5x speedup on the Presburger unittests.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D126708
2022-06-01 16:51:42 +01:00
Arjun P
aafb428237 [MLIR][Presburger][Simplex] symbolic lexmin: add some normalization heuristics
Normalize some of the division and inequality expressions used,
which can improve performance. Also deduplicate some of the
normalization functionality throughout the Presburger library.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123314
2022-04-11 20:46:30 +01:00
Arjun P
79ad5fb295 [MLIR][Presburger] IntegerPolyhedron: add support for symbolic integer lexmin
Add support for computing the symbolic integer lexmin of a polyhedron.
This finds, for every assignment to the symbols, the lexicographically
minimum value attained by the dimensions. For example, the symbolic lexmin
of the set

`(x, y)[a, b, c] : (a <= x, b <= x, x <= c)`

can be written as

```
x = a if b <= a, a <= c
x = b if a <  b, b <= c
```

This also finds the set of assignments to the symbols that make the lexmin unbounded.

This was previously landed in da92f92621e28a56fe8ad79d82eb60e436bf1d39 and
reverted in b238c252e8b1bbebc7ed79c08e06c23514d0dfb4 due to a build failure
in the code. Re-landing now with a fixed build.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122985
2022-04-05 18:50:34 +01:00
Arjun P
b238c252e8 Revert "[MLIR][Presburger] IntegerPolyhedron: add support for symbolic integer lexmin"
This reverts commit da92f92621e28a56fe8ad79d82eb60e436bf1d39.
2022-04-05 00:31:17 +01:00
Arjun P
da92f92621 [MLIR][Presburger] IntegerPolyhedron: add support for symbolic integer lexmin
Add support for computing the symbolic integer lexmin of a polyhedron.
This finds, for every assignment to the symbols, the lexicographically
minimum value attained by the dimensions. For example, the symbolic lexmin
of the set

`(x, y)[a, b, c] : (a <= x, b <= x, x <= c)`

can be written as

```
x = a if b <= a, a <= c
x = b if a <  b, b <= c
```

This also finds the set of assignments to the symbols that make the lexmin unbounded.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122985
2022-04-05 00:24:57 +01:00
Arjun P
30c0a14846 [MLIR][Presburger] Matrix::insertColumns: add doc, fix lint issue, and early exit when possible
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122137
2022-03-24 00:42:55 +00:00
Arjun P
d98dfdea17 [MLIR][Presburger] add a non-const Matrix::getRow() returning a MutableArrayRef
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122136
2022-03-21 15:17:16 +00:00
Arjun P
3edec279df Revert "Matrix::getRow non-const"
This reverts commit 68575ddea52d3104a7a6e2998fa05be278b99b34.
This commit was pushed accidentally.
2022-03-21 14:16:44 +00:00
Arjun P
68575ddea5 Matrix::getRow non-const 2022-03-21 14:16:24 +00:00
Groverkss
eff51cf9f3 [MLIR][Presburger] Use Matrix utilities for IntegerPolyhedron
This patch replaces various functions over inequalities/equalities in
IntegerPolyhedron with Matrix functions already implementing them or refactors
them to a Matrix function.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120482
2022-02-25 17:35:13 +05:30
Groverkss
0c1f6865e9 [MLIR][Presburger] Move Presburger/ files to presburger namespace
This patch moves the Presburger library to a new `presburger` namespace.

This allows to shorten some names, helps to avoid polluting the mlir namespace,
and also provides some structure.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120505
2022-02-25 16:01:29 +05:30
Arjun P
255494144f [MLIR] Matrix: support matrix-vector multiplication
This just moves in the implementation from LinearTransform.

Reviewed By: Groverkss, bondhugula

Differential Revision: https://reviews.llvm.org/D118479
2022-02-02 17:41:14 +05:30
Arjun P
6db019582a [MLIR] Introduce LexSimplex to support lexicographic optimization
This patch introduces a class LexSimplex that can currently be used to find the
lexicographically minimal rational point in an IntegerPolyhedron. This is a
series of patches leading to computing the lexicographically minimal integer
lattice point as well parametric lexicographic minimization.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117437
2022-01-28 22:06:58 +05:30
Arjun P
f263ea1571 [MLIR] Matrix: support resizing horizontally
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D109897
2021-09-17 16:22:31 +05:30
Arjun P
c605dfcfc0 [MLIR] FlatAffineConstraints: Use Matrix objects to store the constraints
This results in significant deduplication of code. This patch is not expected to change any functionality, it's just some simplification in preparation for future work. Also slightly simplified some code that was being touched anyway and added some unit tests for some functions that were touched.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D105152
2021-07-01 22:05:31 +05:30
Arjun P
6ebeba88f5 Support emptiness checks for unbounded FlatAffineConstraints.
With this, we have complete support for emptiness checks. This also paves the way for future support to check if two FlatAffineConstraints are equal.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D94272
2021-01-14 19:33:37 +01:00
Arjun P
10a898b3ec [MLIR] Exact integer emptiness checks for FlatAffineConstraints
This patch adds the capability to perform exact integer emptiness checks for FlatAffineConstraints using the General Basis Reduction algorithm (GBR). Previously, only a heuristic was available for emptiness checks, which was not guaranteed to always give a conclusive result.

This patch adds a `Simplex` class, which can be constructed using a `FlatAffineConstraints`, and can find an integer sample point (if one exists) using the GBR algorithm. Additionally, it adds two classes `Matrix` and `Fraction`, which are used by `Simplex`.

The integer emptiness check functionality can be accessed through the new `FlatAffineConstraints::isIntegerEmpty()` function, which runs the existing heuristic first and, if that proves to be inconclusive, runs the GBR algorithm to produce a conclusive result.

Differential Revision: https://reviews.llvm.org/D80860
2020-07-02 19:53:27 +05:30