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(Matrix &&oMatrix);
26   explicit LinearTransform(const Matrix &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(Matrix 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.
preMultiplyWithRow(ArrayRef<int64_t> rowVec)43   SmallVector<int64_t, 8> preMultiplyWithRow(ArrayRef<int64_t> 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<int64_t, 8>
postMultiplyWithColumn(ArrayRef<int64_t> colVec)50   postMultiplyWithColumn(ArrayRef<int64_t> colVec) const {
51     return matrix.postMultiplyWithColumn(colVec);
52   }
53 
54 private:
55   Matrix matrix;
56 };
57 
58 } // namespace presburger
59 } // namespace mlir
60 
61 #endif // MLIR_ANALYSIS_PRESBURGER_LINEARTRANSFORM_H
62