13 #ifndef MLIR_ANALYSIS_PRESBURGER_UTILS_H
14 #define MLIR_ANALYSIS_PRESBURGER_UTILS_H
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallBitVector.h"
25 namespace presburger {
27 class IntegerRelation;
46 "Bounded optima should be constructed by specifying the optimum!");
59 "This should be called only for bounded optima");
64 "This should be called only for bounded optima");
72 if (kind != other.kind)
76 return optimum == other.optimum;
82 template <
class Function>
121 : dividends(numDivs, numVars + 1), denoms(numDivs,
MPInt(0)) {}
132 bool hasRepr(
unsigned i)
const {
return denoms[i] != 0; }
134 bool hasAllReprs()
const {
return !llvm::is_contained(denoms, 0); }
155 dividends.
setRow(i, dividend);
165 void insertDiv(
unsigned pos,
unsigned num = 1);
178 void print(raw_ostream &os)
const;
209 const MPInt &divisor,
210 unsigned localVarIdx);
212 const MPInt &divisor,
213 unsigned localVarIdx);
Class storing division representation of local variables of a constraint system.
void removeDuplicateDivs(llvm::function_ref< bool(unsigned i, unsigned j)> merge)
Removes duplicate divisions.
MPInt & getDenom(unsigned i)
void clearRepr(unsigned i)
unsigned getNumNonDivs() const
unsigned getNumVars() const
DivisionRepr(unsigned numVars)
SmallVector< std::optional< MPInt >, 4 > divValuesAt(ArrayRef< MPInt > point) const
unsigned getDivOffset() const
void print(raw_ostream &os) const
unsigned getNumDivs() const
bool hasRepr(unsigned i) const
ArrayRef< MPInt > getDividend(unsigned i) const
DivisionRepr(unsigned numVars, unsigned numDivs)
void insertDiv(unsigned pos, ArrayRef< MPInt > dividend, const MPInt &divisor)
void setDiv(unsigned i, ArrayRef< MPInt > dividend, const MPInt &divisor)
MPInt getDenom(unsigned i) const
MutableArrayRef< MPInt > getDividend(unsigned i)
ArrayRef< MPInt > getDenoms() const
This class provides support for multi-precision arithmetic.
This is a class to represent a resizable matrix.
void setRow(unsigned row, ArrayRef< MPInt > elems)
Set the specified row to elems.
unsigned getNumColumns() const
unsigned getNumRows() const
MutableArrayRef< MPInt > getRow(unsigned row)
Get a [Mutable]ArrayRef corresponding to the specified row.
const T & getBoundedOptimum() const
bool operator==(const MaybeOptimum< T > &other) const
MaybeOptimum(const T &optimum)
MaybeOptimum(OptimumKind kind)
OptimumKind getKind() const
std::optional< T > getOptimumIfBounded() const
const T * operator->() const
auto map(const Function &f) const &-> MaybeOptimum< decltype(f(optimum))>
const T & operator*() const
ReprKind
ReprKind enum is used to set the constraint type in MaybeLocalRepr.
SmallVector< MPInt, 8 > getDivLowerBound(ArrayRef< MPInt > dividend, const MPInt &divisor, unsigned localVarIdx)
SmallVector< MPInt, 8 > getDivUpperBound(ArrayRef< MPInt > dividend, const MPInt &divisor, unsigned localVarIdx)
If q is defined to be equal to expr floordiv d, this equivalent to saying that q is an integer and q ...
void mergeLocalVars(IntegerRelation &relA, IntegerRelation &relB, llvm::function_ref< bool(unsigned i, unsigned j)> merge)
Given two relations, A and B, add additional local vars to the sets such that both have the union of ...
OptimumKind
This class represents the result of operations optimizing something subject to some constraints.
MPInt gcdRange(ArrayRef< MPInt > range)
Compute the gcd of the range.
void normalizeDiv(MutableArrayRef< MPInt > num, MPInt &denom)
Normalize the given (numerator, denominator) pair by dividing out the common factors between them.
MaybeLocalRepr computeSingleVarRepr(const IntegerRelation &cst, ArrayRef< bool > foundRepr, unsigned pos, MutableArrayRef< MPInt > dividend, MPInt &divisor)
Returns the MaybeLocalRepr struct which contains the indices of the constraints that can be expressed...
SmallVector< MPInt, 8 > getMPIntVec(ArrayRef< int64_t > range)
Check if the pos^th variable can be expressed as a floordiv of an affine function of other variables ...
SmallVector< MPInt, 8 > getNegatedCoeffs(ArrayRef< MPInt > coeffs)
Return coeffs with all the elements negated.
MPInt normalizeRange(MutableArrayRef< MPInt > range)
Divide the range by its gcd and return the gcd.
SmallVector< int64_t, 8 > getInt64Vec(ArrayRef< MPInt > range)
Return the given array as an array of int64_t.
llvm::SmallBitVector getSubrangeBitVector(unsigned len, unsigned setOffset, unsigned numSet)
SmallVector< MPInt, 8 > getComplementIneq(ArrayRef< MPInt > ineq)
Return the complement of the given inequality.
This header declares functions that assit transformations in the MemRef dialect.
MaybeLocalRepr contains the indices of the constraints that can be expressed as a floordiv of an affi...
union mlir::presburger::MaybeLocalRepr::@2 repr
struct mlir::presburger::MaybeLocalRepr::@2::@3 inequalityPair
Eliminates variable at the specified position using Fourier-Motzkin variable elimination.