MLIR  19.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
mlir::FlatLinearValueConstraints Class Reference

FlatLinearValueConstraints represents an extension of FlatLinearConstraints where each non-local variable can have an SSA Value attached to it. More...

#include "mlir/Analysis/FlatLinearValueConstraints.h"

+ Inheritance diagram for mlir::FlatLinearValueConstraints:

Public Types

using Identifier = presburger::Identifier
 The SSA Values attached to each non-local variable are stored as identifiers in the constraint system's space. More...
 
- Public Types inherited from mlir::presburger::IntegerRelation
enum class  Kind {
  IntegerRelation , IntegerPolyhedron , FlatLinearConstraints , FlatLinearValueConstraints ,
  FlatAffineValueConstraints , FlatAffineRelation
}
 All derived classes of IntegerRelation. More...
 

Public Member Functions

 FlatLinearValueConstraints (unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDims, unsigned numSymbols, unsigned numLocals, ArrayRef< std::optional< Value >> valArgs)
 Constructs a constraint system reserving memory for the specified number of constraints and variables. More...
 
 FlatLinearValueConstraints (unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDims, unsigned numSymbols, unsigned numLocals, ArrayRef< Value > valArgs)
 Constructs a constraint system reserving memory for the specified number of constraints and variables. More...
 
 FlatLinearValueConstraints (unsigned numDims, unsigned numSymbols, unsigned numLocals, ArrayRef< std::optional< Value >> valArgs)
 Constructs a constraint system with the specified number of dimensions and symbols. More...
 
 FlatLinearValueConstraints (unsigned numDims=0, unsigned numSymbols=0, unsigned numLocals=0, ArrayRef< Value > valArgs={})
 Constructs a constraint system with the specified number of dimensions and symbols. More...
 
 FlatLinearValueConstraints (const IntegerPolyhedron &fac, ArrayRef< std::optional< Value >> valArgs={})
 
 FlatLinearValueConstraints (IntegerSet set, ValueRange operands={})
 Creates an affine constraint system from an IntegerSet. More...
 
Kind getKind () const override
 Return the kind of this object. More...
 
void addBound (presburger::BoundType type, Value val, int64_t value)
 Adds a constant bound for the variable associated with the given Value. More...
 
Value getValue (unsigned pos) const
 Returns the Value associated with the pos^th variable. More...
 
void getValues (unsigned start, unsigned end, SmallVectorImpl< Value > *values) const
 Returns the Values associated with variables in range [start, end). More...
 
SmallVector< std::optional< Value > > getMaybeValues () const
 
SmallVector< std::optional< Value > > getMaybeValues (presburger::VarKind kind) const
 
bool hasValue (unsigned pos) const
 Returns true if the pos^th variable has an associated Value. More...
 
unsigned appendDimVar (ValueRange vals)
 
unsigned appendSymbolVar (ValueRange vals)
 
unsigned insertDimVar (unsigned pos, ValueRange vals)
 
unsigned insertSymbolVar (unsigned pos, ValueRange vals)
 
unsigned insertVar (presburger::VarKind kind, unsigned pos, unsigned num=1) override
 Insert num variables of the specified kind at position pos. More...
 
unsigned insertVar (presburger::VarKind kind, unsigned pos, ValueRange vals)
 
void removeVarRange (presburger::VarKind kind, unsigned varStart, unsigned varLimit) override
 Removes variables in the column range [varStart, varLimit), and copies any remaining valid data into place, updates member variables, and resizes arrays as needed. More...
 
void setValue (unsigned pos, Value val)
 Sets the Value associated with the pos^th variable. More...
 
void setValues (unsigned start, unsigned end, ArrayRef< Value > values)
 Sets the Values associated with the variables in the range [start, end). More...
 
bool findVar (Value val, unsigned *pos, unsigned offset=0) const
 Looks up the position of the variable with the specified Value starting with variables at offset offset. More...
 
bool containsVar (Value val) const
 Returns true if a variable with the specified Value exists, false otherwise. More...
 
void projectOut (Value val)
 Projects out the variable that is associate with Value. More...
 
void printSpace (raw_ostream &os) const override
 Prints the number of constraints, dimensions, symbols and locals in the FlatAffineValueConstraints. More...
 
AffineMap computeAlignedMap (AffineMap map, ValueRange operands) const
 Align map with this constraint system based on operands. More...
 
void mergeAndAlignVarsWithOther (unsigned offset, FlatLinearValueConstraints *other)
 Merge and align the variables of this and other starting at offset, so that both constraint systems get the union of the contained variables that is dimension-wise and symbol-wise unique; both constraint systems are updated so that they have the union of all variables, with this's original variables appearing first followed by any of other's variables that didn't appear in this. More...
 
void mergeSymbolVars (FlatLinearValueConstraints &other)
 Merge and align symbols of this and other such that both get union of of symbols that are unique. More...
 
bool areVarsAlignedWithOther (const FlatLinearConstraints &other)
 Returns true if this constraint system and other are in the same space, i.e., if they are associated with the same set of variables, appearing in the same order. More...
 
LogicalResult unionBoundingBox (const FlatLinearValueConstraints &other)
 Updates the constraints to be the smallest bounding (enclosing) box that contains the points of this set and that of other, with the symbols being treated specially. More...
 
LogicalResult addBound (presburger::BoundType type, unsigned pos, AffineMap boundMap, bool isClosedBound)
 Adds a bound for the variable at the specified position with constraints being drawn from the specified bound map. More...
 
LogicalResult addBound (presburger::BoundType type, unsigned pos, AffineMap boundMap)
 Adds a bound for the variable at the specified position with constraints being drawn from the specified bound map. More...
 
unsigned appendDimVar (unsigned num=1)
 Append variables of the specified kind after the last variable of that kind. More...
 
