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