Skip to content

Commit c67d27d

Browse files
authored
[mlir][Presburger] NFC: return var index from IntegerRelation::addLocalFloorDiv (#153463)
addLocalFloorDiv currently returns void and requires the caller to know that the newly added local variable is in a particular index. This commit returns the index of the newly added variable so that callers need not tie themselves to this implementation detail. I found one relevant callsite demonstrating this and updated it. I am using this API out of tree and wanted to make our out-of-tree code a bit more resilient to upstream changes.
1 parent 33761df commit c67d27d

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,12 @@ class IntegerRelation {
479479
/// respect to a positive constant `divisor`. Two constraints are added to the
480480
/// system to capture equivalence with the floordiv:
481481
/// q = dividend floordiv c <=> c*q <= dividend <= c*q + c - 1.
482-
void addLocalFloorDiv(ArrayRef<DynamicAPInt> dividend,
483-
const DynamicAPInt &divisor);
484-
void addLocalFloorDiv(ArrayRef<int64_t> dividend, int64_t divisor) {
485-
addLocalFloorDiv(getDynamicAPIntVec(dividend), DynamicAPInt(divisor));
482+
/// Returns the column position of the new local variable.
483+
unsigned addLocalFloorDiv(ArrayRef<DynamicAPInt> dividend,
484+
const DynamicAPInt &divisor);
485+
unsigned addLocalFloorDiv(ArrayRef<int64_t> dividend, int64_t divisor) {
486+
return addLocalFloorDiv(getDynamicAPIntVec(dividend),
487+
DynamicAPInt(divisor));
486488
}
487489

488490
/// Adds a new local variable as the modulus of an affine function of other

mlir/lib/Analysis/FlatLinearValueConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct AffineExprFlattener : public SimpleAffineExprFlattener {
6060
AffineExpr localExpr) override {
6161
SimpleAffineExprFlattener::addLocalFloorDivId(dividend, divisor, localExpr);
6262
// Update localVarCst.
63-
localVarCst.addLocalFloorDiv(dividend, divisor);
63+
(void)localVarCst.addLocalFloorDiv(dividend, divisor);
6464
}
6565

6666
LogicalResult addLocalIdSemiAffine(ArrayRef<int64_t> lhs,

mlir/lib/Analysis/Presburger/IntegerRelation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,19 +1500,21 @@ void IntegerRelation::addBound(BoundType type, ArrayRef<DynamicAPInt> expr,
15001500
/// respect to a positive constant 'divisor'. Two constraints are added to the
15011501
/// system to capture equivalence with the floordiv.
15021502
/// q = expr floordiv c <=> c*q <= expr <= c*q + c - 1.
1503-
void IntegerRelation::addLocalFloorDiv(ArrayRef<DynamicAPInt> dividend,
1504-
const DynamicAPInt &divisor) {
1503+
/// Returns the column position of the new local variable.
1504+
unsigned IntegerRelation::addLocalFloorDiv(ArrayRef<DynamicAPInt> dividend,
1505+
const DynamicAPInt &divisor) {
15051506
assert(dividend.size() == getNumCols() && "incorrect dividend size");
15061507
assert(divisor > 0 && "positive divisor expected");
15071508

1508-
appendVar(VarKind::Local);
1509+
unsigned newVar = appendVar(VarKind::Local);
15091510

15101511
SmallVector<DynamicAPInt, 8> dividendCopy(dividend);
15111512
dividendCopy.insert(dividendCopy.end() - 1, DynamicAPInt(0));
15121513
addInequality(
15131514
getDivLowerBound(dividendCopy, divisor, dividendCopy.size() - 2));
15141515
addInequality(
15151516
getDivUpperBound(dividendCopy, divisor, dividendCopy.size() - 2));
1517+
return newVar;
15161518
}
15171519

15181520
unsigned IntegerRelation::addLocalModulo(ArrayRef<DynamicAPInt> exprs,

mlir/lib/Analysis/Presburger/Simplex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ LogicalResult SymbolicLexSimplex::addSymbolicCut(unsigned row) {
433433
normalizeDiv(divCoeffs, divDenom);
434434

435435
domainSimplex.addDivisionVariable(divCoeffs, divDenom);
436-
domainPoly.addLocalFloorDiv(divCoeffs, divDenom);
436+
(void)domainPoly.addLocalFloorDiv(divCoeffs, divDenom);
437437

438438
// Update `this` to account for the additional symbol we just added.
439439
appendSymbol();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ FlatAffineValueConstraints::addAffineForOpDomain(AffineForOp forOp) {
9393
int64_t lb = forOp.getConstantLowerBound();
9494
dividend[pos] = 1;
9595
dividend.back() -= lb;
96-
addLocalFloorDiv(dividend, step);
96+
unsigned qPos = addLocalFloorDiv(dividend, step);
9797
// Second constraint: (iv - lb) - step * q = 0.
9898
SmallVector<int64_t, 8> eq(getNumCols(), 0);
9999
eq[pos] = 1;
100100
eq.back() -= lb;
101101
// For the local var just added above.
102-
eq[getNumCols() - 2] = -step;
102+
eq[qPos] = -step;
103103
addEquality(eq);
104104
}
105105
}

0 commit comments

Comments
 (0)