unsigned appendSymbolVar (unsigned num=1)
 
unsigned insertDimVar (unsigned pos, unsigned num=1)
 Insert variables of the specified kind at position pos. More...
 
unsigned insertSymbolVar (unsigned pos, unsigned num=1)
 
- Public Member Functions inherited from mlir::FlatLinearConstraints
 FlatLinearConstraints (unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDims, unsigned numSymbols, unsigned numLocals)
 Constructs a constraint system reserving memory for the specified number of constraints and variables. More...
 
 FlatLinearConstraints (unsigned numDims=0, unsigned numSymbols=0, unsigned numLocals=0)
 Constructs a constraint system with the specified number of dimensions and symbols. More...
 
 FlatLinearConstraints (const IntegerPolyhedron &fac)
 
LogicalResult addBound (presburger::BoundType type, unsigned pos, AffineMap boundMap, bool isClosedBound)
 Adds a bound for the variable at the specified position with constraints being drawn from the specified bound map. More...
 
LogicalResult addBound (presburger::BoundType type, unsigned pos, AffineMap boundMap)
 Adds a bound for the variable at the specified position with constraints being drawn from the specified bound map. More...
 
IntegerSet getAsIntegerSet (MLIRContext *context) const
 Returns the constraint system as an integer set. More...
 
void getSliceBounds (unsigned offset, unsigned num, MLIRContext *context, SmallVectorImpl< AffineMap > *lbMaps, SmallVectorImpl< AffineMap > *ubMaps, bool closedUB=false)
 Computes the lower and upper bounds of the first num dimensional variables (starting at offset) as an affine map of the remaining variables (dimensional and symbolic). More...
 
LogicalResult composeMatchingMap (AffineMap other)
 Composes an affine map whose dimensions and symbols match one to one with the dimensions and symbols of this FlatLinearConstraints. More...
 
std::pair< AffineMap, AffineMapgetLowerAndUpperBound (unsigned pos, unsigned offset, unsigned num, unsigned symStartPos, ArrayRef< AffineExpr > localExprs, MLIRContext *context, bool closedUB=false) const
 Gets the lower and upper bound of the offset + posth variable treating [0, offset) U [offset + num, symStartPos) as dimensions and [symStartPos, getNumDimAndSymbolVars) as symbols, and pos lies in [0, num). More...
 
unsigned insertDimVar (unsigned pos, unsigned num=1)
 Insert variables of the specified kind at position pos. More...
 
unsigned insertSymbolVar (unsigned pos, unsigned num=1)
 
unsigned insertLocalVar (unsigned pos, unsigned num=1)
 
unsigned appendDimVar (unsigned num=1)
 Append variables of the specified kind after the last variable of that kind. More...
 
unsigned appendSymbolVar (unsigned num=1)
 
unsigned appendLocalVar (unsigned num=1)
 
- Public Member Functions inherited from mlir::presburger::IntegerPolyhedron
 IntegerPolyhedron (unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, const PresburgerSpace &space)
 Constructs a set reserving memory for the specified number of constraints and variables. More...
 
 IntegerPolyhedron (const PresburgerSpace &space)
 Constructs a relation with the specified number of dimensions and symbols. More...
 
 IntegerPolyhedron (const PresburgerSpace &space, IntMatrix inequalities)
 Constructs a relation with the specified number of dimensions and symbols and adds the given inequalities. More...
 
 IntegerPolyhedron (const PresburgerSpace &space, FracMatrix inequalities)
 Constructs a relation with the specified number of dimensions and symbols and adds the given inequalities, after normalizing row-wise to integer values. More...
 
 IntegerPolyhedron (const IntegerRelation &rel)
 Construct a set from an IntegerRelation. More...
 
 IntegerPolyhedron (IntegerRelation &&rel)
 Construct a set from an IntegerRelation, but instead of creating a copy, use move constructor. More...
 
Kind getKind () const override
 Return the kind of this IntegerRelation. More...
 
std::unique_ptr< IntegerPolyhedronclone () const
 
unsigned insertVar (VarKind kind, unsigned pos, unsigned num=1) override
 Insert num variables of the specified kind at position pos. More...
 
IntegerPolyhedron intersect (const IntegerPolyhedron &other) const
 Return the intersection of the two relations. More...
 
PresburgerSet subtract (const PresburgerSet &other) const
 Return the set difference of this set and the given set, i.e., return this \ set. More...
 
- Public Member Functions inherited from mlir::presburger::IntegerRelation
 IntegerRelation (unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, const PresburgerSpace &space)
 Constructs a relation reserving memory for the specified number of constraints and variables. More...
 
 IntegerRelation (const PresburgerSpace &space)
 Constructs a relation with the specified number of dimensions and symbols. More...
 
virtual ~IntegerRelation ()=default
 
std::unique_ptr< IntegerRelationclone () const
 
const PresburgerSpacegetSpace () const
 Returns a reference to the underlying space. More...
 
void setSpace (const PresburgerSpace &oSpace)
 Set the space to oSpace, which should have the same number of ids as the current space. More...
 
void setSpaceExceptLocals (const PresburgerSpace &oSpace)
 Set the space to oSpace, which should not have any local ids. More...
 
void setId (VarKind kind, unsigned i, Identifier id)
 Set the identifier for the ith variable of the specified kind of the IntegerRelation's PresburgerSpace. More...
 
void resetIds ()
 
ArrayRef< IdentifiergetIds (VarKind kind)
 Get the identifiers for the variables of specified varKind. More...
 
PresburgerSpace getSpaceWithoutLocals () const
 Returns a copy of the space without locals. More...
 
void append (const IntegerRelation &other)
 Appends constraints from other into this. More...
 
