[Mlir-commits] [mlir] d5e31cf - [MLIR][Presburger] Move Matrix accessors inline

Arjun P llvmlistbot at llvm.org
Wed Jun 1 08:51:47 PDT 2022


Author: Arjun P
Date: 2022-06-01T16:51:42+01:00
New Revision: d5e31cf38adfc2c240fb9717989792537cc9e819

URL: https://github.com/llvm/llvm-project/commit/d5e31cf38adfc2c240fb9717989792537cc9e819
DIFF: https://github.com/llvm/llvm-project/commit/d5e31cf38adfc2c240fb9717989792537cc9e819.diff

LOG: [MLIR][Presburger] Move Matrix accessors inline

This gives a 1.5x speedup on the Presburger unittests.

Reviewed By: Groverkss

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/Matrix.h b/mlir/include/mlir/Analysis/Presburger/Matrix.h
index 494019511f11a..9973beb1368b2 100644
--- a/mlir/include/mlir/Analysis/Presburger/Matrix.h
+++ b/mlir/include/mlir/Analysis/Presburger/Matrix.h
@@ -48,10 +48,23 @@ class Matrix {
   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);

diff  --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 7686cffb852d0..672b30b6cb36c 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -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; }


        


More information about the Mlir-commits mailing list