[Mlir-commits] [mlir] [MLIR][Presburger] Preserve identifiers in IntegerRelation::convertVa… (PR #67909)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Oct 20 10:00:02 PDT 2023


github-actions[bot] wrote:


<!--LLVM CODE FORMAT COMMENT: {clang-format}-->

:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff bde2e6981e7848658e91c7282abf387643054b6a 916786b01f6afc373dedfe50ca0aa30817ac7336 -- mlir/include/mlir/Analysis/Presburger/Matrix.h mlir/lib/Analysis/Presburger/IntegerRelation.cpp mlir/lib/Analysis/Presburger/Matrix.cpp mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp mlir/unittests/Analysis/Presburger/MatrixTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/include/mlir/Analysis/Presburger/Matrix.h b/mlir/include/mlir/Analysis/Presburger/Matrix.h
index ed69ece12729..4618366bde38 100644
--- a/mlir/include/mlir/Analysis/Presburger/Matrix.h
+++ b/mlir/include/mlir/Analysis/Presburger/Matrix.h
@@ -36,7 +36,8 @@ 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> class Matrix {
+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.");
 
diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 3aafe5adb5ac..0648debe8aa8 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,28 +210,31 @@ 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>::moveColumns(unsigned srcPos, unsigned num, unsigned dstPos) {
-  if(num == 0)
+template <typename T>
+void Matrix<T>::moveColumns(unsigned srcPos, unsigned num, unsigned dstPos) {
+  if (num == 0)
     return;
 
   int offset = dstPos - srcPos;
-  if(offset == 0)
+  if (offset == 0)
     return;
 
   assert(0 <= srcPos + offset && srcPos + num + offset <= getNumColumns() &&
-      "invalid move num");
+         "invalid move num");
 
   unsigned insertCount = offset > 0 ? offset : -offset;
   unsigned insertPos = offset > 0 ? srcPos : srcPos + num;
@@ -211,7 +244,7 @@ template <typename T> void Matrix<T>::moveColumns(unsigned srcPos, unsigned num,
   // be moved.
   insertColumns(insertPos, insertCount);
   // Update deletePos if insertion of new columns invalidates it.
-  if(insertPos < deletePos)
+  if (insertPos < deletePos)
     deletePos += insertCount;
 
   // Swap the adjacent columns with inserted zero columns.
@@ -222,38 +255,43 @@ template <typename T> void Matrix<T>::moveColumns(unsigned srcPos, unsigned num,
   removeColumns(deletePos, insertCount);
 }
 
-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));
@@ -263,8 +301,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!");
 
@@ -280,8 +318,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));
@@ -289,7 +328,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) << ' ';
@@ -297,9 +337,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)
@@ -317,8 +361,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);
@@ -327,7 +371,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

``````````

</details>


https://github.com/llvm/llvm-project/pull/67909


More information about the Mlir-commits mailing list