IntegerRelation intersect (IntegerRelation other) const
 Return the intersection of the two relations. More...
 
bool isEqual (const IntegerRelation &other) const
 Return whether this and other are equal. More...
 
bool isObviouslyEqual (const IntegerRelation &other) const
 Perform a quick equality check on this and other. More...
 
bool isSubsetOf (const IntegerRelation &other) const
 Return whether this is a subset of the given IntegerRelation. More...
 
MPInt atEq (unsigned i, unsigned j) const
 Returns the value at the specified equality row and column. More...
 
int64_t atEq64 (unsigned i, unsigned j) const
 The same, but casts to int64_t. More...
 
MPIntatEq (unsigned i, unsigned j)
 
MPInt atIneq (unsigned i, unsigned j) const
 Returns the value at the specified inequality row and column. More...
 
int64_t atIneq64 (unsigned i, unsigned j) const
 The same, but casts to int64_t. More...
 
MPIntatIneq (unsigned i, unsigned j)
 
unsigned getNumConstraints () const
 
unsigned getNumDomainVars () const
 
unsigned getNumRangeVars () const
 
unsigned getNumSymbolVars () const
 
unsigned getNumLocalVars () const
 
unsigned getNumDimVars () const
 
unsigned getNumDimAndSymbolVars () const
 
unsigned getNumVars () const
 
unsigned getNumCols () const
 Returns the number of columns in the constraint system. More...
 
unsigned getNumEqualities () const
 
unsigned getNumInequalities () const
 
unsigned getNumReservedEqualities () const
 
unsigned getNumReservedInequalities () const
 
ArrayRef< MPIntgetEquality (unsigned idx) const
 
ArrayRef< MPIntgetInequality (unsigned idx) const
 
SmallVector< int64_t, 8 > getEquality64 (unsigned idx) const
 The same, but casts to int64_t. More...
 
SmallVector< int64_t, 8 > getInequality64 (unsigned idx) const
 
IntMatrix getInequalities () const
 
unsigned getNumVarKind (VarKind kind) const
 Get the number of vars of the specified kind. More...
 
unsigned getVarKindOffset (VarKind kind) const
 Return the index at which the specified kind of vars starts. More...
 
unsigned getVarKindEnd (VarKind kind) const
 Return the index at Which the specified kind of vars ends. More...
 
unsigned getVarKindOverlap (VarKind kind, unsigned varStart, unsigned varLimit) const
 Get the number of elements of the specified kind in the range [varStart, varLimit). More...
 
VarKind getVarKindAt (unsigned pos) const
 Return the VarKind of the var at the specified position. More...
 
CountsSnapshot getCounts () const
 
void truncate (const CountsSnapshot &counts)
 
unsigned appendVar (VarKind kind, unsigned num=1)
 Append num variables of the specified kind after the last variable of that kind. More...
 
void addInequality (ArrayRef< MPInt > inEq)
 Adds an inequality (>= 0) from the coefficients specified in inEq. More...
 
void addInequality (ArrayRef< int64_t > inEq)
 
void addEquality (ArrayRef< MPInt > eq)
 Adds an equality from the coefficients specified in eq. More...
 
void addEquality (ArrayRef< int64_t > eq)
 
virtual void eliminateRedundantLocalVar (unsigned posA, unsigned posB)
 Eliminate the posB^th local variable, replacing every instance of it with the posA^th local variable. More...
 
void removeVar (VarKind kind, unsigned pos)
 Removes variables of the specified kind with the specified pos (or within the specified range) from the system. More...
 
void removeVar (unsigned pos)
 Removes the specified variable from the system. More...
 
void removeEquality (unsigned pos)
 
void removeInequality (unsigned pos)
 
void removeEqualityRange (unsigned start, unsigned end)
 Remove the (in)equalities at positions [start, end). More...
 
void removeInequalityRange (unsigned start, unsigned end)
 
MaybeOptimum< SmallVector< Fraction, 8 > > findRationalLexMin () const
 Get the lexicographically minimum rational point satisfying the constraints. More...
 
MaybeOptimum< SmallVector< MPInt, 8 > > findIntegerLexMin () const
 Same as above, but returns lexicographically minimal integer point. More...
 
virtual void swapVar (unsigned posA, unsigned posB)
 Swap the posA^th variable with the posB^th variable. More...
 
void clearConstraints ()
 Removes all equalities and inequalities. More...
 
void setAndEliminate (unsigned pos, ArrayRef< MPInt > values)
 Sets the values.size() variables starting at pos to the specified values and removes them. More...
 
void setAndEliminate (unsigned pos, ArrayRef< int64_t > values)
 
virtual void clearAndCopyFrom (const IntegerRelation &other)
 Replaces the contents of this IntegerRelation with other. More...
 
void getLowerAndUpperBoundIndices (unsigned pos, SmallVectorImpl< unsigned > *lbIndices, SmallVectorImpl< unsigned > *ubIndices, SmallVectorImpl< unsigned > *eqIndices=nullptr, unsigned offset=0, unsigned num=0) const
 Gather positions of all lower and upper bounds of the variable at pos, and optionally any equalities on it. More...
 
bool isEmpty () const
 Checks for emptiness by performing variable elimination on all variables, running the GCD test on each equality constraint, and checking for invalid constraints. More...
 
bool isObviouslyEmpty () const
 Performs GCD checks and invalid constraint checks. More...
 
bool isEmptyByGCDTest () const
 Runs the GCD test on all equality constraints. More...
 
bool isIntegerEmpty () const
 Returns true if the set of constraints is found to have no solution, false if a solution exists. More...
 
IntMatrix getBoundedDirections () const
 Returns a matrix where each row is a vector along which the polytope is bounded. More...
 
