|
8 | 8 |
|
9 | 9 | #include "mlir/Analysis/Presburger/IntegerRelation.h"
|
10 | 10 | #include "Parser.h"
|
| 11 | +#include "mlir/Analysis/Presburger/PresburgerSpace.h" |
11 | 12 | #include "mlir/Analysis/Presburger/Simplex.h"
|
12 | 13 |
|
13 | 14 | #include <gmock/gmock.h>
|
@@ -167,3 +168,42 @@ TEST(IntegerRelationTest, symbolicLexmax) {
|
167 | 168 | EXPECT_TRUE(lexmax3.unboundedDomain.isIntegerEmpty());
|
168 | 169 | EXPECT_TRUE(lexmax3.lexopt.isEqual(expectedLexmax3));
|
169 | 170 | }
|
| 171 | + |
| 172 | +TEST(IntegerRelationTest, swapVar) { |
| 173 | + PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 1, 2, 0); |
| 174 | + space.resetIds(); |
| 175 | + |
| 176 | + int identifiers[6] = {0, 1, 2, 3, 4}; |
| 177 | + |
| 178 | + // Attach identifiers to domain identifiers. |
| 179 | + space.getId(VarKind::Domain, 0) = Identifier(&identifiers[0]); |
| 180 | + space.getId(VarKind::Domain, 1) = Identifier(&identifiers[1]); |
| 181 | + |
| 182 | + // Attach identifiers to range identifiers. |
| 183 | + space.getId(VarKind::Range, 0) = Identifier(&identifiers[2]); |
| 184 | + |
| 185 | + // Attach identifiers to symbol identifiers. |
| 186 | + space.getId(VarKind::Symbol, 0) = Identifier(&identifiers[3]); |
| 187 | + space.getId(VarKind::Symbol, 1) = Identifier(&identifiers[4]); |
| 188 | + |
| 189 | + IntegerRelation rel = |
| 190 | + parseRelationFromSet("(x, y, z)[N, M] : (z - x - y == 0, x >= 0, N - x " |
| 191 | + ">= 0, y >= 0, M - y >= 0)", |
| 192 | + 2); |
| 193 | + rel.setSpace(space); |
| 194 | + // Swap (Domain 0, Range 0) |
| 195 | + rel.swapVar(0, 2); |
| 196 | + // Swap (Domain 1, Symbol 1) |
| 197 | + rel.swapVar(1, 4); |
| 198 | + |
| 199 | + PresburgerSpace swappedSpace = rel.getSpace(); |
| 200 | + |
| 201 | + EXPECT_TRUE(swappedSpace.getId(VarKind::Domain, 0) |
| 202 | + .isEqual(space.getId(VarKind::Range, 0))); |
| 203 | + EXPECT_TRUE(swappedSpace.getId(VarKind::Domain, 1) |
| 204 | + .isEqual(space.getId(VarKind::Symbol, 1))); |
| 205 | + EXPECT_TRUE(swappedSpace.getId(VarKind::Range, 0) |
| 206 | + .isEqual(space.getId(VarKind::Domain, 0))); |
| 207 | + EXPECT_TRUE(swappedSpace.getId(VarKind::Symbol, 1) |
| 208 | + .isEqual(space.getId(VarKind::Domain, 1))); |
| 209 | +} |
0 commit comments