13 #ifndef MLIR_ANALYSIS_PRESBURGER_UTILS_H
14 #define MLIR_ANALYSIS_PRESBURGER_UTILS_H
17 #include "llvm/ADT/DynamicAPInt.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallBitVector.h"
20 #include "llvm/Support/raw_ostream.h"
25 namespace presburger {
26 class IntegerRelation;
45 "Bounded optima should be constructed by specifying the optimum!");
58 "This should be called only for bounded optima");
63 "This should be called only for bounded optima");
71 if (kind != other.kind)
75 return optimum == other.optimum;
81 template <
class Function>
120 : dividends(numDivs, numVars + 1), denoms(numDivs, DynamicAPInt(0)) {}
131 bool hasRepr(
unsigned i)
const {
return denoms[i] != 0; }
133 bool hasAllReprs()
const {
return !llvm::is_contained(denoms, 0); }
140 return dividends.
getRow(i);
143 return dividends.
getRow(i);
153 DynamicAPInt &
getDenom(
unsigned i) {
return denoms[i]; }
154 DynamicAPInt
getDenom(
unsigned i)
const {
return denoms[i]; }
159 const DynamicAPInt &divisor) {
160 dividends.
setRow(i, dividend);
170 const DynamicAPInt &divisor);
171 void insertDiv(
unsigned pos,
unsigned num = 1);
184 void print(raw_ostream &os)
const;
215 const DynamicAPInt &divisor,
216 unsigned localVarIdx);
218 const DynamicAPInt &divisor,
219 unsigned localVarIdx);
241 DynamicAPInt &divisor);
316 llvm::raw_string_ostream(str) << val;
319 unsigned preIndent = str.find(m.preAlign);
320 preIndent = (preIndent != (unsigned)std::string::npos) ? preIndent + 1 : 0;
321 m.maxPreIndent =
std::max(m.maxPreIndent, preIndent);
323 std::max(m.maxPostIndent, (
unsigned int)(str.length() - preIndent));
331 llvm::raw_string_ostream(str) << val;
334 preIndent = str.find(m.preAlign);
335 preIndent = (preIndent != (unsigned)std::string::npos) ? preIndent + 1 : 0;
339 for (
unsigned i = 0; i < (minSpacing + m.maxPreIndent - preIndent); ++i)
342 for (
unsigned i = 0; i < m.maxPostIndent - (str.length() - preIndent); ++i)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
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.
void clearRepr(unsigned i)
unsigned getNumNonDivs() const
unsigned getNumVars() const
DivisionRepr(unsigned numVars)
ArrayRef< DynamicAPInt > getDenoms() const
unsigned getDivOffset() const
void print(raw_ostream &os) const
unsigned getNumDivs() const
DynamicAPInt getDenom(unsigned i) const
SmallVector< std::optional< DynamicAPInt >, 4 > divValuesAt(ArrayRef< DynamicAPInt > point) const
ArrayRef< DynamicAPInt > getDividend(unsigned i) const
DynamicAPInt & getDenom(unsigned i)
void insertDiv(unsigned pos, ArrayRef< DynamicAPInt > dividend, const DynamicAPInt &divisor)
void setDiv(unsigned i, ArrayRef< DynamicAPInt > dividend, const DynamicAPInt &divisor)
bool hasRepr(unsigned i) const
DivisionRepr(unsigned numVars, unsigned numDivs)
MutableArrayRef< DynamicAPInt > getDividend(unsigned i)
unsigned getNumRows() const
MutableArrayRef< T > getRow(unsigned row)
Get a [Mutable]ArrayRef corresponding to the specified row.
void setRow(unsigned row, ArrayRef< T > elems)
Set the specified row to elems.
unsigned getNumColumns() const
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
void normalizeDiv(MutableArrayRef< DynamicAPInt > num, DynamicAPInt &denom)
Normalize the given (numerator, denominator) pair by dividing out the common factors between them.
ReprKind
ReprKind enum is used to set the constraint type in MaybeLocalRepr.
SmallVector< DynamicAPInt, 8 > getDynamicAPIntVec(ArrayRef< int64_t > range)
Check if the pos^th variable can be expressed as a floordiv of an affine function of other variables ...
DynamicAPInt gcdRange(ArrayRef< DynamicAPInt > range)
Compute the gcd of the range.
MaybeLocalRepr computeSingleVarRepr(const IntegerRelation &cst, ArrayRef< bool > foundRepr, unsigned pos, MutableArrayRef< DynamicAPInt > dividend, DynamicAPInt &divisor)
Returns the MaybeLocalRepr struct which contains the indices of the constraints that can be expressed...
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.
SmallVector< DynamicAPInt, 8 > getNegatedCoeffs(ArrayRef< DynamicAPInt > coeffs)
Return coeffs with all the elements negated.
Fraction dotProduct(ArrayRef< Fraction > a, ArrayRef< Fraction > b)
Compute the dot product of two vectors.
SmallVector< int64_t, 8 > getInt64Vec(ArrayRef< DynamicAPInt > range)
Return the given array as an array of int64_t.
SmallVector< DynamicAPInt, 8 > getDivUpperBound(ArrayRef< DynamicAPInt > dividend, const DynamicAPInt &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 printWithPrintMetrics(raw_ostream &os, T val, unsigned minSpacing, const PrintTableMetrics &m)
Print val in the table with metrics specified in 'm'.
bool isRangeZero(ArrayRef< Fraction > arr)
std::vector< Fraction > multiplyPolynomials(ArrayRef< Fraction > a, ArrayRef< Fraction > b)
Find the product of two polynomials, each given by an array of coefficients.
llvm::SmallBitVector getSubrangeBitVector(unsigned len, unsigned setOffset, unsigned numSet)
void updatePrintMetrics(T val, PrintTableMetrics &m)
Iterate over each val in the table and update 'm' where .maxPreIndent and .maxPostIndent are initiali...
SmallVector< DynamicAPInt, 8 > getDivLowerBound(ArrayRef< DynamicAPInt > dividend, const DynamicAPInt &divisor, unsigned localVarIdx)
DynamicAPInt normalizeRange(MutableArrayRef< DynamicAPInt > range)
Divide the range by its gcd and return the gcd.
SmallVector< DynamicAPInt, 8 > getComplementIneq(ArrayRef< DynamicAPInt > ineq)
Return the complement of the given inequality.
Include the generated interface declarations.
MaybeLocalRepr contains the indices of the constraints that can be expressed as a floordiv of an affi...
union mlir::presburger::MaybeLocalRepr::@0 repr
struct mlir::presburger::MaybeLocalRepr::@0::@1 inequalityPair
Example usage: Print .12, 3.4, 56.7 preAlign = ".", minSpacing = 1, .12 .12 3.4 3....
Eliminates variable at the specified position using Fourier-Motzkin variable elimination.