std::optional< SmallVector< MPInt, 8 > > findIntegerSample () const
 Find an integer sample point satisfying the constraints using a branch and bound algorithm with generalized basis reduction, with some additional processing using Simplex for unbounded sets. More...
 
std::optional< MPIntcomputeVolume () const
 Compute an overapproximation of the number of integer points in the relation. More...
 
bool containsPoint (ArrayRef< MPInt > point) const
 Returns true if the given point satisfies the constraints, or false otherwise. More...
 
bool containsPoint (ArrayRef< int64_t > point) const
 
std::optional< SmallVector< MPInt, 8 > > containsPointNoLocal (ArrayRef< MPInt > point) const
 Given the values of non-local vars, return a satisfying assignment to the local if one exists, or an empty optional otherwise. More...
 
std::optional< SmallVector< MPInt, 8 > > containsPointNoLocal (ArrayRef< int64_t > point) const
 
DivisionRepr getLocalReprs (std::vector< MaybeLocalRepr > *repr=nullptr) const
 Returns a DivisonRepr representing the division representation of local variables in the constraint system. More...
 
void addBound (BoundType type, unsigned pos, const MPInt &value)
 Adds a constant bound for the specified variable. More...
 
void addBound (BoundType type, unsigned pos, int64_t value)
 
void addBound (BoundType type, ArrayRef< MPInt > expr, const MPInt &value)
 Adds a constant bound for the specified expression. More...
 
void addBound (BoundType type, ArrayRef< int64_t > expr, int64_t value)
 
void addLocalFloorDiv (ArrayRef< MPInt > dividend, const MPInt &divisor)
 Adds a new local variable as the floordiv of an affine function of other variables, the coefficients of which are provided in dividend and with respect to a positive constant divisor. More...
 
void addLocalFloorDiv (ArrayRef< int64_t > dividend, int64_t divisor)
 
void projectOut (unsigned pos, unsigned num)
 Projects out (aka eliminates) num variables starting at position pos. More...
 
void projectOut (unsigned pos)
 
LogicalResult constantFoldVar (unsigned pos)
 Tries to fold the specified variable to a constant using a trivial equality detection; if successful, the constant is substituted for the variable everywhere in the constraint system and then removed from the system. More...
 
void constantFoldVarRange (unsigned pos, unsigned num)
 This method calls constantFoldVar for the specified range of variables, num variables starting at position pos. More...
 
LogicalResult unionBoundingBox (const IntegerRelation &other)
 Updates the constraints to be the smallest bounding (enclosing) box that contains the points of this set and that of other, with the symbols being treated specially. More...
 
std::optional< MPIntgetConstantBoundOnDimSize (unsigned pos, SmallVectorImpl< MPInt > *lb=nullptr, MPInt *boundFloorDivisor=nullptr, SmallVectorImpl< MPInt > *ub=nullptr, unsigned *minLbPos=nullptr, unsigned *minUbPos=nullptr) const
 Returns the smallest known constant bound for the extent of the specified variable (pos^th), i.e., the smallest known constant that is greater than or equal to 'exclusive upper bound' - 'lower bound' of the variable. More...
 
std::optional< int64_t > getConstantBoundOnDimSize64 (unsigned pos, SmallVectorImpl< int64_t > *lb=nullptr, int64_t *boundFloorDivisor=nullptr, SmallVectorImpl< int64_t > *ub=nullptr, unsigned *minLbPos=nullptr, unsigned *minUbPos=nullptr) const
 The same, but casts to int64_t. More...
 
std::optional< MPIntgetConstantBound (BoundType type, unsigned pos) const
 Returns the constant bound for the pos^th variable if there is one; std::nullopt otherwise. More...
 
std::optional< int64_t > getConstantBound64 (BoundType type, unsigned pos) const
 The same, but casts to int64_t. More...
 
void removeIndependentConstraints (unsigned pos, unsigned num)
 Removes constraints that are independent of (i.e., do not have a coefficient) variables in the range [pos, pos + num). More...
 
bool isHyperRectangular (unsigned pos, unsigned num) const
 Returns true if the set can be trivially detected as being hyper-rectangular on the specified contiguous set of variables. More...
 
void removeTrivialRedundancy ()
 Removes duplicate constraints, trivially true constraints, and constraints that can be detected as redundant as a result of differing only in their constant term part. More...
 
void removeRedundantInequalities ()
 A more expensive check than removeTrivialRedundancy to detect redundant inequalities. More...
 
void removeRedundantConstraints ()
 Removes redundant constraints using Simplex. More...
 
void removeDuplicateDivs ()
 
void simplify ()
 Simplify the constraint system by removing canonicalizing constraints and removing redundant constraints. More...
 
void convertVarKind (VarKind srcKind, unsigned varStart, unsigned varLimit, VarKind dstKind, unsigned pos)
 Converts variables of kind srcKind in the range [varStart, varLimit) to variables of kind dstKind. More...
 
void convertVarKind (VarKind srcKind, unsigned varStart, unsigned varLimit, VarKind dstKind)
 
void convertToLocal (VarKind kind, unsigned varStart, unsigned varLimit)
 
void mergeAndAlignSymbols (IntegerRelation &other)
 Merge and align symbol variables of this and other with respect to identifiers. More...
 
unsigned mergeLocalVars (IntegerRelation &other)
 Adds additional local vars to the sets such that they both have the union of the local vars in each set, without changing the set of points that lie in this and other. More...
 
bool hasOnlyDivLocals () const
 Check whether all local ids have a division representation. More...
 
void setDimSymbolSeparation (unsigned newSymbolCount)
 Changes the partition between dimensions and symbols. More...
 
IntegerPolyhedron getDomainSet () const
 Return a set corresponding to all points in the domain of the relation. More...
 
IntegerPolyhedron getRangeSet () const
 Return a set corresponding to all points in the range of the relation. More...
 
