9#ifndef MLIR_ANALYSIS_FLATLINEARVALUECONSTRAINTS_H
10#define MLIR_ANALYSIS_FLATLINEARVALUECONSTRAINTS_H
40 unsigned numReservedEqualities,
41 unsigned numReservedCols,
unsigned numDims,
42 unsigned numSymbols,
unsigned numLocals)
46 numDims, numSymbols, numLocals)) {
55 unsigned numLocals = 0)
58 numDims + numSymbols +
60 numDims, numSymbols, numLocals) {}
119 using IntegerPolyhedron::addBound;
140 std::optional<int64_t>
143 unsigned *minLbPos =
nullptr,
144 unsigned *minUbPos =
nullptr)
const;
164 bool closedUB =
false);
181 std::pair<AffineMap, AffineMap>
184 MLIRContext *context,
bool closedUB =
false)
const;
196 return insertVar(VarKind::SetDim, pos, num);
199 return insertVar(VarKind::Symbol, pos, num);
202 return insertVar(VarKind::Local, pos, num);
250 bool addConservativeSemiAffineBounds =
false);
271 unsigned numReservedEqualities,
272 unsigned numReservedCols,
unsigned numDims,
273 unsigned numSymbols,
unsigned numLocals,
274 ArrayRef<std::optional<Value>> valArgs)
276 numReservedCols, numDims, numSymbols, numLocals) {
278 for (
unsigned i = 0, e = valArgs.size(); i < e; ++i)
288 unsigned numReservedEqualities,
289 unsigned numReservedCols,
unsigned numDims,
290 unsigned numSymbols,
unsigned numLocals,
293 numReservedCols, numDims, numSymbols, numLocals) {
295 for (
unsigned i = 0, e = valArgs.size(); i < e; ++i)
306 ArrayRef<std::optional<Value>> valArgs)
309 numDims + numSymbols +
311 numDims, numSymbols, numLocals, valArgs) {}
318 unsigned numLocals = 0,
322 numDims + numSymbols +
324 numDims, numSymbols, numLocals, valArgs) {}
327 ArrayRef<std::optional<Value>> valArgs = {})
332 for (
unsigned i = 0, e = valArgs.size(); i < e; ++i)
356 assert(
hasValue(pos) &&
"variable's Value not set");
359 return space.getId(kind, relativePos).getValue<
Value>();
367 assert(start <= end &&
"invalid start position");
369 values->reserve(end - start);
370 for (
unsigned i = start; i < end; ++i)
381 maybeValues.push_back(std::nullopt);
388 assert(kind != VarKind::Local &&
389 "Local variables do not have any value attached to them.");
392 const unsigned offset =
space.getVarKindOffset(kind);
395 maybeValues.push_back(
getValue(offset + i));
397 maybeValues.push_back(std::nullopt);
407 return space.getId(kind, relativePos).hasValue();
423 unsigned num = 1)
override;
430 unsigned varLimit)
override;
431 using IntegerPolyhedron::removeVarRange;
445 assert(end <=
getNumVars() &&
"invalid end position");
446 assert(start <= end &&
"invalid start position");
447 assert(values.size() == end - start &&
448 "value should be provided for each variable in the range.");
449 for (
unsigned i = start; i < end; ++i)
456 bool findVar(
Value val,
unsigned *pos,
unsigned offset = 0)
const;
464 using IntegerPolyhedron::projectOut;
519 using IntegerPolyhedron::unionBoundingBox;
531 SmallVectorImpl<int64_t> *flattenedExpr,
532 FlatLinearConstraints *cst =
nullptr,
533 bool addConservativeSemiAffineBounds =
false);
548 FlatLinearConstraints *cst =
nullptr,
549 bool addConservativeSemiAffineBounds =
false);
553 FlatLinearConstraints *cst =
nullptr);
557 presburger::MultiAffineFunction &multiAff);
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)
void printSpace(raw_ostream &os) const override
Prints the number of constraints, dimensions, symbols and locals in the FlatLinearConstraints.
void dumpRow(ArrayRef< int64_t > row, bool fixedColWidth=true) const
An easier to read dump of a row of the same width as the number of columns.
FlatLinearConstraints(const IntegerPolyhedron &fac)
void dumpPretty() const
A more human-readable version of dump().
AddConservativeSemiAffineBounds
Flag to control if conservative semi-affine bounds should be added in addBound().
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...
LogicalResult flattenAlignedMapAndMergeLocals(AffineMap map, std::vector< SmallVector< int64_t, 8 > > *flattenedExprs, bool addConservativeSemiAffineBounds=false)
Given an affine map that is aligned with this constraint system:
LogicalResult addBound(presburger::BoundType type, unsigned pos, AffineMap boundMap, bool isClosedBound, AddConservativeSemiAffineBounds=AddConservativeSemiAffineBounds::No)
Adds a bound for the variable at the specified position with constraints being drawn from the specifi...
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,...
presburger::VarKind VarKind
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.
std::optional< int64_t > getConstantBoundOnDimSize(MLIRContext *context, unsigned pos, AffineMap *lb=nullptr, AffineMap *ub=nullptr, unsigned *minLbPos=nullptr, unsigned *minUbPos=nullptr) const
Returns a non-negative constant bound on the extent (upper bound - lower bound) of the specified vari...
FlatLinearValueConstraints represents an extension of FlatLinearConstraints where each non-local vari...
unsigned insertDimVar(unsigned pos, ValueRange vals)
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.
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...
bool hasValue(unsigned pos) const
Returns true if the pos^th variable has an associated Value.
static bool classof(const IntegerRelation *cst)
presburger::Identifier Identifier
The SSA Values attached to each non-local variable are stored as identifiers in the constraint system...
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...
FlatLinearValueConstraints(const IntegerPolyhedron &fac, ArrayRef< std::optional< Value > > valArgs={})
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.
FlatLinearValueConstraints(unsigned numDims, unsigned numSymbols, unsigned numLocals, ArrayRef< std::optional< Value > > valArgs)
Constructs a constraint system with the specified number of dimensions and symbols.
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.
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 ...
void addBound(presburger::BoundType type, Value val, int64_t value)
Adds a constant bound for the variable associated with the given Value.
unsigned appendDimVar(ValueRange vals)
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...
unsigned insertSymbolVar(unsigned pos, ValueRange vals)
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...
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).
void setValue(unsigned pos, Value val)
Sets the Value associated with the pos^th variable.
SmallVector< std::optional< Value > > getMaybeValues() const
SmallVector< std::optional< Value > > getMaybeValues(presburger::VarKind kind) const
unsigned appendSymbolVar(ValueRange vals)
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 Identifier stores a pointer to an object, such as a Value or an Operation.
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.
VarKind getVarKindAt(unsigned pos) const
Return the VarKind of the var at the specified position.
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 getFlattenedAffineExprs(AffineMap map, std::vector< SmallVector< int64_t, 8 > > *flattenedExprs, FlatLinearConstraints *cst=nullptr, bool addConservativeSemiAffineBounds=false)
Flattens the result expressions of the map to their corresponding flattened forms and set in 'flatten...
LogicalResult getFlattenedAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, SmallVectorImpl< int64_t > *flattenedExpr, FlatLinearConstraints *cst=nullptr, bool addConservativeSemiAffineBounds=false)
Flattens 'expr' into 'flattenedExpr', which contains the coefficients of the dimensions,...
LogicalResult getMultiAffineFunctionFromMap(AffineMap map, presburger::MultiAffineFunction &multiAff)
A mutable affine map. Its affine expressions are however unique.