MLIR  20.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 
14 using namespace mlir;
15 using namespace presburger;
16 
17 LinearTransform::LinearTransform(IntMatrix &&oMatrix) : matrix(oMatrix) {}
18 LinearTransform::LinearTransform(const IntMatrix &oMatrix) : matrix(oMatrix) {}
19 
20 std::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 
46  IntegerRelation result(rel.getSpace());
47 
48  for (unsigned i = 0, e = rel.getNumEqualities(); i < e; ++i) {
50 
51  const DynamicAPInt &c = eq.back();
52 
53  SmallVector<DynamicAPInt, 8> newEq = preMultiplyWithRow(eq.drop_back());
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 }
An IntegerRelation represents the set of points from a PresburgerSpace that satisfy a list of affine ...
ArrayRef< DynamicAPInt > getInequality(unsigned idx) const
void addEquality(ArrayRef< DynamicAPInt > eq)
Adds an equality from the coefficients specified in eq.
void addInequality(ArrayRef< DynamicAPInt > inEq)
Adds an inequality (>= 0) from the coefficients specified in inEq.
ArrayRef< DynamicAPInt > getEquality(unsigned idx) const
const PresburgerSpace & getSpace() const
Returns a reference to the underlying space.
static std::pair< unsigned, LinearTransform > makeTransformToColumnEchelon(const IntMatrix &m)
LinearTransform(IntMatrix &&oMatrix)
IntegerRelation applyTo(const IntegerRelation &rel) const
SmallVector< DynamicAPInt, 8 > preMultiplyWithRow(ArrayRef< DynamicAPInt > rowVec) const
Include the generated interface declarations.