void intersectDomain (const IntegerPolyhedron &poly)
 Intersect the given poly with the domain in-place. More...
 
void intersectRange (const IntegerPolyhedron &poly)
 Intersect the given poly with the range in-place. More...
 
void inverse ()
 Invert the relation i.e., swap its domain and range. More...
 
void compose (const IntegerRelation &rel)
 Let the relation this be R1, and the relation rel be R2. More...
 
void applyDomain (const IntegerRelation &rel)
 Given a relation rel, apply the relation to the domain of this relation. More...
 
void applyRange (const IntegerRelation &rel)
 Given a relation rel, apply the relation to the range of this relation. More...
 
void mergeAndCompose (const IntegerRelation &other)
 Given a relation other: (A -> B), this operation merges the symbol and local variables and then takes the composition of other on this: (B -> C). More...
 
PresburgerRelation computeReprWithOnlyDivLocals () const
 Compute an equivalent representation of the same set, such that all local vars in all disjuncts have division representations. More...
 
SymbolicLexOpt findSymbolicIntegerLexMin () const
 Compute the symbolic integer lexmin of the relation. More...
 
SymbolicLexOpt findSymbolicIntegerLexMax () const
 Same as findSymbolicIntegerLexMin but produces lexmax instead of lexmin. More...
 
PresburgerRelation subtract (const PresburgerRelation &set) const
 Return the set difference of this set and the given set, i.e., return this \ set. More...
 
void removeTrivialEqualities ()
 
bool isFullDim ()
 
void print (raw_ostream &os) const
 
void dump () const
 

Static Public Member Functions

static bool classof (const IntegerRelation *cst)
 
- Static Public Member Functions inherited from mlir::presburger::IntegerPolyhedron
static IntegerPolyhedron getUniverse (const PresburgerSpace &space)
 Return a system with no constraints, i.e., one which is satisfied by all points. More...
 
static bool classof (const IntegerRelation *cst)
 
- Static Public Member Functions inherited from mlir::presburger::IntegerRelation
static IntegerRelation getUniverse (const PresburgerSpace &space)
 Return a system with no constraints, i.e., one which is satisfied by all points. More...
 
static IntegerRelation getEmpty (const PresburgerSpace &space)
 Return an empty system containing an invalid equation 0 = 1. More...
 
static bool classof (const IntegerRelation *cst)
 

Additional Inherited Members

- Protected Types inherited from mlir::FlatLinearConstraints
using VarKind = presburger::VarKind
 
- Protected Member Functions inherited from mlir::FlatLinearConstraints
LogicalResult computeLocalVars (SmallVectorImpl< AffineExpr > &memo, MLIRContext *context) const
 Compute an explicit representation for local vars. More...
 
LogicalResult flattenAlignedMapAndMergeLocals (AffineMap map, std::vector< SmallVector< int64_t, 8 >> *flattenedExprs)
 Given an affine map that is aligned with this constraint system: More...
 
- Protected Member Functions inherited from mlir::presburger::IntegerRelation
bool hasInvalidConstraint () const
 Checks all rows of equality/inequality constraints for trivial contradictions (for example: 1 == 0, 0 >= 1), which may have surfaced after elimination. More...
 
template<bool isLower>
std::optional< MPIntcomputeConstantLowerOrUpperBound (unsigned pos)
 Returns the constant lower bound if isLower is true, and the upper bound if isLower is false. More...
 
template<bool isLower>
std::optional< int64_t > computeConstantLowerOrUpperBound64 (unsigned pos)
 The same, but casts to int64_t. More...
 
LogicalResult gaussianEliminateVar (unsigned position)
 Eliminates a single variable at position from equality and inequality constraints. More...
 
void removeRedundantLocalVars ()
 Removes local variables using equalities. More...
 
unsigned gaussianEliminateVars (unsigned posStart, unsigned posLimit)
 Eliminates variables from equality and inequality constraints in column range [posStart, posLimit). More...
 
bool gaussianEliminate ()
 Perform a Gaussian elimination operation to reduce all equations to standard form. More...
 
virtual void fourierMotzkinEliminate (unsigned pos, bool darkShadow=false, bool *isResultIntegerExact=nullptr)
 Eliminates the variable at the specified position using Fourier-Motzkin variable elimination, but uses Gaussian elimination if there is an equality involving that variable. More...
 
void gcdTightenInequalities ()
 Tightens inequalities given that we are dealing with integer spaces. More...
 
void normalizeConstraintsByGCD ()
 Normalized each constraints by the GCD of its coefficients. More...
 
bool findConstraintWithNonZeroAt (unsigned colIdx, bool isEq, unsigned *rowIdx) const
 Searches for a constraint with a non-zero coefficient at colIdx in equality (isEq=true) or inequality (isEq=false) constraints. More...
 
bool isColZero (unsigned pos) const
 Returns true if the pos^th column is all zero for both inequalities and equalities. More...
 
bool removeDuplicateConstraints ()
 Checks for identical inequalities and eliminates redundant inequalities. More...
 
virtual bool hasConsistentState () const
 Returns false if the fields corresponding to various variable counts, or equality/inequality buffer sizes aren't consistent; true otherwise. More...
 
void removeVarRange (unsigned varStart, unsigned varLimit)
 Removes variables in the column range [varStart, varLimit), and copies any remaining valid data into place, updates member variables, and resizes arrays as needed. More...
 
void truncateVarKind (VarKind kind, unsigned num)
 Truncate the vars of the specified kind to the specified number by dropping some vars at the end. More...
 
void truncateVarKind (VarKind kind, const CountsSnapshot &counts)
 Truncate the vars to the number in the space of the specified CountsSnapshot. More...
 
