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<DynamicAPInt, 8> preMultiplyWithRow(ArrayRef<DynamicAPInt> rowVec)44 preMultiplyWithRow(ArrayRef<DynamicAPInt> rowVec) const { 45 return matrix.preMultiplyWithRow(rowVec); 46 } 47 48 // The given vector is interpreted as a column vector v. Pre-multiply v with 49 // this transform, say T, and return Tv. 50 SmallVector<DynamicAPInt, 8> postMultiplyWithColumn(ArrayRef<DynamicAPInt> colVec)51 postMultiplyWithColumn(ArrayRef<DynamicAPInt> colVec) const { 52 return matrix.postMultiplyWithColumn(colVec); 53 } 54 55 private: 56 IntMatrix matrix; 57 }; 58 59 } // namespace presburger 60 } // namespace mlir 61 62 #endif // MLIR_ANALYSIS_PRESBURGER_LINEARTRANSFORM_H 63