[MLIR][Presburger] Move Matrix accessors inline
authorArjun P <arjunpitchanathan@gmail.com>
Tue, 31 May 2022 16:48:05 +0000 (17:48 +0100)
committerArjun P <arjunpitchanathan@gmail.com>
Wed, 1 Jun 2022 15:51:42 +0000 (16:51 +0100)
This gives a 1.5x speedup on the Presburger unittests.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D126708

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

index 4940195..9973beb 100644 (file)
@@ -48,10 +48,23 @@ public:
   static Matrix identity(unsigned dimension);
 
   /// Access the element at the specified row and column.
-  int64_t &at(unsigned row, unsigned column);
-  int64_t at(unsigned row, unsigned column) const;
-  int64_t &operator()(unsigned row, unsigned column);
-  int64_t operator()(unsigned row, unsigned column) const;
+  int64_t &at(unsigned row, unsigned column) {
+    assert(row < nRows && "Row outside of range");
+    assert(column < nColumns && "Column outside of range");
+    return data[row * nReservedColumns + column];
+  }
+
+  int64_t at(unsigned row, unsigned column) const {
+    assert(row < nRows && "Row outside of range");
+    assert(column < nColumns && "Column outside of range");
+    return data[row * nReservedColumns + column];
+  }
+
+  int64_t &operator()(unsigned row, unsigned column) { return at(row, column); }
+
+  int64_t operator()(unsigned row, unsigned column) const {
+    return at(row, column);
+  }
 
   /// Swap the given columns.
   void swapColumns(unsigned column, unsigned otherColumn);
index 7686cff..672b30b 100644 (file)
@@ -28,26 +28,6 @@ Matrix Matrix::identity(unsigned dimension) {
   return matrix;
 }
 
-int64_t &Matrix::at(unsigned row, unsigned column) {
-  assert(row < nRows && "Row outside of range");
-  assert(column < nColumns && "Column outside of range");
-  return data[row * nReservedColumns + column];
-}
-
-int64_t Matrix::at(unsigned row, unsigned column) const {
-  assert(row < nRows && "Row outside of range");
-  assert(column < nColumns && "Column outside of range");
-  return data[row * nReservedColumns + column];
-}
-
-int64_t &Matrix::operator()(unsigned row, unsigned column) {
-  return at(row, column);
-}
-
-int64_t Matrix::operator()(unsigned row, unsigned column) const {
-  return at(row, column);
-}
-
 unsigned Matrix::getNumRows() const { return nRows; }
 
 unsigned Matrix::getNumColumns() const { return nColumns; }