Skip to content

Commit 5bdb0d6

Browse files
author
git apple-llvm automerger
committed
Merge commit '87cffeb63562' from llvm.org/main into next
2 parents 75c100e + 87cffeb commit 5bdb0d6

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

mlir/include/mlir/Analysis/Presburger/IntegerRelation.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,14 @@ class IntegerRelation : public PresburgerLocalSpace {
390390
/// O(VC) time.
391391
void removeRedundantConstraints();
392392

393-
/// Converts identifiers in the column range [idStart, idLimit) to local
394-
/// variables.
395-
void convertDimToLocal(unsigned dimStart, unsigned dimLimit);
393+
/// Converts identifiers of kind srcKind in the range [idStart, idLimit) to
394+
/// variables of kind dstKind and placed after all the other variables of kind
395+
/// dstKind. The internal ordering among the moved variables is preserved.
396+
void convertIdKind(IdKind srcKind, unsigned idStart, unsigned idLimit,
397+
IdKind dstKind);
398+
void convertToLocal(IdKind kind, unsigned idStart, unsigned idLimit) {
399+
convertIdKind(kind, idStart, idLimit, IdKind::Local);
400+
}
396401

397402
/// Adds additional local ids to the sets such that they both have the union
398403
/// of the local ids in each set, without changing the set of points that

mlir/lib/Analysis/Presburger/IntegerRelation.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,23 +1117,31 @@ void IntegerRelation::removeRedundantLocalVars() {
11171117
}
11181118
}
11191119

