Commit Graph

738 Commits

Author SHA1 Message Date
Markus Böck 0c789db541 [mlir] Add support for operation-produced successor arguments in BranchOpInterface
This patch revamps the BranchOpInterface a bit and allows a proper implementation of what was previously `getMutableSuccessorOperands` for operations, which internally produce arguments to some of the block arguments. A motivating example for this would be an invoke op with a error handling path:
```
invoke %function(%0)
  label ^success ^error(%1 : i32)

^error(%e: !error, %arg0 : i32):
  ...
```
The advantages of this are that any users of `BranchOpInterface` can still argue over remaining block argument operands (such as `%1` in the example above), as well as make use of the modifying capabilities to add more operands, erase an operand etc.

The way this patch implements that functionality is via a new class called `SuccessorOperands`, which is now returned by `getSuccessorOperands`. It basically contains an `unsigned` denoting how many operator produced operands exist, as well as a `MutableOperandRange`, which are the usual forwarded operands we are used to. The produced operands are assumed to the first few block arguments, followed by the forwarded operands afterwards. The role of `SuccessorOperands` is to provide various utility functions to modify and query the successor arguments from a `BranchOpInterface`.

Differential Revision: https://reviews.llvm.org/D123062
2022-04-08 08:28:16 +02:00
Stella Laurenzo 497f87bb7b NFC: Silence unused function 'scaleAndAdd' in release build.
Differential Revision: https://reviews.llvm.org/D123354
2022-04-07 21:19:19 -07:00
Arjun P 00b293e83f [MLIR][Presburger] refactor subtraction to be non-recursive
Subtraction was previously implemented recursively. This refactors it to be
non-recursive to avoid issues with potential stack overflows.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123248
2022-04-07 15:20:19 +01:00
Arjun P 1ba6043332 [MLIR][Presburger] Refactor subtraction in preparation for making it iterative
Refactor the operation of subtraction by
- removing the usage of SimplexRollbackScopeExit since this
  can't be used in the iterative version
- reducing the number of stack variables to make the
  iterative version easier to follow

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123156
2022-04-06 16:35:28 +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 da92f92621 and
reverted in b238c252e8 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 da92f92621.
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
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
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
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
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
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
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
Groverkss fcbe64ddb8 [MLIR][Presburger] Merge PresburgerLocalSpace and PresburgerSpace
This patch is a cleanup patch that merges PresburgerLocalSpace and
PresburgerSpace. Asserting that there are no locals is shifted to the
users of PresburgerSpace themselves.

The reasoning for this patch is that PresburgerLocalSpace did not contribute
much and only introduced additional complexity as locals could still be present
in PresburgerSpace, just not writable. This could introduce problems if a
PresburgerSpace with locals was copied to PresburgerLocalSpace which expected
no locals in a PresburgerSpace.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122353
2022-03-25 05:36:32 +05:30
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 4418669f1e [MLIR][Presburger] PWMAFunction::valueAt: support local ids
Add a baseline implementation of support for local ids for `PWMAFunction::valueAt`. This can be made more efficient later if needed by handling locals with known div representations separately.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122144
2022-03-24 00:42:21 +00:00
Arjun P 5630143af3 [MLIR][Presburger] LexSimplex::addEquality: add equalities as fixed columns
In LexSimplex, instead of adding equalities as a pair of inequalities,
add them as a single row, move them into the basis, and keep them there.

There will always be a valid basis involving all non-redundant equalities. Such
equalities will then be ignored in some other operations, such as when looking
for pivot columns. This speeds them up a little bit.

