MLIR 22.0.0git
LinearTransform.cpp
Go to the documentation of this file.
1//===- LinearTransform.cpp - MLIR LinearTransform Class -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
12#include <utility>
13
14using namespace mlir;
15using namespace presburger;
16
17LinearTransform::LinearTransform(IntMatrix &&oMatrix) : matrix(oMatrix) {}
18LinearTransform::LinearTransform(const IntMatrix &oMatrix) : matrix(oMatrix) {}
19
20std::pair<unsigned, LinearTransform>
22 // Compute the hermite normal form of m. This, is by definition, is in column
23 // echelon form.
24 auto [h, u] = m.computeHermiteNormalForm();
25
26 // Since the matrix is in column ecehlon form, a zero column means the rest of
27 // the columns are zero. Thus, once we find a zero column, we can stop.
28 unsigned col, e;
29 for (col = 0, e = m.getNumColumns(); col < e; ++col) {
30 bool zeroCol = true;
31 for (unsigned row = 0, f = m.getNumRows(); row < f; ++row) {
32 if (h(row, col) != 0) {
33 zeroCol = false;
34 break;
35 }
36 }
37
38 if (zeroCol)
39 break;
40 }
41
42 return {col, LinearTransform(std::move(u))};
43}
44
47
48 for (unsigned i = 0, e = rel.getNumEqualities(); i < e; ++i) {
50
51 const DynamicAPInt &c = eq.back();
52
54 newEq.emplace_back(c);
55 result.addEquality(newEq);
56 }
57
58 for (unsigned i = 0, e = rel.getNumInequalities(); i < e; ++i) {
60
61 const DynamicAPInt &c = ineq.back();
62
63 SmallVector<DynamicAPInt, 8> newIneq = preMultiplyWithRow(ineq.drop_back());
64 newIneq.emplace_back(c);
65 result.addInequality(newIneq);
66 }
67
68 return result;
69}
std::pair< IntMatrix, IntMatrix > computeHermiteNormalForm() const
Given the current matrix M, returns the matrices H, U such that H is the column hermite normal form o...
Definition Matrix.cpp:463
An IntegerRelation represents the set of points from a PresburgerSpace that satisfy a list of affine ...
ArrayRef< DynamicAPInt > getEquality(unsigned idx) const
ArrayRef< DynamicAPInt > getInequality(unsigned idx) const
const PresburgerSpace & getSpace() const
Returns a reference to the underlying space.
static std::pair< unsigned, LinearTransform > makeTransformToColumnEchelon(const IntMatrix &m)
IntegerRelation applyTo(const IntegerRelation &rel) const
SmallVector< DynamicAPInt, 8 > preMultiplyWithRow(ArrayRef< DynamicAPInt > rowVec) const
unsigned getNumRows() const
Definition Matrix.h:86
unsigned getNumColumns() const
Definition Matrix.h:88
Include the generated interface declarations.