1 | //===- LinearTransform.h - MLIR LinearTransform Class -----------*- C++ -*-===// |
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 | // |
9 | // Support for linear transforms and applying them to an IntegerRelation. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef MLIR_ANALYSIS_PRESBURGER_LINEARTRANSFORM_H |
14 | #define MLIR_ANALYSIS_PRESBURGER_LINEARTRANSFORM_H |
15 | |
16 | #include "mlir/Analysis/Presburger/IntegerRelation.h" |
17 | #include "mlir/Analysis/Presburger/Matrix.h" |
18 | #include "llvm/ADT/SmallVector.h" |
19 | |
20 | namespace mlir { |
21 | namespace presburger { |
22 | |
23 | class LinearTransform { |
24 | public: |
25 | explicit LinearTransform(IntMatrix &&oMatrix); |
26 | explicit LinearTransform(const IntMatrix &oMatrix); |
27 | |
28 | // Returns a linear transform T such that MT is M in column echelon form. |
29 | // Also returns the number of non-zero columns in MT. |
30 | // |
31 | // Specifically, T is such that in every column the first non-zero row is |
32 | // strictly below that of the previous column, and all columns which have only |
33 | // zeros are at the end. |
34 | static std::pair<unsigned, LinearTransform> |
35 | makeTransformToColumnEchelon(const IntMatrix &m); |
36 | |
37 | // Returns an IntegerRelation having a constraint vector vT for every |
38 | // constraint vector v in rel, where T is this transform. |
39 | IntegerRelation applyTo(const IntegerRelation &rel) const; |
40 | |
41 | // The given vector is interpreted as a row vector v. Post-multiply v with |
42 | // this transform, say T, and return vT. |
43 | SmallVector<MPInt, 8> preMultiplyWithRow(ArrayRef<MPInt> rowVec) const { |
44 | return matrix.preMultiplyWithRow(rowVec); |
45 | } |
46 | |
47 | // The given vector is interpreted as a column vector v. Pre-multiply v with |
48 | // this transform, say T, and return Tv. |
49 | SmallVector<MPInt, 8> postMultiplyWithColumn(ArrayRef<MPInt> colVec) const { |
50 | return matrix.postMultiplyWithColumn(colVec); |
51 | } |
52 | |
53 | private: |
54 | IntMatrix matrix; |
55 | }; |
56 | |
57 | } // namespace presburger |
58 | } // namespace mlir |
59 | |
60 | #endif // MLIR_ANALYSIS_PRESBURGER_LINEARTRANSFORM_H |
61 | |