9 #ifndef MLIR_ANALYSIS_FLATLINEARVALUECONSTRAINTS_H
10 #define MLIR_ANALYSIS_FLATLINEARVALUECONSTRAINTS_H
26 struct MutableAffineMap;
28 namespace presburger {
41 unsigned numReservedEqualities,
42 unsigned numReservedCols,
unsigned numDims,
43 unsigned numSymbols,
unsigned numLocals)
46 presburger::PresburgerSpace::getSetSpace(
47 numDims, numSymbols, numLocals)) {
56 unsigned numLocals = 0)
59 numDims + numSymbols +
61 numDims, numSymbols, numLocals) {}
98 using IntegerPolyhedron::addBound;
118 bool closedUB =
false);
135 std::pair<AffineMap, AffineMap>
138 MLIRContext *context,
bool closedUB =
false)
const;
150 return insertVar(VarKind::SetDim, pos, num);
153 return insertVar(VarKind::Symbol, pos, num);
156 return insertVar(VarKind::Local, pos, num);
201 void printSpace(raw_ostream &os)
const override;
213 unsigned numReservedEqualities,
214 unsigned numReservedCols,
unsigned numDims,
215 unsigned numSymbols,
unsigned numLocals,
216 ArrayRef<std::optional<Value>> valArgs)
218 numReservedCols, numDims, numSymbols, numLocals) {
220 values.reserve(numReservedCols);
224 values.append(valArgs.begin(), valArgs.end());
232 unsigned numReservedEqualities,
233 unsigned numReservedCols,
unsigned numDims,
234 unsigned numSymbols,
unsigned numLocals,
237 numReservedCols, numDims, numSymbols, numLocals) {
239 values.reserve(numReservedCols);
243 values.append(valArgs.begin(), valArgs.end());
252 ArrayRef<std::optional<Value>> valArgs)
255 numDims + numSymbols +
257 numDims, numSymbols, numLocals, valArgs) {}
264 unsigned numLocals = 0,
268 numDims + numSymbols +
270 numDims, numSymbols, numLocals, valArgs) {}
273 ArrayRef<std::optional<Value>> valArgs = {})
279 values.append(valArgs.begin(), valArgs.end());
304 assert(
hasValue(pos) &&
"variable's Value not set");
313 assert(start <= end &&
"invalid start position");
315 values->reserve(end - start);
316 for (
unsigned i = start; i < end; i++)
326 assert(kind != VarKind::Local &&
327 "Local variables do not have any value attached to them.");
334 return values[pos].has_value();
350 unsigned num = 1)
override;
357 unsigned varLimit)
override;
358 using IntegerPolyhedron::removeVarRange;
369 assert(end <=
getNumVars() &&
"invalid end position");
370 assert(start <= end &&
"invalid start position");
371 assert(
values.size() == end - start &&
372 "value should be provided for each variable in the range.");
373 for (
unsigned i = start; i < end; ++i)
380 bool findVar(
Value val,
unsigned *pos,
unsigned offset = 0)
const;
388 using IntegerPolyhedron::projectOut;
391 void swapVar(
unsigned posA,
unsigned posB)
override;
396 void printSpace(raw_ostream &os)
const override;
446 using IntegerPolyhedron::unionBoundingBox;
457 bool *isResultIntegerExact =
nullptr)
override;
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
FlatLinearConstraints is an extension of IntegerPolyhedron.
unsigned appendDimVar(unsigned num=1)
Append variables of the specified kind after the last variable of that kind.
IntegerSet getAsIntegerSet(MLIRContext *context) const
Returns the constraint system as an integer set.
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...
FlatLinearConstraints(unsigned numDims=0, unsigned numSymbols=0, unsigned numLocals=0)
Constructs a constraint system with the specified number of dimensions and symbols.
unsigned insertSymbolVar(unsigned pos, unsigned num=1)
unsigned appendLocalVar(unsigned num=1)
LogicalResult flattenAlignedMapAndMergeLocals(AffineMap map, std::vector< SmallVector< int64_t, 8 >> *flattenedExprs)
Given an affine map that is aligned with this constraint system:
void printSpace(raw_ostream &os) const override
Prints the number of constraints, dimensions, symbols and locals in the FlatLinearConstraints.
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 specifi...
FlatLinearConstraints(const IntegerPolyhedron &fac)
LogicalResult composeMatchingMap(AffineMap other)
Composes an affine map whose dimensions and symbols match one to one with the dimensions and symbols ...
unsigned appendSymbolVar(unsigned num=1)
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...
std::pair< AffineMap, AffineMap > getLowerAndUpperBound(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,...
unsigned insertLocalVar(unsigned pos, unsigned num=1)
LogicalResult computeLocalVars(SmallVectorImpl< AffineExpr > &memo, MLIRContext *context) const
Compute an explicit representation for local vars.
Kind getKind() const override
Return the kind of this object.
unsigned insertDimVar(unsigned pos, unsigned num=1)
Insert variables of the specified kind at position pos.
FlatLinearValueConstraints represents an extension of FlatLinearConstraints where each non-local vari...
unsigned appendDimVar(unsigned num=1)
Append variables of the specified kind after the last variable of that kind.
void clearAndCopyFrom(const IntegerRelation &other) override
Replaces the contents of this FlatLinearValueConstraints with other.
ArrayRef< std::optional< Value > > getMaybeValues(presburger::VarKind kind) const
void swapVar(unsigned posA, unsigned posB) override
Swap the posA^th variable with the posB^th variable.
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.
FlatLinearValueConstraints(unsigned numDims, unsigned numSymbols, unsigned numLocals, ArrayRef< std::optional< Value >> valArgs)
Constructs a constraint system with the specified number of dimensions and symbols.
LogicalResult unionBoundingBox(const FlatLinearValueConstraints &other)
Updates the constraints to be the smallest bounding (enclosing) box that contains the points of this ...
void mergeAndAlignVarsWithOther(unsigned offset, FlatLinearValueConstraints *other)
Merge and align the variables of this and other starting at offset, so that both constraint systems g...
unsigned insertSymbolVar(unsigned pos, unsigned num=1)
void fourierMotzkinEliminate(unsigned pos, bool darkShadow=false, bool *isResultIntegerExact=nullptr) override
Eliminates the variable at the specified position using Fourier-Motzkin variable elimination,...
SmallVector< std::optional< Value >, 8 > values
Values corresponding to the (column) non-local variables of this constraint system appearing in the o...
bool hasValue(unsigned pos) const
Returns true if the pos^th variable has an associated Value.
static bool classof(const IntegerRelation *cst)
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...
Value getValue(unsigned pos) const
Returns the Value associated with the pos^th variable.
void printSpace(raw_ostream &os) const override
Prints the number of constraints, dimensions, symbols and locals in the FlatAffineValueConstraints.
void mergeSymbolVars(FlatLinearValueConstraints &other)
Merge and align symbols of this and other such that both get union of of symbols that are unique.
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 specifi...
FlatLinearValueConstraints(const IntegerPolyhedron &fac, ArrayRef< std::optional< Value >> valArgs={})
void projectOut(Value val)
Projects out the variable that is associate with Value.
bool containsVar(Value val) const
Returns true if a variable with the specified Value exists, false otherwise.
bool hasConsistentState() const override
Returns false if the fields corresponding to various variable counts, or equality/inequality buffer s...
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 ...
unsigned appendSymbolVar(unsigned num=1)
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 offs...
ArrayRef< std::optional< Value > > getMaybeValues() const
bool areVarsAlignedWithOther(const FlatLinearConstraints &other)
Returns true if this constraint system and other are in the same space, i.e., if they are associated ...
AffineMap computeAlignedMap(AffineMap map, ValueRange operands) const
Align map with this constraint system based on operands.
void getValues(unsigned start, unsigned end, SmallVectorImpl< Value > *values) const
Returns the Values associated with variables in range [start, end).
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...
void setValue(unsigned pos, Value val)
Sets the Value associated with the pos^th variable.
unsigned insertDimVar(unsigned pos, unsigned num=1)
Insert variables of the specified kind at position pos.
unsigned insertVar(presburger::VarKind kind, unsigned pos, unsigned num=1) override
Insert num variables of the specified kind at position pos.
Kind getKind() const override
Return the kind of this object.
void setValues(unsigned start, unsigned end, ArrayRef< Value > values)
Sets the Values associated with the variables in the range [start, end).
An integer set representing a conjunction of one or more affine equalities and inequalities.
MLIRContext is the top-level object for a collection of MLIR operations.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
An IntegerPolyhedron represents the set of points from a PresburgerSpace that satisfy a list of affin...
unsigned insertVar(VarKind kind, unsigned pos, unsigned num=1) override
Insert num variables of the specified kind at position pos.
IntegerPolyhedron(unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, const PresburgerSpace &space)
Constructs a set reserving memory for the specified number of constraints and variables.
Kind
All derived classes of IntegerRelation.
@ FlatLinearValueConstraints
unsigned getNumVarKind(VarKind kind) const
Get the number of vars of the specified kind.
unsigned appendVar(VarKind kind, unsigned num=1)
Append num variables of the specified kind after the last variable of that kind.
IntegerRelation(unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, const PresburgerSpace &space)
Constructs a relation reserving memory for the specified number of constraints and variables.
unsigned getNumVars() const
unsigned getNumDimAndSymbolVars() const
unsigned getVarKindOffset(VarKind kind) const
Return the index at which the specified kind of vars starts.
This class represents a multi-affine function with the domain as Z^d, where d is the number of domain...
BoundType
The type of bound: equal, lower bound or upper bound.
Include the generated interface declarations.
AffineMap alignAffineMapWithValues(AffineMap map, ValueRange operands, ValueRange dims, ValueRange syms, SmallVector< Value > *newSyms=nullptr)
Re-indexes the dimensions and symbols of an affine map with given operands values to align with dims ...
LogicalResult getFlattenedAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, SmallVectorImpl< int64_t > *flattenedExpr, FlatLinearConstraints *cst=nullptr)
Flattens 'expr' into 'flattenedExpr', which contains the coefficients of the dimensions,...
LogicalResult getFlattenedAffineExprs(AffineMap map, std::vector< SmallVector< int64_t, 8 >> *flattenedExprs, FlatLinearConstraints *cst=nullptr)
Flattens the result expressions of the map to their corresponding flattened forms and set in 'flatten...
LogicalResult getMultiAffineFunctionFromMap(AffineMap map, presburger::MultiAffineFunction &multiAff)
This class represents an efficient way to signal success or failure.