Skip to content

Commit a342259

Browse files
committed
Revert "Make compatible with fraction patch"
This reverts commit 2871b0127a3cbc8d2a4cf294e731aade1ed56424.
1 parent ea5256e commit a342259

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

mlir/include/mlir/Analysis/Presburger/Fraction.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This is a simple class to represent fractions. It supports multiplication,
9+
// This is a simple class to represent fractions. It supports arithmetic,
1010
// comparison, floor, and ceiling operations.
1111
//
1212
//===----------------------------------------------------------------------===//
@@ -30,15 +30,15 @@ struct Fraction {
3030
Fraction() = default;
3131

3232
/// Construct a Fraction from a numerator and denominator.
33-
Fraction(const MPInt &oNum, const MPInt &oDen) : num(oNum), den(oDen) {
33+
Fraction(const MPInt &oNum, const MPInt &oDen = MPInt(1)) : num(oNum), den(oDen) {
3434
if (den < 0) {
3535
num = -num;
3636
den = -den;
3737
}
3838
}
3939
/// Overloads for passing literals.
40-
Fraction(const MPInt &num, int64_t den) : Fraction(num, MPInt(den)) {}
41-
Fraction(int64_t num, const MPInt &den) : Fraction(MPInt(num), den) {}
40+
Fraction(const MPInt &num, int64_t den = 1) : Fraction(num, MPInt(den)) {}
41+
Fraction(int64_t num, const MPInt &den = MPInt(1)) : Fraction(MPInt(num), den) {}
4242
Fraction(int64_t num, int64_t den) : Fraction(MPInt(num), MPInt(den)) {}
4343

4444
// Return the value of the fraction as an integer. This should only be called
@@ -48,6 +48,10 @@ struct Fraction {
4848
return num / den;
4949
}
5050

51+
llvm::raw_ostream &print(llvm::raw_ostream &os) const {
52+
return os << "(" << num << "/" << den << ")";
53+
}
54+
5155
/// The numerator and denominator, respectively. The denominator is always
5256
/// positive.
5357
MPInt num{0}, den{1};
@@ -160,6 +164,23 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Fraction &x) {
160164
return os;
161165
}
162166

167+
inline Fraction operator/(const Fraction &x, const Fraction &y) {
168+
return Fraction(x.num * y.den, x.den * y.num);
169+
}
170+
171+
inline Fraction operator+(const Fraction &x, const Fraction &y) {
172+
return Fraction(x.num * y.den + x.den * y.num, x.den * y.den);
173+
}
174+
175+
inline Fraction operator-(const Fraction &x, const Fraction &y) {
176+
return Fraction(x.num * y.den - x.den * y.num, x.den * y.den);
177+
}
178+
179+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Fraction &x) {
180+
x.print(os);
181+
return os;
182+
}
183+
163184
} // namespace presburger
164185
} // namespace mlir
165186

mlir/lib/Analysis/Presburger/Matrix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ template <typename T> void Matrix<T>::addToRow(unsigned row, ArrayRef<T> rowVec,
202202
if (scale == 0)
203203
return;
204204
for (unsigned col = 0; col < nColumns; ++col)
205-
at(row, col) += scale * rowVec[col];
205+
at(row, col) = at(row, col) + scale * rowVec[col];
206206
}
207207

208208
template <typename T> void Matrix<T>::addToColumn(unsigned sourceColumn, unsigned targetColumn,
209209
const T &scale) {
210210
if (scale == 0)
211211
return;
212212
for (unsigned row = 0, e = getNumRows(); row < e; ++row)
213-
at(row, targetColumn) += scale * at(row, sourceColumn);
213+
at(row, targetColumn) = at(row, targetColumn) + scale * at(row, sourceColumn);
214214
}
215215

216216
template <typename T> void Matrix<T>::negateColumn(unsigned column) {
@@ -237,7 +237,7 @@ template <typename T> SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T
237237
SmallVector<T, 8> result(getNumColumns(), T(0));
238238
for (unsigned col = 0, e = getNumColumns(); col < e; ++col)
239239
for (unsigned i = 0, e = getNumRows(); i < e; ++i)
240-
result[col] += rowVec[i] * at(i, col);
240+
result[col] = result[col] + rowVec[i] * at(i, col);
241241
return result;
242242
}
243243

@@ -249,7 +249,7 @@ Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
249249
SmallVector<T, 8> result(getNumRows(), T(0));
250250
for (unsigned row = 0, e = getNumRows(); row < e; row++)
251251
for (unsigned i = 0, e = getNumColumns(); i < e; i++)
252-
result[row] += at(row, i) * colVec[i];
252+
result[row] = result[row] + at(row, i) * colVec[i];
253253
return result;
254254
}
255255

0 commit comments

Comments
 (0)