- Protected Attributes inherited from mlir::presburger::IntegerRelation
PresburgerSpace space
 
IntMatrix equalities
 Coefficients of affine equalities (in == 0 form). More...
 
IntMatrix inequalities
 Coefficients of affine inequalities (in >= 0 form). More...
 
- Static Protected Attributes inherited from mlir::presburger::IntegerRelation
constexpr static unsigned kExplosionFactor = 32
 A parameter that controls detection of an unrealistic number of constraints. More...
 

Detailed Description

FlatLinearValueConstraints represents an extension of FlatLinearConstraints where each non-local variable can have an SSA Value attached to it.

Definition at line 206 of file FlatLinearValueConstraints.h.

Member Typedef Documentation

◆ Identifier

The SSA Values attached to each non-local variable are stored as identifiers in the constraint system's space.

Definition at line 210 of file FlatLinearValueConstraints.h.

Constructor & Destructor Documentation

◆ FlatLinearValueConstraints() [1/6]

mlir::FlatLinearValueConstraints::FlatLinearValueConstraints ( unsigned  numReservedInequalities,
unsigned  numReservedEqualities,
unsigned  numReservedCols,
unsigned  numDims,
unsigned  numSymbols,
unsigned  numLocals,
ArrayRef< std::optional< Value >>  valArgs 
)
inline

Constructs a constraint system reserving memory for the specified number of constraints and variables.

valArgs are the optional SSA values associated with each dimension/symbol. These must either be empty or match the number of dimensions and symbols.

Definition at line 216 of file FlatLinearValueConstraints.h.

References mlir::presburger::IntegerRelation::getNumDimAndSymbolVars(), and setValue().

◆ FlatLinearValueConstraints() [2/6]

mlir::FlatLinearValueConstraints::FlatLinearValueConstraints ( unsigned  numReservedInequalities,
unsigned  numReservedEqualities,
unsigned  numReservedCols,
unsigned  numDims,
unsigned  numSymbols,
unsigned  numLocals,
ArrayRef< Value valArgs 
)
inline

Constructs a constraint system reserving memory for the specified number of constraints and variables.

valArgs are the optional SSA values associated with each dimension/symbol. These must either be empty or match the number of dimensions and symbols.

Definition at line 233 of file FlatLinearValueConstraints.h.

References mlir::presburger::IntegerRelation::getNumDimAndSymbolVars(), and setValue().

◆ FlatLinearValueConstraints() [3/6]

mlir::FlatLinearValueConstraints::FlatLinearValueConstraints ( unsigned  numDims,
unsigned  numSymbols,
unsigned  numLocals,
ArrayRef< std::optional< Value >>  valArgs 
)
inline

Constructs a constraint system with the specified number of dimensions and symbols.

valArgs are the optional SSA values associated with each dimension/symbol. These must either be empty or match the number of dimensions and symbols.

Definition at line 250 of file FlatLinearValueConstraints.h.

◆ FlatLinearValueConstraints() [4/6]

mlir::FlatLinearValueConstraints::FlatLinearValueConstraints ( unsigned  numDims = 0,
unsigned  numSymbols = 0,
unsigned  numLocals = 0,
ArrayRef< Value valArgs = {} 
)
inline

Constructs a constraint system with the specified number of dimensions and symbols.

valArgs are the optional SSA values associated with each dimension/symbol. These must either be empty or match the number of dimensions and symbols.

Definition at line 263 of file FlatLinearValueConstraints.h.

◆ FlatLinearValueConstraints() [5/6]

mlir::FlatLinearValueConstraints::FlatLinearValueConstraints ( const IntegerPolyhedron fac,
ArrayRef< std::optional< Value >>  valArgs = {} 
)
inline

Definition at line 272 of file FlatLinearValueConstraints.h.

◆ FlatLinearValueConstraints() [6/6]

FlatLinearValueConstraints::FlatLinearValueConstraints ( IntegerSet  set,
ValueRange  operands = {} 
)
explicit

Member Function Documentation

◆ addBound() [1/3]

LogicalResult FlatLinearConstraints::addBound

Adds a bound for the variable at the specified position with constraints being drawn from the specified bound map.

In case of an EQ bound, the bound map is expected to have exactly one result. In case of a LB/UB, the bound map may have more than one result, for each of which an inequality is added. Note: The dimensions/symbols of this FlatLinearConstraints must match the dimensions/symbols of the affine map. By default the lower bound is closed and the upper bound is open.

Definition at line 93 of file FlatLinearValueConstraints.cpp.

◆ addBound() [2/3]

LogicalResult FlatLinearConstraints::addBound

Adds a bound for the variable at the specified position with constraints being drawn from the specified bound map.

In case of an EQ bound, the bound map is expected to have exactly one result. In case of a LB/UB, the bound map may have more than one result, for each of which an inequality is added.

The bound can be added as open or closed by specifying isClosedBound. In case of a LB/UB, isClosedBound = false means the bound is added internally as a closed bound by +1/-1 respectively. In case of an EQ bound, it can only be added as a closed bound.

Note: The dimensions/symbols of this FlatLinearConstraints must match the dimensions/symbols of the affine map.

Definition at line 82 of file FlatLinearValueConstraints.cpp.

Referenced by addBound().

◆ addBound() [3/3]

void FlatLinearValueConstraints::addBound ( presburger::BoundType  type,
Value  val,
int64_t  value 
)

Adds a constant bound for the variable associated with the given Value.

Definition at line 1114 of file FlatLinearValueConstraints.cpp.

References addBound(), and findVar().

◆ appendDimVar() [1/2]

unsigned mlir::FlatLinearConstraints::appendDimVar
inline

Append variables of the specified kind after the last variable of that kind.