More importantly, this is an important precursor patch to adding support for
symbolic integer lexmin, as this heuristic can sometimes make a big difference there.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122165
2022-03-24 00:41:17 +00:00
Arjun P 08543a5a47 [MLIR][Presburger] Introduce SimplexRollbackScopeExit to rollback on scope exit
This simplifies many places where we just want to do something in a "transient context"
and return some value.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122172
2022-03-24 00:27:47 +00:00
Arjun P 93b9f50b4c [MLIR][Presburger] IntegerRelation: implement partial rollback support
It is often necessary to "rollback" IntegerRelations to an earlier state. Although providing full rollback support is non-trivial, we really only need to support the case where the only changes made are to append ids or append constraints, and then rollback these additions. This patch adds support to rollback in such situations by recording the number of ids and constraints of each kind and providing support to truncate the IntegerRelation to those counts by removing appended ids and constraints. This already simplifies subtraction a little bit and will also be useful in the implementation of symbolic integer lexmin.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122178
2022-03-24 00:27:21 +00:00
Arjun P 87cffeb635 [MLIR][Presburger] support IntegerRelation::convertIdKind
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122154
2022-03-23 11:12:08 +00:00
Arjun P ff44760427 [MLIR][Presburger] add Simplex:addDivisionVariable
This is a convenience function for adding new divisions to the Simplex given the numerator and denominator.

This will be needed for symbolic integer lexmin support.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122159
2022-03-23 10:53:32 +00:00
Arjun P b68e78cea6 [MLIR][Prebsurger] Add IntegerRelation::intersect supporting locals properly
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122149
2022-03-22 13:13:56 +00:00
Arjun P 7f6112496b [MLIR][Presburger] MultiAffineFunction::removeIdRange: fix bug where kind wasn't passed on to IntegerPolyhedron::removeIdRange
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122158
2022-03-22 13:13:11 +00:00
Arjun P 93ccd7c490 [MLIR][Presburger] fix bug where Simplex::addZeroRow was not undoable
Previously, an UndoLogEntry was added by addRow but not by addZeroRow. So
calling directly into addZeroRow, as LexSimplex::addCut does, was not an
undoable operation. In the current usage of addCut this could never
lead to an incorrect result, and addZeroRow is protected, so it is not
currently possible to add a regression test for this. This bug needs to be
fixed for the symbolic integer lexmin algorithm.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122162
2022-03-22 13:11:56 +00:00
Arjun P 523914c20d [MLIR][Presburger] Deduplicate and move getNegatedCoeffs and getComplementIneq into Utils 2022-03-21 19:29:11 +00:00
Arjun P 8a67c6ee7c [MLIR][Presburger] simplify removeConstraintsInvolvingRange 2022-03-21 18:36:36 +00:00
Arjun P 888894b65a [MLIR][Presburger] Support PWMAFunction::dump by calling into print
This was declared but not defined previously.
2022-03-21 16:01:51 +00:00
Arjun P 35b73917c2 [MLIR][Presburger] fix typo: maybeGetNonIntegeralVarRow -> maybeGetNonIntegralVarRow (NFC) 2022-03-21 15:52:18 +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 68575ddea5.
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
Michel Weber 9d6a6fbbbd [MLIR][Presburger] remove redundant constraints in coalesce
This patch improves the representation size of individual
`IntegerRelation`s by calling the function
`IntegerRelation::removeRedundantConstraints`. While this is only a
slight optimization in the current version, it will be necessary for
patches to come.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121989
2022-03-20 13:00:12 +00:00
Michel Weber ae3e3c6362 [MLIR][Presburger] introduce SetCoalescer
This patch refactors the current coalesce implementation. It introduces
the `SetCoalescer`, a class in which all coalescing functionality lives.
The main advantage over the old design is the fact that the vectors of
constraints do not have to be passed around, but are implemented as
private fields of the SetCoalescer. This will become especially
important once more inequality types are introduced.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121364
2022-03-18 08:19:10 +00:00
Mehdi Amini 71302b6711 Revert "[MLIR][Presburger] introduce SetCoalescer"
This reverts commit dad80e9710.

The build is broken with some configurations (gcc-5 and gcc-8):

