14 #ifndef MLIR_ANALYSIS_PRESBURGER_MATRIX_H
15 #define MLIR_ANALYSIS_PRESBURGER_MATRIX_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/Support/raw_ostream.h"
25 namespace presburger {
45 Matrix(
unsigned rows,
unsigned columns,
unsigned reservedRows = 0,
46 unsigned reservedColumns = 0);
52 MPInt &
at(
unsigned row,
unsigned column) {
53 assert(row < nRows &&
"Row outside of range");
54 assert(column < nColumns &&
"Column outside of range");
55 return data[row * nReservedColumns + column];
58 MPInt at(
unsigned row,
unsigned column)
const {
59 assert(row < nRows &&
"Row outside of range");
60 assert(column < nColumns &&
"Column outside of range");
61 return data[row * nReservedColumns + column];
67 return at(row, column);
71 void swapColumns(
unsigned column,
unsigned otherColumn);
74 void swapRows(
unsigned row,
unsigned otherRow);
107 void insertRows(
unsigned pos,
unsigned count);
123 void removeRows(
unsigned pos,
unsigned count);
126 void copyRow(
unsigned sourceRow,
unsigned targetRow);
132 void addToRow(
unsigned sourceRow,
unsigned targetRow,
const MPInt &scale);
133 void addToRow(
unsigned sourceRow,
unsigned targetRow, int64_t scale) {
140 void addToColumn(
unsigned sourceColumn,
unsigned targetColumn,
187 void resize(
unsigned newNRows,
unsigned newNColumns);
198 void print(raw_ostream &os)
const;
210 unsigned nRows, nColumns, nReservedColumns;
This class provides support for multi-precision arithmetic.
This is a class to represent a resizable matrix.
void addToColumn(unsigned sourceColumn, unsigned targetColumn, int64_t scale)
bool hasConsistentState() const
Return whether the Matrix is in a consistent state with all its invariants satisfied.
void insertRows(unsigned pos, unsigned count)
Insert rows having positions pos, pos + 1, ...
void swapColumns(unsigned column, unsigned otherColumn)
Swap the given columns.
MPInt & operator()(unsigned row, unsigned column)
void removeColumn(unsigned pos)
unsigned appendExtraRow()
Add an extra row at the bottom of the matrix and return its position.
unsigned getNumReservedColumns() const
void print(raw_ostream &os) const
Print the matrix.
void copyRow(unsigned sourceRow, unsigned targetRow)
void addToRow(unsigned sourceRow, unsigned targetRow, int64_t scale)
void insertColumn(unsigned pos)
SmallVector< MPInt, 8 > postMultiplyWithColumn(ArrayRef< MPInt > colVec) const
The given vector is interpreted as a column vector v.
static Matrix identity(unsigned dimension)
Return the identity matrix of the specified dimension.
void removeColumns(unsigned pos, unsigned count)
Remove the columns having positions pos, pos + 1, ...
void insertColumns(unsigned pos, unsigned count)
Insert columns having positions pos, pos + 1, ...
MPInt normalizeRow(unsigned row, unsigned nCols)
Divide the first nCols of the specified row by their GCD.
MPInt & at(unsigned row, unsigned column)
Access the element at the specified row and column.
SmallVector< MPInt, 8 > preMultiplyWithRow(ArrayRef< MPInt > rowVec) const
The given vector is interpreted as a row vector v.
void removeRow(unsigned pos)
MPInt operator()(unsigned row, unsigned column) const
void resizeVertically(unsigned newNRows)
void setRow(unsigned row, ArrayRef< MPInt > elems)
Set the specified row to elems.
unsigned getNumReservedRows() const
Return the maximum number of rows/columns that can be added without incurring a reallocation.
unsigned getNumColumns() const
void fillRow(unsigned row, int64_t value)
void fillRow(unsigned row, const MPInt &value)
unsigned getNumRows() const
void addToColumn(unsigned sourceColumn, unsigned targetColumn, const MPInt &scale)
Add scale multiples of the source column to the target column.
void insertRow(unsigned pos)
MPInt at(unsigned row, unsigned column) const
void swapRows(unsigned row, unsigned otherRow)
Swap the given rows.
void resizeHorizontally(unsigned newNColumns)
void addToRow(unsigned sourceRow, unsigned targetRow, const MPInt &scale)
Add scale multiples of the source row to the target row.
std::pair< Matrix, Matrix > computeHermiteNormalForm() const
Given the current matrix M, returns the matrices H, U such that H is the column hermite normal form o...
void reserveRows(unsigned rows)
Reserve enough space to resize to the specified number of rows without reallocations.
void negateColumn(unsigned column)
Negate the specified column.
void resize(unsigned newNRows, unsigned newNColumns)
Resize the matrix to the specified dimensions.
MutableArrayRef< MPInt > getRow(unsigned row)
Get a [Mutable]ArrayRef corresponding to the specified row.
void negateRow(unsigned row)
Negate the specified row.
void removeRows(unsigned pos, unsigned count)
Remove the rows having positions pos, pos + 1, ...
This header declares functions that assit transformations in the MemRef dialect.