[Mlir-commits] [mlir] 7025ff6 - [MLIR][Presburger] clang-format and clang-tidy
Arjun P
llvmlistbot at llvm.org
Fri Oct 13 03:43:18 PDT 2023
Author: Arjun P
Date: 2023-10-13T11:41:51+01:00
New Revision: 7025ff6fa3dfe2ce8d3d7fcb0ec9de9a357d2c6f
URL: https://github.com/llvm/llvm-project/commit/7025ff6fa3dfe2ce8d3d7fcb0ec9de9a357d2c6f
DIFF: https://github.com/llvm/llvm-project/commit/7025ff6fa3dfe2ce8d3d7fcb0ec9de9a357d2c6f.diff
LOG: [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.)
Added:
Modified:
mlir/include/mlir/Analysis/Presburger/Matrix.h
mlir/lib/Analysis/Presburger/Matrix.cpp
mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
mlir/lib/Analysis/Presburger/Utils.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Analysis/Presburger/Matrix.h b/mlir/include/mlir/Analysis/Presburger/Matrix.h
index bed3a5f75e396c5..29f8b7d2b304e93 100644
--- a/mlir/include/mlir/Analysis/Presburger/Matrix.h
+++ b/mlir/include/mlir/Analysis/Presburger/Matrix.h
@@ -15,8 +15,8 @@
#ifndef MLIR_ANALYSIS_PRESBURGER_MATRIX_H
#define MLIR_ANALYSIS_PRESBURGER_MATRIX_H
-#include "mlir/Support/LLVM.h"
#include "mlir/Analysis/Presburger/Fraction.h"
+#include "mlir/Support/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/raw_ostream.h"
@@ -36,9 +36,11 @@ namespace presburger {
/// This class only works for the types MPInt and Fraction, since the method
/// implementations are in the Matrix.cpp file. Only these two types have
/// been explicitly instantiated there.
-template<typename T>
+template <typename T>
class Matrix {
-static_assert(std::is_same_v<T,MPInt> || std::is_same_v<T,Fraction>, "T must be MPInt or Fraction.");
+ static_assert(std::is_same_v<T, MPInt> || std::is_same_v<T, Fraction>,
+ "T must be MPInt or Fraction.");
+
public:
Matrix() = delete;
@@ -69,9 +71,7 @@ static_assert(std::is_same_v<T,MPInt> || std::is_same_v<T,Fraction>, "T must be
T &operator()(unsigned row, unsigned column) { return at(row, column); }
- T operator()(unsigned row, unsigned column) const {
- return at(row, column);
- }
+ T operator()(unsigned row, unsigned column) const { return at(row, column); }
/// Swap the given columns.
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
// An inherited class for integer matrices, with no new data attributes.
// This is only used for the matrix-related methods which apply only
// to integers (hermite normal form computation and row normalisation).
-class IntMatrix : public Matrix<MPInt>
-{
+class IntMatrix : public Matrix<MPInt> {
public:
IntMatrix(unsigned rows, unsigned columns, unsigned reservedRows = 0,
- unsigned reservedColumns = 0) :
- Matrix<MPInt>(rows, columns, reservedRows, reservedColumns) {};
+ unsigned reservedColumns = 0)
+ : Matrix<MPInt>(rows, columns, reservedRows, reservedColumns){};
- IntMatrix(Matrix<MPInt> m) :
- Matrix<MPInt>(m.getNumRows(), m.getNumColumns(), m.getNumReservedRows(), m.getNumReservedColumns())
- {
+ IntMatrix(Matrix<MPInt> m)
+ : Matrix<MPInt>(m.getNumRows(), m.getNumColumns(), m.getNumReservedRows(),
+ m.getNumReservedColumns()) {
for (unsigned i = 0; i < m.getNumRows(); i++)
for (unsigned j = 0; j < m.getNumColumns(); j++)
at(i, j) = m(i, j);
};
-
+
/// Return the identity matrix of the specified dimension.
static IntMatrix identity(unsigned dimension);
@@ -240,7 +239,6 @@ class IntMatrix : public Matrix<MPInt>
/// Divide the columns of the specified row by their GCD.
/// Returns the GCD of the columns of the specified row.
MPInt normalizeRow(unsigned row);
-
};
} // namespace presburger
diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index f0bcb09fb28f7b1..ce6253e0bda93a2 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -14,35 +14,41 @@
using namespace mlir;
using namespace presburger;
-template <typename T> Matrix<T>::Matrix(unsigned rows, unsigned columns, unsigned reservedRows,
- unsigned reservedColumns)
+template <typename T>
+Matrix<T>::Matrix(unsigned rows, unsigned columns, unsigned reservedRows,
+ unsigned reservedColumns)
: nRows(rows), nColumns(columns),
nReservedColumns(std::max(nColumns, reservedColumns)),
data(nRows * nReservedColumns) {
data.reserve(std::max(nRows, reservedRows) * nReservedColumns);
}
-template <typename T> Matrix<T> Matrix<T>::identity(unsigned dimension) {
+template <typename T>
+Matrix<T> Matrix<T>::identity(unsigned dimension) {
Matrix matrix(dimension, dimension);
for (unsigned i = 0; i < dimension; ++i)
matrix(i, i) = 1;
return matrix;
}
-template <typename T> unsigned Matrix<T>::getNumReservedRows() const {
+template <typename T>
+unsigned Matrix<T>::getNumReservedRows() const {
return data.capacity() / nReservedColumns;
}
-template <typename T> void Matrix<T>::reserveRows(unsigned rows) {
+template <typename T>
+void Matrix<T>::reserveRows(unsigned rows) {
data.reserve(rows * nReservedColumns);
}
-template <typename T> unsigned Matrix<T>::appendExtraRow() {
+template <typename T>
+unsigned Matrix<T>::appendExtraRow() {
resizeVertically(nRows + 1);
return nRows - 1;
}
-template <typename T> unsigned Matrix<T>::appendExtraRow(ArrayRef<T> elems) {
+template <typename T>
+unsigned Matrix<T>::appendExtraRow(ArrayRef<T> elems) {
assert(elems.size() == nColumns && "elems must match row length!");
unsigned row = appendExtraRow();
for (unsigned col = 0; col < nColumns; ++col)
@@ -50,24 +56,28 @@ template <typename T> unsigned Matrix<T>::appendExtraRow(ArrayRef<T> elems) {
return row;
}
-template <typename T> void Matrix<T>::resizeHorizontally(unsigned newNColumns) {
+template <typename T>
+void Matrix<T>::resizeHorizontally(unsigned newNColumns) {
if (newNColumns < nColumns)
removeColumns(newNColumns, nColumns - newNColumns);
if (newNColumns > nColumns)
insertColumns(nColumns, newNColumns - nColumns);
}
-template <typename T> void Matrix<T>::resize(unsigned newNRows, unsigned newNColumns) {
+template <typename T>
+void Matrix<T>::resize(unsigned newNRows, unsigned newNColumns) {
resizeHorizontally(newNColumns);
resizeVertically(newNRows);
}
-template <typename T> void Matrix<T>::resizeVertically(unsigned newNRows) {
+template <typename T>
+void Matrix<T>::resizeVertically(unsigned newNRows) {
nRows = newNRows;
data.resize(nRows * nReservedColumns);
}
-template <typename T> void Matrix<T>::swapRows(unsigned row, unsigned otherRow) {
+template <typename T>
+void Matrix<T>::swapRows(unsigned row, unsigned otherRow) {
assert((row < getNumRows() && otherRow < getNumRows()) &&
"Given row out of bounds");
if (row == otherRow)
@@ -76,7 +86,8 @@ template <typename T> void Matrix<T>::swapRows(unsigned row, unsigned otherRow)
std::swap(at(row, col), at(otherRow, col));
}
-template <typename T> void Matrix<T>::swapColumns(unsigned column, unsigned otherColumn) {
+template <typename T>
+void Matrix<T>::swapColumns(unsigned column, unsigned otherColumn) {
assert((column < getNumColumns() && otherColumn < getNumColumns()) &&
"Given column out of bounds");
if (column == otherColumn)
@@ -85,23 +96,30 @@ template <typename T> void Matrix<T>::swapColumns(unsigned column, unsigned othe
std::swap(at(row, column), at(row, otherColumn));
}
-template <typename T> MutableArrayRef<T> Matrix<T>::getRow(unsigned row) {
+template <typename T>
+MutableArrayRef<T> Matrix<T>::getRow(unsigned row) {
return {&data[row * nReservedColumns], nColumns};
}
-template <typename T> ArrayRef<T> Matrix<T>::getRow(unsigned row) const {
+template <typename T>
+ArrayRef<T> Matrix<T>::getRow(unsigned row) const {
return {&data[row * nReservedColumns], nColumns};
}
-template <typename T> void Matrix<T>::setRow(unsigned row, ArrayRef<T> elems) {
+template <typename T>
+void Matrix<T>::setRow(unsigned row, ArrayRef<T> elems) {
assert(elems.size() == getNumColumns() &&
"elems size must match row length!");
for (unsigned i = 0, e = getNumColumns(); i < e; ++i)
at(row, i) = elems[i];
}
-template <typename T> void Matrix<T>::insertColumn(unsigned pos) { insertColumns(pos, 1); }
-template <typename T> void Matrix<T>::insertColumns(unsigned pos, unsigned count) {
+template <typename T>
+void Matrix<T>::insertColumn(unsigned pos) {
+ insertColumns(pos, 1);
+}
+template <typename T>
+void Matrix<T>::insertColumns(unsigned pos, unsigned count) {
if (count == 0)
return;
assert(pos <= nColumns);
@@ -142,8 +160,12 @@ template <typename T> void Matrix<T>::insertColumns(unsigned pos, unsigned count
}
}
-template <typename T> void Matrix<T>::removeColumn(unsigned pos) { removeColumns(pos, 1); }
-template <typename T> void Matrix<T>::removeColumns(unsigned pos, unsigned count) {
+template <typename T>
+void Matrix<T>::removeColumn(unsigned pos) {
+ removeColumns(pos, 1);
+}
+template <typename T>
+void Matrix<T>::removeColumns(unsigned pos, unsigned count) {
if (count == 0)
return;
assert(pos + count - 1 < nColumns);
@@ -156,8 +178,12 @@ template <typename T> void Matrix<T>::removeColumns(unsigned pos, unsigned count
nColumns -= count;
}
-template <typename T> void Matrix<T>::insertRow(unsigned pos) { insertRows(pos, 1); }
-template <typename T> void Matrix<T>::insertRows(unsigned pos, unsigned count) {
+template <typename T>
+void Matrix<T>::insertRow(unsigned pos) {
+ insertRows(pos, 1);
+}
+template <typename T>
+void Matrix<T>::insertRows(unsigned pos, unsigned count) {
if (count == 0)
return;
@@ -170,8 +196,12 @@ template <typename T> void Matrix<T>::insertRows(unsigned pos, unsigned count) {
at(r, c) = 0;
}
-template <typename T> void Matrix<T>::removeRow(unsigned pos) { removeRows(pos, 1); }
-template <typename T> void Matrix<T>::removeRows(unsigned pos, unsigned count) {
+template <typename T>
+void Matrix<T>::removeRow(unsigned pos) {
+ removeRows(pos, 1);
+}
+template <typename T>
+void Matrix<T>::removeRows(unsigned pos, unsigned count) {
if (count == 0)
return;
assert(pos + count - 1 <= nRows);
@@ -180,50 +210,57 @@ template <typename T> void Matrix<T>::removeRows(unsigned pos, unsigned count) {
resizeVertically(nRows - count);
}
-template <typename T> void Matrix<T>::copyRow(unsigned sourceRow, unsigned targetRow) {
+template <typename T>
+void Matrix<T>::copyRow(unsigned sourceRow, unsigned targetRow) {
if (sourceRow == targetRow)
return;
for (unsigned c = 0; c < nColumns; ++c)
at(targetRow, c) = at(sourceRow, c);
}
-template <typename T> void Matrix<T>::fillRow(unsigned row, const T &value) {
+template <typename T>
+void Matrix<T>::fillRow(unsigned row, const T &value) {
for (unsigned col = 0; col < nColumns; ++col)
at(row, col) = value;
}
-template <typename T> void Matrix<T>::addToRow(unsigned sourceRow, unsigned targetRow,
- const T &scale) {
+template <typename T>
+void Matrix<T>::addToRow(unsigned sourceRow, unsigned targetRow,
+ const T &scale) {
addToRow(targetRow, getRow(sourceRow), scale);
}
-template <typename T> void Matrix<T>::addToRow(unsigned row, ArrayRef<T> rowVec,
- const T &scale) {
+template <typename T>
+void Matrix<T>::addToRow(unsigned row, ArrayRef<T> rowVec, const T &scale) {
if (scale == 0)
return;
for (unsigned col = 0; col < nColumns; ++col)
at(row, col) += scale * rowVec[col];
}
-template <typename T> void Matrix<T>::addToColumn(unsigned sourceColumn, unsigned targetColumn,
- const T &scale) {
+template <typename T>
+void Matrix<T>::addToColumn(unsigned sourceColumn, unsigned targetColumn,
+ const T &scale) {
if (scale == 0)
return;
for (unsigned row = 0, e = getNumRows(); row < e; ++row)
at(row, targetColumn) += scale * at(row, sourceColumn);
}
-template <typename T> void Matrix<T>::negateColumn(unsigned column) {
+template <typename T>
+void Matrix<T>::negateColumn(unsigned column) {
for (unsigned row = 0, e = getNumRows(); row < e; ++row)
at(row, column) = -at(row, column);
}
-template <typename T> void Matrix<T>::negateRow(unsigned row) {
+template <typename T>
+void Matrix<T>::negateRow(unsigned row) {
for (unsigned column = 0, e = getNumColumns(); column < e; ++column)
at(row, column) = -at(row, column);
}
-template <typename T> SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T> rowVec) const {
+template <typename T>
+SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T> rowVec) const {
assert(rowVec.size() == getNumRows() && "Invalid row vector dimension!");
SmallVector<T, 8> result(getNumColumns(), T(0));
@@ -233,8 +270,8 @@ template <typename T> SmallVector<T, 8> Matrix<T>::preMultiplyWithRow(ArrayRef<T
return result;
}
-template <typename T> SmallVector<T, 8>
-Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
+template <typename T>
+SmallVector<T, 8> Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
assert(getNumColumns() == colVec.size() &&
"Invalid column vector dimension!");
@@ -250,8 +287,9 @@ Matrix<T>::postMultiplyWithColumn(ArrayRef<T> colVec) const {
/// sourceCol. This brings M(row, targetCol) to the range [0, M(row,
/// sourceCol)). Apply the same column operation to otherMatrix, with the same
/// integer multiple.
-static void modEntryColumnOperation(Matrix<MPInt> &m, unsigned row, unsigned sourceCol,
- unsigned targetCol, Matrix<MPInt> &otherMatrix) {
+static void modEntryColumnOperation(Matrix<MPInt> &m, unsigned row,
+ unsigned sourceCol, unsigned targetCol,
+ Matrix<MPInt> &otherMatrix) {
assert(m(row, sourceCol) != 0 && "Cannot divide by zero!");
assert(m(row, sourceCol) > 0 && "Source must be positive!");
MPInt ratio = -floorDiv(m(row, targetCol), m(row, sourceCol));
@@ -259,7 +297,8 @@ static void modEntryColumnOperation(Matrix<MPInt> &m, unsigned row, unsigned sou
otherMatrix.addToColumn(sourceCol, targetCol, ratio);
}
-template <typename T> void Matrix<T>::print(raw_ostream &os) const {
+template <typename T>
+void Matrix<T>::print(raw_ostream &os) const {
for (unsigned row = 0; row < nRows; ++row) {
for (unsigned column = 0; column < nColumns; ++column)
os << at(row, column) << ' ';
@@ -267,9 +306,13 @@ template <typename T> void Matrix<T>::print(raw_ostream &os) const {
}
}
-template <typename T> void Matrix<T>::dump() const { print(llvm::errs()); }
+template <typename T>
+void Matrix<T>::dump() const {
+ print(llvm::errs());
+}
-template <typename T> bool Matrix<T>::hasConsistentState() const {
+template <typename T>
+bool Matrix<T>::hasConsistentState() const {
if (data.size() != nRows * nReservedColumns)
return false;
if (nColumns > nReservedColumns)
@@ -287,8 +330,8 @@ namespace mlir {
namespace presburger {
template class Matrix<MPInt>;
template class Matrix<Fraction>;
-}
-}
+} // namespace presburger
+} // namespace mlir
IntMatrix IntMatrix::identity(unsigned dimension) {
IntMatrix matrix(dimension, dimension);
@@ -297,7 +340,6 @@ IntMatrix IntMatrix::identity(unsigned dimension) {
return matrix;
}
-
std::pair<IntMatrix, IntMatrix> IntMatrix::computeHermiteNormalForm() const {
// We start with u as an identity matrix and perform operations on h until h
// is in hermite normal form. We apply the same sequence of operations on u to
diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
index 0b3f6a39128858e..5a9cf71fc86793f 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
@@ -43,7 +43,7 @@ void PresburgerRelation::convertVarKind(VarKind srcKind, unsigned srcPos,
unsigned num, VarKind dstKind,
unsigned dstPos) {
assert(srcKind != VarKind::Local && dstKind != VarKind::Local &&
- "srcKind/dstKind cannot be local");
+ "srcKind/dstKind cannot be local");
assert(srcKind != dstKind && "cannot convert variables to the same kind");
assert(srcPos + num <= space.getNumVarKind(srcKind) &&
"invalid range for source variables");
@@ -636,17 +636,13 @@ bool PresburgerRelation::isPlainEqual(const PresburgerRelation &set) const {
/// one unconstrained disjunct, indicating the absence of constraints or
/// conditions.
bool PresburgerRelation::isPlainUniverse() const {
- for (auto &disjunct : getAllDisjuncts()) {
- if (disjunct.getNumConstraints() == 0)
- return true;
- }
- return false;
+ return llvm::any_of(getAllDisjuncts(), [](const IntegerRelation &disjunct) {
+ return disjunct.getNumConstraints() == 0;
+ });
}
bool PresburgerRelation::isConvexNoLocals() const {
- if (getNumDisjuncts() == 1 && getSpace().getNumLocalVars() == 0)
- return true;
- return false;
+ return getNumDisjuncts() == 1 && getSpace().getNumLocalVars() == 0;
}
/// Return true if there is no disjunct, false otherwise.
@@ -823,8 +819,8 @@ PresburgerRelation SetCoalescer::coalesce() {
}
PresburgerRelation newSet = PresburgerRelation::getEmpty(space);
- for (unsigned i = 0, e = disjuncts.size(); i < e; ++i)
- newSet.unionInPlace(disjuncts[i]);
+ for (const IntegerRelation &disjunct : disjuncts)
+ newSet.unionInPlace(disjunct);
return newSet;
}
diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index e7fd2843b93a372..9aef2f5de109357 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -502,8 +502,8 @@ void DivisionRepr::print(raw_ostream &os) const {
os << "Dividends:\n";
dividends.print(os);
os << "Denominators\n";
- for (unsigned i = 0, e = denoms.size(); i < e; ++i)
- os << denoms[i] << " ";
+ for (const MPInt &denom : denoms)
+ os << denom << " ";
os << "\n";
}
More information about the Mlir-commits
mailing list