The coefficient columns corresponding to the added variables are initialized to zero. vals are the Values corresponding to the variables. Return the absolute column position (i.e., not relative to the kind of variable) of the first appended variable.

Note: Empty Values are allowed in vals.

Definition at line 166 of file FlatLinearValueConstraints.h.

◆ appendDimVar() [2/2]

unsigned FlatLinearValueConstraints::appendDimVar ( ValueRange  vals)

◆ appendSymbolVar() [1/2]

unsigned mlir::FlatLinearConstraints::appendSymbolVar
inline

Definition at line 169 of file FlatLinearValueConstraints.h.

◆ appendSymbolVar() [2/2]

unsigned FlatLinearValueConstraints::appendSymbolVar ( ValueRange  vals)

◆ areVarsAlignedWithOther()

bool FlatLinearValueConstraints::areVarsAlignedWithOther ( const FlatLinearConstraints other)

Returns true if this constraint system and other are in the same space, i.e., if they are associated with the same set of variables, appearing in the same order.

Calls areVarsAligned to check if two constraint systems have the same set of variables in the same order.

Returns false otherwise.

Definition at line 910 of file FlatLinearValueConstraints.cpp.

References areVarsAligned().

Referenced by mlir::affine::computeSliceUnion().

◆ classof()

static bool mlir::FlatLinearValueConstraints::classof ( const IntegerRelation cst)
inlinestatic

◆ computeAlignedMap()

AffineMap FlatLinearValueConstraints::computeAlignedMap ( AffineMap  map,
ValueRange  operands 
) const

◆ containsVar()

bool FlatLinearValueConstraints::containsVar ( Value  val) const

Returns true if a variable with the specified Value exists, false otherwise.

Definition at line 1109 of file FlatLinearValueConstraints.cpp.

References findVar().

Referenced by mlir::affine::ComputationSliceState::getAsConstraints().

◆ findVar()

bool FlatLinearValueConstraints::findVar ( Value  val,
unsigned *  pos,
unsigned  offset = 0 
) const

Looks up the position of the variable with the specified Value starting with variables at offset offset.

Returns true if found (false otherwise). pos is set to the (column) position of the variable.

Definition at line 1098 of file FlatLinearValueConstraints.cpp.

References getMaybeValues().

Referenced by addBound(), containsVar(), mergeAndAlignVars(), mergeSymbolVars(), projectOut(), and turnSymbolIntoDim().

◆ getKind()

Kind mlir::FlatLinearValueConstraints::getKind ( ) const
inlineoverridevirtual

◆ getMaybeValues() [1/2]

SmallVector<std::optional<Value> > mlir::FlatLinearValueConstraints::getMaybeValues ( ) const
inline

◆ getMaybeValues() [2/2]

SmallVector<std::optional<Value> > mlir::FlatLinearValueConstraints::getMaybeValues ( presburger::VarKind  kind) const
inline

Definition at line 333 of file FlatLinearValueConstraints.h.

◆ getValue()

Value mlir::FlatLinearValueConstraints::getValue ( unsigned  pos) const
inline

◆ getValues()

void mlir::FlatLinearValueConstraints::getValues ( unsigned  start,
unsigned  end,
SmallVectorImpl< Value > *  values 
) const
inline

Returns the Values associated with variables in range [start, end).

Asserts if no Value was associated with one of these variables.

Definition at line 310 of file FlatLinearValueConstraints.h.

References mlir::presburger::IntegerRelation::getNumDimAndSymbolVars(), and getValue().

Referenced by mlir::affine::computeSliceUnion(), createPrivateMemRef(), createSeparationCondition(), generateCopy(), mlir::affine::getComputationSliceState(), mergeAndAlignVars(), and mergeSymbolVars().

◆ hasValue()

bool mlir::FlatLinearValueConstraints::hasValue ( unsigned  pos) const
inline

Returns true if the pos^th variable has an associated Value.

Definition at line 349 of file FlatLinearValueConstraints.h.

References mlir::presburger::IntegerRelation::getNumDimAndSymbolVars().

Referenced by computeAlignedMap(), getMaybeValues(), getValue(), and printSpace().

◆ insertDimVar() [1/2]

unsigned mlir::FlatLinearConstraints::insertDimVar
inline

Insert variables of the specified kind at position pos.

Positions are relative to the kind of variable. The coefficient columns corresponding to the added variables are initialized to zero. vals are the Values corresponding to the variables. Values should not be used with VarKind::Local since values can only be attached to non-local variables. Return the absolute column position (i.e., not relative to the kind of variable) of the first added variable.

Note: Empty Values are allowed in vals.

Definition at line 149 of file FlatLinearValueConstraints.h.

◆ insertDimVar() [2/2]

unsigned FlatLinearValueConstraints::insertDimVar ( unsigned  pos,
ValueRange  vals 
)

Definition at line 861 of file FlatLinearValueConstraints.cpp.

References insertVar().

Referenced by mergeAndAlignVars().

◆ insertSymbolVar() [1/2]

unsigned mlir::FlatLinearConstraints::insertSymbolVar
inline

Definition at line 152 of file FlatLinearValueConstraints.h.

Referenced by mergeSymbolVars().

◆ insertSymbolVar() [2/2]

unsigned FlatLinearValueConstraints::insertSymbolVar ( unsigned  pos,
ValueRange  vals 
)

Definition at line 866 of file FlatLinearValueConstraints.cpp.

References insertVar().

Referenced by mergeSymbolVars().

◆ insertVar() [1/2]

unsigned FlatLinearValueConstraints::insertVar ( presburger::VarKind  kind,
unsigned  pos,
unsigned  num = 1 
)
overridevirtual

Insert num variables of the specified kind at position pos.

Positions are relative to the kind of variable. The coefficient columns corresponding to the added variables are initialized to zero. Return the absolute column position (i.e., not relative to the kind of variable) of the first added variable.

