Skip to content

Commit 8663915

Browse files
iambrjGroverkss
authored andcommitted
[MLIR][Presburger] Implement getDomainSet and getRangeSet for PresburgerRelation
This patch implements getDomainSet and getRangeSet for PresburgerRelation Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D158263
1 parent 65f2596 commit 8663915

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class PresburgerRelation {
9797
/// operation returns (A intersection C) -> B.
9898
PresburgerRelation intersectDomain(const PresburgerSet &set) const;
9999

100+
/// Return a set corresponding to the domain of the relation.
101+
PresburgerSet getDomainSet() const;
102+
/// Return a set corresponding to the range of the relation.
103+
PresburgerSet getRangeSet() const;
104+
100105
/// Invert the relation, i.e. swap its domain and range.
101106
///
102107
/// Formally, if `this`: A -> B then `inverse` updates `this` in-place to

mlir/lib/Analysis/Presburger/PresburgerRelation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ PresburgerRelation::intersectDomain(const PresburgerSet &set) const {
164164
return intersect(other);
165165
}
166166

167+
PresburgerSet PresburgerRelation::getDomainSet() const {
168+
PresburgerSet result = PresburgerSet::getEmpty(space.getDomainSpace());
169+
for (const IntegerRelation &cs : disjuncts)
170+
result.unionInPlace(cs.getDomainSet());
171+
return result;
172+
}
173+
174+
PresburgerSet PresburgerRelation::getRangeSet() const {
175+
PresburgerSet result = PresburgerSet::getEmpty(space.getRangeSpace());
176+
for (const IntegerRelation &cs : disjuncts)
177+
result.unionInPlace(cs.getRangeSet());
178+
return result;
179+
}
180+
167181
void PresburgerRelation::inverse() {
168182
for (IntegerRelation &cs : disjuncts)
169183
cs.inverse();

mlir/unittests/Analysis/Presburger/PresburgerRelationTest.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ TEST(PresburgerRelationTest, inverse) {
191191
}
192192
}
193193

194-
TEST(IntegerRelationTest, symbolicLexOpt) {
194+
TEST(PresburgerRelationTest, symbolicLexOpt) {
195195
PresburgerRelation rel1 = parsePresburgerRelationFromPresburgerSet(
196196
{"(x, y)[N, M] : (x >= 0, y >= 0, N - 1 >= 0, M >= 0, M - 2 * N - 1>= 0, "
197197
"2 * N - x >= 0, 2 * N - y >= 0)",
@@ -296,3 +296,29 @@ TEST(IntegerRelationTest, symbolicLexOpt) {
296296
EXPECT_TRUE(lexmax3.unboundedDomain.isIntegerEmpty());
297297
EXPECT_TRUE(lexmax3.lexopt.isEqual(expectedLexMax3));
298298
}
299+
300+
TEST(PresburgerRelationTest, getDomainAndRangeSet) {
301+
PresburgerRelation rel = parsePresburgerRelationFromPresburgerSet(
302+
{// (x, y) -> (x + N, y - N)
303+
"(x, y, a, b)[N] : (a >= 0, b >= 0, N - a >= 0, N - b >= 0, x - a + N "
304+
"== 0, y - b - N == 0)",
305+
// (x, y) -> (- y, - x)
306+
"(x, y, a, b)[N] : (a >= 0, b >= 0, 2 * N - a >= 0, 2 * N - b >= 0, a + "
307+
"y == 0, b + x == 0)"},
308+
2);
309+
310+
PresburgerSet domainSet = rel.getDomainSet();
311+
312+
PresburgerSet expectedDomainSet = parsePresburgerSet(
313+
{"(x, y)[N] : (x + N >= 0, -x >= 0, y - N >= 0, 2 * N - y >= 0)",
314+
"(x, y)[N] : (x + 2 * N >= 0, -x >= 0, y + 2 * N >= 0, -y >= 0)"});
315+
316+
EXPECT_TRUE(domainSet.isEqual(expectedDomainSet));
317+
318+
PresburgerSet rangeSet = rel.getRangeSet();
319+
320+
PresburgerSet expectedRangeSet = parsePresburgerSet(
321+
{"(x, y)[N] : (x >= 0, 2 * N - x >= 0, y >= 0, 2 * N - y >= 0)"});
322+
323+
EXPECT_TRUE(rangeSet.isEqual(expectedRangeSet));
324+
}

0 commit comments

Comments
 (0)