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"
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)) {}
124 unsigned getNumVars()
const {
return dividends.getNumColumns() - 1; }
125 unsigned getNumDivs()
const {
return dividends.getNumRows(); }
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);
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;
323 std::max(m.
maxPostIndent, (
unsigned int)(str.length() - preIndent));
331 llvm::raw_string_ostream(str) << val;
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)
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
ArrayRef< DynamicAPInt > getDividend(unsigned i) const
DynamicAPInt getDenom(unsigned i) const
SmallVector< std::optional< DynamicAPInt >, 4 > divValuesAt(ArrayRef< DynamicAPInt > point) 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)
MutableArrayRef< DynamicAPInt > getDividend(unsigned i)
bool hasRepr(unsigned i) const
DivisionRepr(unsigned numVars, unsigned numDivs)
An IntegerRelation represents the set of points from a PresburgerSpace that satisfy a list of affine ...
const T * operator->() const
bool operator==(const MaybeOptimum< T > &other) const
std::optional< T > getOptimumIfBounded() const
MaybeOptimum(const T &optimum)
MaybeOptimum(OptimumKind kind)
const T & getBoundedOptimum() const
const T & operator*() const
OptimumKind getKind() const
auto map(const Function &f) const &-> MaybeOptimum< decltype(f(optimum))>
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...
struct mlir::presburger::MaybeLocalRepr::@377221123230274054275363221004054023045275014036::@331175230026152333045220100217334046353170055246 inequalityPair
union mlir::presburger::MaybeLocalRepr::@377221123230274054275363221004054023045275014036 repr
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.