Reimplemented from mlir::presburger::IntegerRelation.

Definition at line 871 of file FlatLinearValueConstraints.cpp.

Referenced by appendDimVar(), appendSymbolVar(), FlatLinearValueConstraints(), insertDimVar(), and insertSymbolVar().

◆ insertVar() [2/2]

unsigned FlatLinearValueConstraints::insertVar ( presburger::VarKind  kind,
unsigned  pos,
ValueRange  vals 
)

Definition at line 878 of file FlatLinearValueConstraints.cpp.

◆ mergeAndAlignVarsWithOther()

void FlatLinearValueConstraints::mergeAndAlignVarsWithOther ( unsigned  offset,
FlatLinearValueConstraints other 
)

Merge and align the variables of this and other starting at offset, so that both constraint systems get the union of the contained variables that is dimension-wise and symbol-wise unique; both constraint systems are updated so that they have the union of all variables, with this's original variables appearing first followed by any of other's variables that didn't appear in this.

Local variables in other that have the same division representation as local variables in this are merged into one.

Definition at line 1020 of file FlatLinearValueConstraints.cpp.

References mergeAndAlignVars().

Referenced by mlir::affine::computeSliceUnion().

◆ mergeSymbolVars()

void FlatLinearValueConstraints::mergeSymbolVars ( FlatLinearValueConstraints other)

Merge and align symbols of this and other such that both get union of of symbols that are unique.

Merge and align symbols of this and other such that both get union of of symbols.

Symbols in this and other should be unique. Symbols with Value as None are considered to be inequal to all other symbols.

Existing symbols need not be unique; they will be aligned from left to right with duplicates aligned in the same order. Symbols with Value as None are considered to be inequal to all other symbols.

Definition at line 1029 of file FlatLinearValueConstraints.cpp.

References findVar(), mlir::presburger::IntegerRelation::getNumDimAndSymbolVars(), mlir::presburger::IntegerRelation::getNumDimVars(), mlir::presburger::IntegerRelation::getNumSymbolVars(), getValue(), getValues(), insertSymbolVar(), and mlir::presburger::IntegerRelation::swapVar().

Referenced by mergeAndAlignVars().

◆ printSpace()

void FlatLinearValueConstraints::printSpace ( raw_ostream &  os) const
overridevirtual

Prints the number of constraints, dimensions, symbols and locals in the FlatAffineValueConstraints.

Also, prints for each variable whether there is an SSA Value attached to it.

Reimplemented from mlir::FlatLinearConstraints.

Definition at line 1135 of file FlatLinearValueConstraints.cpp.

References mlir::presburger::IntegerRelation::getNumDimAndSymbolVars(), mlir::presburger::IntegerRelation::getVarKindEnd(), mlir::presburger::IntegerRelation::getVarKindOffset(), hasValue(), and impl::printSpace().

◆ projectOut()

void FlatLinearValueConstraints::projectOut ( Value  val)

◆ removeVarRange()

void FlatLinearValueConstraints::removeVarRange ( presburger::VarKind  kind,
unsigned  varStart,
unsigned  varLimit 
)
overridevirtual

Removes variables in the column range [varStart, varLimit), and copies any remaining valid data into place, updates member variables, and resizes arrays as needed.

Reimplemented from mlir::presburger::IntegerRelation.

Reimplemented in mlir::affine::FlatAffineRelation.

Definition at line 1060 of file FlatLinearValueConstraints.cpp.

◆ setValue()

void mlir::FlatLinearValueConstraints::setValue ( unsigned  pos,
Value  val 
)
inline

Sets the Value associated with the pos^th variable.

Stores the Value in the space's identifiers.

Definition at line 381 of file FlatLinearValueConstraints.h.

References mlir::presburger::IntegerRelation::getNumDimAndSymbolVars().

Referenced by mlir::affine::FlatAffineRelation::compose(), FlatLinearValueConstraints(), mlir::affine::getRelationFromMap(), and setValues().

◆ setValues()

void mlir::FlatLinearValueConstraints::setValues ( unsigned  start,
unsigned  end,
ArrayRef< Value values 
)
inline

Sets the Values associated with the variables in the range [start, end).

The range must contain only dim and symbol variables.

Definition at line 390 of file FlatLinearValueConstraints.h.

References mlir::presburger::IntegerRelation::getNumVars(), and setValue().

◆ unionBoundingBox()

LogicalResult FlatLinearValueConstraints::unionBoundingBox ( const FlatLinearValueConstraints other)

Updates the constraints to be the smallest bounding (enclosing) box that contains the points of this set and that of other, with the symbols being treated specially.

For each of the dimensions, the min of the lower bounds (symbolic) and the max of the upper bounds (symbolic) is computed to determine such a bounding box. other is expected to have the same dimensional variables as this constraint system (in the same order).

E.g.: 1) this = {0 <= d0 <= 127}, other = {16 <= d0 <= 192}, output = {0 <= d0 <= 192} 2) this = {s0 + 5 <= d0 <= s0 + 20}, other = {s0 + 1 <= d0 <= s0 + 9}, output = {s0 + 1 <= d0 <= s0 + 20} 3) this = {0 <= d0 <= 5, 1 <= d1 <= 9} other = {2 <= d0 <= 6, 5 <= d1 <= 15}, output = {0 <= d0 <= 6, 1 <= d1 <= 15}

Definition at line 1159 of file FlatLinearValueConstraints.cpp.

References areVarsAligned(), getMaybeValues(), mlir::presburger::IntegerRelation::getNumDimVars(), mlir::presburger::IntegerRelation::getNumLocalVars(), and mergeAndAlignVars().

Referenced by mlir::affine::computeSliceUnion().


The documentation for this class was generated from the following files: