Skip to content

Commit

Permalink
[MLIR][Presburger] Move Matrix accessors inline
Browse files Browse the repository at this point in the history
This gives a 1.5x speedup on the Presburger unittests.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D126708
  • Loading branch information
Superty committed Jun 1, 2022
1 parent 04a3146 commit d5e31cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
21 changes: 17 additions & 4 deletions mlir/include/mlir/Analysis/Presburger/Matrix.h
Expand Up @@ -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);
Expand Down
20 changes: 0 additions & 20 deletions mlir/lib/Analysis/Presburger/Matrix.cpp
Expand Up @@ -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; }
Expand Down

0 comments on commit d5e31cf

Please sign in to comment.