1120-
void IntegerRelation::convertDimToLocal(unsigned dimStart, unsigned dimLimit) {
1121-
assert(dimLimit <= getNumDimIds() && "Invalid dim pos range");
1120+
void IntegerRelation::convertIdKind(IdKind srcKind, unsigned idStart,
1121+
unsigned idLimit, IdKind dstKind) {
1122+
assert(idLimit <= getNumIdKind(srcKind) && "Invalid id range");
11221123

1123-
if (dimStart >= dimLimit)
1124+
if (idStart >= idLimit)
11241125
return;
11251126

11261127
// Append new local variables corresponding to the dimensions to be converted.
1127-
unsigned convertCount = dimLimit - dimStart;
1128-
unsigned newLocalIdStart = getNumIds();
1129-
appendId(IdKind::Local, convertCount);
1128+
unsigned newIdsBegin = getIdKindEnd(dstKind);
1129+
unsigned convertCount = idLimit - idStart;
1130+
appendId(dstKind, convertCount);
11301131

11311132
// Swap the new local variables with dimensions.
1133+
//
1134+
// Essentially, this moves the information corresponding to the specified ids
1135+
// of kind `srcKind` to the `convertCount` newly created ids of kind
1136+
// `dstKind`. In particular, this moves the columns in the constraint
1137+
// matrices, and zeros out the initially occupied columns (because the newly
1138+
// created ids we're swapping with were zero-initialized).
1139+
unsigned offset = getIdKindOffset(srcKind);
11321140
for (unsigned i = 0; i < convertCount; ++i)
1133-
swapId(i + dimStart, i + newLocalIdStart);
1141+
swapId(offset + idStart + i, newIdsBegin + i);
11341142

1135-
// Remove dimensions converted to local variables.
1136-
removeIdRange(IdKind::SetDim, dimStart, dimLimit);
1143+
// Complete the move by deleting the initially occupied columns.
1144+
removeIdRange(srcKind, idStart, idLimit);
11371145
}
11381146

11391147
void IntegerRelation::addBound(BoundType type, unsigned pos, int64_t value) {

mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,15 +1618,15 @@ AffineMap mlir::alignAffineMapWithValues(AffineMap map, ValueRange operands,
16181618
FlatAffineValueConstraints FlatAffineRelation::getDomainSet() const {
16191619
FlatAffineValueConstraints domain = *this;
16201620
// Convert all range variables to local variables.
1621-
domain.convertDimToLocal(getNumDomainDims(),
1622-
getNumDomainDims() + getNumRangeDims());
1621+
domain.convertToLocal(IdKind::SetDim, getNumDomainDims(),
1622+
getNumDomainDims() + getNumRangeDims());
16231623
return domain;
16241624
}
16251625

16261626
FlatAffineValueConstraints FlatAffineRelation::getRangeSet() const {
16271627
FlatAffineValueConstraints range = *this;
16281628
// Convert all domain variables to local variables.
1629-
range.convertDimToLocal(0, getNumDomainDims());
1629+
range.convertToLocal(IdKind::SetDim, 0, getNumDomainDims());
16301630
return range;
16311631
}
16321632

@@ -1658,12 +1658,13 @@ void FlatAffineRelation::compose(const FlatAffineRelation &other) {
16581658
// Convert `rel` from [otherDomain] -> [otherRange thisRange] to
16591659
// [otherDomain] -> [thisRange] by converting first otherRange range ids
16601660
// to local ids.
1661-
rel.convertDimToLocal(rel.getNumDomainDims(),
1662-
rel.getNumDomainDims() + removeDims);
1661+
rel.convertToLocal(IdKind::SetDim, rel.getNumDomainDims(),
1662+
rel.getNumDomainDims() + removeDims);
16631663
// Convert `this` from [otherDomain thisDomain] -> [thisRange] to
16641664
// [otherDomain] -> [thisRange] by converting last thisDomain domain ids
16651665
// to local ids.
1666-
convertDimToLocal(getNumDomainDims() - removeDims, getNumDomainDims());
1666+
convertToLocal(IdKind::SetDim, getNumDomainDims() - removeDims,
1667+
getNumDomainDims());
16671668

16681669
auto thisMaybeValues = getMaybeDimValues();
16691670
auto relMaybeValues = rel.getMaybeDimValues();

mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprTightUpperBound) {
707707
IntegerPolyhedron poly =
708708
parsePoly("(i, j, q) : (4*q - i - j + 2 >= 0, -4*q + i + j >= 0)");
709709
// Convert `q` to a local variable.
710-
poly.convertDimToLocal(2, 3);
710+
poly.convertToLocal(IdKind::SetDim, 2, 3);
711711

712712
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 1}};
713713
SmallVector<unsigned, 8> denoms = {4};
@@ -721,7 +721,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
721721
{
722722
IntegerPolyhedron poly = parsePoly("(i, j, q) : (-4*q + i + j == 0)");
723723
// Convert `q` to a local variable.
724-
poly.convertDimToLocal(2, 3);
724+
poly.convertToLocal(IdKind::SetDim, 2, 3);
725725

726726
std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 0}};
727727
SmallVector<unsigned, 8> denoms = {4};
@@ -731,7 +731,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
731731
{
732732
IntegerPolyhedron poly = parsePoly("(i, j, q) : (4*q - i - j == 0)");
733733
// Convert `q` to a local variable.
734-
poly.convertDimToLocal(2, 3);
734+
poly.convertToLocal(IdKind::SetDim, 2, 3);
735735

736736
std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 0}};
737737
SmallVector<unsigned, 8> denoms = {4};
@@ -741,7 +741,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
741741
{
742742
IntegerPolyhedron poly = parsePoly("(i, j, q) : (3*q + i + j - 2 == 0)");
743743
// Convert `q` to a local variable.
744-
poly.convertDimToLocal(2, 3);
744+
poly.convertToLocal(IdKind::SetDim, 2, 3);
745745

746746
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, -2}};
747747
SmallVector<unsigned, 8> denoms = {3};
@@ -756,7 +756,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEqualityAndInequality) {
756756
parsePoly("(i, j, q, k) : (-3*k + i + j == 0, 4*q - "
757757
"i - j + 2 >= 0, -4*q + i + j >= 0)");
758758
// Convert `q` and `k` to local variables.
759-
poly.convertDimToLocal(2, 4);
759+
poly.convertToLocal(IdKind::SetDim, 2, 4);
760760

761761
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0, 1},
762762
{-1, -1, 0, 0, 0}};
@@ -770,7 +770,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprNoRepr) {
770770
IntegerPolyhedron poly =
771771
parsePoly("(x, q) : (x - 3 * q >= 0, -x + 3 * q + 3 >= 0)");
772772
// Convert q to a local variable.
773-
poly.convertDimToLocal(1, 2);
773+
poly.convertToLocal(IdKind::SetDim, 1, 2);
774774

775775
std::vector<SmallVector<int64_t, 8>> divisions = {{0, 0, 0}};
776776
SmallVector<unsigned, 8> denoms = {0};
@@ -783,7 +783,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprNegConstNormalize) {
783783
IntegerPolyhedron poly =
784784
parsePoly("(x, q) : (-1 - 3*x - 6 * q >= 0, 6 + 3*x + 6*q >= 0)");
785785
// Convert q to a local variable.
786-
poly.convertDimToLocal(1, 2);
786+
poly.convertToLocal(IdKind::SetDim, 1, 2);
787787

788788
// q = floor((-1/3 - x)/2)
789789
// = floor((1/3) + (-1 - x)/2)

0 commit comments

Comments
 (0)