Skip to content

Commit ec10ff3

Browse files
committed
[MLIR][Presburger] Support isSubsetOf in PresburgerSet and IntegerPolyhedron
Also support isEqual in IntegerPolyhedron. Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D118778
1 parent a007a6d commit ec10ff3

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ class IntegerPolyhedron {
115115
/// intersection with no simplification of any sort attempted.
116116
void append(const IntegerPolyhedron &other);
117117

118+
/// Return whether `this` and `other` are equal. This is integer-exact
119+
/// and somewhat expensive, since it uses the integer emptiness check
120+
/// (see IntegerPolyhedron::findIntegerSample()).
121+
bool isEqual(const IntegerPolyhedron &other) const;
122+
123+
/// Return whether this is a subset of the given IntegerPolyhedron. This is
124+
/// integer-exact and somewhat expensive, since it uses the integer emptiness
125+
/// check (see IntegerPolyhedron::findIntegerSample()).
126+
bool isSubsetOf(const IntegerPolyhedron &other) const;
127+
118128
/// Returns the value at the specified equality row and column.
119129
inline int64_t atEq(unsigned i, unsigned j) const { return equalities(i, j); }
120130
inline int64_t &atEq(unsigned i, unsigned j) { return equalities(i, j); }

mlir/include/mlir/Analysis/Presburger/PresburgerSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class PresburgerSet {
7777
/// divisions.
7878
PresburgerSet subtract(const PresburgerSet &set) const;
7979

80+
/// Return true if this set is a subset of the given set, and false otherwise.
81+
bool isSubsetOf(const PresburgerSet &set) const;
82+
8083
/// Return true if this set is equal to the given set, and false otherwise.
8184
/// All local variables in both sets must correspond to floor divisions.
8285
bool isEqual(const PresburgerSet &set) const;

mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "mlir/Analysis/Presburger/IntegerPolyhedron.h"
1414
#include "mlir/Analysis/Presburger/LinearTransform.h"
15+
#include "mlir/Analysis/Presburger/PresburgerSet.h"
1516
#include "mlir/Analysis/Presburger/Simplex.h"
1617
#include "mlir/Analysis/Presburger/Utils.h"
1718
#include "llvm/ADT/DenseMap.h"
@@ -63,6 +64,14 @@ void IntegerPolyhedron::append(const IntegerPolyhedron &other) {
6364
}
6465
}
6566

67+
bool IntegerPolyhedron::isEqual(const IntegerPolyhedron &other) const {
68+
return PresburgerSet(*this).isEqual(PresburgerSet(other));
69+
}
70+
71+
bool IntegerPolyhedron::isSubsetOf(const IntegerPolyhedron &other) const {
72+
return PresburgerSet(*this).isSubsetOf(PresburgerSet(other));
73+
}
74+
6675
Optional<SmallVector<Fraction, 8>>
6776
IntegerPolyhedron::getRationalLexMin() const {
6877
assert(numSymbols == 0 && "Symbols are not supported!");

mlir/lib/Analysis/Presburger/PresburgerSet.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,17 @@ PresburgerSet PresburgerSet::subtract(const PresburgerSet &set) const {
352352
return result;
353353
}
354354

355-
/// Two sets S and T are equal iff S contains T and T contains S.
356-
/// By "S contains T", we mean that S is a superset of or equal to T.
357-
///
358-
/// S contains T iff T \ S is empty, since if T \ S contains a
359-
/// point then this is a point that is contained in T but not S.
360-
///
361-
/// Therefore, S is equal to T iff S \ T and T \ S are both empty.
355+
/// T is a subset of S iff T \ S is empty, since if T \ S contains a
356+
/// point then this is a point that is contained in T but not S, and
357+
/// if T contains a point that is not in S, this also lies in T \ S.
358+
bool PresburgerSet::isSubsetOf(const PresburgerSet &set) const {
359+
return this->subtract(set).isIntegerEmpty();
360+
}
361+
362+
/// Two sets are equal iff they are subsets of each other.
362363
bool PresburgerSet::isEqual(const PresburgerSet &set) const {
363364
assertDimensionsCompatible(set, *this);
364-
return this->subtract(set).isIntegerEmpty() &&
365-
set.subtract(*this).isIntegerEmpty();
365+
return this->isSubsetOf(set) && set.isSubsetOf(*this);
366366
}
367367

368368
/// Return true if all the sets in the union are known to be integer empty,

0 commit comments

Comments
 (0)