mlir/lib/Analysis/Presburger/PresburgerRelation.cpp:402:32: error: qualified name does not name a class before '{' token
 class presburger::SetCoalescer {
2022-03-17 22:50:16 +00:00
Michel Weber dad80e9710 [MLIR][Presburger] introduce SetCoalescer
This patch refactors the current coalesce implementation. It introduces
the `SetCoalescer`, a class in which all coalescing functionality lives.
The main advantage over the old design is the fact that the vectors of
constraints do not have to be passed around, but are implemented as
private fields of the SetCoalescer. This will become especially
important once more inequality types are introduced.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121364
2022-03-17 19:52:01 +00:00
Groverkss ff1d9a4b97 [MLIR][Presburger] Add support for PresburgerRelation
This patch adds supports for union of relations (PresburgerRelation).  Along
with this, support for PresburgerSet is also maintained.

This patch is part of a series of patches to add support for relations in
Presburger library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121417
2022-03-13 17:31:19 +05:30
Groverkss 58966dd42b [MLIR][Presburger] Remove `spaceKind` from PresburgerSpace
This patch remove `spaceKind` from PresburgerSpace, making PresburgerSpace only
a space supporting relations.

Sets are still implemented in the same way, i.e. with a zero domain but instead
the asserts to check if the space is still set are added to users of
PresburgerSpace which treat it as a Set space.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121357
2022-03-10 22:20:44 +05:30
Michel Weber 06eb057738 [MLIR][Presburger] fix vector update in coalesce
When `addCoalescedPolyhedron` was called with `j == n - 1`,
the `polyhedrons`-vector was not properly updated (the
`IntegerPolyhedron` at position `n - 2` was "lost"). This patch adds
special handling to that case and a regression testcase.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D121356
2022-03-10 15:42:11 +05:30
Groverkss c896e6540a [MLIR][Presburger] Use IdKind for removeIdRange in PresburgerSpace
This patch moves PresburgerSpace::removeIdRange(idStart, idLimit) to
PresburgerSpace::removeIdRange(kind, idStart, idLimit), i.e. identifiers
can only be removed at once for a single kind.

This makes users of PresburgerSpace to not assume any inside ordering of
identifier kinds.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121079
2022-03-10 15:39:32 +05:30
Groverkss abc2c2309a [MLIR][Presburger][NFC] Cleanup PresburgerSet
This patch cleans up the interface to PresburgerSet. At a high level it does
the following changes:

  - Move member functions around to have constructors at top and print/dump
    at end.
  - Move a private function to be a static function instead.
  - Change member functions of type "getAllIntegerPolyhedron" to "getAllPolys"
    instead.
  - Improve documentation for PresburgerSet.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121027
2022-03-08 03:02:12 +05:30
Groverkss ae2764e835 [MLIR][Presburger][NFC] Fix PresburgerLocalSpace::print() output
This change puts a colon before before the printing number of locals in
PresburgerLocalSpace::print().
2022-03-06 16:42:20 +05:30
Michel Weber 21dc4ad56a [MLIR][Presburger] skip IntegerPolyhedrons with LocalIds in coalesce
This patch makes coalesce skip the comparison of all pairs of IntegerPolyhedrons with LocalIds rather than crash. The heuristics to handle these cases will be upstreamed later on.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120995
2022-03-04 16:12:04 +00:00
Michel Weber d1a051f926 [MLIR][Presburger] support a heuristic for the "cut case" in coalesce
This patch introduces the cut case. If one polytope has only cutting and
redundant inequalities for the other and the facet of the cutting
inequalities are contained within the other polytope, then the polytopes are
be combined into a polytope consisting only of their respective
redundant constraints.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120614
2022-03-04 13:02:36 +05:30
Groverkss bb9013555f [MLIR][Presburger] Move functionality from IntegerPolyhedron to IntegerRelation
This patch moves all functionality from IntegerPolyhedron to IntegerRelation.
IntegerPolyhedron is now implemented as a relation with no domain. All existing
functionality is extended to work on relations.

This patch does not affect external users like FlatAffineConstraints as they
can still continue to use IntegerPolyhedron abstraction.

This patch is part of a series of patches to support relations in Presburger
library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120652
2022-03-02 20:10:44 +05:30