Skip to content

Commit 3cc5447

Browse files
committed
[MLIR][Presburger] Use SmallVector instead of std::vector in getLocalRepr
Use `SmallVector` instead of `std::vector` in `getLocalRepr` function. Also, fix the casing of a variable. Reviewed By: arjunp Differential Revision: https://reviews.llvm.org/D118722
1 parent d5bb0de commit 3cc5447

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,14 @@ class IntegerPolyhedron {
285285
/// and the denominators in `denominators`. If no explicit representation
286286
/// could be found for the `i^th` local identifier, `denominators[i]` is set
287287
/// to 0.
288-
void getLocalReprs(std::vector<SmallVector<int64_t, 8>> &dividends,
289-
SmallVector<unsigned, 4> &denominators,
290-
std::vector<presburger_utils::MaybeLocalRepr> &repr) const;
291-
void getLocalReprs(std::vector<presburger_utils::MaybeLocalRepr> &repr) const;
292-
void getLocalReprs(std::vector<SmallVector<int64_t, 8>> &dividends,
293-
SmallVector<unsigned, 4> &denominators) const;
288+
void
289+
getLocalReprs(SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
290+
SmallVectorImpl<unsigned> &denominators,
291+
SmallVectorImpl<presburger_utils::MaybeLocalRepr> &repr) const;
292+
void
293+
getLocalReprs(SmallVectorImpl<presburger_utils::MaybeLocalRepr> &repr) const;
294+
void getLocalReprs(SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
295+
SmallVectorImpl<unsigned> &denominators) const;
294296

295297
/// The type of bound: equal, lower bound or upper bound.
296298
enum BoundType { EQ, LB, UB };

mlir/include/mlir/Analysis/Presburger/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ MaybeLocalRepr computeSingleVarRepr(const IntegerPolyhedron &cst,
6565
/// the divisions are not merged. `merge` can also do side effects, For example
6666
/// it can merge the local identifiers in IntegerPolyhedron.
6767
void removeDuplicateDivs(
68-
std::vector<SmallVector<int64_t, 8>> &divs,
68+
SmallVectorImpl<SmallVector<int64_t, 8>> &divs,
6969
SmallVectorImpl<unsigned> &denoms, unsigned localOffset,
7070
llvm::function_ref<bool(unsigned i, unsigned j)> merge);
7171

mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,23 +829,24 @@ bool IntegerPolyhedron::containsPoint(ArrayRef<int64_t> point) const {
829829
return true;
830830
}
831831

832-
void IntegerPolyhedron::getLocalReprs(std::vector<MaybeLocalRepr> &repr) const {
833-
std::vector<SmallVector<int64_t, 8>> dividends(getNumLocalIds());
832+
void IntegerPolyhedron::getLocalReprs(
833+
SmallVectorImpl<MaybeLocalRepr> &repr) const {
834+
SmallVector<SmallVector<int64_t, 8>> dividends(getNumLocalIds());
834835
SmallVector<unsigned, 4> denominators(getNumLocalIds());
835836
getLocalReprs(dividends, denominators, repr);
836837
}
837838

838839
void IntegerPolyhedron::getLocalReprs(
839-
std::vector<SmallVector<int64_t, 8>> &dividends,
840-
SmallVector<unsigned, 4> &denominators) const {
841-
std::vector<MaybeLocalRepr> repr(getNumLocalIds());
840+
SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
841+
SmallVectorImpl<unsigned> &denominators) const {
842+
SmallVector<MaybeLocalRepr> repr(getNumLocalIds());
842843
getLocalReprs(dividends, denominators, repr);
843844
}
844845

845846
void IntegerPolyhedron::getLocalReprs(
846-
std::vector<SmallVector<int64_t, 8>> &dividends,
847-
SmallVector<unsigned, 4> &denominators,
848-
std::vector<MaybeLocalRepr> &repr) const {
847+
SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
848+
SmallVectorImpl<unsigned> &denominators,
849+
SmallVectorImpl<MaybeLocalRepr> &repr) const {
849850

850851
repr.resize(getNumLocalIds());
851852
dividends.resize(getNumLocalIds());
@@ -1103,7 +1104,7 @@ void IntegerPolyhedron::mergeLocalIds(IntegerPolyhedron &other) {
11031104
polyB.insertLocalId(0, initLocals);
11041105

11051106
// Get division representations from each poly.
1106-
std::vector<SmallVector<int64_t, 8>> divsA, divsB;
1107+
SmallVector<SmallVector<int64_t, 8>> divsA, divsB;
11071108
SmallVector<unsigned, 4> denomsA, denomsB;
11081109
polyA.getLocalReprs(divsA, denomsA);
11091110
polyB.getLocalReprs(divsB, denomsB);

mlir/lib/Analysis/Presburger/PresburgerSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void subtractRecursively(IntegerPolyhedron &b, Simplex &simplex,
213213

214214
// Find out which inequalities of sI correspond to division inequalities for
215215
// the local variables of sI.
216-
std::vector<MaybeLocalRepr> repr(sI.getNumLocalIds());
216+
SmallVector<MaybeLocalRepr> repr(sI.getNumLocalIds());
217217
sI.getLocalReprs(repr);
218218

219219
// Add sI's locals to b, after b's locals. Also add b's locals to sI, before

mlir/lib/Analysis/Presburger/Utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ static LogicalResult getDivRepr(const IntegerPolyhedron &cst, unsigned pos,
160160

161161
// Extract divisor, the divisor can be negative and hence its sign information
162162
// is stored in `signDiv` to reverse the sign of dividend's coefficients.
163-
// Equality must involve the pos-th variable and hence `temp_div` != 0.
164-
int64_t temp_div = cst.atEq(eqInd, pos);
165-
if (temp_div == 0)
163+
// Equality must involve the pos-th variable and hence `tempDiv` != 0.
164+
int64_t tempDiv = cst.atEq(eqInd, pos);
165+
if (tempDiv == 0)
166166
return failure();
167-
int64_t signDiv = temp_div < 0 ? -1 : 1;
167+
int64_t signDiv = tempDiv < 0 ? -1 : 1;
168168

169169
// The divisor is always a positive integer.
170-
divisor = temp_div * signDiv;
170+
divisor = tempDiv * signDiv;
171171

172172
expr.resize(cst.getNumCols(), 0);
173173
for (unsigned i = 0, e = cst.getNumIds(); i < e; ++i)
@@ -254,7 +254,7 @@ MaybeLocalRepr presburger_utils::computeSingleVarRepr(
254254
}
255255

256256
void presburger_utils::removeDuplicateDivs(
257-
std::vector<SmallVector<int64_t, 8>> &divs,
257+
SmallVectorImpl<SmallVector<int64_t, 8>> &divs,
258258
SmallVectorImpl<unsigned> &denoms, unsigned localOffset,
259259
llvm::function_ref<bool(unsigned i, unsigned j)> merge) {
260260

mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ static void checkDivisionRepresentation(
624624
const std::vector<SmallVector<int64_t, 8>> &expectedDividends,
625625
const SmallVectorImpl<unsigned> &expectedDenominators) {
626626

627-
std::vector<SmallVector<int64_t, 8>> dividends;
627+
SmallVector<SmallVector<int64_t, 8>> dividends;
628628
SmallVector<unsigned, 4> denominators;
629629

630630
poly.getLocalReprs(dividends, denominators);

0 commit comments

Comments
 (0)