Skip to content

Commit 7025ff6

Browse files
committed
[MLIR][Presburger] clang-format and clang-tidy
Fix formatting issues mostly introduced in recent commits. (This was possibly missed due to GitHub not having formatting checks at the time, but it's unclear.)
1 parent 7ef1754 commit 7025ff6

File tree

4 files changed

+108
-72
lines changed

4 files changed

+108
-72
lines changed

mlir/include/mlir/Analysis/Presburger/Matrix.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef MLIR_ANALYSIS_PRESBURGER_MATRIX_H
1616
#define MLIR_ANALYSIS_PRESBURGER_MATRIX_H
1717

18-
#include "mlir/Support/LLVM.h"
1918
#include "mlir/Analysis/Presburger/Fraction.h"
19+
#include "mlir/Support/LLVM.h"
2020
#include "llvm/ADT/ArrayRef.h"
2121
#include "llvm/Support/raw_ostream.h"
2222

@@ -36,9 +36,11 @@ namespace presburger {
3636
/// This class only works for the types MPInt and Fraction, since the method
3737
/// implementations are in the Matrix.cpp file. Only these two types have
3838
/// been explicitly instantiated there.
39-
template<typename T>
39+
template <typename T>
4040
class Matrix {
41-
static_assert(std::is_same_v<T,MPInt> || std::is_same_v<T,Fraction>, "T must be MPInt or Fraction.");
41+
static_assert(std::is_same_v<T, MPInt> || std::is_same_v<T, Fraction>,
42+
"T must be MPInt or Fraction.");
43+
4244
public:
4345
Matrix() = delete;
4446

@@ -69,9 +71,7 @@ static_assert(std::is_same_v<T,MPInt> || std::is_same_v<T,Fraction>, "T must be
6971

7072
T &operator()(unsigned row, unsigned column) { return at(row, column); }
7173

72-
T operator()(unsigned row, unsigned column) const {
73-
return at(row, column);
74-
}
74+
T operator()(unsigned row, unsigned column) const { return at(row, column); }
7575

7676
/// Swap the given columns.
7777
void swapColumns(unsigned column, unsigned otherColumn);
@@ -204,21 +204,20 @@ static_assert(std::is_same_v<T,MPInt> || std::is_same_v<T,Fraction>, "T must be
204204
// An inherited class for integer matrices, with no new data attributes.
205205
// This is only used for the matrix-related methods which apply only
206206
// to integers (hermite normal form computation and row normalisation).
207-
class IntMatrix : public Matrix<MPInt>
208-
{
207+
class IntMatrix : public Matrix<MPInt> {
209208
public:
210209
IntMatrix(unsigned rows, unsigned columns, unsigned reservedRows = 0,
211-
unsigned reservedColumns = 0) :
212-
Matrix<MPInt>(rows, columns, reservedRows, reservedColumns) {};
210+
unsigned reservedColumns = 0)
211+
: Matrix<MPInt>(rows, columns, reservedRows, reservedColumns){};
213212

214-
IntMatrix(Matrix<MPInt> m) :
215-
Matrix<MPInt>(m.getNumRows(), m.getNumColumns(), m.getNumReservedRows(), m.getNumReservedColumns())
216-
{
213+
IntMatrix(Matrix<MPInt> m)
214+
: Matrix<MPInt>(m.getNumRows(), m.getNumColumns(), m.getNumReservedRows(),
215+
m.getNumReservedColumns()) {
217216
for (unsigned i = 0; i < m.getNumRows(); i++)
218217
for (unsigned j = 0; j < m.getNumColumns(); j++)
219218
at(i, j) = m(i, j);
220219
};
221-
220+
222221
/// Return the identity matrix of the specified dimension.
223222
static IntMatrix identity(unsigned dimension);
224223

@@ -240,7 +239,6 @@ class IntMatrix : public Matrix<MPInt>
240239
/// Divide the columns of the specified row by their GCD.
241240
/// Returns the GCD of the columns of the specified row.
242241
MPInt normalizeRow(unsigned row);
243-
244242
};
245243

246244
} // namespace presburger

mlir/lib/Analysis/Presburger/Matrix.cpp

Lines changed: 86 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,70 @@
1414
using namespace mlir;
1515
using namespace presburger;
1616

17-
template <typename T> Matrix<T>::Matrix(unsigned rows, unsigned columns, unsigned reservedRows,
18-
unsigned reservedColumns)
17+
template <typename T>
18+
Matrix<T>::Matrix(unsigned rows, unsigned columns, unsigned reservedRows,
19+
unsigned reservedColumns)
1920
: nRows(rows), nColumns(columns),
2021
nReservedColumns(std::max(nColumns, reservedColumns)),
2122
data(nRows * nReservedColumns) {
2223
data.reserve(std::max(nRows, reservedRows) * nReservedColumns);
2324
}
2425

25-
template <typename T> Matrix<T> Matrix<T>::identity(unsigned dimension) {
26+
template <typename T>
27+
Matrix<T> Matrix<T>::identity(unsigned dimension) {
2628
Matrix matrix(dimension, dimension);
2729
for (unsigned i = 0; i < dimension; ++i)
2830
matrix(i, i) = 1;
2931
return matrix;
3032
}
3133

32-
template <typename T> unsigned Matrix<T>::getNumReservedRows() const {
34+
template <typename T>
35+
unsigned Matrix<T>::getNumReservedRows() const {
3336
return data.capacity() / nReservedColumns;
3437
}
3538

36-
template <typename T> void Matrix<T>::reserveRows(unsigned rows) {
39+
template <typename T>
40+
void Matrix<T>::reserveRows(unsigned rows) {
3741
data.reserve(rows * nReservedColumns);
3842
}
3943

40-
template <typename T> unsigned Matrix<T>::appendExtraRow() {
44+
template <typename T>
45+
unsigned Matrix<T>::appendExtraRow() {
4146
resizeVertically(nRows + 1);
4247
return nRows - 1;
4348
}
4449

45-
template <typename T> unsigned Matrix<T>::appendExtraRow(ArrayRef<T> elems) {
50+
template <typename T>
51+
unsigned Matrix<T>::appendExtraRow(ArrayRef<T> elems) {
4652
assert(elems.size() == nColumns && "elems must match row length!");
4753
unsigned row = appendExtraRow();
4854
for (unsigned col = 0; col < nColumns; ++col)
4955
at(row, col) = elems[col];
5056
return row;
5157
}
5258

53-
template <typename T> void Matrix<T>::resizeHorizontally(unsigned newNColumns) {
59+
template <typename T>
60+
void Matrix<T>::resizeHorizontally(unsigned newNColumns) {
5461
if (newNColumns < nColumns)
5562
removeColumns(newNColumns, nColumns - newNColumns);
5663
if (newNColumns > nColumns)
5764
insertColumns(nColumns, newNColumns - nColumns);
5865
}
5966

60-
template <typename T> void Matrix<T>::resize(unsigned newNRows, unsigned newNColumns) {
67+
template <typename T>
68+
void Matrix<T>::resize(unsigned newNRows, unsigned newNColumns) {
6169
resizeHorizontally(newNColumns);
6270
resizeVertically(newNRows);
6371
}
6472

65-
template <typename T> void Matrix<T>::resizeVertically(unsigned newNRows) {
73+
template <typename T>
74+
void Matrix<T>::resizeVertically(unsigned newNRows) {
6675
nRows = newNRows;
6776
data.resize(nRows * nReservedColumns);
6877
}
6978

70-
template <typename T> void Matrix<T>::swapRows(unsigned row, unsigned otherRow) {
79+
template <typename T>
80+
void Matrix<T>::swapRows(unsigned row, unsigned otherRow) {
7181
assert((row < getNumRows() && otherRow < getNumRows()) &&
7282
"Given row out of bounds");
7383
if (row == otherRow)
@@ -76,7 +86,8 @@ template <typename T> void Matrix<T>::swapRows(unsigned row, unsigned otherRow)
7686
std::swap(at(row, col), at(otherRow, col));
7787
}
7888

79-
template <typename T> void Matrix<T>::swapColumns(unsigned column, unsigned otherColumn) {
89+
template <typename T>
90+
void Matrix<T>::swapColumns(unsigned column, unsigned otherColumn) {
8091
assert((column < getNumColumns() && otherColumn < getNumColumns()) &&
8192
"Given column out of bounds");
8293
if (column == otherColumn)
@@ -85,23 +96,30 @@ template <typename T> void Matrix<T>::swapColumns(unsigned column, unsigned othe
8596
std::swap(at(row, column), at(row, otherColumn));
8697
}
8798

88-
template <typename T> MutableArrayRef<T> Matrix<T>::getRow(unsigned row) {
99+
template <typename T>
100+
MutableArrayRef<T> Matrix<T>::getRow(unsigned row) {
89101
return {&data[row * nReservedColumns], nColumns};
90102
}
91103

92-
template <typename T> ArrayRef<T> Matrix<T>::getRow(unsigned row) const {
104+
template <typename T>
105+
ArrayRef<T> Matrix<T>::getRow(unsigned row) const {
93106
return {&data[row * nReservedColumns], nColumns};
94107
}
95108

96-
template <typename T> void Matrix<T>::setRow(unsigned row, ArrayRef<T> elems) {
109+
template <typename T>
110+
void Matrix<T>::setRow(unsigned row, ArrayRef<T> elems) {
97111
assert(elems.size() == getNumColumns() &&
98112
"elems size must match row length!");
99113
for (unsigned i = 0, e = getNumColumns(); i < e; ++i)
100114
at(row, i) = elems[i];
101115
}
102116

103-
template <typename T> void Matrix<T>::insertColumn(unsigned pos) { insertColumns(pos, 1); }
104-
template <typename T> void Matrix<T>::insertColumns(unsigned pos, unsigned count) {
117+
template <typename T>
118+
void Matrix<T>::insertColumn(unsigned pos) {
119+
insertColumns(pos, 1);
120+
}
121+
template <typename T>
122+
void Matrix<T>::insertColumns(unsigned pos, unsigned count) {
105123
if (count == 0)
106124
return;
107125
assert(pos <= nColumns);
@@ -142,8 +160,12 @@ template <typename T> void Matrix<T>::insertColumns(unsigned pos, unsigned count
142160
}
143161
}
144162

145-
template <typename T> void Matrix<T>::removeColumn(unsigned pos) { removeColumns(pos, 1); }
146-
template <typename T> void Matrix<T>::removeColumns(unsigned pos, unsigned count) {
163+
template <typename T>
164+
void Matrix<T>::removeColumn(unsigned pos) {
165+
removeColumns(pos, 1);
166+
}
167+
template <typename T>
168+
void Matrix<T>::removeColumns(unsigned pos, unsigned count) {
147169
if (count == 0)
148170
return;
149171
assert(pos + count - 1 < nColumns);
@@ -156,8 +178,12 @@ template <typename T> void Matrix<T>::removeColumns(unsigned pos, unsigned count
156178
nColumns -= count;
157179
}
158180

159-
template <typename T> void Matrix<T>::insertRow(unsigned pos) { insertRows(pos, 1); }
160-
template <typename T> void Matrix<T>::insertRows(unsigned pos, unsigned count) {
181+
template <typename T>
182+
void Matrix<T>::insertRow(unsigned pos) {
183+
insertRows(pos, 1);
184+
}
185+
template <typename T>
186+
void Matrix<T>::insertRows(unsigned pos, unsigned count) {
161187
if (count == 0)
162188
return;
163189

@@ -170,8 +196,12 @@ template <typename T> void Matrix<T>::insertRows(unsigned pos, unsigned count) {
170196
at(r, c) = 0;
171197
}
172198

173-
template <typename T> void Matrix<T>::removeRow(unsigned pos) { removeRows(pos, 1); }
174-
template <typename T> void Matrix<T>::removeRows(unsigned pos, unsigned count) {
199+
template <typename T>
200+
void Matrix<T>::removeRow(unsigned pos) {
201+
removeRows(pos, 1);
202+
}
203+
template <typename T>
204+
void Matrix<T>::removeRows(unsigned pos, unsigned count) {
175205
if (count == 0)
176206
return;
177207
assert(pos + count - 1 <= nRows);
@@ -180,50 +210,57 @@ template <typename T> void Matrix<T>::removeRows(unsigned pos, unsigned count) {
180210
resizeVertically(nRows - count);
181211
}
182212

183-
template <typename T> void Matrix<T>::copyRow(unsigned sourceRow, unsigned targetRow) {
213+
template <typename T>
214+
void Matrix<T>::copyRow(unsigned sourceRow, unsigned targetRow) {
184215
if (sourceRow == targetRow)
185216
return;
186217
for (unsigned c = 0; c < nColumns; ++c)
187218
at(targetRow, c) = at(sourceRow, c);
188219
}
189220

190-
template <typename T> void Matrix<T>::fillRow(unsigned row, const T &value) {
221+
template <typename T>
222+
void Matrix<T>::fillRow(unsigned row, const T &value) {
191223
for (unsigned col = 0; col < nColumns; ++col)
192224
at(row, col) = value;
193225
}
194226

195-
template <typename T> void Matrix<T>::addToRow(unsigned sourceRow, unsigned targetRow,
196-
const T &scale) {
227+
template <typename T>
228+
void Matrix<T>::addToRow(unsigned sourceRow, unsigned targetRow,
229+
const T &scale) {
197230
addToRow(targetRow, getRow(sourceRow), scale);
198231
}
199232

200-
template <typename T> void Matrix<T>::addToRow(unsigned row, ArrayRef<T> rowVec,
201-
const T &scale) {
233+
template <typename T>
234+
void Matrix<T>::addToRow(unsigned row, ArrayRef<T> rowVec, const T &scale) {
202235
if (scale == 0)
203236
return;
204237
for (unsigned col = 0; col < nColumns; ++col)
205238
at(row, col) += scale * rowVec[col];
206239
}
207240

208-
template <typename T> void Matrix<T>::addToColumn(unsigned sourceColumn, unsigned targetColumn,
209-
const T &scale) {
241+
template <typename T>
242+
void Matrix<T>::addToColumn(unsigned sourceColumn, unsigned targetColumn,
243+
const T &scale) {
210244
if (scale == 0)
211245
return;
212246
for (unsigned row = 0, e = getNumRows(); row < e; ++row)
213247
at(row, targetColumn) += scale * at(row, sourceColumn);
214248
}
215249

216-
template <typename T> void Matrix<T>::negateColumn(unsigned column) {
250+
template <typename T>
251+
void Matrix<T>::negateColumn(unsigned column) {
217252
for (unsigned row = 0, e = getNumRows(); row < e; ++row)
218253
at(row, column) = -at(row, column);
219254
}
220255

221-
template <typename T> void Matrix<T>::negateRow(unsigned row) {
256+
template <typename T>
257+
void Matrix<T>::negateRow(unsigned row) {
222258
for (unsigned column = 0, e = getNumColumns(); column < e; ++column)
223259
at(row, column) = -at(row, column);
224260
}
225261

226-
template <typename T> SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T> rowVec) const {
262+
template <typename T>
263+
SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T> rowVec) const {
227264
assert(rowVec.size() == getNumRows() && "Invalid row vector dimension!");
228265

229266
SmallVector<T, 8> result(getNumColumns(), T(0));
@@ -233,8 +270,8 @@ template <typename T> SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T
233270
return result;
234271
}
235272

236-
template <typename T> SmallVector<T, 8>
237-
Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
273+
template <typename T>
274+
SmallVector<T, 8> Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
238275
assert(getNumColumns() == colVec.size() &&
239276
"Invalid column vector dimension!");
240277

@@ -250,26 +287,32 @@ Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
250287
/// sourceCol. This brings M(row, targetCol) to the range [0, M(row,
251288
/// sourceCol)). Apply the same column operation to otherMatrix, with the same
252289
/// integer multiple.
253-
static void modEntryColumnOperation(Matrix<MPInt> &m, unsigned row, unsigned sourceCol,
254-
unsigned targetCol, Matrix<MPInt> &otherMatrix) {
290+
static void modEntryColumnOperation(Matrix<MPInt> &m, unsigned row,
291+
unsigned sourceCol, unsigned targetCol,
292+
Matrix<MPInt> &otherMatrix) {
255293
assert(m(row, sourceCol) != 0 && "Cannot divide by zero!");
256294
assert(m(row, sourceCol) > 0 && "Source must be positive!");
257295
MPInt ratio = -floorDiv(m(row, targetCol), m(row, sourceCol));
258296
m.addToColumn(sourceCol, targetCol, ratio);
259297
otherMatrix.addToColumn(sourceCol, targetCol, ratio);
260298
}
261299

262-
template <typename T> void Matrix<T>::print(raw_ostream &os) const {
300+
template <typename T>
301+
void Matrix<T>::print(raw_ostream &os) const {
263302
for (unsigned row = 0; row < nRows; ++row) {
264303
for (unsigned column = 0; column < nColumns; ++column)
265304
os << at(row, column) << ' ';
266305
os << '\n';
267306
}
268307
}
269308

270-
template <typename T> void Matrix<T>::dump() const { print(llvm::errs()); }
309+
template <typename T>
310+
void Matrix<T>::dump() const {
311+
print(llvm::errs());
312+
}
271313

272-
template <typename T> bool Matrix<T>::hasConsistentState() const {
314+
template <typename T>
315+
bool Matrix<T>::hasConsistentState() const {
273316
if (data.size() != nRows * nReservedColumns)
274317
return false;
275318
if (nColumns > nReservedColumns)
@@ -287,8 +330,8 @@ namespace mlir {
287330
namespace presburger {
288331
template class Matrix<MPInt>;
289332
template class Matrix<Fraction>;
290-
}
291-
}
333+
} // namespace presburger
334+
} // namespace mlir
292335

293336
IntMatrix IntMatrix::identity(unsigned dimension) {
294337
IntMatrix matrix(dimension, dimension);
@@ -297,7 +340,6 @@ IntMatrix IntMatrix::identity(unsigned dimension) {
297340
return matrix;
298341
}
299342

300-
301343
std::pair<IntMatrix, IntMatrix> IntMatrix::computeHermiteNormalForm() const {
302344
// We start with u as an identity matrix and perform operations on h until h
303345
// is in hermite normal form. We apply the same sequence of operations on u to

0 commit comments

Comments
 (0)