diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h index 935307d4bb88e..1230fa16a5a0e 100644 --- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h @@ -8,7 +8,7 @@ // // A class to represent a relation over integer tuples. A relation is // represented as a constraint system over a space of tuples of integer valued -// variables supporting symbolic identifiers and existential quantification. +// variables supporting symbolic variables and existential quantification. // //===----------------------------------------------------------------------===// @@ -36,7 +36,7 @@ class PresburgerSet; /// Equality : c_0*x_0 + c_1*x_1 + .... + c_{n-1}*x_{n-1} + c_n == 0 /// /// where c_0, c_1, ..., c_n are integers and n is the total number of -/// identifiers in the space. +/// variables in the space. /// /// Such a relation corresponds to the set of integer points lying in a convex /// polyhedron. For example, consider the relation: @@ -45,8 +45,8 @@ class PresburgerSet; /// (x, y) : (1 <= x <= 7, x = 2y) /// This relation contains the pairs (2, 1), (4, 2), and (6, 3). /// -/// Since IntegerRelation makes a distinction between dimensions, IdKind::Range -/// and IdKind::Domain should be used to refer to dimension identifiers. +/// Since IntegerRelation makes a distinction between dimensions, VarKind::Range +/// and VarKind::Domain should be used to refer to dimension variables. class IntegerRelation { public: /// All derived classes of IntegerRelation. @@ -58,22 +58,22 @@ class IntegerRelation { }; /// Constructs a relation reserving memory for the specified number - /// of constraints and identifiers. + /// of constraints and variables. IntegerRelation(unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, const PresburgerSpace &space) - : space(space), equalities(0, space.getNumIds() + 1, + : space(space), equalities(0, space.getNumVars() + 1, numReservedEqualities, numReservedCols), - inequalities(0, space.getNumIds() + 1, numReservedInequalities, + inequalities(0, space.getNumVars() + 1, numReservedInequalities, numReservedCols) { - assert(numReservedCols >= space.getNumIds() + 1); + assert(numReservedCols >= space.getNumVars() + 1); } /// Constructs a relation with the specified number of dimensions and symbols. explicit IntegerRelation(const PresburgerSpace &space) : IntegerRelation(/*numReservedInequalities=*/0, /*numReservedEqualities=*/0, - /*numReservedCols=*/space.getNumIds() + 1, space) {} + /*numReservedCols=*/space.getNumVars() + 1, space) {} virtual ~IntegerRelation() = default; @@ -107,9 +107,9 @@ class IntegerRelation { /// Returns a copy of the space without locals. PresburgerSpace getSpaceWithoutLocals() const { - return PresburgerSpace::getRelationSpace(space.getNumDomainIds(), - space.getNumRangeIds(), - space.getNumSymbolIds()); + return PresburgerSpace::getRelationSpace(space.getNumDomainVars(), + space.getNumRangeVars(), + space.getNumSymbolVars()); } /// Appends constraints from `other` into `this`. This is equivalent to an @@ -144,19 +144,19 @@ class IntegerRelation { return getNumInequalities() + getNumEqualities(); } - unsigned getNumDomainIds() const { return space.getNumDomainIds(); } - unsigned getNumRangeIds() const { return space.getNumRangeIds(); } - unsigned getNumSymbolIds() const { return space.getNumSymbolIds(); } - unsigned getNumLocalIds() const { return space.getNumLocalIds(); } + unsigned getNumDomainVars() const { return space.getNumDomainVars(); } + unsigned getNumRangeVars() const { return space.getNumRangeVars(); } + unsigned getNumSymbolVars() const { return space.getNumSymbolVars(); } + unsigned getNumLocalVars() const { return space.getNumLocalVars(); } - unsigned getNumDimIds() const { return space.getNumDimIds(); } - unsigned getNumDimAndSymbolIds() const { - return space.getNumDimAndSymbolIds(); + unsigned getNumDimVars() const { return space.getNumDimVars(); } + unsigned getNumDimAndSymbolVars() const { + return space.getNumDimAndSymbolVars(); } - unsigned getNumIds() const { return space.getNumIds(); } + unsigned getNumVars() const { return space.getNumVars(); } /// Returns the number of columns in the constraint system. - inline unsigned getNumCols() const { return space.getNumIds() + 1; } + inline unsigned getNumCols() const { return space.getNumVars() + 1; } inline unsigned getNumEqualities() const { return equalities.getNumRows(); } @@ -180,34 +180,38 @@ class IntegerRelation { return inequalities.getRow(idx); } - /// Get the number of ids of the specified kind. - unsigned getNumIdKind(IdKind kind) const { return space.getNumIdKind(kind); }; + /// Get the number of vars of the specified kind. + unsigned getNumVarKind(VarKind kind) const { + return space.getNumVarKind(kind); + }; - /// Return the index at which the specified kind of id starts. - unsigned getIdKindOffset(IdKind kind) const { - return space.getIdKindOffset(kind); + /// Return the index at which the specified kind of vars starts. + unsigned getVarKindOffset(VarKind kind) const { + return space.getVarKindOffset(kind); }; - /// Return the index at Which the specified kind of id ends. - unsigned getIdKindEnd(IdKind kind) const { return space.getIdKindEnd(kind); }; + /// Return the index at Which the specified kind of vars ends. + unsigned getVarKindEnd(VarKind kind) const { + return space.getVarKindEnd(kind); + }; /// Get the number of elements of the specified kind in the range - /// [idStart, idLimit). - unsigned getIdKindOverlap(IdKind kind, unsigned idStart, - unsigned idLimit) const { - return space.getIdKindOverlap(kind, idStart, idLimit); + /// [varStart, varLimit). + unsigned getVarKindOverlap(VarKind kind, unsigned varStart, + unsigned varLimit) const { + return space.getVarKindOverlap(kind, varStart, varLimit); }; - /// Return the IdKind of the id at the specified position. - IdKind getIdKindAt(unsigned pos) const { return space.getIdKindAt(pos); }; + /// Return the VarKind of the var at the specified position. + VarKind getVarKindAt(unsigned pos) const { return space.getVarKindAt(pos); }; - /// The struct CountsSnapshot stores the count of each IdKind, and also of + /// The struct CountsSnapshot stores the count of each VarKind, and also of /// each constraint type. getCounts() returns a CountsSnapshot object /// describing the current state of the IntegerRelation. truncate() truncates - /// all ids of each IdKind and all constraints of both kinds beyond the counts - /// in the specified CountsSnapshot object. This can be used to achieve + /// all vars of each VarKind and all constraints of both kinds beyond the + /// counts in the specified CountsSnapshot object. This can be used to achieve /// rudimentary rollback support. As long as none of the existing constraints - /// or ids are disturbed, and only additional ids or constraints are added, + /// or vars are disturbed, and only additional vars or constraints are added, /// this addition can be rolled back using truncate. struct CountsSnapshot { public: @@ -225,37 +229,38 @@ class IntegerRelation { CountsSnapshot getCounts() const; void truncate(const CountsSnapshot &counts); - /// Insert `num` identifiers of the specified kind at position `pos`. - /// Positions are relative to the kind of identifier. The coefficient columns - /// corresponding to the added identifiers are initialized to zero. Return the - /// absolute column position (i.e., not relative to the kind of identifier) - /// of the first added identifier. - virtual unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1); + /// 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. + virtual unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1); - /// Append `num` identifiers of the specified kind after the last identifier. + /// Append `num` variables of the specified kind after the last variable. /// of that kind. Return the position of the first appended column relative to - /// the kind of identifier. The coefficient columns corresponding to the added - /// identifiers are initialized to zero. - unsigned appendId(IdKind kind, unsigned num = 1); + /// the kind of variable. The coefficient columns corresponding to the added + /// variables are initialized to zero. + unsigned appendVar(VarKind kind, unsigned num = 1); /// Adds an inequality (>= 0) from the coefficients specified in `inEq`. void addInequality(ArrayRef inEq); /// Adds an equality from the coefficients specified in `eq`. void addEquality(ArrayRef eq); - /// Eliminate the `posB^th` local identifier, replacing every instance of it - /// with the `posA^th` local identifier. This should be used when the two + /// Eliminate the `posB^th` local variable, replacing every instance of it + /// with the `posA^th` local variable. This should be used when the two /// local variables are known to always take the same values. - virtual void eliminateRedundantLocalId(unsigned posA, unsigned posB); + virtual void eliminateRedundantLocalVar(unsigned posA, unsigned posB); - /// Removes identifiers of the specified kind with the specified pos (or + /// Removes variables of the specified kind with the specified pos (or /// within the specified range) from the system. The specified location is - /// relative to the first identifier of the specified kind. - void removeId(IdKind kind, unsigned pos); - virtual void removeIdRange(IdKind kind, unsigned idStart, unsigned idLimit); + /// relative to the first variable of the specified kind. + void removeVar(VarKind kind, unsigned pos); + virtual void removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit); - /// Removes the specified identifier from the system. - void removeId(unsigned pos); + /// Removes the specified variable from the system. + void removeVar(unsigned pos); void removeEquality(unsigned pos); void removeInequality(unsigned pos); @@ -277,22 +282,22 @@ class IntegerRelation { /// range. MaybeOptimum> findIntegerLexMin() const; - /// Swap the posA^th identifier with the posB^th identifier. - virtual void swapId(unsigned posA, unsigned posB); + /// Swap the posA^th variable with the posB^th variable. + virtual void swapVar(unsigned posA, unsigned posB); /// Removes all equalities and inequalities. void clearConstraints(); - /// Sets the `values.size()` identifiers starting at `po`s to the specified + /// Sets the `values.size()` variables starting at `po`s to the specified /// values and removes them. void setAndEliminate(unsigned pos, ArrayRef values); /// Replaces the contents of this IntegerRelation with `other`. virtual void clearAndCopyFrom(const IntegerRelation &other); - /// Gather positions of all lower and upper bounds of the identifier at `pos`, + /// Gather positions of all lower and upper bounds of the variable at `pos`, /// and optionally any equalities on it. In addition, the bounds are to be - /// independent of identifiers in position range [`offset`, `offset` + `num`). + /// independent of variables in position range [`offset`, `offset` + `num`). void getLowerAndUpperBoundIndices(unsigned pos, SmallVectorImpl *lbIndices, @@ -301,7 +306,7 @@ class IntegerRelation { unsigned offset = 0, unsigned num = 0) const; /// Checks for emptiness by performing variable elimination on all - /// identifiers, running the GCD test on each equality constraint, and + /// variables, running the GCD test on each equality constraint, and /// checking for invalid constraints. Returns true if the GCD test fails for /// any equality, or if any invalid constraints are discovered on any row. /// Returns false otherwise. @@ -333,19 +338,19 @@ class IntegerRelation { Optional> findIntegerSample() const; /// Compute an overapproximation of the number of integer points in the - /// relation. Symbol ids are currently not supported. If the computed + /// relation. Symbol vars currently not supported. If the computed /// overapproximation is infinite, an empty optional is returned. Optional computeVolume() const; /// Returns true if the given point satisfies the constraints, or false - /// otherwise. Takes the values of all ids including locals. + /// otherwise. Takes the values of all vars including locals. bool containsPoint(ArrayRef point) const; - /// Given the values of non-local ids, return a satisfying assignment to the + /// Given the values of non-local vars, return a satisfying assignment to the /// local if one exists, or an empty optional otherwise. Optional> containsPointNoLocal(ArrayRef point) const; - /// Find equality and pairs of inequality contraints identified by their + /// Find equality and pairs of inequality constraints identified by their /// position indices, using which an explicit representation for each local /// variable can be computed. The indices of the constraints are stored in /// `MaybeLocalRepr` struct. If no such pair can be found, the kind attribute @@ -353,7 +358,7 @@ class IntegerRelation { /// /// The dividends of the explicit representations are stored in `dividends` /// and the denominators in `denominators`. If no explicit representation - /// could be found for the `i^th` local identifier, `denominators[i]` is set + /// could be found for the `i^th` local variable, `denominators[i]` is set /// to 0. void getLocalReprs(std::vector> ÷nds, SmallVector &denominators, @@ -365,20 +370,20 @@ class IntegerRelation { /// The type of bound: equal, lower bound or upper bound. enum BoundType { EQ, LB, UB }; - /// Adds a constant bound for the specified identifier. + /// Adds a constant bound for the specified variable. void addBound(BoundType type, unsigned pos, int64_t value); /// Adds a constant bound for the specified expression. void addBound(BoundType type, ArrayRef expr, int64_t value); - /// Adds a new local identifier as the floordiv of an affine function of other - /// identifiers, the coefficients of which are provided in `dividend` and with + /// 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`. Two constraints are added to the /// system to capture equivalence with the floordiv: /// q = dividend floordiv c <=> c*q <= dividend <= c*q + c - 1. void addLocalFloorDiv(ArrayRef dividend, int64_t divisor); - /// Projects out (aka eliminates) `num` identifiers starting at position + /// Projects out (aka eliminates) `num` variables starting at position /// `pos`. The resulting constraint system is the shadow along the dimensions /// that still exist. This method may not always be integer exact. // TODO: deal with integer exactness when necessary - can return a value to @@ -386,22 +391,22 @@ class IntegerRelation { void projectOut(unsigned pos, unsigned num); inline void projectOut(unsigned pos) { return projectOut(pos, 1); } - /// Tries to fold the specified identifier to a constant using a trivial + /// Tries to fold the specified variable to a constant using a trivial /// equality detection; if successful, the constant is substituted for the - /// identifier everywhere in the constraint system and then removed from the + /// variable everywhere in the constraint system and then removed from the /// system. - LogicalResult constantFoldId(unsigned pos); + LogicalResult constantFoldVar(unsigned pos); - /// This method calls `constantFoldId` for the specified range of identifiers, - /// `num` identifiers starting at position `pos`. - void constantFoldIdRange(unsigned pos, unsigned num); + /// This method calls `constantFoldVar` for the specified range of variables, + /// `num` variables starting at position `pos`. + void constantFoldVarRange(unsigned pos, unsigned num); /// 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 identifiers as this constraint system (in the same order). + /// dimensional variables as this constraint system (in the same order). /// /// E.g.: /// 1) this = {0 <= d0 <= 127}, @@ -416,20 +421,20 @@ class IntegerRelation { LogicalResult unionBoundingBox(const IntegerRelation &other); /// Returns the smallest known constant bound for the extent of the specified - /// identifier (pos^th), i.e., the smallest known constant that is greater + /// variable (pos^th), i.e., the smallest known constant that is greater /// than or equal to 'exclusive upper bound' - 'lower bound' of the - /// identifier. This constant bound is guaranteed to be non-negative. Returns + /// variable. This constant bound is guaranteed to be non-negative. Returns /// None if it's not a constant. This method employs trivial (low complexity / - /// cost) checks and detection. Symbolic identifiers are treated specially, + /// cost) checks and detection. Symbolic variables are treated specially, /// i.e., it looks for constant differences between affine expressions - /// involving only the symbolic identifiers. `lb` and `ub` (along with the + /// involving only the symbolic variables. `lb` and `ub` (along with the /// `boundFloorDivisor`) are set to represent the lower and upper bound /// associated with the constant difference: `lb`, `ub` have the coefficients, /// and `boundFloorDivisor`, their divisor. `minLbPos` and `minUbPos` if /// non-null are set to the position of the constant lower bound and upper /// bound respectively (to the same if they are from an equality). Ex: if the /// lower bound is [(s0 + s2 - 1) floordiv 32] for a system with three - /// symbolic identifiers, *lb = [1, 0, 1], lbDivisor = 32. See comments at + /// symbolic variables, *lb = [1, 0, 1], lbDivisor = 32. See comments at /// function definition for examples. Optional getConstantBoundOnDimSize( unsigned pos, SmallVectorImpl *lb = nullptr, @@ -437,16 +442,16 @@ class IntegerRelation { SmallVectorImpl *ub = nullptr, unsigned *minLbPos = nullptr, unsigned *minUbPos = nullptr) const; - /// Returns the constant bound for the pos^th identifier if there is one; + /// Returns the constant bound for the pos^th variable if there is one; /// None otherwise. Optional getConstantBound(BoundType type, unsigned pos) const; /// Removes constraints that are independent of (i.e., do not have a - /// coefficient) identifiers in the range [pos, pos + num). + /// coefficient) variables in the range [pos, pos + num). void removeIndependentConstraints(unsigned pos, unsigned num); /// Returns true if the set can be trivially detected as being - /// hyper-rectangular on the specified contiguous set of identifiers. + /// hyper-rectangular on the specified contiguous set of variables. bool isHyperRectangular(unsigned pos, unsigned num) const; /// Removes duplicate constraints, trivially true constraints, and constraints @@ -470,33 +475,33 @@ class IntegerRelation { void removeDuplicateDivs(); - /// Converts identifiers of kind srcKind in the range [idStart, idLimit) to + /// Converts variables of kind srcKind in the range [varStart, varLimit) to /// variables of kind dstKind. If `pos` is given, the variables are placed at /// position `pos` of dstKind, otherwise they are placed after all the other /// variables of kind dstKind. The internal ordering among the moved variables /// is preserved. - void convertIdKind(IdKind srcKind, unsigned idStart, unsigned idLimit, - IdKind dstKind, unsigned pos); - void convertIdKind(IdKind srcKind, unsigned idStart, unsigned idLimit, - IdKind dstKind) { - convertIdKind(srcKind, idStart, idLimit, dstKind, getNumIdKind(dstKind)); + void covertVarKind(VarKind srcKind, unsigned varStart, unsigned varLimit, + VarKind dstKind, unsigned pos); + void convertVarKind(VarKind srcKind, unsigned varStart, unsigned varLimit, + VarKind dstKind) { + covertVarKind(srcKind, varStart, varLimit, dstKind, getNumVarKind(dstKind)); } - void convertToLocal(IdKind kind, unsigned idStart, unsigned idLimit) { - convertIdKind(kind, idStart, idLimit, IdKind::Local); + void convertToLocal(VarKind kind, unsigned varStart, unsigned varLimit) { + convertVarKind(kind, varStart, varLimit, VarKind::Local); } - /// Adds additional local ids to the sets such that they both have the union - /// of the local ids in each set, without changing the set of points that + /// 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`. /// - /// While taking union, if a local id in `other` has a division representation - /// which is a duplicate of division representation, of another local id, it - /// is not added to the final union of local ids and is instead merged. The - /// new ordering of local ids is: + /// While taking union, if a local var in `other` has a division + /// representation which is a duplicate of division representation, of another + /// local var, it is not added to the final union of local vars and is instead + /// merged. The new ordering of local vars is: /// - /// [Local ids of `this`] [Non-merged local ids of `other`] + /// [Local vars of `this`] [Non-merged local vars of `other`] /// - /// The relative ordering of local ids is same as before. + /// The relative ordering of local vars is same as before. /// /// After merging, if the `i^th` local variable in one set has a known /// division representation, then the `i^th` local variable in the other set @@ -505,19 +510,19 @@ class IntegerRelation { /// /// The spaces of both relations should be compatible. /// - /// Returns the number of non-merged local ids of `other`, i.e. the number of + /// Returns the number of non-merged local vars of `other`, i.e. the number of /// locals that have been added to `this`. - unsigned mergeLocalIds(IntegerRelation &other); + unsigned mergeLocalVars(IntegerRelation &other); /// Check whether all local ids have a division representation. bool hasOnlyDivLocals() const; /// Changes the partition between dimensions and symbols. Depending on the new - /// symbol count, either a chunk of dimensional identifiers immediately before + /// symbol count, either a chunk of dimensional variables immediately before /// the split become symbols, or some of the symbols immediately after the /// split become dimensions. void setDimSymbolSeparation(unsigned newSymbolCount) { - space.setDimSymbolSeparation(newSymbolCount); + space.setVarSymbolSeperation(newSymbolCount); } /// Return a set corresponding to all points in the domain of the relation. @@ -585,11 +590,11 @@ class IntegerRelation { template Optional computeConstantLowerOrUpperBound(unsigned pos); - /// Eliminates a single identifier at `position` from equality and inequality - /// constraints. Returns `success` if the identifier was eliminated, and + /// Eliminates a single variable at `position` from equality and inequality + /// constraints. Returns `success` if the variable was eliminated, and /// `failure` otherwise. - inline LogicalResult gaussianEliminateId(unsigned position) { - return success(gaussianEliminateIds(position, position + 1) == 1); + inline LogicalResult gaussianEliminateVar(unsigned position) { + return success(gaussianEliminateVars(position, position + 1) == 1); } /// Removes local variables using equalities. Each equality is checked if it @@ -600,14 +605,14 @@ class IntegerRelation { /// variable is also removed. void removeRedundantLocalVars(); - /// Eliminates identifiers from equality and inequality constraints + /// Eliminates variables from equality and inequality constraints /// in column range [posStart, posLimit). /// Returns the number of variables eliminated. - unsigned gaussianEliminateIds(unsigned posStart, unsigned posLimit); + unsigned gaussianEliminateVars(unsigned posStart, unsigned posLimit); - /// Eliminates the identifier at the specified position using Fourier-Motzkin + /// Eliminates the variable at the specified position using Fourier-Motzkin /// variable elimination, but uses Gaussian elimination if there is an - /// equality involving that identifier. If the result of the elimination is + /// equality involving that variable. If the result of the elimination is /// integer exact, `*isResultIntegerExact` is set to true. If `darkShadow` is /// set to true, a potential under approximation (subset) of the rational /// shadow / exact integer shadow is computed. @@ -636,7 +641,7 @@ class IntegerRelation { /// equalities. bool isColZero(unsigned pos) const; - /// Returns false if the fields corresponding to various identifier counts, or + /// Returns false if the fields corresponding to various variable counts, or /// equality/inequality buffer sizes aren't consistent; true otherwise. This /// is meant to be used within an assert internally. virtual bool hasConsistentState() const; @@ -645,28 +650,28 @@ class IntegerRelation { /// IntegerRelation. virtual void printSpace(raw_ostream &os) const; - /// Removes identifiers in the column range [idStart, idLimit), and copies any + /// Removes variables in the column range [varStart, varLimit), and copies any /// remaining valid data into place, updates member variables, and resizes /// arrays as needed. - void removeIdRange(unsigned idStart, unsigned idLimit); + void removeVarRange(unsigned varStart, unsigned varLimit); - /// Truncate the ids of the specified kind to the specified number by dropping - /// some ids at the end. `num` must be less than the current number. - void truncateIdKind(IdKind kind, unsigned num); + /// Truncate the vars of the specified kind to the specified number by + /// dropping some vars at the end. `num` must be less than the current number. + void truncateVarKind(VarKind kind, unsigned num); - /// Truncate the ids to the number in the space of the specified + /// Truncate the vars to the number in the space of the specified /// CountsSnapshot. - void truncateIdKind(IdKind kind, const CountsSnapshot &counts); + void truncateVarKind(VarKind kind, const CountsSnapshot &counts); /// A parameter that controls detection of an unrealistic number of /// constraints. If the number of constraints is this many times the number of /// variables, we consider such a system out of line with the intended use /// case of IntegerRelation. // The rationale for 32 is that in the typical simplest of cases, an - // identifier is expected to have one lower bound and one upper bound - // constraint. With a level of tiling or a connection to another identifier + // variable is expected to have one lower bound and one upper bound + // constraint. With a level of tiling or a connection to another variable // through a div or mod, an extra pair of bounds gets added. As a limit, we - // don't expect an identifier to have more than 32 lower/upper/equality + // don't expect a variable to have more than 32 lower/upper/equality // constraints. This is conservatively set low and can be raised if needed. constexpr static unsigned kExplosionFactor = 32; @@ -689,25 +694,26 @@ struct SymbolicLexMin; /// Equality : c_0*x_0 + c_1*x_1 + .... + c_{n-1}*x_{n-1} + c_n == 0 /// /// where c_0, c_1, ..., c_n are integers and n is the total number of -/// identifiers in the space. +/// variables in the space. /// /// An IntegerPolyhedron is similar to an IntegerRelation but it does not make a -/// distinction between Domain and Range identifiers. Internally, -/// IntegerPolyhedron is implemented as a IntegerRelation with zero domain ids. +/// distinction between Domain and Range variables. Internally, +/// IntegerPolyhedron is implemented as a IntegerRelation with zero domain vars. /// /// Since IntegerPolyhedron does not make a distinction between kinds of -/// dimensions, IdKind::SetDim should be used to refer to dimension identifiers. +/// dimensions, VarKind::SetDim should be used to refer to dimension +/// variables. class IntegerPolyhedron : public IntegerRelation { public: /// Constructs a set reserving memory for the specified number - /// of constraints and identifiers. + /// of constraints and variables. IntegerPolyhedron(unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, const PresburgerSpace &space) : IntegerRelation(numReservedInequalities, numReservedEqualities, numReservedCols, space) { - assert(space.getNumDomainIds() == 0 && - "Number of domain id's should be zero in Set kind space."); + assert(space.getNumDomainVars() == 0 && + "Number of domain vars should be zero in Set kind space."); } /// Constructs a relation with the specified number of dimensions and @@ -715,21 +721,21 @@ class IntegerPolyhedron : public IntegerRelation { explicit IntegerPolyhedron(const PresburgerSpace &space) : IntegerPolyhedron(/*numReservedInequalities=*/0, /*numReservedEqualities=*/0, - /*numReservedCols=*/space.getNumIds() + 1, space) {} + /*numReservedCols=*/space.getNumVars() + 1, space) {} /// Construct a set from an IntegerRelation. The relation should have - /// no domain ids. + /// no domain vars. explicit IntegerPolyhedron(const IntegerRelation &rel) : IntegerRelation(rel) { - assert(space.getNumDomainIds() == 0 && - "Number of domain id's should be zero in Set kind space."); + assert(space.getNumDomainVars() == 0 && + "Number of domain vars should be zero in Set kind space."); } /// Construct a set from an IntegerRelation, but instead of creating a copy, - /// use move constructor. The relation should have no domain ids. + /// use move constructor. The relation should have no domain vars. explicit IntegerPolyhedron(IntegerRelation &&rel) : IntegerRelation(rel) { - assert(space.getNumDomainIds() == 0 && - "Number of domain id's should be zero in Set kind space."); + assert(space.getNumDomainVars() == 0 && + "Number of domain vars should be zero in Set kind space."); } /// Return a system with no constraints, i.e., one which is satisfied by all @@ -748,11 +754,11 @@ class IntegerPolyhedron : public IntegerRelation { // Clones this object. std::unique_ptr clone() const; - /// Insert `num` identifiers of the specified kind at position `pos`. - /// Positions are relative to the kind of identifier. Return the absolute - /// column position (i.e., not relative to the kind of identifier) of the - /// first added identifier. - unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1) override; + /// Insert `num` variables of the specified kind at position `pos`. + /// Positions are relative to the kind of variable. Return the absolute + /// column position (i.e., not relative to the kind of variable) of the + /// first added variable. + unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1) override; /// Compute an equivalent representation of the same set, such that all local /// ids have division representations. This representation may involve diff --git a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h index ecb5d34cc3803..00de5b5ac96a6 100644 --- a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h +++ b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h @@ -9,7 +9,7 @@ // Support for piece-wise multi-affine functions. These are functions that are // defined on a domain that is a union of IntegerPolyhedrons, and on each domain // the value of the function is a tuple of integers, with each value in the -// tuple being an affine expression in the ids of the IntegerPolyhedron. +// tuple being an affine expression in the vars of the IntegerPolyhedron. // //===----------------------------------------------------------------------===// @@ -25,7 +25,7 @@ namespace presburger { /// This class represents a multi-affine function whose domain is given by an /// IntegerPolyhedron. This can be thought of as an IntegerPolyhedron with a /// tuple of integer values attached to every point in the polyhedron, with the -/// value of each element of the tuple given by an affine expression in the ids +/// value of each element of the tuple given by an affine expression in the vars /// of the polyhedron. For example we could have the domain /// /// (x, y) : (x >= 5, y >= x) @@ -35,10 +35,10 @@ namespace presburger { /// (x, y) -> (x + 2, 2*x - 3y + 5, 2*x + y). /// /// In this way every point in the polyhedron has a tuple of integers associated -/// with it. If the integer polyhedron has local ids, then the output +/// with it. If the integer polyhedron has local vars, then the output /// expressions can use them as well. The output expressions are represented as /// a matrix with one row for every element in the output vector one column for -/// each id, and an extra column at the end for the constant term. +/// each var, and an extra column at the end for the constant term. /// /// Checking equality of two such functions is supported, as well as finding the /// value of the function at a specified point. @@ -49,28 +49,28 @@ class MultiAffineFunction { MultiAffineFunction(const Matrix &output, const PresburgerSpace &space) : domainSet(space), output(output) {} - unsigned getNumInputs() const { return domainSet.getNumDimAndSymbolIds(); } + unsigned getNumInputs() const { return domainSet.getNumDimAndSymbolVars(); } unsigned getNumOutputs() const { return output.getNumRows(); } bool isConsistent() const { - return output.getNumColumns() == domainSet.getNumIds() + 1; + return output.getNumColumns() == domainSet.getNumVars() + 1; } const IntegerPolyhedron &getDomain() const { return domainSet; } const PresburgerSpace &getDomainSpace() const { return domainSet.getSpace(); } - /// Insert `num` identifiers of the specified kind at position `pos`. - /// Positions are relative to the kind of identifier. The coefficient columns - /// corresponding to the added identifiers are initialized to zero. Return the - /// absolute column position (i.e., not relative to the kind of identifier) - /// of the first added identifier. - unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1); + /// 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. + unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1); - /// Remove the specified range of ids. - void removeIdRange(IdKind kind, unsigned idStart, unsigned idLimit); + /// Remove the specified range of vars. + void removeVarRange(VarKind kind, unsigned varStart, unsigned varLimit); - /// Given a MAF `other`, merges local identifiers such that both funcitons - /// have union of local ids, without changing the set of points in domain or + /// Given a MAF `other`, merges local variables such that both funcitons + /// have union of local vars, without changing the set of points in domain or /// the output. - void mergeLocalIds(MultiAffineFunction &other); + void mergeLocalVars(MultiAffineFunction &other); /// Return whether the outputs of `this` and `other` agree wherever both /// functions are defined, i.e., the outputs should be equal for all points in @@ -88,7 +88,7 @@ class MultiAffineFunction { /// Truncate the output dimensions to the first `count` dimensions. /// - /// TODO: refactor so that this can be accomplished through removeIdRange. + /// TODO: refactor so that this can be accomplished through removeVarRange. void truncateOutput(unsigned count); void print(raw_ostream &os) const; @@ -118,8 +118,8 @@ class MultiAffineFunction { /// this class is undefined. The domains need not cover all possible points; /// this represents a partial function and so could be undefined at some points. /// -/// As in PresburgerSets, the input ids are partitioned into dimension ids and -/// symbolic ids. +/// As in PresburgerSets, the input vars are partitioned into dimension vars and +/// symbolic vars. /// /// Support is provided to compare equality of two such functions as well as /// finding the value of the function at a point. @@ -127,10 +127,10 @@ class PWMAFunction { public: PWMAFunction(const PresburgerSpace &space, unsigned numOutputs) : space(space), numOutputs(numOutputs) { - assert(space.getNumDomainIds() == 0 && - "Set type space should have zero domain ids."); - assert(space.getNumLocalIds() == 0 && - "PWMAFunction cannot have local ids."); + assert(space.getNumDomainVars() == 0 && + "Set type space should have zero domain vars."); + assert(space.getNumLocalVars() == 0 && + "PWMAFunction cannot have local vars."); assert(numOutputs >= 1 && "The function must output something!"); } @@ -142,7 +142,7 @@ class PWMAFunction { const MultiAffineFunction &getPiece(unsigned i) const { return pieces[i]; } unsigned getNumPieces() const { return pieces.size(); } unsigned getNumOutputs() const { return numOutputs; } - unsigned getNumInputs() const { return space.getNumIds(); } + unsigned getNumInputs() const { return space.getNumVars(); } MultiAffineFunction &getPiece(unsigned i) { return pieces[i]; } /// Return the domain of this piece-wise MultiAffineFunction. This is the @@ -160,7 +160,7 @@ class PWMAFunction { /// Truncate the output dimensions to the first `count` dimensions. /// - /// TODO: refactor so that this can be accomplished through removeIdRange. + /// TODO: refactor so that this can be accomplished through removeVarRange. void truncateOutput(unsigned count); void print(raw_ostream &os) const; @@ -172,7 +172,7 @@ class PWMAFunction { /// The list of pieces in this piece-wise MultiAffineFunction. SmallVector pieces; - /// The number of output ids. + /// The number of output vars. unsigned numOutputs; }; diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h index 89a3deb30e689..50c4586cf87ff 100644 --- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h @@ -44,11 +44,11 @@ class PresburgerRelation { explicit PresburgerRelation(const IntegerRelation &disjunct); - unsigned getNumDomainIds() const { return space.getNumDomainIds(); } - unsigned getNumRangeIds() const { return space.getNumRangeIds(); } - unsigned getNumSymbolIds() const { return space.getNumSymbolIds(); } - unsigned getNumLocalIds() const { return space.getNumLocalIds(); } - unsigned getNumIds() const { return space.getNumIds(); } + unsigned getNumDomainVars() const { return space.getNumDomainVars(); } + unsigned getNumRangeVars() const { return space.getNumRangeVars(); } + unsigned getNumSymbolVars() const { return space.getNumSymbolVars(); } + unsigned getNumLocalVars() const { return space.getNumLocalVars(); } + unsigned getNumVars() const { return space.getNumVars(); } /// Return the number of disjuncts in the union. unsigned getNumDisjuncts() const; @@ -111,7 +111,7 @@ class PresburgerRelation { bool findIntegerSample(SmallVectorImpl &sample); /// Compute an overapproximation of the number of integer points in the - /// disjunct. Symbol ids are currently not supported. If the computed + /// disjunct. Symbol vars are currently not supported. If the computed /// overapproximation is infinite, an empty optional is returned. /// /// This currently just sums up the overapproximations of the volumes of the @@ -136,8 +136,8 @@ class PresburgerRelation { /// Construct an empty PresburgerRelation with the specified number of /// dimension and symbols. explicit PresburgerRelation(const PresburgerSpace &space) : space(space) { - assert(space.getNumLocalIds() == 0 && - "PresburgerRelation cannot have local ids."); + assert(space.getNumLocalVars() == 0 && + "PresburgerRelation cannot have local vars."); } PresburgerSpace space; @@ -174,9 +174,10 @@ class PresburgerSet : public PresburgerRelation { /// dimension and symbols. explicit PresburgerSet(const PresburgerSpace &space) : PresburgerRelation(space) { - assert(space.getNumDomainIds() == 0 && "Set type cannot have domain ids."); - assert(space.getNumLocalIds() == 0 && - "PresburgerRelation cannot have local ids."); + assert(space.getNumDomainVars() == 0 && + "Set type cannot have domain vars."); + assert(space.getNumLocalVars() == 0 && + "PresburgerRelation cannot have local vars."); } }; diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h index fda5835450d5e..bea5d3a8d074d 100644 --- a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// // -// Classes representing space information like number of identifiers and kind of -// identifiers. +// Classes representing space information like number of variables and kind of +// variables. // //===----------------------------------------------------------------------===// @@ -23,23 +23,23 @@ namespace mlir { namespace presburger { -/// Kind of identifier. Implementation wise SetDims are treated as Range -/// ids, and spaces with no distinction between dimension ids are treated -/// as relations with zero domain ids. -enum class IdKind { Symbol, Local, Domain, Range, SetDim = Range }; +/// Kind of variable. Implementation wise SetDims are treated as Range +/// vars, and spaces with no distinction between dimension vars are treated +/// as relations with zero domain vars. +enum class VarKind { Symbol, Local, Domain, Range, SetDim = Range }; /// PresburgerSpace is the space of all possible values of a tuple of integer -/// valued variables/identifiers. Each identifier has one of the three types: +/// valued variables/variables. Each variable has one of the three types: /// /// Dimension: Ordinary variables over which the space is represented. /// -/// Symbol: Symbol identifiers correspond to fixed but unknown values. -/// Mathematically, a space with symbolic identifiers is like a -/// family of spaces indexed by the symbolic identifiers. +/// Symbol: Symbol variables correspond to fixed but unknown values. +/// Mathematically, a space with symbolic variables is like a +/// family of spaces indexed by the symbolic variables. /// -/// Local: Local identifiers correspond to existentially quantified variables. +/// Local: Local variables correspond to existentially quantified variables. /// For example, consider the space: `(x, exists q)` where x is a dimension -/// identifier and q is a local identifier. Let us put the constraints: +/// variable and q is a local variable. Let us put the constraints: /// `1 <= x <= 7, x = 2q` /// on this space to get the set: /// `(x) : (exists q : q <= x <= 7, x = 2q)`. @@ -52,19 +52,19 @@ enum class IdKind { Symbol, Local, Domain, Range, SetDim = Range }; /// i.e. we obtained {2, 4, 6} by projecting out the second dimension from /// {(2, 1), (4, 2), (6, 2)}. /// -/// Dimension identifiers are further divided into Domain and Range identifiers +/// Dimension variables are further divided into Domain and Range variables /// to support building relations. /// -/// Identifiers are stored in the following order: +/// Variables are stored in the following order: /// [Domain, Range, Symbols, Locals] /// -/// A space with no distinction between types of dimension identifiers can -/// be implemented as a space with zero domain. IdKind::SetDim should be used +/// A space with no distinction between types of dimension variables can +/// be implemented as a space with zero domain. VarKind::SetDim should be used /// to refer to dimensions in such spaces. /// -/// Compatibility of two spaces implies that number of identifiers of each kind +/// Compatibility of two spaces implies that number of variables of each kind /// other than Locals are equal. Equality of two spaces implies that number of -/// identifiers of each kind are equal. +/// variables of each kind are equal. /// /// PresburgerSpace optionally also supports attaching attachments to each /// variable in space. `resetAttachments` enables attaching @@ -91,67 +91,67 @@ class PresburgerSpace { numLocals); } - unsigned getNumDomainIds() const { return numDomain; } - unsigned getNumRangeIds() const { return numRange; } - unsigned getNumSetDimIds() const { return numRange; } - unsigned getNumSymbolIds() const { return numSymbols; } - unsigned getNumLocalIds() const { return numLocals; } + unsigned getNumDomainVars() const { return numDomain; } + unsigned getNumRangeVars() const { return numRange; } + unsigned getNumSetDimVars() const { return numRange; } + unsigned getNumSymbolVars() const { return numSymbols; } + unsigned getNumLocalVars() const { return numLocals; } - unsigned getNumDimIds() const { return numDomain + numRange; } - unsigned getNumDimAndSymbolIds() const { + unsigned getNumDimVars() const { return numDomain + numRange; } + unsigned getNumDimAndSymbolVars() const { return numDomain + numRange + numSymbols; } - unsigned getNumIds() const { + unsigned getNumVars() const { return numDomain + numRange + numSymbols + numLocals; } - /// Get the number of ids of the specified kind. - unsigned getNumIdKind(IdKind kind) const; + /// Get the number of vars of the specified kind. + unsigned getNumVarKind(VarKind kind) const; - /// Return the index at which the specified kind of id starts. - unsigned getIdKindOffset(IdKind kind) const; + /// Return the index at which the specified kind of var starts. + unsigned getVarKindOffset(VarKind kind) const; - /// Return the index at Which the specified kind of id ends. - unsigned getIdKindEnd(IdKind kind) const; + /// Return the index at Which the specified kind of var ends. + unsigned getVarKindEnd(VarKind kind) const; /// Get the number of elements of the specified kind in the range - /// [idStart, idLimit). - unsigned getIdKindOverlap(IdKind kind, unsigned idStart, - unsigned idLimit) const; + /// [varStart, varLimit). + unsigned getVarKindOverlap(VarKind kind, unsigned varStart, + unsigned varLimit) const; - /// Return the IdKind of the id at the specified position. - IdKind getIdKindAt(unsigned pos) const; + /// Return the VarKind of the var at the specified position. + VarKind getVarKindAt(unsigned pos) const; - /// Insert `num` identifiers of the specified kind at position `pos`. - /// Positions are relative to the kind of identifier. Return the absolute - /// column position (i.e., not relative to the kind of identifier) of the - /// first added identifier. + /// Insert `num` variables of the specified kind at position `pos`. + /// Positions are relative to the kind of variable. Return the absolute + /// column position (i.e., not relative to the kind of variable) of the + /// first added variable. /// /// If attachments are being used, the newly added variables have no /// attachments. - unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1); + unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1); - /// Removes identifiers of the specified kind in the column range [idStart, - /// idLimit). The range is relative to the kind of identifier. - void removeIdRange(IdKind kind, unsigned idStart, unsigned idLimit); + /// Removes variables of the specified kind in the column range [varStart, + /// varLimit). The range is relative to the kind of variable. + void removeVarRange(VarKind kind, unsigned varStart, unsigned varLimit); /// Swaps the posA^th variable of kindA and posB^th variable of kindB. - void swapId(IdKind kindA, IdKind kindB, unsigned posA, unsigned posB); + void swapVar(VarKind kindA, VarKind kindB, unsigned posA, unsigned posB); /// Returns true if both the spaces are compatible i.e. if both spaces have - /// the same number of identifiers of each kind (excluding locals). + /// the same number of variables of each kind (excluding locals). bool isCompatible(const PresburgerSpace &other) const; - /// Returns true if both the spaces are equal including local identifiers i.e. - /// if both spaces have the same number of identifiers of each kind (including + /// Returns true if both the spaces are equal including local variables i.e. + /// if both spaces have the same number of variables of each kind (including /// locals). bool isEqual(const PresburgerSpace &other) const; /// Changes the partition between dimensions and symbols. Depending on the new - /// symbol count, either a chunk of dimensional identifiers immediately before + /// symbol count, either a chunk of dimensional variables immediately before /// the split become symbols, or some of the symbols immediately after the /// split become dimensions. - void setDimSymbolSeparation(unsigned newSymbolCount); + void setVarSymbolSeperation(unsigned newSymbolCount); void print(llvm::raw_ostream &os) const; void dump() const; @@ -163,7 +163,7 @@ class PresburgerSpace { /// Set the attachment for `i^th` variable to `attachment`. `T` here should /// match the type used to enable attachments. template - void setAttachment(IdKind kind, unsigned i, T attachment) { + void setAttachment(VarKind kind, unsigned i, T attachment) { #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS assert(TypeID::get() == attachmentType && "Type mismatch"); #endif @@ -174,7 +174,7 @@ class PresburgerSpace { /// Get the attachment for `i^th` variable casted to type `T`. `T` here /// should match the type used to enable attachments. template - T getAttachment(IdKind kind, unsigned i) const { + T getAttachment(VarKind kind, unsigned i) const { #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS assert(TypeID::get() == attachmentType && "Type mismatch"); #endif @@ -184,7 +184,7 @@ class PresburgerSpace { /// Check if the i^th variable of the specified kind has a non-null /// attachment. - bool hasAttachment(IdKind kind, unsigned i) const { + bool hasAttachment(VarKind kind, unsigned i) const { return atAttachment(kind, i) != nullptr; } @@ -193,14 +193,14 @@ class PresburgerSpace { bool isAligned(const PresburgerSpace &other) const; /// Check if the number of variables of the specified kind match, and have /// same attachments with the other space. - bool isAligned(const PresburgerSpace &other, IdKind kind) const; + bool isAligned(const PresburgerSpace &other, VarKind kind) const; /// Find the variable of the specified kind with attachment `val`. /// PresburgerSpace::kIdNotFound if attachment is not found. template - unsigned findId(IdKind kind, T val) const { + unsigned findId(VarKind kind, T val) const { unsigned i = 0; - for (unsigned e = getNumIdKind(kind); i < e; ++i) + for (unsigned e = getNumVarKind(kind); i < e; ++i) if (hasAttachment(kind, i) && getAttachment(kind, i) == val) return i; return kIdNotFound; @@ -215,7 +215,7 @@ class PresburgerSpace { template void resetAttachments() { attachments.clear(); - attachments.resize(getNumDimAndSymbolIds()); + attachments.resize(getNumDimAndSymbolVars()); #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS attachmentType = TypeID::get(); #endif @@ -235,32 +235,34 @@ class PresburgerSpace { : numDomain(numDomain), numRange(numRange), numSymbols(numSymbols), numLocals(numLocals) {} - void *&atAttachment(IdKind kind, unsigned i) { + void *&atAttachment(VarKind kind, unsigned i) { assert(usingAttachments && "Cannot access attachments when `usingAttachments` is false."); - assert(kind != IdKind::Local && "Local variables cannot have attachments."); - return attachments[getIdKindOffset(kind) + i]; + assert(kind != VarKind::Local && + "Local variables cannot have attachments."); + return attachments[getVarKindOffset(kind) + i]; } - void *atAttachment(IdKind kind, unsigned i) const { + void *atAttachment(VarKind kind, unsigned i) const { assert(usingAttachments && "Cannot access attachments when `usingAttachments` is false."); - assert(kind != IdKind::Local && "Local variables cannot have attachments."); - return attachments[getIdKindOffset(kind) + i]; + assert(kind != VarKind::Local && + "Local variables cannot have attachments."); + return attachments[getVarKindOffset(kind) + i]; } private: - // Number of identifiers corresponding to domain identifiers. + // Number of variables corresponding to domain variables. unsigned numDomain; - // Number of identifiers corresponding to range identifiers. + // Number of variables corresponding to range variables. unsigned numRange; - /// Number of identifiers corresponding to symbols (unknown but constant for + /// Number of variables corresponding to symbols (unknown but constant for /// analysis). unsigned numSymbols; - /// Number of identifers corresponding to locals (identifiers corresponding + /// Number of variables corresponding to locals (variables corresponding /// to existentially quantified variables). unsigned numLocals; @@ -272,7 +274,7 @@ class PresburgerSpace { TypeID attachmentType; #endif - /// Stores a attachment for each non-local identifier as a `void` pointer. + /// Stores a attachment for each non-local variable as a `void` pointer. SmallVector attachments; }; diff --git a/mlir/include/mlir/Analysis/Presburger/Simplex.h b/mlir/include/mlir/Analysis/Presburger/Simplex.h index f583c59ef24be..250ed92dd50b8 100644 --- a/mlir/include/mlir/Analysis/Presburger/Simplex.h +++ b/mlir/include/mlir/Analysis/Presburger/Simplex.h @@ -425,9 +425,9 @@ class LexSimplexBase : public SimplexBase { LexSimplexBase(unsigned nVar, unsigned symbolOffset, unsigned nSymbol) : SimplexBase(nVar, /*mustUseBigM=*/true, symbolOffset, nSymbol) {} explicit LexSimplexBase(const IntegerRelation &constraints) - : LexSimplexBase(constraints.getNumIds(), - constraints.getIdKindOffset(IdKind::Symbol), - constraints.getNumSymbolIds()) { + : LexSimplexBase(constraints.getNumVars(), + constraints.getVarKindOffset(VarKind::Symbol), + constraints.getNumSymbolVars()) { intersectIntegerRelation(constraints); } @@ -474,7 +474,7 @@ class LexSimplex : public LexSimplexBase { : LexSimplexBase(nVar, /*symbolOffset=*/0, /*nSymbol=*/0) {} explicit LexSimplex(const IntegerRelation &constraints) : LexSimplexBase(constraints) { - assert(constraints.getNumSymbolIds() == 0 && + assert(constraints.getNumSymbolVars() == 0 && "LexSimplex does not support symbols!"); } @@ -568,31 +568,31 @@ class SymbolicLexSimplex : public LexSimplexBase { public: /// `constraints` is the set for which the symbolic lexmin will be computed. /// `symbolDomain` is the set of values of the symbols for which the lexmin - /// will be computed. `symbolDomain` should have a dim id for every symbol in - /// `constraints`, and no other ids. + /// will be computed. `symbolDomain` should have a dim var for every symbol in + /// `constraints`, and no other vars. SymbolicLexSimplex(const IntegerPolyhedron &constraints, const IntegerPolyhedron &symbolDomain) : SymbolicLexSimplex(constraints, - constraints.getIdKindOffset(IdKind::Symbol), + constraints.getVarKindOffset(VarKind::Symbol), symbolDomain) { - assert(constraints.getNumSymbolIds() == symbolDomain.getNumIds()); + assert(constraints.getNumSymbolVars() == symbolDomain.getNumVars()); } /// An overload to select some other subrange of ids as symbols for lexmin. /// The symbol ids are the range of ids with absolute index - /// [symbolOffset, symbolOffset + symbolDomain.getNumIds()) + /// [symbolOffset, symbolOffset + symbolDomain.getNumVars()) /// symbolDomain should only have dim ids. SymbolicLexSimplex(const IntegerPolyhedron &constraints, unsigned symbolOffset, const IntegerPolyhedron &symbolDomain) - : LexSimplexBase(/*nVar=*/constraints.getNumIds(), symbolOffset, - symbolDomain.getNumIds()), + : LexSimplexBase(/*nVar=*/constraints.getNumVars(), symbolOffset, + symbolDomain.getNumVars()), domainPoly(symbolDomain), domainSimplex(symbolDomain) { // TODO consider supporting this case. It amounts // to just returning the input constraints. - assert(domainPoly.getNumIds() > 0 && + assert(domainPoly.getNumVars() > 0 && "there must be some non-symbols to optimize!"); - assert(domainPoly.getNumIds() == domainPoly.getNumDimIds()); + assert(domainPoly.getNumVars() == domainPoly.getNumDimVars()); intersectIntegerRelation(constraints); } @@ -683,7 +683,7 @@ class Simplex : public SimplexBase { : SimplexBase(nVar, /*mustUseBigM=*/false, /*symbolOffset=*/0, /*nSymbol=*/0) {} explicit Simplex(const IntegerRelation &constraints) - : Simplex(constraints.getNumIds()) { + : Simplex(constraints.getNumVars()) { intersectIntegerRelation(constraints); } ~Simplex() override = default; diff --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h index 28ccb836dfc8e..5e887fbf0cabb 100644 --- a/mlir/include/mlir/Analysis/Presburger/Utils.h +++ b/mlir/include/mlir/Analysis/Presburger/Utils.h @@ -85,10 +85,11 @@ class MaybeOptimum { /// `ReprKind` enum is used to set the constraint type in `MaybeLocalRepr`. enum class ReprKind { Inequality, Equality, None }; -/// `MaybeLocalRepr` contains the indices of the contraints that can be +/// `MaybeLocalRepr` contains the indices of the constraints that can be /// expressed as a floordiv of an affine function. If it's an `equality` -/// contraint `equalityIdx` is set, in case of `inequality` the `lowerBoundIdx` -/// and `upperBoundIdx` is set. By default the kind attribute is set to None. +/// constraint, `equalityIdx` is set, in case of `inequality` the +/// `lowerBoundIdx` and `upperBoundIdx` is set. By default the kind attribute is +/// set to None. struct MaybeLocalRepr { ReprKind kind = ReprKind::None; explicit operator bool() const { return kind != ReprKind::None; } @@ -100,10 +101,10 @@ struct MaybeLocalRepr { } repr; }; -/// Check if the pos^th identifier can be expressed as a floordiv of an affine -/// function of other identifiers (where the divisor is a positive constant). -/// `foundRepr` contains a boolean for each identifier indicating if the -/// explicit representation for that identifier has already been computed. +/// Check if the pos^th variable can be expressed as a floordiv of an affine +/// function of other variables (where the divisor is a positive constant). +/// `foundRepr` contains a boolean for each variable indicating if the +/// explicit representation for that variable has already been computed. /// Returns the `MaybeLocalRepr` struct which contains the indices of the /// constraints that can be expressed as a floordiv of an affine function. If /// the representation could be computed, `dividend` and `denominator` are set. @@ -116,7 +117,7 @@ MaybeLocalRepr computeSingleVarRepr(const IntegerRelation &cst, /// Given dividends of divisions `divs` and denominators `denoms`, detects and /// removes duplicate divisions. `localOffset` is the offset in dividend of a -/// division from where local identifiers start. +/// division from where local variables start. /// /// On every possible duplicate division found, `merge(i, j)`, where `i`, `j` /// are current index of the duplicate divisions, is called and division at @@ -124,26 +125,26 @@ MaybeLocalRepr computeSingleVarRepr(const IntegerRelation &cst, /// `true`, the divisions are merged i.e. `j^th` division gets eliminated and /// it's each instance is replaced by `i^th` division. If it returns `false`, /// the divisions are not merged. `merge` can also do side effects, For example -/// it can merge the local identifiers in IntegerRelation. +/// it can merge the local variables in IntegerRelation. void removeDuplicateDivs( std::vector> &divs, SmallVectorImpl &denoms, unsigned localOffset, llvm::function_ref merge); -/// Given two relations, A and B, add additional local ids to the sets such -/// that both have the union of the local ids in each set, without changing +/// Given two relations, A and B, add additional local vars to the sets such +/// that both have the union of the local vars in each set, without changing /// the set of points that lie in A and B. /// -/// While taking union, if a local id in any set has a division representation -/// which is a duplicate of division representation, of another local id in any -/// set, it is not added to the final union of local ids and is instead merged. +/// While taking union, if a local var in any set has a division representation +/// which is a duplicate of division representation, of another local var in any +/// set, it is not added to the final union of local vars and is instead merged. /// /// On every possible merge, `merge(i, j)` is called. `i`, `j` are position -/// of local identifiers in both sets which are being merged. If `merge(i, j)` +/// of local variables in both sets which are being merged. If `merge(i, j)` /// returns true, the divisions are merged, otherwise the divisions are not /// merged. -void mergeLocalIds(IntegerRelation &relA, IntegerRelation &relB, - llvm::function_ref merge); +void mergeLocalVars(IntegerRelation &relA, IntegerRelation &relB, + llvm::function_ref merge); /// Compute the gcd of the range. int64_t gcdRange(ArrayRef range); diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h index ac6e0a8d09448..63a69e87a2a54 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h @@ -65,7 +65,7 @@ bool isLoopMemoryParallel(AffineForOp forOp); void getReachableAffineApplyOps(ArrayRef operands, SmallVectorImpl &affineApplyOps); -/// Builds a system of constraints with dimensional identifiers corresponding to +/// Builds a system of constraints with dimensional variables corresponding to /// the loop IVs of the forOps and AffineIfOp's operands appearing in /// that order. Bounds of the loop are used to add appropriate inequalities. /// Constraints from the index sets of AffineIfOp are also added. Any symbols diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h index b307f0d4d2e33..60c495a74b02f 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h @@ -33,11 +33,11 @@ class MemRefType; struct MutableAffineMap; /// FlatAffineValueConstraints represents an extension of IntegerPolyhedron -/// where each non-local identifier can have an SSA Value attached to it. +/// where each non-local variable can have an SSA Value attached to it. class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { public: /// Constructs a constraint system reserving memory for the specified number - /// of constraints and identifiers. + /// of constraints and variables. FlatAffineValueConstraints(unsigned numReservedInequalities, unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDims, @@ -47,11 +47,11 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { numReservedCols, presburger::PresburgerSpace::getSetSpace( numDims, numSymbols, numLocals)) { - assert(numReservedCols >= getNumIds() + 1); - assert(valArgs.empty() || valArgs.size() == getNumDimAndSymbolIds()); + assert(numReservedCols >= getNumVars() + 1); + assert(valArgs.empty() || valArgs.size() == getNumDimAndSymbolVars()); values.reserve(numReservedCols); if (valArgs.empty()) - values.resize(getNumDimAndSymbolIds(), None); + values.resize(getNumDimAndSymbolVars(), None); else values.append(valArgs.begin(), valArgs.end()); } @@ -70,9 +70,9 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { FlatAffineValueConstraints(const IntegerPolyhedron &fac, ArrayRef> valArgs = {}) : IntegerPolyhedron(fac) { - assert(valArgs.empty() || valArgs.size() == getNumDimAndSymbolIds()); + assert(valArgs.empty() || valArgs.size() == getNumDimAndSymbolVars()); if (valArgs.empty()) - values.resize(getNumDimAndSymbolIds(), None); + values.resize(getNumDimAndSymbolVars(), None); else values.append(valArgs.begin(), valArgs.end()); } @@ -98,7 +98,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { // ----+-----+-----+--------- // -1 0 1 >= 0 // - // All dimensions as set as DimId. + // All dimensions as set as VarKind::SetDim. static FlatAffineValueConstraints getHyperrectangular(ValueRange ivs, ValueRange lbs, ValueRange ubs); @@ -127,11 +127,11 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// Adds constraints (lower and upper bounds) for the specified 'affine.for' /// operation's Value using IR information stored in its bound maps. The - /// right identifier is first looked up using `forOp`'s Value. Asserts if the + /// right variable is first looked up using `forOp`'s Value. Asserts if the /// Value corresponding to the 'affine.for' operation isn't found in the /// constraint system. Returns failure for the yet unimplemented/unsupported - /// cases. Any new identifiers that are found in the bound operands of the - /// 'affine.for' operation are added as trailing identifiers (either + /// cases. Any new variables that are found in the bound operands of the + /// 'affine.for' operation are added as trailing variables (either /// dimensional or symbolic depending on whether the operand is a valid /// symbol). // TODO: add support for non-unit strides. @@ -143,10 +143,10 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// the nest, sorted outer-to-inner. `operands` contains the bound operands /// for a single bound map. All the bound maps will use the same bound /// operands. Note that some loops described by a computation slice might not - /// exist yet in the IR so the Value attached to those dimension identifiers + /// exist yet in the IR so the Value attached to those dimension variables /// might be empty. For that reason, this method doesn't perform Value - /// look-ups to retrieve the dimension identifier positions. Instead, it - /// assumes the position of the dim identifiers in the constraint system is + /// look-ups to retrieve the dimension variable positions. Instead, it + /// assumes the position of the dim variables in the constraint system is /// the same as the position of the loop in the loop nest. LogicalResult addDomainFromSliceMaps(ArrayRef lbMaps, ArrayRef ubMaps, @@ -161,7 +161,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// the columns in the current one regarding numbers and values. void addAffineIfOpDomain(AffineIfOp ifOp); - /// Adds a bound for the identifier at the specified position with constraints + /// 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 @@ -177,7 +177,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { LogicalResult addBound(BoundType type, unsigned pos, AffineMap boundMap, bool isClosedBound); - /// Adds a bound for the identifier at the specified position with constraints + /// 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 @@ -187,7 +187,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// and the upper bound is open. LogicalResult addBound(BoundType type, unsigned pos, AffineMap boundMap); - /// Adds a bound for the identifier at the specified position with constraints + /// Adds a bound for the variable at the specified position with constraints /// being drawn from the specified bound map and operands. 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 @@ -195,7 +195,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { LogicalResult addBound(BoundType type, unsigned pos, AffineMap boundMap, ValueRange operands); - /// Adds a constant bound for the identifier associated with the given Value. + /// Adds a constant bound for the variable associated with the given Value. void addBound(BoundType type, Value val, int64_t value); /// The `addBound` overload above hides the inherited overloads by default, so @@ -209,10 +209,10 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { IntegerSet getAsIntegerSet(MLIRContext *context) const; /// Computes the lower and upper bounds of the first `num` dimensional - /// identifiers (starting at `offset`) as an affine map of the remaining - /// identifiers (dimensional and symbolic). This method is able to detect - /// identifiers as floordiv's and mod's of affine expressions of other - /// identifiers with respect to (positive) constants. Sets bound map to a + /// variables (starting at `offset`) as an affine map of the remaining + /// variables (dimensional and symbolic). This method is able to detect + /// variables as floordiv's and mod's of affine expressions of other + /// variables with respect to (positive) constants. Sets bound map to a /// null AffineMap if such a bound can't be found (or yet unimplemented). /// /// By default the returned lower bounds are closed and upper bounds are open. @@ -228,29 +228,29 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// system. Returns failure if `other` is a semi-affine map. LogicalResult composeMatchingMap(AffineMap other); - /// Gets the lower and upper bound of the `offset` + `pos`th identifier + /// Gets the lower and upper bound of the `offset` + `pos`th variable /// treating [0, offset) U [offset + num, symStartPos) as dimensions and - /// [symStartPos, getNumDimAndSymbolIds) as symbols, and `pos` lies in + /// [symStartPos, getNumDimAndSymbolVars) as symbols, and `pos` lies in /// [0, num). The multi-dimensional maps in the returned pair represent the /// max and min of potentially multiple affine expressions. The upper bound is /// exclusive. `localExprs` holds pre-computed AffineExpr's for all local - /// identifiers in the system. + /// variables in the system. std::pair getLowerAndUpperBound(unsigned pos, unsigned offset, unsigned num, unsigned symStartPos, ArrayRef localExprs, MLIRContext *context) const; - /// Returns the bound for the identifier at `pos` from the inequality at + /// Returns the bound for the variable at `pos` from the inequality at /// `ineqPos` as a 1-d affine value map (affine map + operands). The returned /// affine value map can either be a lower bound or an upper bound depending /// on the sign of atIneq(ineqPos, pos). Asserts if the row at `ineqPos` does - /// not involve the `pos`th identifier. + /// not involve the `pos`th variable. void getIneqAsAffineValueMap(unsigned pos, unsigned ineqPos, AffineValueMap &vmap, MLIRContext *context) const; /// Adds slice lower bounds represented by lower bounds in `lbMaps` and upper - /// bounds in `ubMaps` to each identifier in the constraint system which has + /// bounds in `ubMaps` to each variable in the constraint system which has /// a value in `values`. Note that both lower/upper bounds share the same /// operand list `operands`. /// This function assumes `values.size` == `lbMaps.size` == `ubMaps.size`. @@ -260,73 +260,73 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { ArrayRef ubMaps, ArrayRef operands); - /// Looks up the position of the identifier with the specified Value. Returns + /// Looks up the position of the variable with the specified Value. Returns /// true if found (false otherwise). `pos` is set to the (column) position of - /// the identifier. - bool findId(Value val, unsigned *pos) const; + /// the variable. + bool findVar(Value val, unsigned *pos) const; - /// Returns true if an identifier with the specified Value exists, false + /// Returns true if an variable with the specified Value exists, false /// otherwise. - bool containsId(Value val) const; + bool containsVar(Value mayBeVar) const; - /// Swap the posA^th identifier with the posB^th identifier. - void swapId(unsigned posA, unsigned posB) override; + /// Swap the posA^th variable with the posB^th variable. + void swapVar(unsigned posA, unsigned posB) override; - /// Insert identifiers of the specified kind at position `pos`. Positions are - /// relative to the kind of identifier. The coefficient columns corresponding - /// to the added identifiers are initialized to zero. `vals` are the Values - /// corresponding to the identifiers. Values should not be used with - /// IdKind::Local since values can only be attached to non-local identifiers. + /// 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 - /// identifier) of the first added identifier. + /// variable) of the first added variable. /// /// Note: Empty Values are allowed in `vals`. - unsigned insertDimId(unsigned pos, unsigned num = 1) { - return insertId(IdKind::SetDim, pos, num); + unsigned insertDimVar(unsigned pos, unsigned num = 1) { + return insertVar(VarKind::SetDim, pos, num); } - unsigned insertSymbolId(unsigned pos, unsigned num = 1) { - return insertId(IdKind::Symbol, pos, num); + unsigned insertSymbolVar(unsigned pos, unsigned num = 1) { + return insertVar(VarKind::Symbol, pos, num); } - unsigned insertLocalId(unsigned pos, unsigned num = 1) { - return insertId(IdKind::Local, pos, num); + unsigned insertLocalVar(unsigned pos, unsigned num = 1) { + return insertVar(VarKind::Local, pos, num); } - unsigned insertDimId(unsigned pos, ValueRange vals); - unsigned insertSymbolId(unsigned pos, ValueRange vals); - unsigned insertId(presburger::IdKind kind, unsigned pos, - unsigned num = 1) override; - unsigned insertId(presburger::IdKind kind, unsigned pos, ValueRange vals); - - /// Append identifiers of the specified kind after the last identifier of that - /// kind. The coefficient columns corresponding to the added identifiers are + unsigned insertDimVar(unsigned pos, ValueRange vals); + unsigned insertSymbolVar(unsigned pos, ValueRange vals); + unsigned insertVar(presburger::VarKind kind, unsigned pos, + unsigned num = 1) override; + unsigned insertVar(presburger::VarKind kind, unsigned pos, ValueRange vals); + + /// 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 - /// identifiers. Return the position of the first added column. + /// variables. Return the position of the first added column. /// /// Note: Empty Values are allowed in `vals`. - unsigned appendDimId(ValueRange vals); - unsigned appendSymbolId(ValueRange vals); - unsigned appendDimId(unsigned num = 1) { - return appendId(IdKind::SetDim, num); + unsigned appendDimVar(ValueRange vals); + unsigned appendSymbolVar(ValueRange vals); + unsigned appendDimVar(unsigned num = 1) { + return appendVar(VarKind::SetDim, num); } - unsigned appendSymbolId(unsigned num = 1) { - return appendId(IdKind::Symbol, num); + unsigned appendSymbolVar(unsigned num = 1) { + return appendVar(VarKind::Symbol, num); } - unsigned appendLocalId(unsigned num = 1) { - return appendId(IdKind::Local, num); + unsigned appendLocalVar(unsigned num = 1) { + return appendVar(VarKind::Local, num); } - /// Removes identifiers in the column range [idStart, idLimit), and copies any + /// Removes variables in the column range [varStart, varLimit), and copies any /// remaining valid data into place, updates member variables, and resizes /// arrays as needed. - void removeIdRange(presburger::IdKind kind, unsigned idStart, - unsigned idLimit) override; - using IntegerPolyhedron::removeIdRange; - - /// Add the specified values as a dim or symbol id depending on its nature, if - /// it already doesn't exist in the system. `val` has to be either a terminal - /// symbol or a loop IV, i.e., it cannot be the result affine.apply of any - /// symbols or loop IVs. The identifier is added to the end of the existing - /// dims or symbols. Additional information on the identifier is extracted - /// from the IR and added to the constraint system. + void removeVarRange(presburger::VarKind kind, unsigned varStart, + unsigned varLimit) override; + using IntegerPolyhedron::removeVarRange; + + /// Add the specified values as a dim or symbol var depending on its nature, + /// if it already doesn't exist in the system. `val` has to be either a + /// terminal symbol or a loop IV, i.e., it cannot be the result affine.apply + /// of any symbols or loop IVs. The variable is added to the end of the + /// existing dims or symbols. Additional information on the variable is + /// extracted from the IR and added to the constraint system. void addInductionVarOrTerminalSymbol(Value val); /// Align `map` with this constraint system based on `operands`. Each operand @@ -345,11 +345,11 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// the same associated Value). LogicalResult composeMap(const AffineValueMap *vMap); - /// Projects out the identifier that is associate with Value. + /// Projects out the variable that is associate with Value. void projectOut(Value val); using IntegerPolyhedron::projectOut; - /// Changes all symbol identifiers which are loop IVs to dim identifiers. + /// Changes all symbol variables which are loop IVs to dim variables. void convertLoopIVSymbolsToDims(); /// Updates the constraints to be the smallest bounding (enclosing) box that @@ -357,7 +357,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// 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 identifiers as this constraint system (in the same order). + /// dimensional variables as this constraint system (in the same order). /// /// E.g.: /// 1) this = {0 <= d0 <= 127}, @@ -372,51 +372,51 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { LogicalResult unionBoundingBox(const FlatAffineValueConstraints &other); using IntegerPolyhedron::unionBoundingBox; - /// Merge and align the identifiers of `this` and `other` starting at + /// Merge and align the variables of `this` and `other` starting at /// `offset`, so that both constraint systems get the union of the contained - /// identifiers that is dimension-wise and symbol-wise unique; both + /// variables that is dimension-wise and symbol-wise unique; both /// constraint systems are updated so that they have the union of all - /// identifiers, with `this`'s original identifiers appearing first followed - /// by any of `other`'s identifiers that didn't appear in `this`. Local - /// identifiers in `other` that have the same division representation as local - /// identifiers in `this` are merged into one. + /// 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. // E.g.: Input: `this` has (%i, %j) [%M, %N] // `other` has (%k, %j) [%P, %N, %M] // Output: both `this`, `other` have (%i, %j, %k) [%M, %N, %P] // - void mergeAndAlignIdsWithOther(unsigned offset, - FlatAffineValueConstraints *other); + void mergeAndAlignVarsWithOther(unsigned offset, + FlatAffineValueConstraints *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 identifiers, + /// space, i.e., if they are associated with the same set of variables, /// appearing in the same order. Returns false otherwise. - bool areIdsAlignedWithOther(const FlatAffineValueConstraints &other); + bool areVarsAlignedWithOther(const FlatAffineValueConstraints &other); /// Replaces the contents of this FlatAffineValueConstraints with `other`. void clearAndCopyFrom(const IntegerRelation &other) override; - /// Returns the Value associated with the pos^th identifier. Asserts if - /// no Value identifier was associated. + /// Returns the Value associated with the pos^th variable. Asserts if + /// no Value variable was associated. inline Value getValue(unsigned pos) const { - assert(pos < getNumDimAndSymbolIds() && "Invalid position"); - assert(hasValue(pos) && "identifier's Value not set"); + assert(pos < getNumDimAndSymbolVars() && "Invalid position"); + assert(hasValue(pos) && "variable's Value not set"); return values[pos].getValue(); } - /// Returns true if the pos^th identifier has an associated Value. + /// Returns true if the pos^th variable has an associated Value. inline bool hasValue(unsigned pos) const { - assert(pos < getNumDimAndSymbolIds() && "Invalid position"); + assert(pos < getNumDimAndSymbolVars() && "Invalid position"); return values[pos].hasValue(); } - /// Returns true if at least one identifier has an associated Value. + /// Returns true if at least one variable has an associated Value. bool hasValues() const; - /// Returns the Values associated with identifiers in range [start, end). - /// Asserts if no Value was associated with one of these identifiers. + /// Returns the Values associated with variables in range [start, end). + /// Asserts if no Value was associated with one of these variables. inline void getValues(unsigned start, unsigned end, SmallVectorImpl *values) const { - assert(end <= getNumDimAndSymbolIds() && "invalid end position"); + assert(end <= getNumDimAndSymbolVars() && "invalid end position"); assert(start <= end && "invalid start position"); values->clear(); values->reserve(end - start); @@ -424,7 +424,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { values->push_back(getValue(i)); } inline void getAllValues(SmallVectorImpl *values) const { - getValues(0, getNumDimAndSymbolIds(), values); + getValues(0, getNumDimAndSymbolVars(), values); } inline ArrayRef> getMaybeValues() const { @@ -432,25 +432,25 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { } inline ArrayRef> - getMaybeValues(presburger::IdKind kind) const { - assert(kind != IdKind::Local && - "Local identifiers do not have any value attached to them."); - return {values.data() + getIdKindOffset(kind), getNumIdKind(kind)}; + getMaybeValues(presburger::VarKind kind) const { + assert(kind != VarKind::Local && + "Local variables do not have any value attached to them."); + return {values.data() + getVarKindOffset(kind), getNumVarKind(kind)}; } - /// Sets the Value associated with the pos^th identifier. + /// Sets the Value associated with the pos^th variable. inline void setValue(unsigned pos, Value val) { - assert(pos < getNumDimAndSymbolIds() && "invalid id position"); + assert(pos < getNumDimAndSymbolVars() && "invalid var position"); values[pos] = val; } - /// Sets the Values associated with the identifiers in the range [start, end). - /// The range must contain only dim and symbol identifiers. + /// Sets the Values associated with the variables in the range [start, end). + /// The range must contain only dim and symbol variables. void setValues(unsigned start, unsigned end, ArrayRef values) { - assert(end <= getNumIds() && "invalid end position"); + assert(end <= getNumVars() && "invalid end position"); assert(start <= end && "invalid start position"); assert(values.size() == end - start && - "value should be provided for each identifier in the range."); + "value should be provided for each variable in the range."); for (unsigned i = start; i < end; ++i) setValue(i, values[i - start]); } @@ -459,12 +459,12 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { /// of symbols that are unique. Symbols in `this` and `other` should be /// unique. Symbols with Value as `None` are considered to be inequal to all /// other symbols. - void mergeSymbolIds(FlatAffineValueConstraints &other); + void mergeSymbolVars(FlatAffineValueConstraints &other); protected: - using IdKind = presburger::IdKind; + using VarKind = presburger::VarKind; - /// Returns false if the fields corresponding to various identifier counts, or + /// Returns false if the fields corresponding to various variable counts, or /// equality/inequality buffer sizes aren't consistent; true otherwise. This /// is meant to be used within an assert internally. bool hasConsistentState() const override; @@ -482,9 +482,9 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { LogicalResult flattenAlignedMapAndMergeLocals( AffineMap map, std::vector> *flattenedExprs); - /// Eliminates the identifier at the specified position using Fourier-Motzkin + /// Eliminates the variable at the specified position using Fourier-Motzkin /// variable elimination, but uses Gaussian elimination if there is an - /// equality involving that identifier. If the result of the elimination is + /// equality involving that variable. If the result of the elimination is /// integer exact, `*isResultIntegerExact` is set to true. If `darkShadow` is /// set to true, a potential under approximation (subset) of the rational /// shadow / exact integer shadow is computed. @@ -493,22 +493,22 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron { bool *isResultIntegerExact = nullptr) override; /// Prints the number of constraints, dimensions, symbols and locals in the - /// FlatAffineConstraints. Also, prints for each identifier whether there is + /// FlatAffineConstraints. Also, prints for each variable whether there is /// an SSA Value attached to it. void printSpace(raw_ostream &os) const override; - /// Values corresponding to the (column) non-local identifiers of this - /// constraint system appearing in the order the identifiers correspond to - /// columns. Identifiers that aren't associated with any Value are set to + /// Values corresponding to the (column) non-local variables of this + /// constraint system appearing in the order the variables correspond to + /// columns. Variables that aren't associated with any Value are set to /// None. SmallVector, 8> values; }; /// A FlatAffineRelation represents a set of ordered pairs (domain -> range) -/// where "domain" and "range" are tuples of identifiers. The relation is +/// where "domain" and "range" are tuples of variables. The relation is /// represented as a FlatAffineValueConstraints with separation of dimension -/// identifiers into domain and range. The identifiers are stored as: -/// [domainIds, rangeIds, symbolIds, localIds, constant]. +/// variables into domain and range. The variables are stored as: +/// [domainVars, rangeVars, symbolVars, localVars, constant]. class FlatAffineRelation : public FlatAffineValueConstraints { public: FlatAffineRelation(unsigned numReservedInequalities, @@ -541,7 +541,7 @@ class FlatAffineRelation : public FlatAffineValueConstraints { FlatAffineValueConstraints getDomainSet() const; FlatAffineValueConstraints getRangeSet() const; - /// Returns the number of identifiers corresponding to domain/range of + /// Returns the number of variables corresponding to domain/range of /// relation. inline unsigned getNumDomainDims() const { return numDomainDims; } inline unsigned getNumRangeDims() const { return numRangeDims; } @@ -556,29 +556,30 @@ class FlatAffineRelation : public FlatAffineValueConstraints { /// `(domain -> range)` is converted to `(range -> domain)`. void inverse(); - /// Insert `num` identifiers of the specified kind after the `pos` identifier + /// Insert `num` variables of the specified kind after the `pos` variable /// of that kind. The coefficient columns corresponding to the added - /// identifiers are initialized to zero. - void insertDomainId(unsigned pos, unsigned num = 1); - void insertRangeId(unsigned pos, unsigned num = 1); + /// variables are initialized to zero. + void insertDomainVar(unsigned pos, unsigned num = 1); + void insertRangeVar(unsigned pos, unsigned num = 1); - /// Append `num` identifiers of the specified kind after the last identifier + /// Append `num` variables of the specified kind after the last variable /// of that kind. The coefficient columns corresponding to the added - /// identifiers are initialized to zero. - void appendDomainId(unsigned num = 1); - void appendRangeId(unsigned num = 1); + /// variables are initialized to zero. + void appendDomainVar(unsigned num = 1); + void appendRangeVar(unsigned num = 1); - /// Removes identifiers in the column range [idStart, idLimit), and copies any + /// Removes variables in the column range [varStart, varLimit), and copies any /// remaining valid data into place, updates member variables, and resizes /// arrays as needed. - void removeIdRange(IdKind kind, unsigned idStart, unsigned idLimit) override; - using IntegerRelation::removeIdRange; + void removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit) override; + using IntegerRelation::removeVarRange; protected: - // Number of dimension identifers corresponding to domain identifers. + // Number of dimension variables corresponding to domain variables. unsigned numDomainDims; - // Number of dimension identifers corresponding to range identifers. + // Number of dimension variables corresponding to range variables. unsigned numRangeDims; }; @@ -586,8 +587,8 @@ class FlatAffineRelation : public FlatAffineValueConstraints { /// dimensions, symbols, and additional variables that represent floor divisions /// of dimensions, symbols, and in turn other floor divisions. Returns failure /// if 'expr' could not be flattened (i.e., semi-affine is not yet handled). -/// 'cst' contains constraints that connect newly introduced local identifiers -/// to existing dimensional and symbolic identifiers. See documentation for +/// 'cst' contains constraints that connect newly introduced local variables +/// to existing dimensional and symbolic variables. See documentation for /// AffineExprFlattener on how mod's and div's are flattened. LogicalResult getFlattenedAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, @@ -597,8 +598,8 @@ LogicalResult getFlattenedAffineExpr(AffineExpr expr, unsigned numDims, /// Flattens the result expressions of the map to their corresponding flattened /// forms and set in 'flattenedExprs'. Returns failure if any expression in the /// map could not be flattened (i.e., semi-affine is not yet handled). 'cst' -/// contains constraints that connect newly introduced local identifiers to -/// existing dimensional and / symbolic identifiers. See documentation for +/// contains constraints that connect newly introduced local variables to +/// existing dimensional and / symbolic variables. See documentation for /// AffineExprFlattener on how mod's and div's are flattened. For all affine /// expressions that share the same operands (like those of an affine map), this /// method should be used instead of repeatedly calling getFlattenedAffineExpr diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h index 1a25eaffedd0d..f6fde0383e448 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h @@ -88,7 +88,7 @@ struct ComputationSliceState { Block::iterator insertPoint; // Adds to 'cst' with constraints which represent the slice bounds on 'ivs' // in 'this'. Specifically, the values in 'ivs' are added to 'cst' as dim - // identifiers and the values in 'lb/ubOperands' are added as symbols. + // variables and the values in 'lb/ubOperands' are added as symbols. // Constraints are added for all loop IV bounds (dim or symbol), and // constraints are added for slice bounds in 'lbs'/'ubs'. // Returns failure if we cannot add loop bounds because of unsupported cases. @@ -250,8 +250,8 @@ struct MemRefRegion { /// Computes the memory region accessed by this memref with the region /// represented as constraints symbolic/parametric in 'loopDepth' loops /// surrounding opInst. The computed region's 'cst' field has exactly as many - /// dimensional identifiers as the rank of the memref, and *potentially* - /// additional symbolic identifiers which could include any of the loop IVs + /// dimensional variables as the rank of the memref, and *potentially* + /// additional symbolic variables which could include any of the loop IVs /// surrounding opInst up until 'loopDepth' and another additional Function /// symbols involved with the access (for eg., those appear in affine.apply's, /// loop bounds, etc.). If 'sliceState' is non-null, operands from @@ -292,7 +292,7 @@ struct MemRefRegion { /// bounded by a known constant (always possible for static shapes), None /// otherwise. Note that the symbols of the region are treated specially, /// i.e., the returned bounding constant holds for *any given* value of the - /// symbol identifiers. The 'shape' vector is set to the corresponding + /// symbol variables. The 'shape' vector is set to the corresponding /// dimension-wise bounds major to minor. The number of elements and all the /// dimension-wise bounds are guaranteed to be non-negative. We use int64_t /// instead of uint64_t since index types can be at most int64_t. `lbs` are @@ -303,14 +303,14 @@ struct MemRefRegion { std::vector> *lbs = nullptr, SmallVectorImpl *lbDivisors = nullptr) const; - /// Gets the lower and upper bound map for the dimensional identifier at + /// Gets the lower and upper bound map for the dimensional variable at /// `pos`. void getLowerAndUpperBound(unsigned pos, AffineMap &lbMap, AffineMap &ubMap) const; /// A wrapper around FlatAffineValueConstraints::getConstantBoundOnDimSize(). /// 'pos' corresponds to the position of the memref shape's dimension (major - /// to minor) which matches 1:1 with the dimensional identifier positions in + /// to minor) which matches 1:1 with the dimensional variable positions in /// 'cst'. Optional getConstantBoundOnDimSize(unsigned pos, @@ -340,10 +340,10 @@ struct MemRefRegion { Location loc; /// Region (data space) of the memref accessed. This set will thus have at - /// least as many dimensional identifiers as the shape dimensionality of the + /// least as many dimensional variables as the shape dimensionality of the /// memref, and these are the leading dimensions of the set appearing in that /// order (major to minor / outermost to innermost). There may be additional - /// identifiers since getMemRefRegion() is called with a specific loop depth, + /// variables since getMemRefRegion() is called with a specific loop depth, /// and thus the region is symbolic in the outer surrounding loops at that /// depth. // TODO: Replace this to exploit HyperRectangularSet. diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp index 7376747663e62..d9c3c86105b2a 100644 --- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp @@ -8,7 +8,7 @@ // // A class to represent an relation over integer tuples. A relation is // represented as a constraint system over a space of tuples of integer valued -// varaiables supporting symbolic identifiers and existential quantification. +// variables supporting symbolic variables and existential quantification. // //===----------------------------------------------------------------------===// @@ -39,16 +39,16 @@ std::unique_ptr IntegerPolyhedron::clone() const { } void IntegerRelation::setSpace(const PresburgerSpace &oSpace) { - assert(space.getNumIds() == oSpace.getNumIds() && "invalid space!"); + assert(space.getNumVars() == oSpace.getNumVars() && "invalid space!"); space = oSpace; } void IntegerRelation::setSpaceExceptLocals(const PresburgerSpace &oSpace) { - assert(oSpace.getNumLocalIds() == 0 && "no locals should be present!"); - assert(oSpace.getNumIds() <= getNumIds() && "invalid space!"); - unsigned newNumLocals = getNumIds() - oSpace.getNumIds(); + assert(oSpace.getNumLocalVars() == 0 && "no locals should be present!"); + assert(oSpace.getNumVars() <= getNumVars() && "invalid space!"); + unsigned newNumLocals = getNumVars() - oSpace.getNumVars(); space = oSpace; - space.insertId(IdKind::Local, 0, newNumLocals); + space.insertVar(VarKind::Local, 0, newNumLocals); } void IntegerRelation::append(const IntegerRelation &other) { @@ -68,7 +68,7 @@ void IntegerRelation::append(const IntegerRelation &other) { IntegerRelation IntegerRelation::intersect(IntegerRelation other) const { IntegerRelation result = *this; - result.mergeLocalIds(other); + result.mergeLocalVars(other); result.append(other); return result; } @@ -85,7 +85,7 @@ bool IntegerRelation::isSubsetOf(const IntegerRelation &other) const { MaybeOptimum> IntegerRelation::findRationalLexMin() const { - assert(getNumSymbolIds() == 0 && "Symbols are not supported!"); + assert(getNumSymbolVars() == 0 && "Symbols are not supported!"); MaybeOptimum> maybeLexMin = LexSimplex(*this).findRationalLexMin(); @@ -94,18 +94,18 @@ IntegerRelation::findRationalLexMin() const { // The Simplex returns the lexmin over all the variables including locals. But // locals are not actually part of the space and should not be returned in the - // result. Since the locals are placed last in the list of identifiers, they + // result. Since the locals are placed last in the list of variables, they // will be minimized last in the lexmin. So simply truncating out the locals // from the end of the answer gives the desired lexmin over the dimensions. - assert(maybeLexMin->size() == getNumIds() && + assert(maybeLexMin->size() == getNumVars() && "Incorrect number of vars in lexMin!"); - maybeLexMin->resize(getNumDimAndSymbolIds()); + maybeLexMin->resize(getNumDimAndSymbolVars()); return maybeLexMin; } MaybeOptimum> IntegerRelation::findIntegerLexMin() const { - assert(getNumSymbolIds() == 0 && "Symbols are not supported!"); + assert(getNumSymbolVars() == 0 && "Symbols are not supported!"); MaybeOptimum> maybeLexMin = LexSimplex(*this).findIntegerLexMin(); @@ -114,12 +114,12 @@ IntegerRelation::findIntegerLexMin() const { // The Simplex returns the lexmin over all the variables including locals. But // locals are not actually part of the space and should not be returned in the - // result. Since the locals are placed last in the list of identifiers, they + // result. Since the locals are placed last in the list of variables, they // will be minimized last in the lexmin. So simply truncating out the locals // from the end of the answer gives the desired lexmin over the dimensions. - assert(maybeLexMin->size() == getNumIds() && + assert(maybeLexMin->size() == getNumVars() && "Incorrect number of vars in lexMin!"); - maybeLexMin->resize(getNumDimAndSymbolIds()); + maybeLexMin->resize(getNumDimAndSymbolVars()); return maybeLexMin; } @@ -127,8 +127,8 @@ static bool rangeIsZero(ArrayRef range) { return llvm::all_of(range, [](int64_t x) { return x == 0; }); } -void removeConstraintsInvolvingIdRange(IntegerRelation &poly, unsigned begin, - unsigned count) { +static void removeConstraintsInvolvingVarRange(IntegerRelation &poly, + unsigned begin, unsigned count) { // We loop until i > 0 and index into i - 1 to avoid sign issues. // // We iterate backwards so that whether we remove constraint i - 1 or not, the @@ -145,29 +145,29 @@ IntegerRelation::CountsSnapshot IntegerRelation::getCounts() const { return {getSpace(), getNumInequalities(), getNumEqualities()}; } -void IntegerRelation::truncateIdKind(IdKind kind, unsigned num) { - unsigned curNum = getNumIdKind(kind); - assert(num <= curNum && "Can't truncate to more ids!"); - removeIdRange(kind, num, curNum); +void IntegerRelation::truncateVarKind(VarKind kind, unsigned num) { + unsigned curNum = getNumVarKind(kind); + assert(num <= curNum && "Can't truncate to more vars!"); + removeVarRange(kind, num, curNum); } -void IntegerRelation::truncateIdKind(IdKind kind, - const CountsSnapshot &counts) { - truncateIdKind(kind, counts.getSpace().getNumIdKind(kind)); +void IntegerRelation::truncateVarKind(VarKind kind, + const CountsSnapshot &counts) { + truncateVarKind(kind, counts.getSpace().getNumVarKind(kind)); } void IntegerRelation::truncate(const CountsSnapshot &counts) { - truncateIdKind(IdKind::Domain, counts); - truncateIdKind(IdKind::Range, counts); - truncateIdKind(IdKind::Symbol, counts); - truncateIdKind(IdKind::Local, counts); + truncateVarKind(VarKind::Domain, counts); + truncateVarKind(VarKind::Range, counts); + truncateVarKind(VarKind::Symbol, counts); + truncateVarKind(VarKind::Local, counts); removeInequalityRange(counts.getNumIneqs(), getNumInequalities()); removeEqualityRange(counts.getNumEqs(), getNumEqualities()); } PresburgerSet IntegerPolyhedron::computeReprWithOnlyDivLocals() const { // If there are no locals, we're done. - if (getNumLocalIds() == 0) + if (getNumLocalVars() == 0) return PresburgerSet(*this); // Move all the non-div locals to the end, as the current API to @@ -181,13 +181,13 @@ PresburgerSet IntegerPolyhedron::computeReprWithOnlyDivLocals() const { // Iterate through all the locals. The last `numNonDivLocals` are the locals // that have been scanned already and do not have division representations. unsigned numNonDivLocals = 0; - unsigned offset = copy.getIdKindOffset(IdKind::Local); - for (unsigned i = 0, e = copy.getNumLocalIds(); i < e - numNonDivLocals;) { + unsigned offset = copy.getVarKindOffset(VarKind::Local); + for (unsigned i = 0, e = copy.getNumLocalVars(); i < e - numNonDivLocals;) { if (!reprs[i]) { // Whenever we come across a local that does not have a division // representation, we swap it to the `numNonDivLocals`-th last position // and increment `numNonDivLocal`s. `reprs` also needs to be swapped. - copy.swapId(offset + i, offset + e - numNonDivLocals - 1); + copy.swapVar(offset + i, offset + e - numNonDivLocals - 1); std::swap(reprs[i], reprs[e - numNonDivLocals - 1]); ++numNonDivLocals; continue; @@ -213,7 +213,7 @@ PresburgerSet IntegerPolyhedron::computeReprWithOnlyDivLocals() const { SymbolicLexMin lexminResult = SymbolicLexSimplex(copy, /*symbolOffset*/ 0, IntegerPolyhedron(PresburgerSpace::getSetSpace( - /*numDims=*/copy.getNumIds() - numNonDivLocals))) + /*numDims=*/copy.getNumVars() - numNonDivLocals))) .computeSymbolicIntegerLexMin(); PresburgerSet result = lexminResult.lexmin.getDomain().unionSet(lexminResult.unboundedDomain); @@ -221,7 +221,7 @@ PresburgerSet IntegerPolyhedron::computeReprWithOnlyDivLocals() const { // The result set might lie in the wrong space -- all its ids are dims. // Set it to the desired space and return. PresburgerSpace space = getSpace(); - space.removeIdRange(IdKind::Local, 0, getNumLocalIds()); + space.removeVarRange(VarKind::Local, 0, getNumLocalVars()); result.setSpace(space); return result; } @@ -231,28 +231,28 @@ SymbolicLexMin IntegerPolyhedron::findSymbolicIntegerLexMin() const { // the actual symbols of this set. SymbolicLexMin result = SymbolicLexSimplex(*this, IntegerPolyhedron(PresburgerSpace::getSetSpace( - /*numDims=*/getNumSymbolIds()))) + /*numDims=*/getNumSymbolVars()))) .computeSymbolicIntegerLexMin(); // We want to return only the lexmin over the dims, so strip the locals from // the computed lexmin. result.lexmin.truncateOutput(result.lexmin.getNumOutputs() - - getNumLocalIds()); + getNumLocalVars()); return result; } -unsigned IntegerRelation::insertId(IdKind kind, unsigned pos, unsigned num) { - assert(pos <= getNumIdKind(kind)); +unsigned IntegerRelation::insertVar(VarKind kind, unsigned pos, unsigned num) { + assert(pos <= getNumVarKind(kind)); - unsigned insertPos = space.insertId(kind, pos, num); + unsigned insertPos = space.insertVar(kind, pos, num); inequalities.insertColumns(insertPos, num); equalities.insertColumns(insertPos, num); return insertPos; } -unsigned IntegerRelation::appendId(IdKind kind, unsigned num) { - unsigned pos = getNumIdKind(kind); - return insertId(kind, pos, num); +unsigned IntegerRelation::appendVar(VarKind kind, unsigned num) { + unsigned pos = getNumVarKind(kind); + return insertVar(kind, pos, num); } void IntegerRelation::addEquality(ArrayRef eq) { @@ -269,44 +269,44 @@ void IntegerRelation::addInequality(ArrayRef inEq) { inequalities(row, i) = inEq[i]; } -void IntegerRelation::removeId(IdKind kind, unsigned pos) { - removeIdRange(kind, pos, pos + 1); +void IntegerRelation::removeVar(VarKind kind, unsigned pos) { + removeVarRange(kind, pos, pos + 1); } -void IntegerRelation::removeId(unsigned pos) { removeIdRange(pos, pos + 1); } +void IntegerRelation::removeVar(unsigned pos) { removeVarRange(pos, pos + 1); } -void IntegerRelation::removeIdRange(IdKind kind, unsigned idStart, - unsigned idLimit) { - assert(idLimit <= getNumIdKind(kind)); +void IntegerRelation::removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit) { + assert(varLimit <= getNumVarKind(kind)); - if (idStart >= idLimit) + if (varStart >= varLimit) return; - // Remove eliminated identifiers from the constraints. - unsigned offset = getIdKindOffset(kind); - equalities.removeColumns(offset + idStart, idLimit - idStart); - inequalities.removeColumns(offset + idStart, idLimit - idStart); + // Remove eliminated variables from the constraints. + unsigned offset = getVarKindOffset(kind); + equalities.removeColumns(offset + varStart, varLimit - varStart); + inequalities.removeColumns(offset + varStart, varLimit - varStart); - // Remove eliminated identifiers from the space. - space.removeIdRange(kind, idStart, idLimit); + // Remove eliminated variables from the space. + space.removeVarRange(kind, varStart, varLimit); } -void IntegerRelation::removeIdRange(unsigned idStart, unsigned idLimit) { - assert(idLimit <= getNumIds()); +void IntegerRelation::removeVarRange(unsigned varStart, unsigned varLimit) { + assert(varLimit <= getNumVars()); - if (idStart >= idLimit) + if (varStart >= varLimit) return; - // Helper function to remove ids of the specified kind in the given range + // Helper function to remove vars of the specified kind in the given range // [start, limit), The range is absolute (i.e. it is not relative to the kind - // of identifier). Also updates `limit` to reflect the deleted identifiers. - auto removeIdKindInRange = [this](IdKind kind, unsigned &start, - unsigned &limit) { + // of variable). Also updates `limit` to reflect the deleted variables. + auto removeVarKindInRange = [this](VarKind kind, unsigned &start, + unsigned &limit) { if (start >= limit) return; - unsigned offset = getIdKindOffset(kind); - unsigned num = getNumIdKind(kind); + unsigned offset = getVarKindOffset(kind); + unsigned num = getNumVarKind(kind); // Get `start`, `limit` relative to the specified kind. unsigned relativeStart = @@ -314,19 +314,19 @@ void IntegerRelation::removeIdRange(unsigned idStart, unsigned idLimit) { unsigned relativeLimit = limit <= offset ? 0 : std::min(num, limit - offset); - // Remove ids of the specified kind in the relative range. - removeIdRange(kind, relativeStart, relativeLimit); + // Remove vars of the specified kind in the relative range. + removeVarRange(kind, relativeStart, relativeLimit); - // Update `limit` to reflect deleted identifiers. - // `start` does not need to be updated because any identifiers that are + // Update `limit` to reflect deleted variables. + // `start` does not need to be updated because any variables that are // deleted are after position `start`. limit -= relativeLimit - relativeStart; }; - removeIdKindInRange(IdKind::Domain, idStart, idLimit); - removeIdKindInRange(IdKind::Range, idStart, idLimit); - removeIdKindInRange(IdKind::Symbol, idStart, idLimit); - removeIdKindInRange(IdKind::Local, idStart, idLimit); + removeVarKindInRange(VarKind::Domain, varStart, varLimit); + removeVarKindInRange(VarKind::Range, varStart, varLimit); + removeVarKindInRange(VarKind::Symbol, varStart, varLimit); + removeVarKindInRange(VarKind::Local, varStart, varLimit); } void IntegerRelation::removeEquality(unsigned pos) { @@ -349,9 +349,9 @@ void IntegerRelation::removeInequalityRange(unsigned start, unsigned end) { inequalities.removeRows(start, end - start); } -void IntegerRelation::swapId(unsigned posA, unsigned posB) { - assert(posA < getNumIds() && "invalid position A"); - assert(posB < getNumIds() && "invalid position B"); +void IntegerRelation::swapVar(unsigned posA, unsigned posB) { + assert(posA < getNumVars() && "invalid position A"); + assert(posB < getNumVars() && "invalid position B"); if (posA == posB) return; @@ -365,17 +365,17 @@ void IntegerRelation::clearConstraints() { inequalities.resizeVertically(0); } -/// Gather all lower and upper bounds of the identifier at `pos`, and +/// Gather all lower and upper bounds of the variable at `pos`, and /// optionally any equalities on it. In addition, the bounds are to be -/// independent of identifiers in position range [`offset`, `offset` + `num`). +/// independent of variables in position range [`offset`, `offset` + `num`). void IntegerRelation::getLowerAndUpperBoundIndices( unsigned pos, SmallVectorImpl *lbIndices, SmallVectorImpl *ubIndices, SmallVectorImpl *eqIndices, unsigned offset, unsigned num) const { - assert(pos < getNumIds() && "invalid position"); + assert(pos < getNumVars() && "invalid position"); assert(offset + num < getNumCols() && "invalid range"); - // Checks for a constraint that has a non-zero coeff for the identifiers in + // Checks for a constraint that has a non-zero coeff for the variables in // the position range [offset, offset + num) while ignoring `pos`. auto containsConstraintDependentOnRange = [&](unsigned r, bool isEq) { unsigned c, f; @@ -406,7 +406,7 @@ void IntegerRelation::getLowerAndUpperBoundIndices( } // An equality is both a lower and upper bound. Record any equalities - // involving the pos^th identifier. + // involving the pos^th variable. if (!eqIndices) return; @@ -430,17 +430,17 @@ bool IntegerRelation::hasConsistentState() const { void IntegerRelation::setAndEliminate(unsigned pos, ArrayRef values) { if (values.empty()) return; - assert(pos + values.size() <= getNumIds() && + assert(pos + values.size() <= getNumVars() && "invalid position or too many values"); // Setting x_j = p in sum_i a_i x_i + c is equivalent to adding p*a_j to the - // constant term and removing the id x_j. We do this for all the ids + // constant term and removing the var x_j. We do this for all the vars // pos, pos + 1, ... pos + values.size() - 1. unsigned constantColPos = getNumCols() - 1; for (unsigned i = 0, numVals = values.size(); i < numVals; ++i) inequalities.addToColumn(i + pos, constantColPos, values[i]); for (unsigned i = 0, numVals = values.size(); i < numVals; ++i) equalities.addToColumn(i + pos, constantColPos, values[i]); - removeIdRange(pos, pos + values.size()); + removeVarRange(pos, pos + values.size()); } void IntegerRelation::clearAndCopyFrom(const IntegerRelation &other) { @@ -502,7 +502,7 @@ bool IntegerRelation::hasInvalidConstraint() const { return check(/*isEq=*/false); } -/// Eliminate identifier from constraint at `rowIdx` based on coefficient at +/// Eliminate variable from constraint at `rowIdx` based on coefficient at /// pivotRow, pivotCol. Columns in range [elimColStart, pivotCol) will not be /// updated as they have already been eliminated. static void eliminateFromConstraint(IntegerRelation *constraints, @@ -537,14 +537,14 @@ static void eliminateFromConstraint(IntegerRelation *constraints, } } -/// Returns the position of the identifier that has the minimum times from the specified range of -/// identifiers [start, end). It is often best to eliminate in the increasing +/// variables [start, end). It is often best to eliminate in the increasing /// order of these counts when doing Fourier-Motzkin elimination since FM adds /// that many new constraints. -static unsigned getBestIdToEliminate(const IntegerRelation &cst, unsigned start, - unsigned end) { - assert(start < cst.getNumIds() && end < cst.getNumIds() + 1); +static unsigned getBestVarToEliminate(const IntegerRelation &cst, + unsigned start, unsigned end) { + assert(start < cst.getNumVars() && end < cst.getNumVars() + 1); auto getProductOfNumLowerUpperBounds = [&](unsigned pos) { unsigned numLb = 0; @@ -571,7 +571,7 @@ static unsigned getBestIdToEliminate(const IntegerRelation &cst, unsigned start, return minLoc; } -// Checks for emptiness of the set by eliminating identifiers successively and +// Checks for emptiness of the set by eliminating variables successively and // using the GCD test (on all equality constraints) and checking for trivially // invalid constraints. Returns 'true' if the constraint system is found to be // empty; false otherwise. @@ -586,10 +586,10 @@ bool IntegerRelation::isEmpty() const { if (tmpCst.isEmptyByGCDTest() || tmpCst.hasInvalidConstraint()) return true; - // Eliminate as many identifiers as possible using Gaussian elimination. + // Eliminate as many variables as possible using Gaussian elimination. unsigned currentPos = 0; - while (currentPos < tmpCst.getNumIds()) { - tmpCst.gaussianEliminateIds(currentPos, tmpCst.getNumIds()); + while (currentPos < tmpCst.getNumVars()) { + tmpCst.gaussianEliminateVars(currentPos, tmpCst.getNumVars()); ++currentPos; // We check emptiness through trivial checks after eliminating each ID to // detect emptiness early. Since the checks isEmptyByGCDTest() and @@ -600,15 +600,15 @@ bool IntegerRelation::isEmpty() const { } // Eliminate the remaining using FM. - for (unsigned i = 0, e = tmpCst.getNumIds(); i < e; i++) { + for (unsigned i = 0, e = tmpCst.getNumVars(); i < e; i++) { tmpCst.fourierMotzkinEliminate( - getBestIdToEliminate(tmpCst, 0, tmpCst.getNumIds())); + getBestVarToEliminate(tmpCst, 0, tmpCst.getNumVars())); // Check for a constraint explosion. This rarely happens in practice, but // this check exists as a safeguard against improperly constructed // constraint systems or artificially created arbitrarily complex systems // that aren't the intended use case for IntegerRelation. This is // needed since FM has a worst case exponential complexity in theory. - if (tmpCst.getNumConstraints() >= kExplosionFactor * getNumIds()) { + if (tmpCst.getNumConstraints() >= kExplosionFactor * getNumVars()) { LLVM_DEBUG(llvm::dbgs() << "FM constraint explosion detected\n"); return false; } @@ -780,10 +780,10 @@ Optional> IntegerRelation::findIntegerSample() const { // obtain a bounded set. IntegerRelation boundedSet(transformedSet); unsigned numBoundedDims = result.first; - unsigned numUnboundedDims = getNumIds() - numBoundedDims; - removeConstraintsInvolvingIdRange(boundedSet, numBoundedDims, - numUnboundedDims); - boundedSet.removeIdRange(numBoundedDims, boundedSet.getNumIds()); + unsigned numUnboundedDims = getNumVars() - numBoundedDims; + removeConstraintsInvolvingVarRange(boundedSet, numBoundedDims, + numUnboundedDims); + boundedSet.removeVarRange(numBoundedDims, boundedSet.getNumVars()); // 3) Try to obtain a sample from the bounded set. Optional> boundedSample = @@ -824,10 +824,10 @@ Optional> IntegerRelation::findIntegerSample() const { // negative a_i, so we accomodate this by shifting the inequality by this // amount for the shrunken cone. for (unsigned i = 0, e = cone.getNumInequalities(); i < e; ++i) { - for (unsigned j = 0; j < cone.getNumIds(); ++j) { + for (unsigned j = 0; j < cone.getNumVars(); ++j) { int64_t coeff = cone.atIneq(i, j); if (coeff < 0) - cone.atIneq(i, cone.getNumIds()) += coeff; + cone.atIneq(i, cone.getNumVars()) += coeff; } } @@ -878,7 +878,7 @@ bool IntegerRelation::containsPoint(ArrayRef point) const { } /// Just substitute the values given and check if an integer sample exists for -/// the local ids. +/// the local vars. /// /// TODO: this could be made more efficient by handling divisions separately. /// Instead of finding an integer sample over all the locals, we can first @@ -887,9 +887,9 @@ bool IntegerRelation::containsPoint(ArrayRef point) const { /// Handling this correctly requires ordering the divs, though. Optional> IntegerRelation::containsPointNoLocal(ArrayRef point) const { - assert(point.size() == getNumIds() - getNumLocalIds() && - "Point should contain all ids except locals!"); - assert(getIdKindOffset(IdKind::Local) == getNumIds() - getNumLocalIds() && + assert(point.size() == getNumVars() - getNumLocalVars() && + "Point should contain all vars except locals!"); + assert(getVarKindOffset(VarKind::Local) == getNumVars() - getNumLocalVars() && "This function depends on locals being stored last!"); IntegerRelation copy = *this; copy.setAndEliminate(0, point); @@ -897,15 +897,15 @@ IntegerRelation::containsPointNoLocal(ArrayRef point) const { } void IntegerRelation::getLocalReprs(std::vector &repr) const { - std::vector> dividends(getNumLocalIds()); - SmallVector denominators(getNumLocalIds()); + std::vector> dividends(getNumLocalVars()); + SmallVector denominators(getNumLocalVars()); getLocalReprs(dividends, denominators, repr); } void IntegerRelation::getLocalReprs( std::vector> ÷nds, SmallVector &denominators) const { - std::vector repr(getNumLocalIds()); + std::vector repr(getNumLocalVars()); getLocalReprs(dividends, denominators, repr); } @@ -914,21 +914,21 @@ void IntegerRelation::getLocalReprs( SmallVector &denominators, std::vector &repr) const { - repr.resize(getNumLocalIds()); - dividends.resize(getNumLocalIds()); - denominators.resize(getNumLocalIds()); + repr.resize(getNumLocalVars()); + dividends.resize(getNumLocalVars()); + denominators.resize(getNumLocalVars()); - SmallVector foundRepr(getNumIds(), false); - for (unsigned i = 0, e = getNumDimAndSymbolIds(); i < e; ++i) + SmallVector foundRepr(getNumVars(), false); + for (unsigned i = 0, e = getNumDimAndSymbolVars(); i < e; ++i) foundRepr[i] = true; - unsigned divOffset = getNumDimAndSymbolIds(); + unsigned divOffset = getNumDimAndSymbolVars(); bool changed; do { // Each time changed is true, at end of this iteration, one or more local // vars have been detected as floor divs. changed = false; - for (unsigned i = 0, e = getNumLocalIds(); i < e; ++i) { + for (unsigned i = 0, e = getNumLocalVars(); i < e; ++i) { if (!foundRepr[i + divOffset]) { MaybeLocalRepr res = computeSingleVarRepr( *this, foundRepr, divOffset + i, dividends[i], denominators[i]); @@ -941,7 +941,7 @@ void IntegerRelation::getLocalReprs( } } while (changed); - // Set 0 denominator for identifiers for which no division representation + // Set 0 denominator for variables for which no division representation // could be found. for (unsigned i = 0, e = repr.size(); i < e; ++i) if (!repr[i]) @@ -966,12 +966,12 @@ void IntegerRelation::gcdTightenInequalities() { } } -// Eliminates all identifier variables in column range [posStart, posLimit). +// Eliminates all variable variables in column range [posStart, posLimit). // Returns the number of variables eliminated. -unsigned IntegerRelation::gaussianEliminateIds(unsigned posStart, - unsigned posLimit) { - // Return if identifier positions to eliminate are out of range. - assert(posLimit <= getNumIds()); +unsigned IntegerRelation::gaussianEliminateVars(unsigned posStart, + unsigned posLimit) { + // Return if variable positions to eliminate are out of range. + assert(posLimit <= getNumVars()); assert(hasConsistentState()); if (posStart >= posLimit) @@ -993,14 +993,14 @@ unsigned IntegerRelation::gaussianEliminateIds(unsigned posStart, break; } - // Eliminate identifier at 'pivotCol' from each equality row. + // Eliminate variable at 'pivotCol' from each equality row. for (unsigned i = 0, e = getNumEqualities(); i < e; ++i) { eliminateFromConstraint(this, i, pivotRow, pivotCol, posStart, /*isEq=*/true); equalities.normalizeRow(i); } - // Eliminate identifier at 'pivotCol' from each inequality row. + // Eliminate variable at 'pivotCol' from each inequality row. for (unsigned i = 0, e = getNumInequalities(); i < e; ++i) { eliminateFromConstraint(this, i, pivotRow, pivotCol, posStart, /*isEq=*/false); @@ -1012,7 +1012,7 @@ unsigned IntegerRelation::gaussianEliminateIds(unsigned posStart, // Update position limit based on number eliminated. posLimit = pivotCol; // Remove eliminated columns from all constraints. - removeIdRange(posStart, posLimit); + removeVarRange(posStart, posLimit); return posLimit - posStart; } @@ -1082,7 +1082,7 @@ void IntegerRelation::removeRedundantConstraints() { } Optional IntegerRelation::computeVolume() const { - assert(getNumSymbolIds() == 0 && "Symbols are not yet supported!"); + assert(getNumSymbolVars() == 0 && "Symbols are not yet supported!"); Simplex simplex(*this); // If the polytope is rationally empty, there are certainly no integer @@ -1090,11 +1090,11 @@ Optional IntegerRelation::computeVolume() const { if (simplex.isEmpty()) return 0; - // Just find the maximum and minimum integer value of each non-local id - // separately, thus finding the number of integer values each such id can + // Just find the maximum and minimum integer value of each non-local var + // separately, thus finding the number of integer values each such var can // take. Multiplying these together gives a valid overapproximation of the // number of integer points in the relation. The result this gives is - // equivalent to projecting (rationally) the relation onto its non-local ids + // equivalent to projecting (rationally) the relation onto its non-local vars // and returning the number of integer points in a minimal axis-parallel // hyperrectangular overapproximation of that. // @@ -1105,9 +1105,9 @@ Optional IntegerRelation::computeVolume() const { // If there is no such empty dimension, if any dimension is unbounded we // just return the result as unbounded. uint64_t count = 1; - SmallVector dim(getNumIds() + 1); - bool hasUnboundedId = false; - for (unsigned i = 0, e = getNumDimAndSymbolIds(); i < e; ++i) { + SmallVector dim(getNumVars() + 1); + bool hasUnboundedVar = false; + for (unsigned i = 0, e = getNumDimAndSymbolVars(); i < e; ++i) { dim[i] = 1; MaybeOptimum min, max; std::tie(min, max) = simplex.computeIntegerBounds(dim); @@ -1119,7 +1119,7 @@ Optional IntegerRelation::computeVolume() const { // One of the dimensions is unbounded. Note this fact. We will return // unbounded if none of the other dimensions makes the volume zero. if (min.isUnbounded() || max.isUnbounded()) { - hasUnboundedId = true; + hasUnboundedVar = true; continue; } @@ -1133,21 +1133,21 @@ Optional IntegerRelation::computeVolume() const { if (count == 0) return 0; - if (hasUnboundedId) + if (hasUnboundedVar) return {}; return count; } -void IntegerRelation::eliminateRedundantLocalId(unsigned posA, unsigned posB) { - assert(posA < getNumLocalIds() && "Invalid local id position"); - assert(posB < getNumLocalIds() && "Invalid local id position"); +void IntegerRelation::eliminateRedundantLocalVar(unsigned posA, unsigned posB) { + assert(posA < getNumLocalVars() && "Invalid local var position"); + assert(posB < getNumLocalVars() && "Invalid local var position"); - unsigned localOffset = getIdKindOffset(IdKind::Local); + unsigned localOffset = getVarKindOffset(VarKind::Local); posA += localOffset; posB += localOffset; inequalities.addToColumn(posB, posA, 1); equalities.addToColumn(posB, posA, 1); - removeId(posB); + removeVar(posB); } /// Adds additional local ids to the sets such that they both have the union @@ -1163,14 +1163,14 @@ void IntegerRelation::eliminateRedundantLocalId(unsigned posA, unsigned posB) { /// It is possible that division representation for some local id cannot be /// obtained, and thus these local ids are not considered for detecting /// duplicates. -unsigned IntegerRelation::mergeLocalIds(IntegerRelation &other) { +unsigned IntegerRelation::mergeLocalVars(IntegerRelation &other) { IntegerRelation &relA = *this; IntegerRelation &relB = other; - unsigned oldALocals = relA.getNumLocalIds(); + unsigned oldALocals = relA.getNumLocalVars(); // Merge function that merges the local variables in both sets by treating - // them as the same identifier. + // them as the same variable. auto merge = [&relA, &relB, oldALocals](unsigned i, unsigned j) -> bool { // We only merge from local at pos j to local at pos i, where j > i. if (i >= j) @@ -1182,16 +1182,16 @@ unsigned IntegerRelation::mergeLocalIds(IntegerRelation &other) { return false; // Merge local at pos j into local at position i. - relA.eliminateRedundantLocalId(i, j); - relB.eliminateRedundantLocalId(i, j); + relA.eliminateRedundantLocalVar(i, j); + relB.eliminateRedundantLocalVar(i, j); return true; }; - presburger::mergeLocalIds(*this, other, merge); + presburger::mergeLocalVars(*this, other, merge); // Since we do not remove duplicate divisions in relA, this is guranteed to be // non-negative. - return relA.getNumLocalIds() - oldALocals; + return relA.getNumLocalVars() - oldALocals; } bool IntegerRelation::hasOnlyDivLocals() const { @@ -1207,11 +1207,11 @@ void IntegerRelation::removeDuplicateDivs() { getLocalReprs(divs, denoms); auto merge = [this](unsigned i, unsigned j) -> bool { - eliminateRedundantLocalId(i, j); + eliminateRedundantLocalVar(i, j); return true; }; - presburger::removeDuplicateDivs(divs, denoms, getIdKindOffset(IdKind::Local), - merge); + presburger::removeDuplicateDivs(divs, denoms, + getVarKindOffset(VarKind::Local), merge); } /// Removes local variables using equalities. Each equality is checked if it @@ -1230,7 +1230,7 @@ void IntegerRelation::removeRedundantLocalVars() { unsigned i, e, j, f; for (i = 0, e = getNumEqualities(); i < e; ++i) { // Find a local variable to eliminate using ith equality. - for (j = getNumDimAndSymbolIds(), f = getNumIds(); j < f; ++j) + for (j = getNumDimAndSymbolVars(), f = getNumVars(); j < f; ++j) if (std::abs(atEq(i, j)) == 1) break; @@ -1257,22 +1257,22 @@ void IntegerRelation::removeRedundantLocalVars() { eliminateFromConstraint(this, k, i, j, j, /*isEq=*/false); // Remove the ith equality and the found local variable. - removeId(j); + removeVar(j); removeEquality(i); } } -void IntegerRelation::convertIdKind(IdKind srcKind, unsigned idStart, - unsigned idLimit, IdKind dstKind, +void IntegerRelation::covertVarKind(VarKind srcKind, unsigned idStart, + unsigned idLimit, VarKind dstKind, unsigned pos) { - assert(idLimit <= getNumIdKind(srcKind) && "Invalid id range"); + assert(idLimit <= getNumVarKind(srcKind) && "Invalid id range"); if (idStart >= idLimit) return; // Append new local variables corresponding to the dimensions to be converted. unsigned convertCount = idLimit - idStart; - unsigned newIdsBegin = insertId(dstKind, pos, convertCount); + unsigned newVarsBegin = insertVar(dstKind, pos, convertCount); // Swap the new local variables with dimensions. // @@ -1281,12 +1281,12 @@ void IntegerRelation::convertIdKind(IdKind srcKind, unsigned idStart, // `dstKind`. In particular, this moves the columns in the constraint // matrices, and zeros out the initially occupied columns (because the newly // created ids we're swapping with were zero-initialized). - unsigned offset = getIdKindOffset(srcKind); + unsigned offset = getVarKindOffset(srcKind); for (unsigned i = 0; i < convertCount; ++i) - swapId(offset + idStart + i, newIdsBegin + i); + swapVar(offset + idStart + i, newVarsBegin + i); // Complete the move by deleting the initially occupied columns. - removeIdRange(srcKind, idStart, idLimit); + removeVarRange(srcKind, idStart, idLimit); } void IntegerRelation::addBound(BoundType type, unsigned pos, int64_t value) { @@ -1314,8 +1314,8 @@ void IntegerRelation::addBound(BoundType type, ArrayRef expr, type == BoundType::LB ? -value : value; } -/// Adds a new local identifier as the floordiv of an affine function of other -/// identifiers, the coefficients of which are provided in 'dividend' and with +/// 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'. Two constraints are added to the /// system to capture equivalence with the floordiv. /// q = expr floordiv c <=> c*q <= expr <= c*q + c - 1. @@ -1324,16 +1324,16 @@ void IntegerRelation::addLocalFloorDiv(ArrayRef dividend, assert(dividend.size() == getNumCols() && "incorrect dividend size"); assert(divisor > 0 && "positive divisor expected"); - appendId(IdKind::Local); + appendVar(VarKind::Local); - // Add two constraints for this new identifier 'q'. + // Add two constraints for this new variable 'q'. SmallVector bound(dividend.size() + 1); // dividend - q * divisor >= 0 std::copy(dividend.begin(), dividend.begin() + dividend.size() - 1, bound.begin()); bound.back() = dividend.back(); - bound[getNumIds() - 1] = -divisor; + bound[getNumVars() - 1] = -divisor; addInequality(bound); // -dividend +qdivisor * q + divisor - 1 >= 0 @@ -1343,38 +1343,38 @@ void IntegerRelation::addLocalFloorDiv(ArrayRef dividend, addInequality(bound); } -/// Finds an equality that equates the specified identifier to a constant. +/// Finds an equality that equates the specified variable to a constant. /// Returns the position of the equality row. If 'symbolic' is set to true, /// symbols are also treated like a constant, i.e., an affine function of the /// symbols is also treated like a constant. Returns -1 if such an equality /// could not be found. static int findEqualityToConstant(const IntegerRelation &cst, unsigned pos, bool symbolic = false) { - assert(pos < cst.getNumIds() && "invalid position"); + assert(pos < cst.getNumVars() && "invalid position"); for (unsigned r = 0, e = cst.getNumEqualities(); r < e; r++) { int64_t v = cst.atEq(r, pos); if (v * v != 1) continue; unsigned c; - unsigned f = symbolic ? cst.getNumDimIds() : cst.getNumIds(); + unsigned f = symbolic ? cst.getNumDimVars() : cst.getNumVars(); // This checks for zeros in all positions other than 'pos' in [0, f) for (c = 0; c < f; c++) { if (c == pos) continue; if (cst.atEq(r, c) != 0) { - // Dependent on another identifier. + // Dependent on another variable. break; } } if (c == f) - // Equality is free of other identifiers. + // Equality is free of other variables. return r; } return -1; } -LogicalResult IntegerRelation::constantFoldId(unsigned pos) { - assert(pos < getNumIds() && "invalid position"); +LogicalResult IntegerRelation::constantFoldVar(unsigned pos) { + assert(pos < getNumVars() && "invalid position"); int rowIdx; if ((rowIdx = findEqualityToConstant(*this, pos)) == -1) return failure(); @@ -1386,21 +1386,21 @@ LogicalResult IntegerRelation::constantFoldId(unsigned pos) { return success(); } -void IntegerRelation::constantFoldIdRange(unsigned pos, unsigned num) { +void IntegerRelation::constantFoldVarRange(unsigned pos, unsigned num) { for (unsigned s = pos, t = pos, e = pos + num; s < e; s++) { - if (failed(constantFoldId(t))) + if (failed(constantFoldVar(t))) t++; } } /// Returns a non-negative constant bound on the extent (upper bound - lower -/// bound) of the specified identifier if it is found to be a constant; returns -/// None if it's not a constant. This methods treats symbolic identifiers +/// bound) of the specified variable if it is found to be a constant; returns +/// None if it's not a constant. This methods treats symbolic variables /// specially, i.e., it looks for constant differences between affine -/// expressions involving only the symbolic identifiers. See comments at +/// expressions involving only the symbolic variables. See comments at /// function definition for example. 'lb', if provided, is set to the lower /// bound associated with the constant difference. Note that 'lb' is purely -/// symbolic and thus will contain the coefficients of the symbolic identifiers +/// symbolic and thus will contain the coefficients of the symbolic variables /// and the constant coefficient. // Egs: 0 <= i <= 15, return 16. // s0 + 2 <= i <= s0 + 17, returns 16. (s0 has to be a symbol) @@ -1411,32 +1411,32 @@ Optional IntegerRelation::getConstantBoundOnDimSize( unsigned pos, SmallVectorImpl *lb, int64_t *boundFloorDivisor, SmallVectorImpl *ub, unsigned *minLbPos, unsigned *minUbPos) const { - assert(pos < getNumDimIds() && "Invalid identifier position"); + assert(pos < getNumDimVars() && "Invalid variable position"); - // Find an equality for 'pos'^th identifier that equates it to some function - // of the symbolic identifiers (+ constant). + // Find an equality for 'pos'^th variable that equates it to some function + // of the symbolic variables (+ constant). int eqPos = findEqualityToConstant(*this, pos, /*symbolic=*/true); if (eqPos != -1) { auto eq = getEquality(eqPos); // If the equality involves a local var, punt for now. // TODO: this can be handled in the future by using the explicit // representation of the local vars. - if (!std::all_of(eq.begin() + getNumDimAndSymbolIds(), eq.end() - 1, + if (!std::all_of(eq.begin() + getNumDimAndSymbolVars(), eq.end() - 1, [](int64_t coeff) { return coeff == 0; })) return None; - // This identifier can only take a single value. + // This variable can only take a single value. if (lb) { // Set lb to that symbolic value. - lb->resize(getNumSymbolIds() + 1); + lb->resize(getNumSymbolVars() + 1); if (ub) - ub->resize(getNumSymbolIds() + 1); - for (unsigned c = 0, f = getNumSymbolIds() + 1; c < f; c++) { + ub->resize(getNumSymbolVars() + 1); + for (unsigned c = 0, f = getNumSymbolVars() + 1; c < f; c++) { int64_t v = atEq(eqPos, pos); // atEq(eqRow, pos) is either -1 or 1. assert(v * v == 1); - (*lb)[c] = v < 0 ? atEq(eqPos, getNumDimIds() + c) / -v - : -atEq(eqPos, getNumDimIds() + c) / v; + (*lb)[c] = v < 0 ? atEq(eqPos, getNumDimVars() + c) / -v + : -atEq(eqPos, getNumDimVars() + c) / v; // Since this is an equality, ub = lb. if (ub) (*ub)[c] = (*lb)[c]; @@ -1452,7 +1452,7 @@ Optional IntegerRelation::getConstantBoundOnDimSize( return 1; } - // Check if the identifier appears at all in any of the inequalities. + // Check if the variable appears at all in any of the inequalities. unsigned r, e; for (r = 0, e = getNumInequalities(); r < e; r++) { if (atIneq(r, pos) != 0) @@ -1466,12 +1466,12 @@ Optional IntegerRelation::getConstantBoundOnDimSize( SmallVector lbIndices, ubIndices; // Gather all symbolic lower bounds and upper bounds of the variable, i.e., - // the bounds can only involve symbolic (and local) identifiers. Since the + // the bounds can only involve symbolic (and local) variables. Since the // canonical form c_1*x_1 + c_2*x_2 + ... + c_0 >= 0, a constraint is a lower // bound for x_i if c_i >= 1, and an upper bound if c_i <= -1. getLowerAndUpperBoundIndices(pos, &lbIndices, &ubIndices, /*eqIndices=*/nullptr, /*offset=*/0, - /*num=*/getNumDimIds()); + /*num=*/getNumDimVars()); Optional minDiff = None; unsigned minLbPosition = 0, minUbPosition = 0; @@ -1504,27 +1504,27 @@ Optional IntegerRelation::getConstantBoundOnDimSize( } if (lb && minDiff) { // Set lb to the symbolic lower bound. - lb->resize(getNumSymbolIds() + 1); + lb->resize(getNumSymbolVars() + 1); if (ub) - ub->resize(getNumSymbolIds() + 1); + ub->resize(getNumSymbolVars() + 1); // The lower bound is the ceildiv of the lb constraint over the coefficient // of the variable at 'pos'. We express the ceildiv equivalently as a floor // for uniformity. For eg., if the lower bound constraint was: 32*d0 - N + // 31 >= 0, the lower bound for d0 is ceil(N - 31, 32), i.e., floor(N, 32). *boundFloorDivisor = atIneq(minLbPosition, pos); assert(*boundFloorDivisor == -atIneq(minUbPosition, pos)); - for (unsigned c = 0, e = getNumSymbolIds() + 1; c < e; c++) { - (*lb)[c] = -atIneq(minLbPosition, getNumDimIds() + c); + for (unsigned c = 0, e = getNumSymbolVars() + 1; c < e; c++) { + (*lb)[c] = -atIneq(minLbPosition, getNumDimVars() + c); } if (ub) { - for (unsigned c = 0, e = getNumSymbolIds() + 1; c < e; c++) - (*ub)[c] = atIneq(minUbPosition, getNumDimIds() + c); + for (unsigned c = 0, e = getNumSymbolVars() + 1; c < e; c++) + (*ub)[c] = atIneq(minUbPosition, getNumDimVars() + c); } // The lower bound leads to a ceildiv while the upper bound is a floordiv // whenever the coefficient at pos != 1. ceildiv (val / d) = floordiv (val + // d - 1 / d); hence, the addition of 'atIneq(minLbPosition, pos) - 1' to // the constant term for the lower bound. - (*lb)[getNumSymbolIds()] += atIneq(minLbPosition, pos) - 1; + (*lb)[getNumSymbolVars()] += atIneq(minLbPosition, pos) - 1; } if (minLbPos) *minLbPos = minLbPosition; @@ -1536,17 +1536,17 @@ Optional IntegerRelation::getConstantBoundOnDimSize( template Optional IntegerRelation::computeConstantLowerOrUpperBound(unsigned pos) { - assert(pos < getNumIds() && "invalid position"); + assert(pos < getNumVars() && "invalid position"); // Project to 'pos'. projectOut(0, pos); - projectOut(1, getNumIds() - 1); - // Check if there's an equality equating the '0'^th identifier to a constant. + projectOut(1, getNumVars() - 1); + // Check if there's an equality equating the '0'^th variable to a constant. int eqRowIdx = findEqualityToConstant(*this, 0, /*symbolic=*/false); if (eqRowIdx != -1) // atEq(rowIdx, 0) is either -1 or 1. return -atEq(eqRowIdx, getNumCols() - 1) / atEq(eqRowIdx, 0); - // Check if the identifier appears at all in any of the inequalities. + // Check if the variable appears at all in any of the inequalities. unsigned r, e; for (r = 0, e = getNumInequalities(); r < e; r++) { if (atIneq(r, 0) != 0) @@ -1709,7 +1709,7 @@ void IntegerRelation::removeTrivialRedundancy() { #undef DEBUG_TYPE #define DEBUG_TYPE "fm" -/// Eliminates identifier at the specified position using Fourier-Motzkin +/// Eliminates variable at the specified position using Fourier-Motzkin /// variable elimination. This technique is exact for rational spaces but /// conservative (in "rare" cases) for integer spaces. The operation corresponds /// to a projection operation yielding the (convex) set of integer points @@ -1756,14 +1756,14 @@ void IntegerRelation::fourierMotzkinEliminate(unsigned pos, bool darkShadow, bool *isResultIntegerExact) { LLVM_DEBUG(llvm::dbgs() << "FM input (eliminate pos " << pos << "):\n"); LLVM_DEBUG(dump()); - assert(pos < getNumIds() && "invalid position"); + assert(pos < getNumVars() && "invalid position"); assert(hasConsistentState()); - // Check if this identifier can be eliminated through a substitution. + // Check if this variable can be eliminated through a substitution. for (unsigned r = 0, e = getNumEqualities(); r < e; r++) { if (atEq(r, pos) != 0) { // Use Gaussian elimination here (since we have an equality). - LogicalResult ret = gaussianEliminateId(pos); + LogicalResult ret = gaussianEliminateVar(pos); (void)ret; assert(succeeded(ret) && "Gaussian elimination guaranteed to succeed"); LLVM_DEBUG(llvm::dbgs() << "FM output (through Gaussian elimination):\n"); @@ -1775,11 +1775,11 @@ void IntegerRelation::fourierMotzkinEliminate(unsigned pos, bool darkShadow, // A fast linear time tightening. gcdTightenInequalities(); - // Check if the identifier appears at all in any of the inequalities. + // Check if the variable appears at all in any of the inequalities. if (isColZero(pos)) { // If it doesn't appear, just remove the column and return. // TODO: refactor removeColumns to use it from here. - removeId(pos); + removeVar(pos); LLVM_DEBUG(llvm::dbgs() << "FM output:\n"); LLVM_DEBUG(dump()); return; @@ -1798,7 +1798,7 @@ void IntegerRelation::fourierMotzkinEliminate(unsigned pos, bool darkShadow, // bound for x_i if c_i >= 1, and an upper bound if c_i <= -1. for (unsigned r = 0, e = getNumInequalities(); r < e; r++) { if (atIneq(r, pos) == 0) { - // Id does not appear in bound. + // Var does not appear in bound. nbIndices.push_back(r); } else if (atIneq(r, pos) >= 1) { // Lower bound. @@ -1810,11 +1810,11 @@ void IntegerRelation::fourierMotzkinEliminate(unsigned pos, bool darkShadow, } PresburgerSpace newSpace = getSpace(); - IdKind idKindRemove = newSpace.getIdKindAt(pos); - unsigned relativePos = pos - newSpace.getIdKindOffset(idKindRemove); - newSpace.removeIdRange(idKindRemove, relativePos, relativePos + 1); + VarKind idKindRemove = newSpace.getVarKindAt(pos); + unsigned relativePos = pos - newSpace.getVarKindOffset(idKindRemove); + newSpace.removeVarRange(idKindRemove, relativePos, relativePos + 1); - /// Create the new system which has one identifier less. + /// Create the new system which has one variable less. IntegerRelation newRel(lbIndices.size() * ubIndices.size() + nbIndices.size(), getNumEqualities(), getNumCols() - 1, newSpace); @@ -1914,14 +1914,14 @@ void IntegerRelation::projectOut(unsigned pos, unsigned num) { assert((getNumCols() < 2 || pos <= getNumCols() - 2) && "invalid position"); assert(pos + num < getNumCols() && "invalid range"); - // Eliminate as many identifiers as possible using Gaussian elimination. + // Eliminate as many variables as possible using Gaussian elimination. unsigned currentPos = pos; unsigned numToEliminate = num; unsigned numGaussianEliminated = 0; - while (currentPos < getNumIds()) { + while (currentPos < getNumVars()) { unsigned curNumEliminated = - gaussianEliminateIds(currentPos, currentPos + numToEliminate); + gaussianEliminateVars(currentPos, currentPos + numToEliminate); ++currentPos; numToEliminate -= curNumEliminated + 1; numGaussianEliminated += curNumEliminated; @@ -1931,7 +1931,7 @@ void IntegerRelation::projectOut(unsigned pos, unsigned num) { for (unsigned i = 0; i < num - numGaussianEliminated; i++) { unsigned numToEliminate = num - numGaussianEliminated - i; fourierMotzkinEliminate( - getBestIdToEliminate(*this, pos, pos + numToEliminate)); + getBestVarToEliminate(*this, pos, pos + numToEliminate)); } // Fast/trivial simplifications. @@ -1950,7 +1950,7 @@ enum BoundCmpResult { Greater, Less, Equal, Unknown }; static BoundCmpResult compareBounds(ArrayRef a, ArrayRef b) { assert(a.size() == b.size()); - // For the bounds to be comparable, their corresponding identifier + // For the bounds to be comparable, their corresponding variable // coefficients should be equal; the constant terms are then compared to // determine less/greater/equal. @@ -1992,7 +1992,7 @@ static void getCommonConstraints(const IntegerRelation &a, LogicalResult IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) { assert(space.isEqual(otherCst.getSpace()) && "Spaces should match."); - assert(getNumLocalIds() == 0 && "local ids not supported yet here"); + assert(getNumLocalVars() == 0 && "local ids not supported yet here"); // Get the constraints common to both systems; these will be added as is to // the union. @@ -2001,19 +2001,19 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) { std::vector> boundingLbs; std::vector> boundingUbs; - boundingLbs.reserve(2 * getNumDimIds()); - boundingUbs.reserve(2 * getNumDimIds()); + boundingLbs.reserve(2 * getNumDimVars()); + boundingUbs.reserve(2 * getNumDimVars()); // To hold lower and upper bounds for each dimension. SmallVector lb, otherLb, ub, otherUb; // To compute min of lower bounds and max of upper bounds for each dimension. - SmallVector minLb(getNumSymbolIds() + 1); - SmallVector maxUb(getNumSymbolIds() + 1); + SmallVector minLb(getNumSymbolVars() + 1); + SmallVector maxUb(getNumSymbolVars() + 1); // To compute final new lower and upper bounds for the union. SmallVector newLb(getNumCols()), newUb(getNumCols()); int64_t lbFloorDivisor, otherLbFloorDivisor; - for (unsigned d = 0, e = getNumDimIds(); d < e; ++d) { + for (unsigned d = 0, e = getNumDimVars(); d < e; ++d) { auto extent = getConstantBoundOnDimSize(d, &lb, &lbFloorDivisor, &ub); if (!extent.hasValue()) // TODO: symbolic extents when necessary. @@ -2073,10 +2073,10 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) { newLb[d] = lbFloorDivisor; newUb[d] = -lbFloorDivisor; // Copy over the symbolic part + constant term. - std::copy(minLb.begin(), minLb.end(), newLb.begin() + getNumDimIds()); - std::transform(newLb.begin() + getNumDimIds(), newLb.end(), - newLb.begin() + getNumDimIds(), std::negate()); - std::copy(maxUb.begin(), maxUb.end(), newUb.begin() + getNumDimIds()); + std::copy(minLb.begin(), minLb.end(), newLb.begin() + getNumDimVars()); + std::transform(newLb.begin() + getNumDimVars(), newLb.end(), + newLb.begin() + getNumDimVars(), std::negate()); + std::copy(maxUb.begin(), maxUb.end(), newUb.begin() + getNumDimVars()); boundingLbs.push_back(newLb); boundingUbs.push_back(newUb); @@ -2084,7 +2084,7 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) { // Clear all constraints and add the lower/upper bounds for the bounding box. clearConstraints(); - for (unsigned d = 0, e = getNumDimIds(); d < e; ++d) { + for (unsigned d = 0, e = getNumDimVars(); d < e; ++d) { addInequality(boundingLbs[d]); addInequality(boundingUbs[d]); } @@ -2107,13 +2107,13 @@ bool IntegerRelation::isColZero(unsigned pos) const { } /// Find positions of inequalities and equalities that do not have a coefficient -/// for [pos, pos + num) identifiers. +/// for [pos, pos + num) variables. static void getIndependentConstraints(const IntegerRelation &cst, unsigned pos, unsigned num, SmallVectorImpl &nbIneqIndices, SmallVectorImpl &nbEqIndices) { - assert(pos < cst.getNumIds() && "invalid start position"); - assert(pos + num <= cst.getNumIds() && "invalid limit"); + assert(pos < cst.getNumVars() && "invalid start position"); + assert(pos + num <= cst.getNumVars() && "invalid limit"); for (unsigned r = 0, e = cst.getNumInequalities(); r < e; r++) { // The bounds are to be independent of [offset, offset + num) columns. @@ -2139,9 +2139,9 @@ static void getIndependentConstraints(const IntegerRelation &cst, unsigned pos, } void IntegerRelation::removeIndependentConstraints(unsigned pos, unsigned num) { - assert(pos + num <= getNumIds() && "invalid range"); + assert(pos + num <= getNumVars() && "invalid range"); - // Remove constraints that are independent of these identifiers. + // Remove constraints that are independent of these variables. SmallVector nbIneqIndices, nbEqIndices; getIndependentConstraints(*this, /*pos=*/0, num, nbIneqIndices, nbEqIndices); @@ -2158,12 +2158,12 @@ IntegerPolyhedron IntegerRelation::getDomainSet() const { IntegerRelation copyRel = *this; // Convert Range variables to Local variables. - copyRel.convertIdKind(IdKind::Range, 0, getNumIdKind(IdKind::Range), - IdKind::Local); + copyRel.convertVarKind(VarKind::Range, 0, getNumVarKind(VarKind::Range), + VarKind::Local); // Convert Domain variables to SetDim(Range) variables. - copyRel.convertIdKind(IdKind::Domain, 0, getNumIdKind(IdKind::Domain), - IdKind::SetDim); + copyRel.convertVarKind(VarKind::Domain, 0, getNumVarKind(VarKind::Domain), + VarKind::SetDim); return IntegerPolyhedron(std::move(copyRel)); } @@ -2172,8 +2172,8 @@ IntegerPolyhedron IntegerRelation::getRangeSet() const { IntegerRelation copyRel = *this; // Convert Domain variables to Local variables. - copyRel.convertIdKind(IdKind::Domain, 0, getNumIdKind(IdKind::Domain), - IdKind::Local); + copyRel.convertVarKind(VarKind::Domain, 0, getNumVarKind(VarKind::Domain), + VarKind::Local); // We do not need to do anything to Range variables since they are already in // SetDim position. @@ -2190,10 +2190,10 @@ void IntegerRelation::intersectDomain(const IntegerPolyhedron &poly) { rel.inverse(); // Append dummy range variables to make the spaces compatible. - rel.appendId(IdKind::Range, getNumRangeIds()); + rel.appendVar(VarKind::Range, getNumRangeVars()); // Intersect in place. - mergeLocalIds(rel); + mergeLocalVars(rel); append(rel); } @@ -2204,16 +2204,17 @@ void IntegerRelation::intersectRange(const IntegerPolyhedron &poly) { IntegerRelation rel = poly; // Append dummy domain variables to make the spaces compatible. - rel.appendId(IdKind::Domain, getNumDomainIds()); + rel.appendVar(VarKind::Domain, getNumDomainVars()); - mergeLocalIds(rel); + mergeLocalVars(rel); append(rel); } void IntegerRelation::inverse() { - unsigned numRangeIds = getNumIdKind(IdKind::Range); - convertIdKind(IdKind::Domain, 0, getIdKindEnd(IdKind::Domain), IdKind::Range); - convertIdKind(IdKind::Range, 0, numRangeIds, IdKind::Domain); + unsigned numRangeVars = getNumVarKind(VarKind::Range); + convertVarKind(VarKind::Domain, 0, getVarKindEnd(VarKind::Domain), + VarKind::Range); + convertVarKind(VarKind::Range, 0, numRangeVars, VarKind::Domain); } void IntegerRelation::compose(const IntegerRelation &rel) { @@ -2227,19 +2228,19 @@ void IntegerRelation::compose(const IntegerRelation &rel) { // R1 with R2. After this, we get R1: A -> C, by projecting out B. // TODO: Using nested spaces here would help, since we could directly // intersect the range with another relation. - unsigned numBIds = getNumRangeIds(); + unsigned numBVars = getNumRangeVars(); // Convert R1 from A -> B to A -> (B X C). - appendId(IdKind::Range, copyRel.getNumRangeIds()); + appendVar(VarKind::Range, copyRel.getNumRangeVars()); // Convert R2 to B X C. - copyRel.convertIdKind(IdKind::Domain, 0, numBIds, IdKind::Range, 0); + copyRel.covertVarKind(VarKind::Domain, 0, numBVars, VarKind::Range, 0); // Intersect R2 to range of R1. intersectRange(IntegerPolyhedron(copyRel)); // Project out B in R1. - convertIdKind(IdKind::Range, 0, numBIds, IdKind::Local); + convertVarKind(VarKind::Range, 0, numBVars, VarKind::Local); } void IntegerRelation::applyDomain(const IntegerRelation &rel) { @@ -2275,8 +2276,9 @@ void IntegerRelation::print(raw_ostream &os) const { void IntegerRelation::dump() const { print(llvm::errs()); } -unsigned IntegerPolyhedron::insertId(IdKind kind, unsigned pos, unsigned num) { - assert((kind != IdKind::Domain || num == 0) && +unsigned IntegerPolyhedron::insertVar(VarKind kind, unsigned pos, + unsigned num) { + assert((kind != VarKind::Domain || num == 0) && "Domain has to be zero in a set"); - return IntegerRelation::insertId(kind, pos, num); -} + return IntegerRelation::insertVar(kind, pos, num); +} \ No newline at end of file diff --git a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp index a9e0f8d2ba789..39c828a20c609 100644 --- a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp +++ b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp @@ -35,7 +35,7 @@ PresburgerSet PWMAFunction::getDomain() const { Optional> MultiAffineFunction::valueAt(ArrayRef point) const { - assert(point.size() == domainSet.getNumDimAndSymbolIds() && + assert(point.size() == domainSet.getNumDimAndSymbolVars() && "Point has incorrect dimensionality!"); Optional> maybeLocalValues = @@ -47,7 +47,7 @@ MultiAffineFunction::valueAt(ArrayRef point) const { SmallVector pointHomogenous{llvm::to_vector(point)}; // The given point didn't include the values of locals which the output is a // function of; we have computed one possible set of values and use them - // here. The function is not allowed to have local ids that take more than + // here. The function is not allowed to have local vars that take more than // one possible value. pointHomogenous.append(*maybeLocalValues); // The matrix `output` has an affine expression in the ith row, corresponding @@ -88,19 +88,19 @@ bool MultiAffineFunction::isEqual(const MultiAffineFunction &other) const { isEqualWhereDomainsOverlap(other); } -unsigned MultiAffineFunction::insertId(IdKind kind, unsigned pos, - unsigned num) { - assert(kind != IdKind::Domain && "Domain has to be zero in a set"); - unsigned absolutePos = domainSet.getIdKindOffset(kind) + pos; +unsigned MultiAffineFunction::insertVar(VarKind kind, unsigned pos, + unsigned num) { + assert(kind != VarKind::Domain && "Domain has to be zero in a set"); + unsigned absolutePos = domainSet.getVarKindOffset(kind) + pos; output.insertColumns(absolutePos, num); - return domainSet.insertId(kind, pos, num); + return domainSet.insertVar(kind, pos, num); } -void MultiAffineFunction::removeIdRange(IdKind kind, unsigned idStart, - unsigned idLimit) { - output.removeColumns(idStart + domainSet.getIdKindOffset(kind), - idLimit - idStart); - domainSet.removeIdRange(kind, idStart, idLimit); +void MultiAffineFunction::removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit) { + output.removeColumns(varStart + domainSet.getVarKindOffset(kind), + varLimit - varStart); + domainSet.removeVarRange(kind, varStart, varLimit); } void MultiAffineFunction::truncateOutput(unsigned count) { @@ -115,21 +115,21 @@ void PWMAFunction::truncateOutput(unsigned count) { numOutputs = count; } -void MultiAffineFunction::mergeLocalIds(MultiAffineFunction &other) { - // Merge output local ids of both functions without using division - // information i.e. append local ids of `other` to `this` and insert - // local ids of `this` to `other` at the start of it's local ids. - output.insertColumns(domainSet.getIdKindEnd(IdKind::Local), - other.domainSet.getNumLocalIds()); - other.output.insertColumns(other.domainSet.getIdKindOffset(IdKind::Local), - domainSet.getNumLocalIds()); +void MultiAffineFunction::mergeLocalVars(MultiAffineFunction &other) { + // Merge output local vars of both functions without using division + // information i.e. append local vars of `other` to `this` and insert + // local vars of `this` to `other` at the start of it's local vars. + output.insertColumns(domainSet.getVarKindEnd(VarKind::Local), + other.domainSet.getNumLocalVars()); + other.output.insertColumns(other.domainSet.getVarKindOffset(VarKind::Local), + domainSet.getNumLocalVars()); auto merge = [this, &other](unsigned i, unsigned j) -> bool { // Merge local at position j into local at position i in function domain. - domainSet.eliminateRedundantLocalId(i, j); - other.domainSet.eliminateRedundantLocalId(i, j); + domainSet.eliminateRedundantLocalVar(i, j); + other.domainSet.eliminateRedundantLocalVar(i, j); - unsigned localOffset = domainSet.getIdKindOffset(IdKind::Local); + unsigned localOffset = domainSet.getVarKindOffset(VarKind::Local); // Merge local at position j into local at position i in output domain. output.addToColumn(localOffset + j, localOffset + i, 1); @@ -140,7 +140,7 @@ void MultiAffineFunction::mergeLocalIds(MultiAffineFunction &other) { return true; }; - presburger::mergeLocalIds(domainSet, other.domainSet, merge); + presburger::mergeLocalVars(domainSet, other.domainSet, merge); } bool MultiAffineFunction::isEqualWhereDomainsOverlap( @@ -150,9 +150,9 @@ bool MultiAffineFunction::isEqualWhereDomainsOverlap( // `commonFunc` has the same output as `this`. MultiAffineFunction commonFunc = *this; - // After this merge, `commonFunc` and `other` have the same local ids; they + // After this merge, `commonFunc` and `other` have the same local vars; they // are merged. - commonFunc.mergeLocalIds(other); + commonFunc.mergeLocalVars(other); // After this, the domain of `commonFunc` will be the intersection of the // domains of `this` and `other`. commonFunc.domainSet.append(other.domainSet); @@ -161,7 +161,7 @@ bool MultiAffineFunction::isEqualWhereDomainsOverlap( // where the outputs of `this` and `other` match. // // We want to add constraints equating the outputs of `this` and `other`. - // However, `this` may have difference local ids from `other`, whereas we + // However, `this` may have difference local vars from `other`, whereas we // need both to have the same locals. Accordingly, we use `commonFunc.output` // in place of `this->output`, since `commonFunc` has the same output but also // has its locals merged. diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp index 1b5d48b9cf896..9131aaeed3ac5 100644 --- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp @@ -22,7 +22,7 @@ PresburgerRelation::PresburgerRelation(const IntegerRelation &disjunct) } void PresburgerRelation::setSpace(const PresburgerSpace &oSpace) { - assert(space.getNumLocalIds() == 0 && "no locals should be present"); + assert(space.getNumLocalVars() == 0 && "no locals should be present"); space = oSpace; for (IntegerRelation &disjunct : disjuncts) disjunct.setSpaceExceptLocals(space); @@ -175,7 +175,7 @@ static PresburgerRelation getSetDifference(IntegerRelation b, return PresburgerRelation::getEmpty(b.getSpaceWithoutLocals()); // Remove duplicate divs up front here to avoid existing - // divs disappearing in the call to mergeLocalIds below. + // divs disappearing in the call to mergeLocalVars below. b.removeDuplicateDivs(); PresburgerRelation result = @@ -217,7 +217,7 @@ static PresburgerRelation getSetDifference(IntegerRelation b, // No frame for this level yet, so we have just recursed into this level. IntegerRelation sI = s.getDisjunct(level - 1); // Remove the duplicate divs up front to avoid them possibly disappearing - // in the call to mergeLocalIds below. + // in the call to mergeLocalVars below. sI.removeDuplicateDivs(); // Below, we append some additional constraints and ids to b. We want to @@ -230,14 +230,14 @@ static PresburgerRelation getSetDifference(IntegerRelation b, // Find out which inequalities of sI correspond to division inequalities // for the local variables of sI. - std::vector repr(sI.getNumLocalIds()); + std::vector repr(sI.getNumLocalVars()); sI.getLocalReprs(repr); // Add sI's locals to b, after b's locals. Only those locals of sI which // do not already exist in b will be added. (i.e., duplicate divisions // will not be added.) Also add b's locals to sI, in such a way that both // have the same locals in the same order in the end. - b.mergeLocalIds(sI); + b.mergeLocalVars(sI); // Mark which inequalities of sI are division inequalities and add all // such inequalities to b. @@ -274,7 +274,7 @@ static PresburgerRelation getSetDifference(IntegerRelation b, unsigned offset = simplex.getNumConstraints(); unsigned numLocalsAdded = - b.getNumLocalIds() - initBCounts.getSpace().getNumLocalIds(); + b.getNumLocalVars() - initBCounts.getSpace().getNumLocalVars(); simplex.appendVariable(numLocalsAdded); unsigned snapshotBeforeIntersect = simplex.getSnapshot(); @@ -436,7 +436,7 @@ bool PresburgerRelation::findIntegerSample(SmallVectorImpl &sample) { } Optional PresburgerRelation::computeVolume() const { - assert(getNumSymbolIds() == 0 && "Symbols are not yet supported!"); + assert(getNumSymbolVars() == 0 && "Symbols are not yet supported!"); // The sum of the volumes of the disjuncts is a valid overapproximation of the // volume of their union, even if they overlap. uint64_t result = 0; @@ -715,7 +715,7 @@ LogicalResult SetCoalescer::coalescePair(unsigned i, unsigned j) { /// Handling of local ids is not yet implemented, so these cases are /// skipped. /// TODO: implement local id support. - if (a.getNumLocalIds() != 0 || b.getNumLocalIds() != 0) + if (a.getNumLocalVars() != 0 || b.getNumLocalVars() != 0) return failure(); Simplex &simpA = simplices[i]; Simplex &simpB = simplices[j]; diff --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp index 6d82145eddc26..dafb15e171e71 100644 --- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp @@ -13,123 +13,123 @@ using namespace mlir; using namespace presburger; -unsigned PresburgerSpace::getNumIdKind(IdKind kind) const { - if (kind == IdKind::Domain) - return getNumDomainIds(); - if (kind == IdKind::Range) - return getNumRangeIds(); - if (kind == IdKind::Symbol) - return getNumSymbolIds(); - if (kind == IdKind::Local) +unsigned PresburgerSpace::getNumVarKind(VarKind kind) const { + if (kind == VarKind::Domain) + return getNumDomainVars(); + if (kind == VarKind::Range) + return getNumRangeVars(); + if (kind == VarKind::Symbol) + return getNumSymbolVars(); + if (kind == VarKind::Local) return numLocals; - llvm_unreachable("IdKind does not exist!"); + llvm_unreachable("VarKind does not exist!"); } -unsigned PresburgerSpace::getIdKindOffset(IdKind kind) const { - if (kind == IdKind::Domain) +unsigned PresburgerSpace::getVarKindOffset(VarKind kind) const { + if (kind == VarKind::Domain) return 0; - if (kind == IdKind::Range) - return getNumDomainIds(); - if (kind == IdKind::Symbol) - return getNumDimIds(); - if (kind == IdKind::Local) - return getNumDimAndSymbolIds(); - llvm_unreachable("IdKind does not exist!"); + if (kind == VarKind::Range) + return getNumDomainVars(); + if (kind == VarKind::Symbol) + return getNumDimVars(); + if (kind == VarKind::Local) + return getNumDimAndSymbolVars(); + llvm_unreachable("VarKind does not exist!"); } -unsigned PresburgerSpace::getIdKindEnd(IdKind kind) const { - return getIdKindOffset(kind) + getNumIdKind(kind); +unsigned PresburgerSpace::getVarKindEnd(VarKind kind) const { + return getVarKindOffset(kind) + getNumVarKind(kind); } -unsigned PresburgerSpace::getIdKindOverlap(IdKind kind, unsigned idStart, - unsigned idLimit) const { - unsigned idRangeStart = getIdKindOffset(kind); - unsigned idRangeEnd = getIdKindEnd(kind); +unsigned PresburgerSpace::getVarKindOverlap(VarKind kind, unsigned varStart, + unsigned varLimit) const { + unsigned varRangeStart = getVarKindOffset(kind); + unsigned varRangeEnd = getVarKindEnd(kind); - // Compute number of elements in intersection of the ranges [idStart, idLimit) - // and [idRangeStart, idRangeEnd). - unsigned overlapStart = std::max(idStart, idRangeStart); - unsigned overlapEnd = std::min(idLimit, idRangeEnd); + // Compute number of elements in intersection of the ranges [varStart, + // varLimit) and [varRangeStart, varRangeEnd). + unsigned overlapStart = std::max(varStart, varRangeStart); + unsigned overlapEnd = std::min(varLimit, varRangeEnd); if (overlapStart > overlapEnd) return 0; return overlapEnd - overlapStart; } -IdKind PresburgerSpace::getIdKindAt(unsigned pos) const { - assert(pos < getNumIds() && "`pos` should represent a valid id position"); - if (pos < getIdKindEnd(IdKind::Domain)) - return IdKind::Domain; - if (pos < getIdKindEnd(IdKind::Range)) - return IdKind::Range; - if (pos < getIdKindEnd(IdKind::Symbol)) - return IdKind::Symbol; - if (pos < getIdKindEnd(IdKind::Local)) - return IdKind::Local; - llvm_unreachable("`pos` should represent a valid id position"); +VarKind PresburgerSpace::getVarKindAt(unsigned pos) const { + assert(pos < getNumVars() && "`pos` should represent a valid var position"); + if (pos < getVarKindEnd(VarKind::Domain)) + return VarKind::Domain; + if (pos < getVarKindEnd(VarKind::Range)) + return VarKind::Range; + if (pos < getVarKindEnd(VarKind::Symbol)) + return VarKind::Symbol; + if (pos < getVarKindEnd(VarKind::Local)) + return VarKind::Local; + llvm_unreachable("`pos` should represent a valid var position"); } -unsigned PresburgerSpace::insertId(IdKind kind, unsigned pos, unsigned num) { - assert(pos <= getNumIdKind(kind)); +unsigned PresburgerSpace::insertVar(VarKind kind, unsigned pos, unsigned num) { + assert(pos <= getNumVarKind(kind)); - unsigned absolutePos = getIdKindOffset(kind) + pos; + unsigned absolutePos = getVarKindOffset(kind) + pos; - if (kind == IdKind::Domain) + if (kind == VarKind::Domain) numDomain += num; - else if (kind == IdKind::Range) + else if (kind == VarKind::Range) numRange += num; - else if (kind == IdKind::Symbol) + else if (kind == VarKind::Symbol) numSymbols += num; else numLocals += num; // Insert NULL attachments if `usingAttachments` and variables inserted are // not locals. - if (usingAttachments && kind != IdKind::Local) + if (usingAttachments && kind != VarKind::Local) attachments.insert(attachments.begin() + absolutePos, num, nullptr); return absolutePos; } -void PresburgerSpace::removeIdRange(IdKind kind, unsigned idStart, - unsigned idLimit) { - assert(idLimit <= getNumIdKind(kind) && "invalid id limit"); +void PresburgerSpace::removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit) { + assert(varLimit <= getNumVarKind(kind) && "invalid var limit"); - if (idStart >= idLimit) + if (varStart >= varLimit) return; - unsigned numIdsEliminated = idLimit - idStart; - if (kind == IdKind::Domain) - numDomain -= numIdsEliminated; - else if (kind == IdKind::Range) - numRange -= numIdsEliminated; - else if (kind == IdKind::Symbol) - numSymbols -= numIdsEliminated; + unsigned numVarsEliminated = varLimit - varStart; + if (kind == VarKind::Domain) + numDomain -= numVarsEliminated; + else if (kind == VarKind::Range) + numRange -= numVarsEliminated; + else if (kind == VarKind::Symbol) + numSymbols -= numVarsEliminated; else - numLocals -= numIdsEliminated; + numLocals -= numVarsEliminated; // Remove attachments if `usingAttachments` and variables removed are not // locals. - if (usingAttachments && kind != IdKind::Local) - attachments.erase(attachments.begin() + getIdKindOffset(kind) + idStart, - attachments.begin() + getIdKindOffset(kind) + idLimit); + if (usingAttachments && kind != VarKind::Local) + attachments.erase(attachments.begin() + getVarKindOffset(kind) + varStart, + attachments.begin() + getVarKindOffset(kind) + varLimit); } -void PresburgerSpace::swapId(IdKind kindA, IdKind kindB, unsigned posA, - unsigned posB) { +void PresburgerSpace::swapVar(VarKind kindA, VarKind kindB, unsigned posA, + unsigned posB) { if (!usingAttachments) return; - if (kindA == IdKind::Local && kindB == IdKind::Local) + if (kindA == VarKind::Local && kindB == VarKind::Local) return; - if (kindA == IdKind::Local) { + if (kindA == VarKind::Local) { atAttachment(kindB, posB) = nullptr; return; } - if (kindB == IdKind::Local) { + if (kindB == VarKind::Local) { atAttachment(kindA, posA) = nullptr; return; } @@ -138,13 +138,13 @@ void PresburgerSpace::swapId(IdKind kindA, IdKind kindB, unsigned posA, } bool PresburgerSpace::isCompatible(const PresburgerSpace &other) const { - return getNumDomainIds() == other.getNumDomainIds() && - getNumRangeIds() == other.getNumRangeIds() && - getNumSymbolIds() == other.getNumSymbolIds(); + return getNumDomainVars() == other.getNumDomainVars() && + getNumRangeVars() == other.getNumRangeVars() && + getNumSymbolVars() == other.getNumSymbolVars(); } bool PresburgerSpace::isEqual(const PresburgerSpace &other) const { - return isCompatible(other) && getNumLocalIds() == other.getNumLocalIds(); + return isCompatible(other) && getNumLocalVars() == other.getNumLocalVars(); } bool PresburgerSpace::isAligned(const PresburgerSpace &other) const { @@ -155,22 +155,22 @@ bool PresburgerSpace::isAligned(const PresburgerSpace &other) const { } bool PresburgerSpace::isAligned(const PresburgerSpace &other, - IdKind kind) const { + VarKind kind) const { assert(isUsingAttachments() && other.isUsingAttachments() && "Both spaces should be using attachments to check for " "alignment."); ArrayRef kindAttachments = makeArrayRef(attachments) - .slice(getIdKindOffset(kind), getNumIdKind(kind)); + .slice(getVarKindOffset(kind), getNumVarKind(kind)); ArrayRef otherKindAttachments = makeArrayRef(other.attachments) - .slice(other.getIdKindOffset(kind), other.getNumIdKind(kind)); + .slice(other.getVarKindOffset(kind), other.getNumVarKind(kind)); return kindAttachments == otherKindAttachments; } -void PresburgerSpace::setDimSymbolSeparation(unsigned newSymbolCount) { - assert(newSymbolCount <= getNumDimAndSymbolIds() && +void PresburgerSpace::setVarSymbolSeperation(unsigned newSymbolCount) { + assert(newSymbolCount <= getNumDimAndSymbolVars() && "invalid separation position"); numRange = numRange + numSymbols - newSymbolCount; numSymbols = newSymbolCount; @@ -179,10 +179,10 @@ void PresburgerSpace::setDimSymbolSeparation(unsigned newSymbolCount) { } void PresburgerSpace::print(llvm::raw_ostream &os) const { - os << "Domain: " << getNumDomainIds() << ", " - << "Range: " << getNumRangeIds() << ", " - << "Symbols: " << getNumSymbolIds() << ", " - << "Locals: " << getNumLocalIds() << "\n"; + os << "Domain: " << getNumDomainVars() << ", " + << "Range: " << getNumRangeVars() << ", " + << "Symbols: " << getNumSymbolVars() << ", " + << "Locals: " << getNumLocalVars() << "\n"; if (usingAttachments) { #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS diff --git a/mlir/lib/Analysis/Presburger/Simplex.cpp b/mlir/lib/Analysis/Presburger/Simplex.cpp index 36b16f51ae9c5..0574f155cd433 100644 --- a/mlir/lib/Analysis/Presburger/Simplex.cpp +++ b/mlir/lib/Analysis/Presburger/Simplex.cpp @@ -429,7 +429,7 @@ LogicalResult SymbolicLexSimplex::addSymbolicCut(unsigned row) { } void SymbolicLexSimplex::recordOutput(SymbolicLexMin &result) const { - Matrix output(0, domainPoly.getNumIds() + 1); + Matrix output(0, domainPoly.getNumVars() + 1); output.reserveRows(result.lexmin.getNumOutputs()); for (const Unknown &u : var) { if (u.isSymbol) @@ -1295,7 +1295,7 @@ void SimplexBase::appendVariable(unsigned count) { /// Add all the constraints from the given IntegerRelation. void SimplexBase::intersectIntegerRelation(const IntegerRelation &rel) { - assert(rel.getNumIds() == getNumVariables() && + assert(rel.getNumVars() == getNumVariables() && "IntegerRelation must have same dimensionality as simplex"); for (unsigned i = 0, e = rel.getNumInequalities(); i < e; ++i) addInequality(rel.getInequality(i)); diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp index 2ada5051aa073..e985c821fb9f6 100644 --- a/mlir/lib/Analysis/Presburger/Utils.cpp +++ b/mlir/lib/Analysis/Presburger/Utils.cpp @@ -49,16 +49,16 @@ static void normalizeDivisionByGCD(SmallVectorImpl ÷nd, divisor /= gcd; } -/// Check if the pos^th identifier can be represented as a division using upper +/// Check if the pos^th variable can be represented as a division using upper /// bound inequality at position `ubIneq` and lower bound inequality at position /// `lbIneq`. /// -/// Let `id` be the pos^th identifier, then `id` is equivalent to +/// Let `var` be the pos^th variable, then `var` is equivalent to /// `expr floordiv divisor` if there are constraints of the form: -/// 0 <= expr - divisor * id <= divisor - 1 +/// 0 <= expr - divisor * var <= divisor - 1 /// Rearranging, we have: -/// divisor * id - expr + (divisor - 1) >= 0 <-- Lower bound for 'id' -/// -divisor * id + expr >= 0 <-- Upper bound for 'id' +/// divisor * var - expr + (divisor - 1) >= 0 <-- Lower bound for 'var' +/// -divisor * var + expr >= 0 <-- Upper bound for 'var' /// /// For example: /// 32*k >= 16*i + j - 31 <-- Lower bound for 'k' @@ -79,10 +79,10 @@ static void normalizeDivisionByGCD(SmallVectorImpl ÷nd, /// /// To extract floor divisions with tighter bounds, we assume that that the /// constraints are of the form: -/// c <= expr - divisior * id <= divisor - 1, where 0 <= c <= divisor - 1 +/// c <= expr - divisior * var <= divisor - 1, where 0 <= c <= divisor - 1 /// Rearranging, we have: -/// divisor * id - expr + (divisor - 1) >= 0 <-- Lower bound for 'id' -/// -divisor * id + expr - c >= 0 <-- Upper bound for 'id' +/// divisor * var - expr + (divisor - 1) >= 0 <-- Lower bound for 'var' +/// -divisor * var + expr - c >= 0 <-- Upper bound for 'var' /// /// If successful, `expr` is set to dividend of the division and `divisor` is /// set to the denominator of the division. The final division expression is @@ -92,7 +92,7 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos, SmallVector &expr, unsigned &divisor) { - assert(pos <= cst.getNumIds() && "Invalid identifier position"); + assert(pos <= cst.getNumVars() && "Invalid variable position"); assert(ubIneq <= cst.getNumInequalities() && "Invalid upper bound inequality position"); assert(lbIneq <= cst.getNumInequalities() && @@ -104,7 +104,7 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos, // First, check if the constraints are opposite of each other except the // constant term. unsigned i = 0, e = 0; - for (i = 0, e = cst.getNumIds(); i < e; ++i) + for (i = 0, e = cst.getNumVars(); i < e; ++i) if (cst.atIneq(ubIneq, i) != -cst.atIneq(lbIneq, i)) break; @@ -127,7 +127,7 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos, // Set `expr` to the dividend of the division except the constant term, which // is set below. expr.resize(cst.getNumCols(), 0); - for (i = 0, e = cst.getNumIds(); i < e; ++i) + for (i = 0, e = cst.getNumVars(); i < e; ++i) if (i != pos) expr[i] = cst.atIneq(ubIneq, i); @@ -140,7 +140,7 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos, return success(); } -/// Check if the pos^th identifier can be represented as a division using +/// Check if the pos^th variable can be represented as a division using /// equality at position `eqInd`. /// /// For example: @@ -155,7 +155,7 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos, unsigned eqInd, SmallVector &expr, unsigned &divisor) { - assert(pos <= cst.getNumIds() && "Invalid identifier position"); + assert(pos <= cst.getNumVars() && "Invalid variable position"); assert(eqInd <= cst.getNumEqualities() && "Invalid equality position"); // Extract divisor, the divisor can be negative and hence its sign information @@ -170,7 +170,7 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos, divisor = tempDiv * signDiv; expr.resize(cst.getNumCols(), 0); - for (unsigned i = 0, e = cst.getNumIds(); i < e; ++i) + for (unsigned i = 0, e = cst.getNumVars(); i < e; ++i) if (i != pos) expr[i] = -signDiv * cst.atEq(eqInd, i); @@ -187,15 +187,15 @@ static bool checkExplicitRepresentation(const IntegerRelation &cst, ArrayRef dividend, unsigned pos) { // Exit to avoid circular dependencies between divisions. - for (unsigned c = 0, e = cst.getNumIds(); c < e; ++c) { + for (unsigned c = 0, e = cst.getNumVars(); c < e; ++c) { if (c == pos) continue; if (!foundRepr[c] && dividend[c] != 0) { // Expression can't be constructed as it depends on a yet unknown - // identifier. + // variable. // - // TODO: Visit/compute the identifiers in an order so that this doesn't + // TODO: Visit/compute the variables in an order so that this doesn't // happen. More complex but much more efficient. return false; } @@ -204,10 +204,10 @@ static bool checkExplicitRepresentation(const IntegerRelation &cst, return true; } -/// Check if the pos^th identifier can be expressed as a floordiv of an affine -/// function of other identifiers (where the divisor is a positive constant). -/// `foundRepr` contains a boolean for each identifier indicating if the -/// explicit representation for that identifier has already been computed. +/// Check if the pos^th variable can be expressed as a floordiv of an affine +/// function of other variables (where the divisor is a positive constant). +/// `foundRepr` contains a boolean for each variable indicating if the +/// explicit representation for that variable has already been computed. /// Returns the `MaybeLocalRepr` struct which contains the indices of the /// constraints that can be expressed as a floordiv of an affine function. If /// the representation could be computed, `dividend` and `denominator` are set. @@ -216,8 +216,8 @@ static bool checkExplicitRepresentation(const IntegerRelation &cst, MaybeLocalRepr presburger::computeSingleVarRepr( const IntegerRelation &cst, ArrayRef foundRepr, unsigned pos, SmallVector ÷nd, unsigned &divisor) { - assert(pos < cst.getNumIds() && "invalid position"); - assert(foundRepr.size() == cst.getNumIds() && + assert(pos < cst.getNumVars() && "invalid position"); + assert(foundRepr.size() == cst.getNumVars() && "Size of foundRepr does not match total number of variables"); SmallVector lbIndices, ubIndices, eqIndices; @@ -262,16 +262,16 @@ void presburger::removeDuplicateDivs( // TODO: Add division normalization to support divisions that differ by // a constant. // TODO: Add division ordering such that a division representation for local - // identifier at position `i` only depends on local identifiers at position < + // variable at position `i` only depends on local variables at position < // `i`. This would make sure that all divisions depending on other local // variables that can be merged, are merged. for (unsigned i = 0; i < divs.size(); ++i) { - // Check if a division representation exists for the `i^th` local id. + // Check if a division representation exists for the `i^th` local var. if (denoms[i] == 0) continue; // Check if a division exists which is a duplicate of the division at `i`. for (unsigned j = i + 1; j < divs.size(); ++j) { - // Check if a division representation exists for the `j^th` local id. + // Check if a division representation exists for the `j^th` local var. if (denoms[j] == 0) continue; // Check if the denominators match. @@ -304,18 +304,19 @@ void presburger::removeDuplicateDivs( } } -void presburger::mergeLocalIds( +void presburger::mergeLocalVars( IntegerRelation &relA, IntegerRelation &relB, llvm::function_ref merge) { assert(relA.getSpace().isCompatible(relB.getSpace()) && "Spaces should be compatible."); - // Merge local ids of relA and relB without using division information, - // i.e. append local ids of `relB` to `relA` and insert local ids of `relA` - // to `relB` at start of its local ids. - unsigned initLocals = relA.getNumLocalIds(); - relA.insertId(IdKind::Local, relA.getNumLocalIds(), relB.getNumLocalIds()); - relB.insertId(IdKind::Local, 0, initLocals); + // Merge local vars of relA and relB without using division information, + // i.e. append local vars of `relB` to `relA` and insert local vars of `relA` + // to `relB` at start of its local vars. + unsigned initLocals = relA.getNumLocalVars(); + relA.insertVar(VarKind::Local, relA.getNumLocalVars(), + relB.getNumLocalVars()); + relB.insertVar(VarKind::Local, 0, initLocals); // Get division representations from each rel. std::vector> divsA, divsB; @@ -333,7 +334,7 @@ void presburger::mergeLocalIds( denomsA.begin() + initLocals); // Merge all divisions by removing duplicate divisions. - unsigned localOffset = relA.getIdKindOffset(IdKind::Local); + unsigned localOffset = relA.getVarKindOffset(VarKind::Local); presburger::removeDuplicateDivs(divsA, denomsA, localOffset, merge); } diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp index 7a419ae24301a..b1d662bf08e5f 100644 --- a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp @@ -287,7 +287,7 @@ getNumCommonLoops(const FlatAffineValueConstraints &srcDomain, SmallVectorImpl *commonLoops = nullptr) { // Find the number of common loops shared by src and dst accesses. unsigned minNumLoops = - std::min(srcDomain.getNumDimIds(), dstDomain.getNumDimIds()); + std::min(srcDomain.getNumDimVars(), dstDomain.getNumDimVars()); unsigned numCommonLoops = 0; for (unsigned i = 0; i < minNumLoops; ++i) { if (!isForInductionVar(srcDomain.getValue(i)) || @@ -386,7 +386,7 @@ addOrderingConstraints(const FlatAffineValueConstraints &srcDomain, FlatAffineValueConstraints *dependenceDomain) { unsigned numCols = dependenceDomain->getNumCols(); SmallVector eq(numCols); - unsigned numSrcDims = srcDomain.getNumDimIds(); + unsigned numSrcDims = srcDomain.getNumDimVars(); unsigned numCommonLoops = getNumCommonLoops(srcDomain, dstDomain); unsigned numCommonLoopConstraints = std::min(numCommonLoops, loopDepth); for (unsigned i = 0; i < numCommonLoopConstraints; ++i) { @@ -418,16 +418,16 @@ static void computeDirectionVector( if (numCommonLoops == 0) return; // Compute direction vectors for requested loop depth. - unsigned numIdsToEliminate = dependenceDomain->getNumIds(); + unsigned numIdsToEliminate = dependenceDomain->getNumVars(); // Add new variables to 'dependenceDomain' to represent the direction // constraints for each shared loop. - dependenceDomain->insertDimId(/*pos=*/0, /*num=*/numCommonLoops); + dependenceDomain->insertDimVar(/*pos=*/0, /*num=*/numCommonLoops); // Add equality constraints for each common loop, setting newly introduced // variable at column 'j' to the 'dst' IV minus the 'src IV. SmallVector eq; eq.resize(dependenceDomain->getNumCols()); - unsigned numSrcDims = srcDomain.getNumDimIds(); + unsigned numSrcDims = srcDomain.getNumDimVars(); // Constraint variables format: // [num-common-loops][num-src-dim-ids][num-dst-dim-ids][num-symbols][constant] for (unsigned j = 0; j < numCommonLoops; ++j) { @@ -473,20 +473,20 @@ LogicalResult MemRefAccess::getAccessRelation(FlatAffineRelation &rel) const { // Merge and align domain ids of `ret` and ids of `domain`. Since the domain // of the access map is a subset of the domain of access, the domain ids of // `ret` are guranteed to be a subset of ids of `domain`. - for (unsigned i = 0, e = domain.getNumDimIds(); i < e; ++i) { + for (unsigned i = 0, e = domain.getNumDimVars(); i < e; ++i) { unsigned loc; - if (rel.findId(domain.getValue(i), &loc)) { - rel.swapId(i, loc); + if (rel.findVar(domain.getValue(i), &loc)) { + rel.swapVar(i, loc); } else { - rel.insertDomainId(i); + rel.insertDomainVar(i); rel.setValue(i, domain.getValue(i)); } } // Append domain constraints to `rel`. - domainRel.appendRangeId(rel.getNumRangeDims()); - domainRel.mergeSymbolIds(rel); - domainRel.mergeLocalIds(rel); + domainRel.appendRangeVar(rel.getNumRangeDims()); + domainRel.mergeSymbolVars(rel); + domainRel.mergeLocalVars(rel); rel.append(domainRel); return success(); diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp index e1e66219d0143..ffe92cd1bcff7 100644 --- a/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp @@ -50,9 +50,9 @@ struct AffineExprFlattener : public SimpleAffineExprFlattener { localVarCst(PresburgerSpace::getSetSpace(nDims, nSymbols)) {} private: - // Add a local identifier (needed to flatten a mod, floordiv, ceildiv expr). - // The local identifier added is always a floordiv of a pure add/mul affine - // function of other identifiers, coefficients of which are specified in + // Add a local variable (needed to flatten a mod, floordiv, ceildiv expr). + // The local variable added is always a floordiv of a pure add/mul affine + // function of other variables, coefficients of which are specified in // `dividend' and with respect to the positive constant `divisor'. localExpr // is the simplified tree expression (AffineExpr) corresponding to the // quantifier. @@ -80,7 +80,7 @@ getFlattenedAffineExprs(ArrayRef exprs, unsigned numDims, AffineExprFlattener flattener(numDims, numSymbols); // Use the same flattener to simplify each expression successively. This way - // local identifiers / expressions are shared. + // local variables / expressions are shared. for (auto expr : exprs) { if (!expr.isPureAffine()) return failure(); @@ -157,7 +157,7 @@ FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set) /*numLocals=*/0)) { // Resize values. - values.resize(getNumDimAndSymbolIds(), None); + values.resize(getNumDimAndSymbolVars(), None); // Flatten expressions and add them to the constraint system. std::vector> flatExprs; @@ -167,8 +167,8 @@ FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set) return; } assert(flatExprs.size() == set.getNumConstraints()); - insertId(IdKind::Local, getNumIdKind(IdKind::Local), - /*num=*/localVarCst.getNumLocalIds()); + insertVar(VarKind::Local, getNumVarKind(VarKind::Local), + /*num=*/localVarCst.getNumLocalVars()); for (unsigned i = 0, e = flatExprs.size(); i < e; ++i) { const auto &flatExpr = flatExprs[i]; @@ -179,7 +179,7 @@ FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set) addInequality(flatExpr); } } - // Add the other constraints involving local id's from flattening. + // Add the other constraints involving local vars from flattening. append(localVarCst); } @@ -193,7 +193,7 @@ FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set) // ----+-----+-----+--------- // -1 0 1 >= 0 // -// All dimensions as set as DimId. +// All dimensions as set as VarKind::SetDim. FlatAffineValueConstraints FlatAffineValueConstraints::getHyperrectangular(ValueRange ivs, ValueRange lbs, ValueRange ubs) { @@ -205,9 +205,9 @@ FlatAffineValueConstraints::getHyperrectangular(ValueRange ivs, ValueRange lbs, if (nIvs == 0) return res; - res.appendDimId(ivs); - unsigned lbsStart = res.appendDimId(lbs); - unsigned ubsStart = res.appendDimId(ubs); + res.appendDimVar(ivs); + unsigned lbsStart = res.appendDimVar(lbs); + unsigned ubsStart = res.appendDimVar(ubs); MLIRContext *ctx = ivs.front().getContext(); for (int ivIdx = 0, e = nIvs; ivIdx < e; ++ivIdx) { @@ -269,182 +269,183 @@ void FlatAffineValueConstraints::reset(unsigned newNumDims, newNumSymbols, newNumLocals, valArgs); } -unsigned FlatAffineValueConstraints::appendDimId(ValueRange vals) { - unsigned pos = getNumDimIds(); - insertId(IdKind::SetDim, pos, vals); +unsigned FlatAffineValueConstraints::appendDimVar(ValueRange vals) { + unsigned pos = getNumDimVars(); + insertVar(VarKind::SetDim, pos, vals); return pos; } -unsigned FlatAffineValueConstraints::appendSymbolId(ValueRange vals) { - unsigned pos = getNumSymbolIds(); - insertId(IdKind::Symbol, pos, vals); +unsigned FlatAffineValueConstraints::appendSymbolVar(ValueRange vals) { + unsigned pos = getNumSymbolVars(); + insertVar(VarKind::Symbol, pos, vals); return pos; } -unsigned FlatAffineValueConstraints::insertDimId(unsigned pos, - ValueRange vals) { - return insertId(IdKind::SetDim, pos, vals); +unsigned FlatAffineValueConstraints::insertDimVar(unsigned pos, + ValueRange vals) { + return insertVar(VarKind::SetDim, pos, vals); } -unsigned FlatAffineValueConstraints::insertSymbolId(unsigned pos, - ValueRange vals) { - return insertId(IdKind::Symbol, pos, vals); +unsigned FlatAffineValueConstraints::insertSymbolVar(unsigned pos, + ValueRange vals) { + return insertVar(VarKind::Symbol, pos, vals); } -unsigned FlatAffineValueConstraints::insertId(IdKind kind, unsigned pos, - unsigned num) { - unsigned absolutePos = IntegerPolyhedron::insertId(kind, pos, num); +unsigned FlatAffineValueConstraints::insertVar(VarKind kind, unsigned pos, + unsigned num) { + unsigned absolutePos = IntegerPolyhedron::insertVar(kind, pos, num); - if (kind != IdKind::Local) { + if (kind != VarKind::Local) { values.insert(values.begin() + absolutePos, num, None); - assert(values.size() == getNumDimAndSymbolIds()); + assert(values.size() == getNumDimAndSymbolVars()); } return absolutePos; } -unsigned FlatAffineValueConstraints::insertId(IdKind kind, unsigned pos, - ValueRange vals) { +unsigned FlatAffineValueConstraints::insertVar(VarKind kind, unsigned pos, + ValueRange vals) { assert(!vals.empty() && "expected ValueRange with Values."); - assert(kind != IdKind::Local && - "values cannot be attached to local identifiers."); + assert(kind != VarKind::Local && + "values cannot be attached to local variables."); unsigned num = vals.size(); - unsigned absolutePos = IntegerPolyhedron::insertId(kind, pos, num); + unsigned absolutePos = IntegerPolyhedron::insertVar(kind, pos, num); // If a Value is provided, insert it; otherwise use None. for (unsigned i = 0; i < num; ++i) values.insert(values.begin() + absolutePos + i, vals[i] ? Optional(vals[i]) : None); - assert(values.size() == getNumDimAndSymbolIds()); + assert(values.size() == getNumDimAndSymbolVars()); return absolutePos; } bool FlatAffineValueConstraints::hasValues() const { - return llvm::find_if(values, [](Optional id) { - return id.hasValue(); + return llvm::find_if(values, [](Optional var) { + return var.hasValue(); }) != values.end(); } /// Checks if two constraint systems are in the same space, i.e., if they are -/// associated with the same set of identifiers, appearing in the same order. -static bool areIdsAligned(const FlatAffineValueConstraints &a, - const FlatAffineValueConstraints &b) { - return a.getNumDimIds() == b.getNumDimIds() && - a.getNumSymbolIds() == b.getNumSymbolIds() && - a.getNumIds() == b.getNumIds() && +/// associated with the same set of variables, appearing in the same order. +static bool areVarsAligned(const FlatAffineValueConstraints &a, + const FlatAffineValueConstraints &b) { + return a.getNumDimVars() == b.getNumDimVars() && + a.getNumSymbolVars() == b.getNumSymbolVars() && + a.getNumVars() == b.getNumVars() && a.getMaybeValues().equals(b.getMaybeValues()); } -/// Calls areIdsAligned to check if two constraint systems have the same set -/// of identifiers in the same order. -bool FlatAffineValueConstraints::areIdsAlignedWithOther( +/// Calls areVarsAligned to check if two constraint systems have the same set +/// of variables in the same order. +bool FlatAffineValueConstraints::areVarsAlignedWithOther( const FlatAffineValueConstraints &other) { - return areIdsAligned(*this, other); + return areVarsAligned(*this, other); } -/// Checks if the SSA values associated with `cst`'s identifiers in range +/// Checks if the SSA values associated with `cst`'s variables in range /// [start, end) are unique. -static bool LLVM_ATTRIBUTE_UNUSED areIdsUnique( +static bool LLVM_ATTRIBUTE_UNUSED areVarsUnique( const FlatAffineValueConstraints &cst, unsigned start, unsigned end) { - assert(start <= cst.getNumDimAndSymbolIds() && + assert(start <= cst.getNumDimAndSymbolVars() && "Start position out of bounds"); - assert(end <= cst.getNumDimAndSymbolIds() && "End position out of bounds"); + assert(end <= cst.getNumDimAndSymbolVars() && "End position out of bounds"); if (start >= end) return true; - SmallPtrSet uniqueIds; + SmallPtrSet uniqueVars; ArrayRef> maybeValues = cst.getMaybeValues().slice(start, end - start); for (Optional val : maybeValues) { - if (val && !uniqueIds.insert(*val).second) + if (val && !uniqueVars.insert(*val).second) return false; } return true; } -/// Checks if the SSA values associated with `cst`'s identifiers are unique. +/// Checks if the SSA values associated with `cst`'s variables are unique. static bool LLVM_ATTRIBUTE_UNUSED -areIdsUnique(const FlatAffineValueConstraints &cst) { - return areIdsUnique(cst, 0, cst.getNumDimAndSymbolIds()); +areVarsUnique(const FlatAffineValueConstraints &cst) { + return areVarsUnique(cst, 0, cst.getNumDimAndSymbolVars()); } -/// Checks if the SSA values associated with `cst`'s identifiers of kind `kind` +/// Checks if the SSA values associated with `cst`'s variables of kind `kind` /// are unique. static bool LLVM_ATTRIBUTE_UNUSED -areIdsUnique(const FlatAffineValueConstraints &cst, IdKind kind) { +areVarsUnique(const FlatAffineValueConstraints &cst, VarKind kind) { - if (kind == IdKind::SetDim) - return areIdsUnique(cst, 0, cst.getNumDimIds()); - if (kind == IdKind::Symbol) - return areIdsUnique(cst, cst.getNumDimIds(), cst.getNumDimAndSymbolIds()); - llvm_unreachable("Unexpected IdKind"); + if (kind == VarKind::SetDim) + return areVarsUnique(cst, 0, cst.getNumDimVars()); + if (kind == VarKind::Symbol) + return areVarsUnique(cst, cst.getNumDimVars(), + cst.getNumDimAndSymbolVars()); + llvm_unreachable("Unexpected VarKind"); } -/// Merge and align the identifiers of A and B starting at 'offset', so that -/// both constraint systems get the union of the contained identifiers that is +/// Merge and align the variables of A and B 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 identifiers, with A's original -/// identifiers appearing first followed by any of B's identifiers that didn't -/// appear in A. Local identifiers in B that have the same division -/// representation as local identifiers in A are merged into one. +/// so that they have the union of all variables, with A's original +/// variables appearing first followed by any of B's variables that didn't +/// appear in A. Local variables in B that have the same division +/// representation as local variables in A are merged into one. // E.g.: Input: A has ((%i, %j) [%M, %N]) and B has (%k, %j) [%P, %N, %M]) // Output: both A, B have (%i, %j, %k) [%M, %N, %P] -static void mergeAndAlignIds(unsigned offset, FlatAffineValueConstraints *a, - FlatAffineValueConstraints *b) { - assert(offset <= a->getNumDimIds() && offset <= b->getNumDimIds()); - // A merge/align isn't meaningful if a cst's ids aren't distinct. - assert(areIdsUnique(*a) && "A's values aren't unique"); - assert(areIdsUnique(*b) && "B's values aren't unique"); +static void mergeAndAlignVars(unsigned offset, FlatAffineValueConstraints *a, + FlatAffineValueConstraints *b) { + assert(offset <= a->getNumDimVars() && offset <= b->getNumDimVars()); + // A merge/align isn't meaningful if a cst's vars aren't distinct. + assert(areVarsUnique(*a) && "A's values aren't unique"); + assert(areVarsUnique(*b) && "B's values aren't unique"); assert(std::all_of(a->getMaybeValues().begin() + offset, a->getMaybeValues().end(), - [](Optional id) { return id.hasValue(); })); + [](Optional var) { return var.hasValue(); })); assert(std::all_of(b->getMaybeValues().begin() + offset, b->getMaybeValues().end(), - [](Optional id) { return id.hasValue(); })); + [](Optional var) { return var.hasValue(); })); SmallVector aDimValues; - a->getValues(offset, a->getNumDimIds(), &aDimValues); + a->getValues(offset, a->getNumDimVars(), &aDimValues); { // Merge dims from A into B. unsigned d = offset; for (auto aDimValue : aDimValues) { unsigned loc; - if (b->findId(aDimValue, &loc)) { + if (b->findVar(aDimValue, &loc)) { assert(loc >= offset && "A's dim appears in B's aligned range"); - assert(loc < b->getNumDimIds() && + assert(loc < b->getNumDimVars() && "A's dim appears in B's non-dim position"); - b->swapId(d, loc); + b->swapVar(d, loc); } else { - b->insertDimId(d, aDimValue); + b->insertDimVar(d, aDimValue); } d++; } // Dimensions that are in B, but not in A, are added at the end. - for (unsigned t = a->getNumDimIds(), e = b->getNumDimIds(); t < e; t++) { - a->appendDimId(b->getValue(t)); + for (unsigned t = a->getNumDimVars(), e = b->getNumDimVars(); t < e; t++) { + a->appendDimVar(b->getValue(t)); } - assert(a->getNumDimIds() == b->getNumDimIds() && + assert(a->getNumDimVars() == b->getNumDimVars() && "expected same number of dims"); } // Merge and align symbols of A and B - a->mergeSymbolIds(*b); - // Merge and align local ids of A and B - a->mergeLocalIds(*b); + a->mergeSymbolVars(*b); + // Merge and align locals of A and B + a->mergeLocalVars(*b); - assert(areIdsAligned(*a, *b) && "IDs expected to be aligned"); + assert(areVarsAligned(*a, *b) && "IDs expected to be aligned"); } -// Call 'mergeAndAlignIds' to align constraint systems of 'this' and 'other'. -void FlatAffineValueConstraints::mergeAndAlignIdsWithOther( +// Call 'mergeAndAlignVars' to align constraint systems of 'this' and 'other'. +void FlatAffineValueConstraints::mergeAndAlignVarsWithOther( unsigned offset, FlatAffineValueConstraints *other) { - mergeAndAlignIds(offset, this, other); + mergeAndAlignVars(offset, this, other); } LogicalResult @@ -457,8 +458,8 @@ FlatAffineValueConstraints::composeMap(const AffineValueMap *vMap) { // constraint system nor are they looked at -- the dimensions and symbols of // `other` are expected to correspond 1:1 to `this` system. LogicalResult FlatAffineValueConstraints::composeMatchingMap(AffineMap other) { - assert(other.getNumDims() == getNumDimIds() && "dim mismatch"); - assert(other.getNumSymbols() == getNumSymbolIds() && "symbol mismatch"); + assert(other.getNumDims() == getNumDimVars() && "dim mismatch"); + assert(other.getNumSymbols() == getNumSymbolVars() && "symbol mismatch"); std::vector> flatExprs; if (failed(flattenAlignedMapAndMergeLocals(other, &flatExprs))) @@ -466,10 +467,10 @@ LogicalResult FlatAffineValueConstraints::composeMatchingMap(AffineMap other) { assert(flatExprs.size() == other.getNumResults()); // Add dimensions corresponding to the map's results. - insertDimId(/*pos=*/0, /*num=*/other.getNumResults()); + insertDimVar(/*pos=*/0, /*num=*/other.getNumResults()); // We add one equality for each result connecting the result dim of the map to - // the other identifiers. + // the other variables. // E.g.: if the expression is 16*i0 + i1, and this is the r^th // iteration/result of the value map, we are adding the equality: // d_r - 16*i0 - i1 = 0. Similarly, when flattening (i0 + 1, i0 + 8*i2), we @@ -488,7 +489,7 @@ LogicalResult FlatAffineValueConstraints::composeMatchingMap(AffineMap other) { eqToAdd[e + i] = -flatExpr[i]; } // Local columns of `eq` are at the beginning. - unsigned j = getNumDimIds() + getNumSymbolIds(); + unsigned j = getNumDimVars() + getNumSymbolVars(); unsigned end = flatExpr.size() - 1; for (unsigned i = other.getNumInputs(); i < end; i++, j++) { eqToAdd[j] = -flatExpr[i]; @@ -505,12 +506,12 @@ LogicalResult FlatAffineValueConstraints::composeMatchingMap(AffineMap other) { } // Turn a symbol into a dimension. -static void turnSymbolIntoDim(FlatAffineValueConstraints *cst, Value id) { +static void turnSymbolIntoDim(FlatAffineValueConstraints *cst, Value value) { unsigned pos; - if (cst->findId(id, &pos) && pos >= cst->getNumDimIds() && - pos < cst->getNumDimAndSymbolIds()) { - cst->swapId(pos, cst->getNumDimIds()); - cst->setDimSymbolSeparation(cst->getNumSymbolIds() - 1); + if (cst->findVar(value, &pos) && pos >= cst->getNumDimVars() && + pos < cst->getNumDimAndSymbolVars()) { + cst->swapVar(pos, cst->getNumDimVars()); + cst->setDimSymbolSeparation(cst->getNumSymbolVars() - 1); } } @@ -518,57 +519,57 @@ static void turnSymbolIntoDim(FlatAffineValueConstraints *cst, Value id) { /// of symbols that are unique. Symbols in `this` and `other` should be /// unique. Symbols with Value as `None` are considered to be inequal to all /// other symbols. -void FlatAffineValueConstraints::mergeSymbolIds( +void FlatAffineValueConstraints::mergeSymbolVars( FlatAffineValueConstraints &other) { - assert(areIdsUnique(*this, IdKind::Symbol) && "Symbol ids are not unique"); - assert(areIdsUnique(other, IdKind::Symbol) && "Symbol ids are not unique"); + assert(areVarsUnique(*this, VarKind::Symbol) && "Symbol vars are not unique"); + assert(areVarsUnique(other, VarKind::Symbol) && "Symbol vars are not unique"); SmallVector aSymValues; - getValues(getNumDimIds(), getNumDimAndSymbolIds(), &aSymValues); + getValues(getNumDimVars(), getNumDimAndSymbolVars(), &aSymValues); // Merge symbols: merge symbols into `other` first from `this`. - unsigned s = other.getNumDimIds(); + unsigned s = other.getNumDimVars(); for (Value aSymValue : aSymValues) { unsigned loc; - // If the id is a symbol in `other`, then align it, otherwise assume that + // If the var is a symbol in `other`, then align it, otherwise assume that // it is a new symbol - if (other.findId(aSymValue, &loc) && loc >= other.getNumDimIds() && - loc < other.getNumDimAndSymbolIds()) - other.swapId(s, loc); + if (other.findVar(aSymValue, &loc) && loc >= other.getNumDimVars() && + loc < other.getNumDimAndSymbolVars()) + other.swapVar(s, loc); else - other.insertSymbolId(s - other.getNumDimIds(), aSymValue); + other.insertSymbolVar(s - other.getNumDimVars(), aSymValue); s++; } // Symbols that are in other, but not in this, are added at the end. - for (unsigned t = other.getNumDimIds() + getNumSymbolIds(), - e = other.getNumDimAndSymbolIds(); + for (unsigned t = other.getNumDimVars() + getNumSymbolVars(), + e = other.getNumDimAndSymbolVars(); t < e; t++) - insertSymbolId(getNumSymbolIds(), other.getValue(t)); + insertSymbolVar(getNumSymbolVars(), other.getValue(t)); - assert(getNumSymbolIds() == other.getNumSymbolIds() && + assert(getNumSymbolVars() == other.getNumSymbolVars() && "expected same number of symbols"); - assert(areIdsUnique(*this, IdKind::Symbol) && "Symbol ids are not unique"); - assert(areIdsUnique(other, IdKind::Symbol) && "Symbol ids are not unique"); + assert(areVarsUnique(*this, VarKind::Symbol) && "Symbol vars are not unique"); + assert(areVarsUnique(other, VarKind::Symbol) && "Symbol vars are not unique"); } -// Changes all symbol identifiers which are loop IVs to dim identifiers. +// Changes all symbol variables which are loop IVs to dim variables. void FlatAffineValueConstraints::convertLoopIVSymbolsToDims() { // Gather all symbols which are loop IVs. SmallVector loopIVs; - for (unsigned i = getNumDimIds(), e = getNumDimAndSymbolIds(); i < e; i++) { + for (unsigned i = getNumDimVars(), e = getNumDimAndSymbolVars(); i < e; i++) { if (hasValue(i) && getForInductionVarOwner(getValue(i))) loopIVs.push_back(getValue(i)); } - // Turn each symbol in 'loopIVs' into a dim identifier. + // Turn each symbol in 'loopIVs' into a dim variable. for (auto iv : loopIVs) { turnSymbolIntoDim(this, iv); } } void FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(Value val) { - if (containsId(val)) + if (containsVar(val)) return; // Caller is expected to fully compose map/operands if necessary. @@ -576,14 +577,14 @@ void FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(Value val) { "non-terminal symbol / loop IV expected"); // Outer loop IVs could be used in forOp's bounds. if (auto loop = getForInductionVarOwner(val)) { - appendDimId(val); + appendDimVar(val); if (failed(this->addAffineForOpDomain(loop))) LLVM_DEBUG( loop.emitWarning("failed to add domain info to constraint system")); return; } // Add top level symbol. - appendSymbolId(val); + appendSymbolVar(val); // Check if the symbol is a constant. if (auto constOp = val.getDefiningOp()) addBound(BoundType::EQ, val, constOp.value()); @@ -593,7 +594,7 @@ LogicalResult FlatAffineValueConstraints::addAffineForOpDomain(AffineForOp forOp) { unsigned pos; // Pre-condition for this method. - if (!findId(forOp.getInductionVar(), &pos)) { + if (!findVar(forOp.getInductionVar(), &pos)) { assert(false && "Value not found"); return failure(); } @@ -646,7 +647,7 @@ FlatAffineValueConstraints::addDomainFromSliceMaps(ArrayRef lbMaps, ArrayRef ubMaps, ArrayRef operands) { assert(lbMaps.size() == ubMaps.size()); - assert(lbMaps.size() <= getNumDimIds()); + assert(lbMaps.size() <= getNumDimVars()); for (unsigned i = 0, e = lbMaps.size(); i < e; ++i) { AffineMap lbMap = lbMaps[i]; @@ -681,7 +682,7 @@ FlatAffineValueConstraints::addDomainFromSliceMaps(ArrayRef lbMaps, } // This slice refers to a loop that doesn't exist in the IR yet. Add its - // bounds to the system assuming its dimension identifier position is the + // bounds to the system assuming its dimension variable position is the // same as the position of the loop in the loop nest. if (lbMap && failed(addBound(BoundType::LB, i, lbMap, operands))) return failure(); @@ -695,50 +696,50 @@ void FlatAffineValueConstraints::addAffineIfOpDomain(AffineIfOp ifOp) { // Create the base constraints from the integer set attached to ifOp. FlatAffineValueConstraints cst(ifOp.getIntegerSet()); - // Bind ids in the constraints to ifOp operands. + // Bind vars in the constraints to ifOp operands. SmallVector operands = ifOp.getOperands(); - cst.setValues(0, cst.getNumDimAndSymbolIds(), operands); + cst.setValues(0, cst.getNumDimAndSymbolVars(), operands); // Merge the constraints from ifOp to the current domain. We need first merge // and align the IDs from both constraints, and then append the constraints // from the ifOp into the current one. - mergeAndAlignIdsWithOther(0, &cst); + mergeAndAlignVarsWithOther(0, &cst); append(cst); } bool FlatAffineValueConstraints::hasConsistentState() const { return IntegerPolyhedron::hasConsistentState() && - values.size() == getNumDimAndSymbolIds(); + values.size() == getNumDimAndSymbolVars(); } -void FlatAffineValueConstraints::removeIdRange(IdKind kind, unsigned idStart, - unsigned idLimit) { - IntegerPolyhedron::removeIdRange(kind, idStart, idLimit); - unsigned offset = getIdKindOffset(kind); +void FlatAffineValueConstraints::removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit) { + IntegerPolyhedron::removeVarRange(kind, varStart, varLimit); + unsigned offset = getVarKindOffset(kind); - if (kind != IdKind::Local) { - values.erase(values.begin() + idStart + offset, - values.begin() + idLimit + offset); + if (kind != VarKind::Local) { + values.erase(values.begin() + varStart + offset, + values.begin() + varLimit + offset); } } -// Determine whether the identifier at 'pos' (say id_r) can be expressed as -// modulo of another known identifier (say id_n) w.r.t a constant. For example, +// Determine whether the variable at 'pos' (say var_r) can be expressed as +// modulo of another known variable (say var_n) w.r.t a constant. For example, // if the following constraints hold true: // ``` -// 0 <= id_r <= divisor - 1 -// id_n - (divisor * q_expr) = id_r +// 0 <= var_r <= divisor - 1 +// var_n - (divisor * q_expr) = var_r // ``` -// where `id_n` is a known identifier (called dividend), and `q_expr` is an -// `AffineExpr` (called the quotient expression), `id_r` can be written as: +// where `var_n` is a known variable (called dividend), and `q_expr` is an +// `AffineExpr` (called the quotient expression), `var_r` can be written as: // -// `id_r = id_n mod divisor`. +// `var_r = var_n mod divisor`. // // Additionally, in a special case of the above constaints where `q_expr` is an -// identifier itself that is not yet known (say `id_q`), it can be written as a +// variable itself that is not yet known (say `var_q`), it can be written as a // floordiv in the following way: // -// `id_q = id_n floordiv divisor`. +// `var_q = var_n floordiv divisor`. // // Returns true if the above mod or floordiv are detected, updating 'memo' with // these new expressions. Returns false otherwise. @@ -746,9 +747,9 @@ static bool detectAsMod(const FlatAffineValueConstraints &cst, unsigned pos, int64_t lbConst, int64_t ubConst, SmallVectorImpl &memo, MLIRContext *context) { - assert(pos < cst.getNumIds() && "invalid position"); + assert(pos < cst.getNumVars() && "invalid position"); - // Check if a divisor satisfying the condition `0 <= id_r <= divisor - 1` can + // Check if a divisor satisfying the condition `0 <= var_r <= divisor - 1` can // be determined. if (lbConst != 0 || ubConst < 1) return false; @@ -758,7 +759,7 @@ static bool detectAsMod(const FlatAffineValueConstraints &cst, unsigned pos, for (unsigned curEquality = 0, numEqualities = cst.getNumEqualities(); curEquality < numEqualities; curEquality++) { int64_t coefficientAtPos = cst.atEq(curEquality, pos); - // If current equality does not involve `id_r`, continue to the next + // If current equality does not involve `var_r`, continue to the next // equality. if (coefficientAtPos == 0) continue; @@ -768,9 +769,9 @@ static bool detectAsMod(const FlatAffineValueConstraints &cst, unsigned pos, continue; // Traverse through the equality and construct the dividend expression - // `dividendExpr`, to contain all the identifiers which are known and are + // `dividendExpr`, to contain all the variables which are known and are // not divisible by `(coefficientAtPos * divisor)`. Hope here is that the - // `dividendExpr` gets simplified into a single identifier `id_n` discussed + // `dividendExpr` gets simplified into a single variable `var_n` discussed // above. auto dividendExpr = getAffineConstantExpr(0, context); @@ -781,62 +782,62 @@ static bool detectAsMod(const FlatAffineValueConstraints &cst, unsigned pos, int quotientSign = 1; // Consider each term in the current equality. - unsigned curId, e; - for (curId = 0, e = cst.getNumDimAndSymbolIds(); curId < e; ++curId) { - // Ignore id_r. - if (curId == pos) + unsigned curVar, e; + for (curVar = 0, e = cst.getNumDimAndSymbolVars(); curVar < e; ++curVar) { + // Ignore var_r. + if (curVar == pos) continue; - int64_t coefficientOfCurId = cst.atEq(curEquality, curId); - // Ignore ids that do not contribute to the current equality. - if (coefficientOfCurId == 0) + int64_t coefficientOfCurVar = cst.atEq(curEquality, curVar); + // Ignore vars that do not contribute to the current equality. + if (coefficientOfCurVar == 0) continue; - // Check if the current id goes into the quotient expression. - if (coefficientOfCurId % (divisor * coefficientAtPos) == 0) { + // Check if the current var goes into the quotient expression. + if (coefficientOfCurVar % (divisor * coefficientAtPos) == 0) { quotientCount++; - quotientPosition = curId; - quotientSign = (coefficientOfCurId * coefficientAtPos) > 0 ? 1 : -1; + quotientPosition = curVar; + quotientSign = (coefficientOfCurVar * coefficientAtPos) > 0 ? 1 : -1; continue; } - // Identifiers that are part of dividendExpr should be known. - if (!memo[curId]) + // Variables that are part of dividendExpr should be known. + if (!memo[curVar]) break; - // Append the current identifier to the dividend expression. - dividendExpr = dividendExpr + memo[curId] * coefficientOfCurId; + // Append the current variable to the dividend expression. + dividendExpr = dividendExpr + memo[curVar] * coefficientOfCurVar; } - // Can't construct expression as it depends on a yet uncomputed id. - if (curId < e) + // Can't construct expression as it depends on a yet uncomputed var. + if (curVar < e) continue; - // Express `id_r` in terms of the other ids collected so far. + // Express `var_r` in terms of the other vars collected so far. if (coefficientAtPos > 0) dividendExpr = (-dividendExpr).floorDiv(coefficientAtPos); else dividendExpr = dividendExpr.floorDiv(-coefficientAtPos); // Simplify the expression. - dividendExpr = simplifyAffineExpr(dividendExpr, cst.getNumDimIds(), - cst.getNumSymbolIds()); - // Only if the final dividend expression is just a single id (which we call - // `id_n`), we can proceed. + dividendExpr = simplifyAffineExpr(dividendExpr, cst.getNumDimVars(), + cst.getNumSymbolVars()); + // Only if the final dividend expression is just a single var (which we call + // `var_n`), we can proceed. // TODO: Handle AffineSymbolExpr as well. There is no reason to restrict it // to dims themselves. auto dimExpr = dividendExpr.dyn_cast(); if (!dimExpr) continue; - // Express `id_r` as `id_n % divisor` and store the expression in `memo`. + // Express `var_r` as `var_n % divisor` and store the expression in `memo`. if (quotientCount >= 1) { auto ub = cst.getConstantBound(FlatAffineValueConstraints::BoundType::UB, dimExpr.getPosition()); - // If `id_n` has an upperbound that is less than the divisor, mod can be + // If `var_n` has an upperbound that is less than the divisor, mod can be // eliminated altogether. if (ub && *ub < divisor) memo[pos] = dimExpr; else memo[pos] = dimExpr % divisor; - // If a unique quotient `id_q` was seen, it can be expressed as - // `id_n floordiv divisor`. + // If a unique quotient `var_q` was seen, it can be expressed as + // `var_n floordiv divisor`. if (quotientCount == 1 && !memo[quotientPosition]) memo[quotientPosition] = dimExpr.floorDiv(divisor) * quotientSign; @@ -846,8 +847,8 @@ static bool detectAsMod(const FlatAffineValueConstraints &cst, unsigned pos, return false; } -/// Check if the pos^th identifier can be expressed as a floordiv of an affine -/// function of other identifiers (where the divisor is a positive constant) +/// Check if the pos^th variable can be expressed as a floordiv of an affine +/// function of other variables (where the divisor is a positive constant) /// given the initial set of expressions in `exprs`. If it can be, the /// corresponding position in `exprs` is set as the detected affine expr. For /// eg: 4q <= i + j <= 4q + 3 <=> q = (i + j) floordiv 4. An equality can @@ -856,11 +857,11 @@ static bool detectAsMod(const FlatAffineValueConstraints &cst, unsigned pos, static bool detectAsFloorDiv(const FlatAffineValueConstraints &cst, unsigned pos, MLIRContext *context, SmallVectorImpl &exprs) { - assert(pos < cst.getNumIds() && "invalid position"); + assert(pos < cst.getNumVars() && "invalid position"); // Get upper-lower bound pair for this variable. - SmallVector foundRepr(cst.getNumIds(), false); - for (unsigned i = 0, e = cst.getNumIds(); i < e; ++i) + SmallVector foundRepr(cst.getNumVars(), false); + for (unsigned i = 0, e = cst.getNumVars(); i < e; ++i) if (exprs[i]) foundRepr[i] = true; @@ -874,7 +875,7 @@ static bool detectAsFloorDiv(const FlatAffineValueConstraints &cst, // Construct the dividend expression. auto dividendExpr = getAffineConstantExpr(dividend.back(), context); - for (unsigned c = 0, f = cst.getNumIds(); c < f; c++) + for (unsigned c = 0, f = cst.getNumVars(); c < f; c++) if (dividend[c] != 0) dividendExpr = dividendExpr + dividend[c] * exprs[c]; @@ -887,9 +888,9 @@ std::pair FlatAffineValueConstraints::getLowerAndUpperBound( unsigned pos, unsigned offset, unsigned num, unsigned symStartPos, ArrayRef localExprs, MLIRContext *context) const { - assert(pos + offset < getNumDimIds() && "invalid dim start pos"); + assert(pos + offset < getNumDimVars() && "invalid dim start pos"); assert(symStartPos >= (pos + offset) && "invalid sym start pos"); - assert(getNumLocalIds() == localExprs.size() && + assert(getNumLocalVars() == localExprs.size() && "incorrect local exprs count"); SmallVector lbIndices, ubIndices, eqIndices; @@ -908,7 +909,7 @@ FlatAffineValueConstraints::getLowerAndUpperBound( SmallVector lb, ub; SmallVector lbExprs; unsigned dimCount = symStartPos - num; - unsigned symCount = getNumDimAndSymbolIds() - symStartPos; + unsigned symCount = getNumDimAndSymbolVars() - symStartPos; lbExprs.reserve(lbIndices.size() + eqIndices.size()); // Lower bound expressions. for (auto idx : lbIndices) { @@ -968,41 +969,41 @@ FlatAffineValueConstraints::getLowerAndUpperBound( } /// Computes the lower and upper bounds of the first 'num' dimensional -/// identifiers (starting at 'offset') as affine maps of the remaining -/// identifiers (dimensional and symbolic identifiers). Local identifiers are -/// themselves explicitly computed as affine functions of other identifiers in +/// variables (starting at 'offset') as affine maps of the remaining +/// variables (dimensional and symbolic variables). Local variables are +/// themselves explicitly computed as affine functions of other variables in /// this process if needed. void FlatAffineValueConstraints::getSliceBounds( unsigned offset, unsigned num, MLIRContext *context, SmallVectorImpl *lbMaps, SmallVectorImpl *ubMaps, bool getClosedUB) { - assert(num < getNumDimIds() && "invalid range"); + assert(num < getNumDimVars() && "invalid range"); // Basic simplification. normalizeConstraintsByGCD(); LLVM_DEBUG(llvm::dbgs() << "getSliceBounds for first " << num - << " identifiers\n"); + << " variables\n"); LLVM_DEBUG(dump()); - // Record computed/detected identifiers. - SmallVector memo(getNumIds()); - // Initialize dimensional and symbolic identifiers. - for (unsigned i = 0, e = getNumDimIds(); i < e; i++) { + // Record computed/detected variables. + SmallVector memo(getNumVars()); + // Initialize dimensional and symbolic variables. + for (unsigned i = 0, e = getNumDimVars(); i < e; i++) { if (i < offset) memo[i] = getAffineDimExpr(i, context); else if (i >= offset + num) memo[i] = getAffineDimExpr(i - num, context); } - for (unsigned i = getNumDimIds(), e = getNumDimAndSymbolIds(); i < e; i++) - memo[i] = getAffineSymbolExpr(i - getNumDimIds(), context); + for (unsigned i = getNumDimVars(), e = getNumDimAndSymbolVars(); i < e; i++) + memo[i] = getAffineSymbolExpr(i - getNumDimVars(), context); bool changed; do { changed = false; - // Identify yet unknown identifiers as constants or mod's / floordiv's of - // other identifiers if possible. - for (unsigned pos = 0; pos < getNumIds(); pos++) { + // Identify yet unknown variables as constants or mod's / floordiv's of + // other variables if possible. + for (unsigned pos = 0; pos < getNumVars(); pos++) { if (memo[pos]) continue; @@ -1016,7 +1017,7 @@ void FlatAffineValueConstraints::getSliceBounds( continue; } - // Detect an identifier as modulo of another identifier w.r.t a + // Detect an variable as modulo of another variable w.r.t a // constant. if (detectAsMod(*this, pos, lbConst.getValue(), ubConst.getValue(), memo, context)) { @@ -1025,23 +1026,23 @@ void FlatAffineValueConstraints::getSliceBounds( } } - // Detect an identifier as a floordiv of an affine function of other - // identifiers (divisor is a positive constant). + // Detect an variable as a floordiv of an affine function of other + // variables (divisor is a positive constant). if (detectAsFloorDiv(*this, pos, context, memo)) { changed = true; continue; } - // Detect an identifier as an expression of other identifiers. + // Detect an variable as an expression of other variables. unsigned idx; if (!findConstraintWithNonZeroAt(pos, /*isEq=*/true, &idx)) { continue; } - // Build AffineExpr solving for identifier 'pos' in terms of all others. + // Build AffineExpr solving for variable 'pos' in terms of all others. auto expr = getAffineConstantExpr(0, context); unsigned j, e; - for (j = 0, e = getNumIds(); j < e; ++j) { + for (j = 0, e = getNumVars(); j < e; ++j) { if (j == pos) continue; int64_t c = atEq(idx, j); @@ -1054,11 +1055,11 @@ void FlatAffineValueConstraints::getSliceBounds( } if (j < e) // Can't construct expression as it depends on a yet uncomputed - // identifier. + // variable. continue; // Add constant term to AffineExpr. - expr = expr + atEq(idx, getNumIds()); + expr = expr + atEq(idx, getNumVars()); int64_t vPos = atEq(idx, pos); assert(vPos != 0 && "expected non-zero here"); if (vPos > 0) @@ -1071,19 +1072,19 @@ void FlatAffineValueConstraints::getSliceBounds( changed = true; } // This loop is guaranteed to reach a fixed point - since once an - // identifier's explicit form is computed (in memo[pos]), it's not updated + // variable's explicit form is computed (in memo[pos]), it's not updated // again. } while (changed); int64_t ubAdjustment = getClosedUB ? 0 : 1; - // Set the lower and upper bound maps for all the identifiers that were + // Set the lower and upper bound maps for all the variables that were // computed as affine expressions of the rest as the "detected expr" and // "detected expr + 1" respectively; set the undetected ones to null. Optional tmpClone; for (unsigned pos = 0; pos < num; pos++) { - unsigned numMapDims = getNumDimIds() - num; - unsigned numMapSymbols = getNumSymbolIds(); + unsigned numMapDims = getNumDimVars() - num; + unsigned numMapSymbols = getNumSymbolVars(); AffineExpr expr = memo[pos + offset]; if (expr) expr = simplifyAffineExpr(expr, numMapDims, numMapSymbols); @@ -1095,10 +1096,10 @@ void FlatAffineValueConstraints::getSliceBounds( lbMap = AffineMap::get(numMapDims, numMapSymbols, expr); ubMap = AffineMap::get(numMapDims, numMapSymbols, expr + ubAdjustment); } else { - // TODO: Whenever there are local identifiers in the dependence + // TODO: Whenever there are local variables in the dependence // constraints, we'll conservatively over-approximate, since we don't // always explicitly compute them above (in the while loop). - if (getNumLocalIds() == 0) { + if (getNumLocalVars() == 0) { // Work on a copy so that we don't update this constraint system. if (!tmpClone) { tmpClone.emplace(FlatAffineValueConstraints(*this)); @@ -1107,7 +1108,7 @@ void FlatAffineValueConstraints::getSliceBounds( tmpClone->removeRedundantInequalities(); } std::tie(lbMap, ubMap) = tmpClone->getLowerAndUpperBound( - pos, offset, num, getNumDimIds(), /*localExprs=*/{}, context); + pos, offset, num, getNumDimVars(), /*localExprs=*/{}, context); } // If the above fails, we'll just use the constant lower bound and the @@ -1156,12 +1157,12 @@ LogicalResult FlatAffineValueConstraints::flattenAlignedMapAndMergeLocals( } // Add localCst information. - if (localCst.getNumLocalIds() > 0) { - unsigned numLocalIds = getNumLocalIds(); + if (localCst.getNumLocalVars() > 0) { + unsigned numLocalVars = getNumLocalVars(); // Insert local dims of localCst at the beginning. - insertLocalId(/*pos=*/0, /*num=*/localCst.getNumLocalIds()); + insertLocalVar(/*pos=*/0, /*num=*/localCst.getNumLocalVars()); // Insert local dims of `this` at the end of localCst. - localCst.appendLocalId(/*num=*/numLocalIds); + localCst.appendLocalVar(/*num=*/numLocalVars); // Dimensions of localCst and this constraint set match. Append localCst to // this constraint set. append(localCst); @@ -1173,9 +1174,9 @@ LogicalResult FlatAffineValueConstraints::flattenAlignedMapAndMergeLocals( LogicalResult FlatAffineValueConstraints::addBound(BoundType type, unsigned pos, AffineMap boundMap, bool isClosedBound) { - assert(boundMap.getNumDims() == getNumDimIds() && "dim mismatch"); - assert(boundMap.getNumSymbols() == getNumSymbolIds() && "symbol mismatch"); - assert(pos < getNumDimAndSymbolIds() && "invalid position"); + assert(boundMap.getNumDims() == getNumDimVars() && "dim mismatch"); + assert(boundMap.getNumSymbols() == getNumSymbolVars() && "symbol mismatch"); + assert(pos < getNumDimAndSymbolVars() && "invalid position"); assert((type != BoundType::EQ || isClosedBound) && "EQ bound must be closed."); @@ -1204,7 +1205,7 @@ LogicalResult FlatAffineValueConstraints::addBound(BoundType type, unsigned pos, continue; ineq[pos] = lower ? 1 : -1; // Local columns of `ineq` are at the beginning. - unsigned j = getNumDimIds() + getNumSymbolIds(); + unsigned j = getNumDimVars() + getNumSymbolVars(); unsigned end = flatExpr.size() - 1; for (unsigned i = boundMap.getNumInputs(); i < end; i++, j++) { ineq[j] = lower ? -flatExpr[i] : flatExpr[i]; @@ -1240,14 +1241,14 @@ FlatAffineValueConstraints::computeAlignedMap(AffineMap map, SmallVector *newSymsPtr = nullptr; #endif // NDEBUG - dims.reserve(getNumDimIds()); - syms.reserve(getNumSymbolIds()); - for (unsigned i = getIdKindOffset(IdKind::SetDim), - e = getIdKindEnd(IdKind::SetDim); + dims.reserve(getNumDimVars()); + syms.reserve(getNumSymbolVars()); + for (unsigned i = getVarKindOffset(VarKind::SetDim), + e = getVarKindEnd(VarKind::SetDim); i < e; ++i) dims.push_back(values[i] ? *values[i] : Value()); - for (unsigned i = getIdKindOffset(IdKind::Symbol), - e = getIdKindEnd(IdKind::Symbol); + for (unsigned i = getVarKindOffset(VarKind::Symbol), + e = getVarKindEnd(VarKind::Symbol); i < e; ++i) syms.push_back(values[i] ? *values[i] : Value()); @@ -1292,7 +1293,7 @@ LogicalResult FlatAffineValueConstraints::addSliceBounds( for (unsigned i = 0, e = lbMaps.size(); i < e; ++i) { unsigned pos; - if (!findId(values[i], &pos)) + if (!findVar(values[i], &pos)) continue; AffineMap lbMap = lbMaps[i]; @@ -1327,10 +1328,10 @@ LogicalResult FlatAffineValueConstraints::addSliceBounds( return success(); } -bool FlatAffineValueConstraints::findId(Value val, unsigned *pos) const { +bool FlatAffineValueConstraints::findVar(Value val, unsigned *pos) const { unsigned i = 0; - for (const auto &mayBeId : values) { - if (mayBeId && *mayBeId == val) { + for (const auto &mayBeVar : values) { + if (mayBeVar && *mayBeVar == val) { *pos = i; return true; } @@ -1339,22 +1340,23 @@ bool FlatAffineValueConstraints::findId(Value val, unsigned *pos) const { return false; } -bool FlatAffineValueConstraints::containsId(Value val) const { - return llvm::any_of(values, [&](const Optional &mayBeId) { - return mayBeId && *mayBeId == val; +bool FlatAffineValueConstraints::containsVar(Value val) const { + return llvm::any_of(values, [&](const Optional &mayBeVar) { + return mayBeVar && *mayBeVar == val; }); } -void FlatAffineValueConstraints::swapId(unsigned posA, unsigned posB) { - IntegerPolyhedron::swapId(posA, posB); +void FlatAffineValueConstraints::swapVar(unsigned posA, unsigned posB) { + IntegerPolyhedron::swapVar(posA, posB); - if (getIdKindAt(posA) == IdKind::Local && getIdKindAt(posB) == IdKind::Local) + if (getVarKindAt(posA) == VarKind::Local && + getVarKindAt(posB) == VarKind::Local) return; - // Treat value of a local identifer as None. - if (getIdKindAt(posA) == IdKind::Local) + // Treat value of a local variable as None. + if (getVarKindAt(posA) == VarKind::Local) values[posB] = None; - else if (getIdKindAt(posB) == IdKind::Local) + else if (getVarKindAt(posB) == VarKind::Local) values[posA] = None; else std::swap(values[posA], values[posB]); @@ -1363,23 +1365,23 @@ void FlatAffineValueConstraints::swapId(unsigned posA, unsigned posB) { void FlatAffineValueConstraints::addBound(BoundType type, Value val, int64_t value) { unsigned pos; - if (!findId(val, &pos)) + if (!findVar(val, &pos)) // This is a pre-condition for this method. - assert(0 && "id not found"); + assert(0 && "var not found"); addBound(type, pos, value); } void FlatAffineValueConstraints::printSpace(raw_ostream &os) const { IntegerPolyhedron::printSpace(os); os << "("; - for (unsigned i = 0, e = getNumDimAndSymbolIds(); i < e; i++) { + for (unsigned i = 0, e = getNumDimAndSymbolVars(); i < e; i++) { if (hasValue(i)) os << "Value "; else os << "None "; } - for (unsigned i = getIdKindOffset(IdKind::Local), - e = getIdKindEnd(IdKind::Local); + for (unsigned i = getVarKindOffset(VarKind::Local), + e = getVarKindEnd(VarKind::Local); i < e; ++i) os << "Local "; os << " const)\n"; @@ -1394,25 +1396,25 @@ void FlatAffineValueConstraints::clearAndCopyFrom( } else { *static_cast(this) = other; values.clear(); - values.resize(getNumDimAndSymbolIds(), None); + values.resize(getNumDimAndSymbolVars(), None); } } void FlatAffineValueConstraints::fourierMotzkinEliminate( unsigned pos, bool darkShadow, bool *isResultIntegerExact) { SmallVector, 8> newVals = values; - if (getIdKindAt(pos) != IdKind::Local) + if (getVarKindAt(pos) != VarKind::Local) newVals.erase(newVals.begin() + pos); // Note: Base implementation discards all associated Values. IntegerPolyhedron::fourierMotzkinEliminate(pos, darkShadow, isResultIntegerExact); values = newVals; - assert(values.size() == getNumDimAndSymbolIds()); + assert(values.size() == getNumDimAndSymbolVars()); } void FlatAffineValueConstraints::projectOut(Value val) { unsigned pos; - bool ret = findId(val, &pos); + bool ret = findVar(val, &pos); assert(ret); (void)ret; fourierMotzkinEliminate(pos); @@ -1420,18 +1422,18 @@ void FlatAffineValueConstraints::projectOut(Value val) { LogicalResult FlatAffineValueConstraints::unionBoundingBox( const FlatAffineValueConstraints &otherCst) { - assert(otherCst.getNumDimIds() == getNumDimIds() && "dims mismatch"); + assert(otherCst.getNumDimVars() == getNumDimVars() && "dims mismatch"); assert(otherCst.getMaybeValues() - .slice(0, getNumDimIds()) - .equals(getMaybeValues().slice(0, getNumDimIds())) && + .slice(0, getNumDimVars()) + .equals(getMaybeValues().slice(0, getNumDimVars())) && "dim values mismatch"); - assert(otherCst.getNumLocalIds() == 0 && "local ids not supported here"); - assert(getNumLocalIds() == 0 && "local ids not supported yet here"); + assert(otherCst.getNumLocalVars() == 0 && "local vars not supported here"); + assert(getNumLocalVars() == 0 && "local vars not supported yet here"); // Align `other` to this. - if (!areIdsAligned(*this, otherCst)) { + if (!areVarsAligned(*this, otherCst)) { FlatAffineValueConstraints otherCopy(otherCst); - mergeAndAlignIds(/*offset=*/getNumDimIds(), this, &otherCopy); + mergeAndAlignVars(/*offset=*/getNumDimVars(), this, &otherCopy); return IntegerPolyhedron::unionBoundingBox(otherCopy); } @@ -1444,10 +1446,10 @@ LogicalResult FlatAffineValueConstraints::unionBoundingBox( static LogicalResult computeLocalVars(const FlatAffineValueConstraints &cst, SmallVectorImpl &memo, MLIRContext *context) { - unsigned numDims = cst.getNumDimIds(); - unsigned numSyms = cst.getNumSymbolIds(); + unsigned numDims = cst.getNumDimVars(); + unsigned numSyms = cst.getNumSymbolVars(); - // Initialize dimensional and symbolic identifiers. + // Initialize dimensional and symbolic variables. for (unsigned i = 0; i < numDims; i++) memo[i] = getAffineDimExpr(i, context); for (unsigned i = numDims, e = numDims + numSyms; i < e; i++) @@ -1459,14 +1461,14 @@ static LogicalResult computeLocalVars(const FlatAffineValueConstraints &cst, // local vars would have been detected as floordivs and set in memo; so the // number of null entries in memo[...] strictly reduces; so this converges. changed = false; - for (unsigned i = 0, e = cst.getNumLocalIds(); i < e; ++i) + for (unsigned i = 0, e = cst.getNumLocalVars(); i < e; ++i) if (!memo[numDims + numSyms + i] && detectAsFloorDiv(cst, /*pos=*/numDims + numSyms + i, context, memo)) changed = true; } while (changed); ArrayRef localExprs = - ArrayRef(memo).take_back(cst.getNumLocalIds()); + ArrayRef(memo).take_back(cst.getNumLocalVars()); return success( llvm::all_of(localExprs, [](AffineExpr expr) { return expr; })); } @@ -1474,18 +1476,18 @@ static LogicalResult computeLocalVars(const FlatAffineValueConstraints &cst, void FlatAffineValueConstraints::getIneqAsAffineValueMap( unsigned pos, unsigned ineqPos, AffineValueMap &vmap, MLIRContext *context) const { - unsigned numDims = getNumDimIds(); - unsigned numSyms = getNumSymbolIds(); + unsigned numDims = getNumDimVars(); + unsigned numSyms = getNumSymbolVars(); assert(pos < numDims && "invalid position"); assert(ineqPos < getNumInequalities() && "invalid inequality position"); // Get expressions for local vars. - SmallVector memo(getNumIds(), AffineExpr()); + SmallVector memo(getNumVars(), AffineExpr()); if (failed(computeLocalVars(*this, memo, context))) assert(false && "one or more local exprs do not have an explicit representation"); - auto localExprs = ArrayRef(memo).take_back(getNumLocalIds()); + auto localExprs = ArrayRef(memo).take_back(getNumLocalVars()); // Compute the AffineExpr lower/upper bound for this inequality. ArrayRef inequality = getInequality(ineqPos); @@ -1511,7 +1513,7 @@ void FlatAffineValueConstraints::getIneqAsAffineValueMap( SmallVector operands; getValues(0, pos, &operands); SmallVector trailingOperands; - getValues(pos + 1, getNumDimAndSymbolIds(), &trailingOperands); + getValues(pos + 1, getNumDimAndSymbolVars(), &trailingOperands); operands.append(trailingOperands.begin(), trailingOperands.end()); vmap.reset(AffineMap::get(numDims - 1, numSyms, boundExpr), operands); } @@ -1520,19 +1522,19 @@ IntegerSet FlatAffineValueConstraints::getAsIntegerSet(MLIRContext *context) const { if (getNumConstraints() == 0) // Return universal set (always true): 0 == 0. - return IntegerSet::get(getNumDimIds(), getNumSymbolIds(), + return IntegerSet::get(getNumDimVars(), getNumSymbolVars(), getAffineConstantExpr(/*constant=*/0, context), /*eqFlags=*/true); // Construct local references. - SmallVector memo(getNumIds(), AffineExpr()); + SmallVector memo(getNumVars(), AffineExpr()); if (failed(computeLocalVars(*this, memo, context))) { // Check if the local variables without an explicit representation have // zero coefficients everywhere. SmallVector noLocalRepVars; - unsigned numDimsSymbols = getNumDimAndSymbolIds(); - for (unsigned i = numDimsSymbols, e = getNumIds(); i < e; ++i) { + unsigned numDimsSymbols = getNumDimAndSymbolVars(); + for (unsigned i = numDimsSymbols, e = getNumVars(); i < e; ++i) { if (!memo[i] && !isColZero(/*pos=*/i)) noLocalRepVars.push_back(i - numDimsSymbols); } @@ -1548,11 +1550,11 @@ FlatAffineValueConstraints::getAsIntegerSet(MLIRContext *context) const { } ArrayRef localExprs = - ArrayRef(memo).take_back(getNumLocalIds()); + ArrayRef(memo).take_back(getNumLocalVars()); // Construct the IntegerSet from the equalities/inequalities. - unsigned numDims = getNumDimIds(); - unsigned numSyms = getNumSymbolIds(); + unsigned numDims = getNumDimVars(); + unsigned numSyms = getNumSymbolVars(); SmallVector eqFlags(getNumConstraints()); std::fill(eqFlags.begin(), eqFlags.begin() + getNumEqualities(), true); @@ -1618,7 +1620,7 @@ AffineMap mlir::alignAffineMapWithValues(AffineMap map, ValueRange operands, FlatAffineValueConstraints FlatAffineRelation::getDomainSet() const { FlatAffineValueConstraints domain = *this; // Convert all range variables to local variables. - domain.convertToLocal(IdKind::SetDim, getNumDomainDims(), + domain.convertToLocal(VarKind::SetDim, getNumDomainDims(), getNumDomainDims() + getNumRangeDims()); return domain; } @@ -1626,7 +1628,7 @@ FlatAffineValueConstraints FlatAffineRelation::getDomainSet() const { FlatAffineValueConstraints FlatAffineRelation::getRangeSet() const { FlatAffineValueConstraints range = *this; // Convert all domain variables to local variables. - range.convertToLocal(IdKind::SetDim, 0, getNumDomainDims()); + range.convertToLocal(VarKind::SetDim, 0, getNumDomainDims()); return range; } @@ -1648,26 +1650,26 @@ void FlatAffineRelation::compose(const FlatAffineRelation &other) { // to // [otherDomain thisDomain] -> [thisRange]. unsigned removeDims = rel.getNumRangeDims(); - insertDomainId(0, rel.getNumDomainDims()); - rel.appendRangeId(getNumRangeDims()); + insertDomainVar(0, rel.getNumDomainDims()); + rel.appendRangeVar(getNumRangeDims()); - // Merge symbol and local identifiers. - mergeSymbolIds(rel); - mergeLocalIds(rel); + // Merge symbol and local variables. + mergeSymbolVars(rel); + mergeLocalVars(rel); // Convert `rel` from [otherDomain] -> [otherRange thisRange] to - // [otherDomain] -> [thisRange] by converting first otherRange range ids - // to local ids. - rel.convertToLocal(IdKind::SetDim, rel.getNumDomainDims(), + // [otherDomain] -> [thisRange] by converting first otherRange range vars + // to local vars. + rel.convertToLocal(VarKind::SetDim, rel.getNumDomainDims(), rel.getNumDomainDims() + removeDims); // Convert `this` from [otherDomain thisDomain] -> [thisRange] to - // [otherDomain] -> [thisRange] by converting last thisDomain domain ids - // to local ids. - convertToLocal(IdKind::SetDim, getNumDomainDims() - removeDims, + // [otherDomain] -> [thisRange] by converting last thisDomain domain vars + // to local vars. + convertToLocal(VarKind::SetDim, getNumDomainDims() - removeDims, getNumDomainDims()); - auto thisMaybeValues = getMaybeValues(IdKind::SetDim); - auto relMaybeValues = rel.getMaybeValues(IdKind::SetDim); + auto thisMaybeValues = getMaybeValues(VarKind::SetDim); + auto relMaybeValues = rel.getMaybeValues(VarKind::SetDim); // Add and match domain of `rel` to domain of `this`. for (unsigned i = 0, e = rel.getNumDomainDims(); i < e; ++i) @@ -1690,60 +1692,60 @@ void FlatAffineRelation::compose(const FlatAffineRelation &other) { void FlatAffineRelation::inverse() { unsigned oldDomain = getNumDomainDims(); unsigned oldRange = getNumRangeDims(); - // Add new range ids. - appendRangeId(oldDomain); - // Swap new ids with domain. + // Add new range vars. + appendRangeVar(oldDomain); + // Swap new vars with domain. for (unsigned i = 0; i < oldDomain; ++i) - swapId(i, oldDomain + oldRange + i); + swapVar(i, oldDomain + oldRange + i); // Remove the swapped domain. - removeIdRange(0, oldDomain); + removeVarRange(0, oldDomain); // Set domain and range as inverse. numDomainDims = oldRange; numRangeDims = oldDomain; } -void FlatAffineRelation::insertDomainId(unsigned pos, unsigned num) { +void FlatAffineRelation::insertDomainVar(unsigned pos, unsigned num) { assert(pos <= getNumDomainDims() && - "Id cannot be inserted at invalid position"); - insertDimId(pos, num); + "Var cannot be inserted at invalid position"); + insertDimVar(pos, num); numDomainDims += num; } -void FlatAffineRelation::insertRangeId(unsigned pos, unsigned num) { +void FlatAffineRelation::insertRangeVar(unsigned pos, unsigned num) { assert(pos <= getNumRangeDims() && - "Id cannot be inserted at invalid position"); - insertDimId(getNumDomainDims() + pos, num); + "Var cannot be inserted at invalid position"); + insertDimVar(getNumDomainDims() + pos, num); numRangeDims += num; } -void FlatAffineRelation::appendDomainId(unsigned num) { - insertDimId(getNumDomainDims(), num); +void FlatAffineRelation::appendDomainVar(unsigned num) { + insertDimVar(getNumDomainDims(), num); numDomainDims += num; } -void FlatAffineRelation::appendRangeId(unsigned num) { - insertDimId(getNumDimIds(), num); +void FlatAffineRelation::appendRangeVar(unsigned num) { + insertDimVar(getNumDimVars(), num); numRangeDims += num; } -void FlatAffineRelation::removeIdRange(IdKind kind, unsigned idStart, - unsigned idLimit) { - assert(idLimit <= getNumIdKind(kind)); - if (idStart >= idLimit) +void FlatAffineRelation::removeVarRange(VarKind kind, unsigned varStart, + unsigned varLimit) { + assert(varLimit <= getNumVarKind(kind)); + if (varStart >= varLimit) return; - FlatAffineValueConstraints::removeIdRange(kind, idStart, idLimit); + FlatAffineValueConstraints::removeVarRange(kind, varStart, varLimit); // If kind is not SetDim, domain and range don't need to be updated. - if (kind != IdKind::SetDim) + if (kind != VarKind::SetDim) return; - // Compute number of domain and range identifiers to remove. This is done by - // intersecting the range of domain/range ids with range of ids to remove. - unsigned intersectDomainLHS = std::min(idLimit, getNumDomainDims()); - unsigned intersectDomainRHS = idStart; - unsigned intersectRangeLHS = std::min(idLimit, getNumDimIds()); - unsigned intersectRangeRHS = std::max(idStart, getNumDomainDims()); + // Compute number of domain and range variables to remove. This is done by + // intersecting the range of domain/range vars with range of vars to remove. + unsigned intersectDomainLHS = std::min(varLimit, getNumDomainDims()); + unsigned intersectDomainRHS = varStart; + unsigned intersectRangeLHS = std::min(varLimit, getNumDimVars()); + unsigned intersectRangeRHS = std::max(varStart, getNumDomainDims()); if (intersectDomainLHS > intersectDomainRHS) numDomainDims -= intersectDomainLHS - intersectDomainRHS; @@ -1759,13 +1761,13 @@ LogicalResult mlir::getRelationFromMap(AffineMap &map, if (failed(getFlattenedAffineExprs(map, &flatExprs, &localVarCst))) return failure(); - unsigned oldDimNum = localVarCst.getNumDimIds(); + unsigned oldDimNum = localVarCst.getNumDimVars(); unsigned oldCols = localVarCst.getNumCols(); - unsigned numRangeIds = map.getNumResults(); - unsigned numDomainIds = map.getNumDims(); + unsigned numRangeVars = map.getNumResults(); + unsigned numDomainVars = map.getNumDims(); // Add range as the new expressions. - localVarCst.appendDimId(numRangeIds); + localVarCst.appendDimVar(numRangeVars); // Add equalities between source and range. SmallVector eq(localVarCst.getNumCols()); @@ -1776,14 +1778,14 @@ LogicalResult mlir::getRelationFromMap(AffineMap &map, for (unsigned j = 0, f = oldDimNum; j < f; ++j) eq[j] = flatExprs[i][j]; for (unsigned j = oldDimNum, f = oldCols; j < f; ++j) - eq[j + numRangeIds] = flatExprs[i][j]; + eq[j + numRangeVars] = flatExprs[i][j]; // Set this dimension to -1 to equate lhs and rhs and add equality. - eq[numDomainIds + i] = -1; + eq[numDomainVars + i] = -1; localVarCst.addEquality(eq); } // Create relation and return success. - rel = FlatAffineRelation(numDomainIds, numRangeIds, localVarCst); + rel = FlatAffineRelation(numDomainVars, numRangeVars, localVarCst); return success(); } @@ -1797,8 +1799,8 @@ LogicalResult mlir::getRelationFromMap(const AffineValueMap &map, // Set symbol values for domain dimensions and symbols. for (unsigned i = 0, e = rel.getNumDomainDims(); i < e; ++i) rel.setValue(i, map.getOperand(i)); - for (unsigned i = rel.getNumDimIds(), e = rel.getNumDimAndSymbolIds(); i < e; - ++i) + for (unsigned i = rel.getNumDimVars(), e = rel.getNumDimAndSymbolVars(); + i < e; ++i) rel.setValue(i, map.getOperand(i - rel.getNumRangeDims())); return success(); diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp index 6a9a03886f5d9..7783a6d53ffc7 100644 --- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp @@ -82,7 +82,7 @@ ComputationSliceState::getSourceAsConstraints(FlatAffineValueConstraints &cst) { LogicalResult ComputationSliceState::getAsConstraints(FlatAffineValueConstraints *cst) { assert(!lbOperands.empty()); - // Adds src 'ivs' as dimension identifiers in 'cst'. + // Adds src 'ivs' as dimension variables in 'cst'. unsigned numDims = ivs.size(); // Adds operands (dst ivs and symbols) as symbols in 'cst'. unsigned numSymbols = lbOperands[0].size(); @@ -96,7 +96,7 @@ ComputationSliceState::getAsConstraints(FlatAffineValueConstraints *cst) { // of fusion and equality constraints for symbols which are constants. for (unsigned i = numDims, end = values.size(); i < end; ++i) { Value value = values[i]; - assert(cst->containsId(value) && "value expected to be present"); + assert(cst->containsVar(value) && "value expected to be present"); if (isValidSymbol(value)) { // Check if the symbol is a constant. if (auto cOp = value.getDefiningOp()) @@ -242,14 +242,14 @@ Optional ComputationSliceState::isSliceValid() { } // As the set difference utility currently cannot handle symbols in its // operands, validity of the slice cannot be determined. - if (srcConstraints.getNumSymbolIds() > 0) { + if (srcConstraints.getNumSymbolVars() > 0) { LLVM_DEBUG(llvm::dbgs() << "Cannot handle symbols in source domain\n"); return llvm::None; } - // TODO: Handle local ids in the source domains while using the 'projectOut' + // TODO: Handle local vars in the source domains while using the 'projectOut' // utility below. Currently, aligning is not done assuming that there will be - // no local ids in the source domain. - if (srcConstraints.getNumLocalIds() != 0) { + // no local vars in the source domain. + if (srcConstraints.getNumLocalVars() != 0) { LLVM_DEBUG(llvm::dbgs() << "Cannot handle locals in source domain\n"); return llvm::None; } @@ -265,7 +265,7 @@ Optional ComputationSliceState::isSliceValid() { // Projecting out every dimension other than the 'ivs' to express slice's // domain completely in terms of source's IVs. sliceConstraints.projectOut(ivs.size(), - sliceConstraints.getNumIds() - ivs.size()); + sliceConstraints.getNumVars() - ivs.size()); LLVM_DEBUG(llvm::dbgs() << "Domain of the source of the slice:\n"); LLVM_DEBUG(srcConstraints.dump()); @@ -325,7 +325,7 @@ Optional ComputationSliceState::isMaximal() const { if (failed(sliceConstraints.addDomainFromSliceMaps(lbs, ubs, lbOperands[0]))) return llvm::None; - if (srcConstraints.getNumDimIds() != sliceConstraints.getNumDimIds()) + if (srcConstraints.getNumDimVars() != sliceConstraints.getNumDimVars()) // Constraint dims are different. The integer set difference can't be // computed so we don't know if the slice is maximal. return llvm::None; @@ -350,7 +350,7 @@ Optional MemRefRegion::getConstantBoundingSizeAndShape( if (shape) shape->reserve(rank); - assert(rank == cst.getNumDimIds() && "inconsistent memref region"); + assert(rank == cst.getNumDimVars() && "inconsistent memref region"); // Use a copy of the region constraints that has upper/lower bounds for each // memref dimension with static size added to guard against potential @@ -387,7 +387,7 @@ Optional MemRefRegion::getConstantBoundingSizeAndShape( return None; diffConstant = dimSize; // Lower bound becomes 0. - lb.resize(cstWithShapeBounds.getNumSymbolIds() + 1, 0); + lb.resize(cstWithShapeBounds.getNumSymbolVars() + 1, 0); lbDivisor = 1; } numElements *= diffConstant; @@ -405,21 +405,21 @@ Optional MemRefRegion::getConstantBoundingSizeAndShape( void MemRefRegion::getLowerAndUpperBound(unsigned pos, AffineMap &lbMap, AffineMap &ubMap) const { - assert(pos < cst.getNumDimIds() && "invalid position"); + assert(pos < cst.getNumDimVars() && "invalid position"); auto memRefType = memref.getType().cast(); unsigned rank = memRefType.getRank(); - assert(rank == cst.getNumDimIds() && "inconsistent memref region"); + assert(rank == cst.getNumDimVars() && "inconsistent memref region"); auto boundPairs = cst.getLowerAndUpperBound( - pos, /*offset=*/0, /*num=*/rank, cst.getNumDimAndSymbolIds(), + pos, /*offset=*/0, /*num=*/rank, cst.getNumDimAndSymbolVars(), /*localExprs=*/{}, memRefType.getContext()); lbMap = boundPairs.first; ubMap = boundPairs.second; assert(lbMap && "lower bound for a region must exist"); assert(ubMap && "upper bound for a region must exist"); - assert(lbMap.getNumInputs() == cst.getNumDimAndSymbolIds() - rank); - assert(ubMap.getNumInputs() == cst.getNumDimAndSymbolIds() - rank); + assert(lbMap.getNumInputs() == cst.getNumDimAndSymbolVars() - rank); + assert(ubMap.getNumInputs() == cst.getNumDimAndSymbolVars() - rank); } LogicalResult MemRefRegion::unionBoundingBox(const MemRefRegion &other) { @@ -548,10 +548,10 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth, return failure(); } - // Set all identifiers appearing after the first 'rank' identifiers as - // symbolic identifiers - so that the ones corresponding to the memref - // dimensions are the dimensional identifiers for the memref region. - cst.setDimSymbolSeparation(cst.getNumDimAndSymbolIds() - rank); + // Set all variables appearing after the first 'rank' variables as + // symbolic variables - so that the ones corresponding to the memref + // dimensions are the dimensional variables for the memref region. + cst.setDimSymbolSeparation(cst.getNumDimAndSymbolVars() - rank); // Eliminate any loop IVs other than the outermost 'loopDepth' IVs, on which // this memref region is symbolic. @@ -559,25 +559,25 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth, getLoopIVs(*op, &enclosingIVs); assert(loopDepth <= enclosingIVs.size() && "invalid loop depth"); enclosingIVs.resize(loopDepth); - SmallVector ids; - cst.getValues(cst.getNumDimIds(), cst.getNumDimAndSymbolIds(), &ids); - for (auto id : ids) { + SmallVector vars; + cst.getValues(cst.getNumDimVars(), cst.getNumDimAndSymbolVars(), &vars); + for (auto var : vars) { AffineForOp iv; - if ((iv = getForInductionVarOwner(id)) && + if ((iv = getForInductionVarOwner(var)) && !llvm::is_contained(enclosingIVs, iv)) { - cst.projectOut(id); + cst.projectOut(var); } } // Project out any local variables (these would have been added for any // mod/divs). - cst.projectOut(cst.getNumDimAndSymbolIds(), cst.getNumLocalIds()); + cst.projectOut(cst.getNumDimAndSymbolVars(), cst.getNumLocalVars()); - // Constant fold any symbolic identifiers. - cst.constantFoldIdRange(/*pos=*/cst.getNumDimIds(), - /*num=*/cst.getNumSymbolIds()); + // Constant fold any symbolic variables. + cst.constantFoldVarRange(/*pos=*/cst.getNumDimVars(), + /*num=*/cst.getNumSymbolVars()); - assert(cst.getNumDimIds() == rank && "unexpected MemRefRegion format"); + assert(cst.getNumDimVars() == rank && "unexpected MemRefRegion format"); // Add upper/lower bounds for each memref dimension with static size // to guard against potential over-approximation from projection. @@ -762,7 +762,7 @@ static Operation *getInstAtPosition(ArrayRef positions, // Adds loop IV bounds to 'cst' for loop IVs not found in 'ivs'. static LogicalResult addMissingLoopIVBounds(SmallPtrSet &ivs, FlatAffineValueConstraints *cst) { - for (unsigned i = 0, e = cst->getNumDimIds(); i < e; ++i) { + for (unsigned i = 0, e = cst->getNumDimVars(); i < e; ++i) { auto value = cst->getValue(i); if (ivs.count(value) == 0) { assert(isForInductionVar(value)); @@ -815,7 +815,7 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, // Compute the union of slice bounds between all pairs in 'opsA' and // 'opsB' in 'sliceUnionCst'. FlatAffineValueConstraints sliceUnionCst; - assert(sliceUnionCst.getNumDimAndSymbolIds() == 0); + assert(sliceUnionCst.getNumDimAndSymbolVars() == 0); std::vector> dependentOpPairs; for (auto *i : opsA) { MemRefAccess srcAccess(i); @@ -851,14 +851,14 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, mlir::getComputationSliceState(i, j, &dependenceConstraints, loopDepth, isBackwardSlice, &tmpSliceState); - if (sliceUnionCst.getNumDimAndSymbolIds() == 0) { + if (sliceUnionCst.getNumDimAndSymbolVars() == 0) { // Initialize 'sliceUnionCst' with the bounds computed in previous step. if (failed(tmpSliceState.getAsConstraints(&sliceUnionCst))) { LLVM_DEBUG(llvm::dbgs() << "Unable to compute slice bound constraints\n"); return SliceComputationResult::GenericFailure; } - assert(sliceUnionCst.getNumDimAndSymbolIds() > 0); + assert(sliceUnionCst.getNumDimAndSymbolVars() > 0); continue; } @@ -871,21 +871,21 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, } // Align coordinate spaces of 'sliceUnionCst' and 'tmpSliceCst' if needed. - if (!sliceUnionCst.areIdsAlignedWithOther(tmpSliceCst)) { + if (!sliceUnionCst.areVarsAlignedWithOther(tmpSliceCst)) { - // Pre-constraint id alignment: record loop IVs used in each constraint + // Pre-constraint var alignment: record loop IVs used in each constraint // system. SmallPtrSet sliceUnionIVs; - for (unsigned k = 0, l = sliceUnionCst.getNumDimIds(); k < l; ++k) + for (unsigned k = 0, l = sliceUnionCst.getNumDimVars(); k < l; ++k) sliceUnionIVs.insert(sliceUnionCst.getValue(k)); SmallPtrSet tmpSliceIVs; - for (unsigned k = 0, l = tmpSliceCst.getNumDimIds(); k < l; ++k) + for (unsigned k = 0, l = tmpSliceCst.getNumDimVars(); k < l; ++k) tmpSliceIVs.insert(tmpSliceCst.getValue(k)); - sliceUnionCst.mergeAndAlignIdsWithOther(/*offset=*/0, &tmpSliceCst); + sliceUnionCst.mergeAndAlignVarsWithOther(/*offset=*/0, &tmpSliceCst); - // Post-constraint id alignment: add loop IV bounds missing after - // id alignment to constraint systems. This can occur if one constraint + // Post-constraint var alignment: add loop IV bounds missing after + // var alignment to constraint systems. This can occur if one constraint // system uses an loop IV that is not used by the other. The call // to unionBoundingBox below expects constraints for each Loop IV, even // if they are the unsliced full loop bounds added here. @@ -895,8 +895,8 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, return SliceComputationResult::GenericFailure; } // Compute union bounding box of 'sliceUnionCst' and 'tmpSliceCst'. - if (sliceUnionCst.getNumLocalIds() > 0 || - tmpSliceCst.getNumLocalIds() > 0 || + if (sliceUnionCst.getNumLocalVars() > 0 || + tmpSliceCst.getNumLocalVars() > 0 || failed(sliceUnionCst.unionBoundingBox(tmpSliceCst))) { LLVM_DEBUG(llvm::dbgs() << "Unable to compute union bounding box of slice bounds\n"); @@ -906,7 +906,7 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, } // Empty union. - if (sliceUnionCst.getNumDimAndSymbolIds() == 0) + if (sliceUnionCst.getNumDimAndSymbolVars() == 0) return SliceComputationResult::GenericFailure; // Gather loops surrounding ops from loop nest where slice will be inserted. @@ -923,9 +923,9 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, } // Store 'numSliceLoopIVs' before converting dst loop IVs to dims. - unsigned numSliceLoopIVs = sliceUnionCst.getNumDimIds(); + unsigned numSliceLoopIVs = sliceUnionCst.getNumDimVars(); - // Convert any dst loop IVs which are symbol identifiers to dim identifiers. + // Convert any dst loop IVs which are symbol variables to dim variables. sliceUnionCst.convertLoopIVSymbolsToDims(); sliceUnion->clearBounds(); sliceUnion->lbs.resize(numSliceLoopIVs, AffineMap()); @@ -939,7 +939,7 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, // Add slice bound operands of union. SmallVector sliceBoundOperands; sliceUnionCst.getValues(numSliceLoopIVs, - sliceUnionCst.getNumDimAndSymbolIds(), + sliceUnionCst.getNumDimAndSymbolVars(), &sliceBoundOperands); // Copy src loop IVs from 'sliceUnionCst' to 'sliceUnion'. @@ -1082,7 +1082,7 @@ void mlir::getComputationSliceState( // Set up bound operands for the slice's lower and upper bounds. SmallVector sliceBoundOperands; - unsigned numDimsAndSymbols = dependenceConstraints->getNumDimAndSymbolIds(); + unsigned numDimsAndSymbols = dependenceConstraints->getNumDimAndSymbolVars(); for (unsigned i = 0; i < numDimsAndSymbols; ++i) { if (i < offset || i >= offset + numSliceLoopIVs) { sliceBoundOperands.push_back(dependenceConstraints->getValue(i)); diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp index b77ef90b471b9..4229a2b1deb81 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp @@ -921,7 +921,7 @@ static Value createPrivateMemRef(AffineForOp forOp, Operation *srcStoreOpInst, // on; this would correspond to loop IVs surrounding the level at which the // slice is being materialized. SmallVector outerIVs; - cst->getValues(rank, cst->getNumIds(), &outerIVs); + cst->getValues(rank, cst->getNumVars(), &outerIVs); // Build 'rank' AffineExprs from MemRefRegion 'lbs' SmallVector offsets; diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp index 09f11ebfaeab3..cee9616579803 100644 --- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp @@ -1873,7 +1873,7 @@ findHighestBlockForPlacement(const MemRefRegion ®ion, Block &block, Block::iterator *copyOutPlacementStart) { const auto *cst = region.getConstraints(); SmallVector symbols; - cst->getValues(cst->getNumDimIds(), cst->getNumDimAndSymbolIds(), &symbols); + cst->getValues(cst->getNumDimVars(), cst->getNumDimAndSymbolVars(), &symbols); SmallVector enclosingFors; getLoopIVs(*block.begin(), &enclosingFors); @@ -2110,7 +2110,7 @@ static LogicalResult generateCopy( // on; these typically include loop IVs surrounding the level at which the // copy generation is being done or other valid symbols in MLIR. SmallVector regionSymbols; - cst->getValues(rank, cst->getNumIds(), ®ionSymbols); + cst->getValues(rank, cst->getNumVars(), ®ionSymbols); // Construct the index expressions for the fast memory buffer. The index // expression for a particular dimension of the fast buffer is obtained by @@ -2144,7 +2144,7 @@ static LogicalResult generateCopy( // The coordinate for the start location is just the lower bound along the // corresponding dimension on the memory region (stored in 'offset'). auto map = AffineMap::get( - cst->getNumDimIds() + cst->getNumSymbolIds() - rank, 0, offset); + cst->getNumDimVars() + cst->getNumSymbolVars() - rank, 0, offset); memIndices.push_back(b.create(loc, map, regionSymbols)); } // The fast buffer is copied into at location zero; addressing is relative. @@ -2671,7 +2671,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef loops, // TODO: Non-unit stride is not an issue to generalize to. assert(loop.getStep() == 1 && "point loop step expected to be one"); // Mark everything symbols for the purpose of finding a constant diff pair. - cst.setDimSymbolSeparation(/*newSymbolCount=*/cst.getNumDimAndSymbolIds() - + cst.setDimSymbolSeparation(/*newSymbolCount=*/cst.getNumDimAndSymbolVars() - 1); unsigned fullTileLbPos, fullTileUbPos; if (!cst.getConstantBoundOnDimSize(0, /*lb=*/nullptr, @@ -2700,7 +2700,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef loops, for (unsigned i = 0, e = cst.getNumCols(); i < e; ++i) cst.atIneq(ubIndex, i) -= fullTileUb[i]; - cst.removeId(0); + cst.removeVar(0); } // The previous step leads to all zeros for the full tile lb and ub position @@ -2719,7 +2719,7 @@ static AffineIfOp createSeparationCondition(MutableArrayRef loops, return nullptr; SmallVector setOperands; - cst.getValues(0, cst.getNumDimAndSymbolIds(), &setOperands); + cst.getValues(0, cst.getNumDimAndSymbolVars(), &setOperands); canonicalizeSetAndOperands(&ifCondSet, &setOperands); return b.create(loops[0].getLoc(), ifCondSet, setOperands, /*withElseRegion=*/true); @@ -2745,7 +2745,7 @@ createFullTiles(MutableArrayRef inputNest, (void)getIndexSet(loopOp, &cst); // We will mark everything other than this loop IV as symbol for getting a // pair of with a constant difference. - cst.setDimSymbolSeparation(cst.getNumDimAndSymbolIds() - 1); + cst.setDimSymbolSeparation(cst.getNumDimAndSymbolVars() - 1); unsigned lbPos, ubPos; if (!cst.getConstantBoundOnDimSize(/*pos=*/0, /*lb=*/nullptr, /*lbDivisor=*/nullptr, /*ub=*/nullptr, diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp index 5f9eee572cbbe..3d58e1ddb5471 100644 --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -1778,7 +1778,7 @@ MemRefType mlir::normalizeMemRefType(MemRefType memrefType, OpBuilder b, return memrefType; // TODO: Handle semi-affine maps. // Project out the old data dimensions. - fac.projectOut(newRank, fac.getNumIds() - newRank - fac.getNumLocalIds()); + fac.projectOut(newRank, fac.getNumVars() - newRank - fac.getNumLocalVars()); SmallVector newShape(newRank); for (unsigned d = 0; d < newRank; ++d) { // Check if each dimension of normalized memrefType is dynamic. diff --git a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp index 1090119e1d6e1..d5a1c17a70079 100644 --- a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp @@ -240,18 +240,18 @@ void getUpperBoundForIndex(Value value, AffineMap &boundMap, // Helper to find or create an identifier for the given value. auto findOrCreateId = [&](Value value) { - if (!constraints.containsId(value)) { - constraints.appendDimId(value); + if (!constraints.containsVar(value)) { + constraints.appendDimVar(value); return true; } unsigned pos; - constraints.findId(value, &pos); - return pos < constraints.getNumDimIds(); + constraints.findVar(value, &pos); + return pos < constraints.getNumDimVars(); }; // Helper to get the position for the given value. auto getPosition = [&](Value value) { unsigned pos; - bool exists = constraints.findId(value, &pos); + bool exists = constraints.findVar(value, &pos); (void)exists; assert(exists && "expect to find the identifier"); return pos; diff --git a/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp b/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp index 958b5a2757148..d8ea6607b529b 100644 --- a/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp +++ b/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp @@ -43,13 +43,13 @@ static LogicalResult alignAndAddBound(FlatAffineValueConstraints &constraints, unsigned pos, AffineMap map, ValueRange operands) { SmallVector dims, syms, newSyms; - unpackOptionalValues(constraints.getMaybeValues(IdKind::SetDim), dims); - unpackOptionalValues(constraints.getMaybeValues(IdKind::Symbol), syms); + unpackOptionalValues(constraints.getMaybeValues(VarKind::SetDim), dims); + unpackOptionalValues(constraints.getMaybeValues(VarKind::Symbol), syms); AffineMap alignedMap = alignAffineMapWithValues(map, operands, dims, syms, &newSyms); for (unsigned i = syms.size(); i < newSyms.size(); ++i) - constraints.appendSymbolId(newSyms[i]); + constraints.appendSymbolVar(newSyms[i]); return constraints.addBound(type, pos, alignedMap); } @@ -108,9 +108,9 @@ canonicalizeMinMaxOp(RewriterBase &rewriter, Operation *op, AffineMap map, unsigned numResults = map.getNumResults(); // Add a few extra dimensions. - unsigned dimOp = constraints.appendDimId(); // `op` - unsigned dimOpBound = constraints.appendDimId(); // `op` lower/upper bound - unsigned resultDimStart = constraints.appendDimId(/*num=*/numResults); + unsigned dimOp = constraints.appendDimVar(); // `op` + unsigned dimOpBound = constraints.appendDimVar(); // `op` lower/upper bound + unsigned resultDimStart = constraints.appendDimVar(/*num=*/numResults); // Add an inequality for each result expr_i of map: // isMin: op <= expr_i, !isMin: op >= expr_i @@ -185,7 +185,7 @@ canonicalizeMinMaxOp(RewriterBase &rewriter, Operation *op, AffineMap map, unpackOptionalValues(constraints.getMaybeValues(), newOperands); // If dims/symbols have known constant values, use those in order to simplify // the affine map further. - for (int64_t i = 0, e = constraints.getNumIds(); i < e; ++i) { + for (int64_t i = 0, e = constraints.getNumVars(); i < e; ++i) { // Skip unused operands and operands that are already constants. if (!newOperands[i] || getConstantIntValue(newOperands[i])) continue; @@ -209,13 +209,13 @@ addLoopRangeConstraints(FlatAffineValueConstraints &constraints, Value iv, if (!stepInt) return failure(); - unsigned dimIv = constraints.appendDimId(iv); + unsigned dimIv = constraints.appendDimVar(iv); auto lbv = lb.dyn_cast(); unsigned dimLb = - lbv ? constraints.appendDimId(lbv) : constraints.appendDimId(/*num=*/1); + lbv ? constraints.appendDimVar(lbv) : constraints.appendDimVar(/*num=*/1); auto ubv = ub.dyn_cast(); unsigned dimUb = - ubv ? constraints.appendDimId(ubv) : constraints.appendDimId(/*num=*/1); + ubv ? constraints.appendDimVar(ubv) : constraints.appendDimVar(/*num=*/1); // If loop lower/upper bounds are constant: Add EQ constraint. Optional lbInt = getConstantIntValue(lb); @@ -249,8 +249,8 @@ addLoopRangeConstraints(FlatAffineValueConstraints &constraints, Value iv, ivUb = exprLb + 1 + (*stepInt * ((exprUb - exprLb - 1).floorDiv(*stepInt))); } auto map = AffineMap::get( - /*dimCount=*/constraints.getNumDimIds(), - /*symbolCount=*/constraints.getNumSymbolIds(), /*result=*/ivUb); + /*dimCount=*/constraints.getNumDimVars(), + /*symbolCount=*/constraints.getNumSymbolVars(), /*result=*/ivUb); return constraints.addBound(IntegerPolyhedron::UB, dimIv, map); } @@ -323,7 +323,7 @@ LogicalResult scf::rewritePeeledMinMaxOp(RewriterBase &rewriter, Operation *op, bool isMin, Value iv, Value ub, Value step, bool insideLoop) { FlatAffineValueConstraints constraints; - constraints.appendDimId({iv, ub, step}); + constraints.appendDimVar({iv, ub, step}); if (auto constUb = getConstantIntValue(ub)) constraints.addBound(IntegerPolyhedron::EQ, 1, *constUb); if (auto constStep = getConstantIntValue(step)) diff --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp index 4364cc8b70380..098b58b6df6ca 100644 --- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp +++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp @@ -183,17 +183,17 @@ TEST(IntegerPolyhedronTest, removeIdRange) { IntegerPolyhedron set(PresburgerSpace::getSetSpace(3, 2, 1)); set.addInequality({10, 11, 12, 20, 21, 30, 40}); - set.removeId(IdKind::Symbol, 1); + set.removeVar(VarKind::Symbol, 1); EXPECT_THAT(set.getInequality(0), testing::ElementsAre(10, 11, 12, 20, 30, 40)); - set.removeIdRange(IdKind::SetDim, 0, 2); + set.removeVarRange(VarKind::SetDim, 0, 2); EXPECT_THAT(set.getInequality(0), testing::ElementsAre(12, 20, 30, 40)); - set.removeIdRange(IdKind::Local, 1, 1); + set.removeVarRange(VarKind::Local, 1, 1); EXPECT_THAT(set.getInequality(0), testing::ElementsAre(12, 20, 30, 40)); - set.removeIdRange(IdKind::Local, 0, 1); + set.removeVarRange(VarKind::Local, 0, 1); EXPECT_THAT(set.getInequality(0), testing::ElementsAre(12, 20, 40)); } @@ -709,7 +709,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprTightUpperBound) { IntegerPolyhedron poly = parsePoly("(i, j, q) : (4*q - i - j + 2 >= 0, -4*q + i + j >= 0)"); // Convert `q` to a local variable. - poly.convertToLocal(IdKind::SetDim, 2, 3); + poly.convertToLocal(VarKind::SetDim, 2, 3); std::vector> divisions = {{1, 1, 0, 1}}; SmallVector denoms = {4}; @@ -723,7 +723,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) { { IntegerPolyhedron poly = parsePoly("(i, j, q) : (-4*q + i + j == 0)"); // Convert `q` to a local variable. - poly.convertToLocal(IdKind::SetDim, 2, 3); + poly.convertToLocal(VarKind::SetDim, 2, 3); std::vector> divisions = {{1, 1, 0, 0}}; SmallVector denoms = {4}; @@ -733,7 +733,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) { { IntegerPolyhedron poly = parsePoly("(i, j, q) : (4*q - i - j == 0)"); // Convert `q` to a local variable. - poly.convertToLocal(IdKind::SetDim, 2, 3); + poly.convertToLocal(VarKind::SetDim, 2, 3); std::vector> divisions = {{1, 1, 0, 0}}; SmallVector denoms = {4}; @@ -743,7 +743,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) { { IntegerPolyhedron poly = parsePoly("(i, j, q) : (3*q + i + j - 2 == 0)"); // Convert `q` to a local variable. - poly.convertToLocal(IdKind::SetDim, 2, 3); + poly.convertToLocal(VarKind::SetDim, 2, 3); std::vector> divisions = {{-1, -1, 0, 2}}; SmallVector denoms = {3}; @@ -758,7 +758,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEqualityAndInequality) { parsePoly("(i, j, q, k) : (-3*k + i + j == 0, 4*q - " "i - j + 2 >= 0, -4*q + i + j >= 0)"); // Convert `q` and `k` to local variables. - poly.convertToLocal(IdKind::SetDim, 2, 4); + poly.convertToLocal(VarKind::SetDim, 2, 4); std::vector> divisions = {{1, 1, 0, 0, 1}, {1, 1, 0, 0, 0}}; @@ -772,7 +772,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprNoRepr) { IntegerPolyhedron poly = parsePoly("(x, q) : (x - 3 * q >= 0, -x + 3 * q + 3 >= 0)"); // Convert q to a local variable. - poly.convertToLocal(IdKind::SetDim, 1, 2); + poly.convertToLocal(VarKind::SetDim, 1, 2); std::vector> divisions = {{0, 0, 0}}; SmallVector denoms = {0}; @@ -785,7 +785,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprNegConstNormalize) { IntegerPolyhedron poly = parsePoly("(x, q) : (-1 - 3*x - 6 * q >= 0, 6 + 3*x + 6*q >= 0)"); // Convert q to a local variable. - poly.convertToLocal(IdKind::SetDim, 1, 2); + poly.convertToLocal(VarKind::SetDim, 1, 2); // q = floor((-1/3 - x)/2) // = floor((1/3) + (-1 - x)/2) @@ -833,16 +833,16 @@ TEST(IntegerPolyhedronTest, mergeDivisionsSimple) { IntegerPolyhedron poly2(PresburgerSpace::getSetSpace(1)); poly2.addLocalFloorDiv({1, 0}, 2); // y = [x / 2]. poly2.addEquality({1, -5, 0}); // x = 5y. - poly2.appendId(IdKind::Local); // Add local id z. + poly2.appendVar(VarKind::Local); // Add local id z. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 1 division should be matched + 2 unmatched local ids. - EXPECT_EQ(poly1.getNumLocalIds(), 3u); - EXPECT_EQ(poly2.getNumLocalIds(), 3u); + EXPECT_EQ(poly1.getNumLocalVars(), 3u); + EXPECT_EQ(poly2.getNumLocalVars(), 3u); } { @@ -858,14 +858,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsSimple) { poly2.addLocalFloorDiv({1, 0, 0}, 5); // z = [x / 5]. poly2.addEquality({1, 0, -5, 0}); // x = 5z. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 2 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 2u); - EXPECT_EQ(poly2.getNumLocalIds(), 2u); + EXPECT_EQ(poly1.getNumLocalVars(), 2u); + EXPECT_EQ(poly2.getNumLocalVars(), 2u); } { @@ -881,16 +881,16 @@ TEST(IntegerPolyhedronTest, mergeDivisionsSimple) { IntegerPolyhedron poly2(PresburgerSpace::getSetSpace(1)); poly2.addLocalFloorDiv({1, 0}, 2); // y = [x / 2]. poly2.addEquality({1, -5, 0}); // x = 5y. - poly2.appendId(IdKind::Local); // Add local id z. + poly2.appendVar(VarKind::Local); // Add local id z. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // One division should be matched + 2 unmatched local ids. - EXPECT_EQ(poly1.getNumLocalIds(), 3u); - EXPECT_EQ(poly2.getNumLocalIds(), 3u); + EXPECT_EQ(poly1.getNumLocalVars(), 3u); + EXPECT_EQ(poly2.getNumLocalVars(), 3u); } } @@ -908,14 +908,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsNestedDivsions) { poly2.addLocalFloorDiv({1, 1, 0}, 3); // z = [x + y / 3]. poly2.addInequality({1, -1, -1, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 2 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 2u); - EXPECT_EQ(poly2.getNumLocalIds(), 2u); + EXPECT_EQ(poly1.getNumLocalVars(), 2u); + EXPECT_EQ(poly2.getNumLocalVars(), 2u); } { @@ -933,14 +933,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsNestedDivsions) { poly2.addLocalFloorDiv({0, 0, 1, 1}, 5); // w = [z + 1 / 5]. poly2.addInequality({1, -1, -1, 0, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 3 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 3u); - EXPECT_EQ(poly2.getNumLocalIds(), 3u); + EXPECT_EQ(poly1.getNumLocalVars(), 3u); + EXPECT_EQ(poly2.getNumLocalVars(), 3u); } { // (x) : (exists y = [x / 2], z = [x + y / 3]: y + z >= x). @@ -956,14 +956,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsNestedDivsions) { poly2.addLocalFloorDiv({3, 3, 0}, 9); // z = [3x + 3y / 9] -> [x + y / 3]. poly2.addInequality({1, -1, -1, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 2 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 2u); - EXPECT_EQ(poly2.getNumLocalIds(), 2u); + EXPECT_EQ(poly1.getNumLocalVars(), 2u); + EXPECT_EQ(poly2.getNumLocalVars(), 2u); } } @@ -981,14 +981,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsConstants) { poly2.addLocalFloorDiv({1, 0, 2}, 3); // z = [x + 2 / 3]. poly2.addInequality({1, -1, -1, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 2 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 2u); - EXPECT_EQ(poly2.getNumLocalIds(), 2u); + EXPECT_EQ(poly1.getNumLocalVars(), 2u); + EXPECT_EQ(poly2.getNumLocalVars(), 2u); } { // (x) : (exists y = [x + 1 / 3], z = [x + 2 / 3]: y + z >= x). @@ -1005,14 +1005,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsConstants) { poly2.addLocalFloorDiv({1, 0, 2}, 3); // z = [x + 2 / 3]. poly2.addInequality({1, -1, -1, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 2 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 2u); - EXPECT_EQ(poly2.getNumLocalIds(), 2u); + EXPECT_EQ(poly1.getNumLocalVars(), 2u); + EXPECT_EQ(poly2.getNumLocalVars(), 2u); } } @@ -1029,14 +1029,14 @@ TEST(IntegerPolyhedronTest, mergeDivisionsDuplicateInSameSet) { poly2.addLocalFloorDiv({1, 0, 2}, 3); // z = [x + 2 / 3]. poly2.addInequality({1, -1, -1, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Local space should be same. - EXPECT_EQ(poly1.getNumLocalIds(), poly2.getNumLocalIds()); + EXPECT_EQ(poly1.getNumLocalVars(), poly2.getNumLocalVars()); // 1 divisions should be matched. - EXPECT_EQ(poly1.getNumLocalIds(), 3u); - EXPECT_EQ(poly2.getNumLocalIds(), 3u); + EXPECT_EQ(poly1.getNumLocalVars(), 3u); + EXPECT_EQ(poly2.getNumLocalVars(), 3u); } TEST(IntegerPolyhedronTest, negativeDividends) { @@ -1054,7 +1054,7 @@ TEST(IntegerPolyhedronTest, negativeDividends) { poly2.addLocalFloorDiv({-1, 0, -2}, 3); // z = [-x - 2 / 3]. poly2.addInequality({1, -1, -1, 0}); // y + z <= x. - poly1.mergeLocalIds(poly2); + poly1.mergeLocalVars(poly2); // Merging triggers normalization. std::vector> divisions = {{-1, 0, 0, 1}, @@ -1165,15 +1165,15 @@ void expectSymbolicIntegerLexMin( ArrayRef expectedUnboundedDomainRepr) { IntegerPolyhedron poly = parsePoly(polyStr); - ASSERT_NE(poly.getNumDimIds(), 0u); - ASSERT_NE(poly.getNumSymbolIds(), 0u); + ASSERT_NE(poly.getNumDimVars(), 0u); + ASSERT_NE(poly.getNumSymbolVars(), 0u); PWMAFunction expectedLexmin = - parsePWMAF(/*numInputs=*/poly.getNumSymbolIds(), - /*numOutputs=*/poly.getNumDimIds(), expectedLexminRepr); + parsePWMAF(/*numInputs=*/poly.getNumSymbolVars(), + /*numOutputs=*/poly.getNumDimVars(), expectedLexminRepr); PresburgerSet expectedUnboundedDomain = parsePresburgerSetFromPolyStrings( - poly.getNumSymbolIds(), expectedUnboundedDomainRepr); + poly.getNumSymbolVars(), expectedUnboundedDomainRepr); SymbolicLexMin result = poly.findSymbolicIntegerLexMin(); diff --git a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp index eda5bfecdcba3..51a649205bfce 100644 --- a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp +++ b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp @@ -18,7 +18,7 @@ using namespace presburger; static IntegerRelation parseRelationFromSet(StringRef set, unsigned numDomain) { IntegerRelation rel = parsePoly(set); - rel.convertIdKind(IdKind::SetDim, 0, numDomain, IdKind::Domain); + rel.convertVarKind(VarKind::SetDim, 0, numDomain, VarKind::Domain); return rel; } diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp index 0c98f488ea074..07d4565d116ce 100644 --- a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp @@ -756,8 +756,8 @@ TEST(SetTest, computeVolume) { void testComputeReprAtPoints(IntegerPolyhedron poly, ArrayRef> points, unsigned numToProject) { - poly.convertIdKind(IdKind::SetDim, poly.getNumDimIds() - numToProject, - poly.getNumDimIds(), IdKind::Local); + poly.convertVarKind(VarKind::SetDim, poly.getNumDimVars() - numToProject, + poly.getNumDimVars(), VarKind::Local); PresburgerSet repr = poly.computeReprWithOnlyDivLocals(); EXPECT_TRUE(repr.hasOnlyDivLocals()); EXPECT_TRUE(repr.getSpace().isCompatible(poly.getSpace())); @@ -769,8 +769,8 @@ void testComputeReprAtPoints(IntegerPolyhedron poly, void testComputeRepr(IntegerPolyhedron poly, const PresburgerSet &expected, unsigned numToProject) { - poly.convertIdKind(IdKind::SetDim, poly.getNumDimIds() - numToProject, - poly.getNumDimIds(), IdKind::Local); + poly.convertVarKind(VarKind::SetDim, poly.getNumDimVars() - numToProject, + poly.getNumDimVars(), VarKind::Local); PresburgerSet repr = poly.computeReprWithOnlyDivLocals(); EXPECT_TRUE(repr.hasOnlyDivLocals()); EXPECT_TRUE(repr.getSpace().isCompatible(poly.getSpace())); diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp index 87164cc8f43f5..f5d457771c44e 100644 --- a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp @@ -17,12 +17,12 @@ TEST(PresburgerSpaceTest, insertId) { PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 2, 1); // Try inserting 2 domain ids. - space.insertId(IdKind::Domain, 0, 2); - EXPECT_EQ(space.getNumDomainIds(), 4u); + space.insertVar(VarKind::Domain, 0, 2); + EXPECT_EQ(space.getNumDomainVars(), 4u); // Try inserting 1 range ids. - space.insertId(IdKind::Range, 0, 1); - EXPECT_EQ(space.getNumRangeIds(), 3u); + space.insertVar(VarKind::Range, 0, 1); + EXPECT_EQ(space.getNumRangeVars(), 3u); } TEST(PresburgerSpaceTest, insertIdSet) { @@ -31,23 +31,23 @@ TEST(PresburgerSpaceTest, insertIdSet) { // Try inserting 2 dimension ids. The space should have 4 range ids since // spaces which do not distinguish between domain, range are implemented like // this. - space.insertId(IdKind::SetDim, 0, 2); - EXPECT_EQ(space.getNumRangeIds(), 4u); + space.insertVar(VarKind::SetDim, 0, 2); + EXPECT_EQ(space.getNumRangeVars(), 4u); } TEST(PresburgerSpaceTest, removeIdRange) { PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 1, 3); // Remove 1 domain identifier. - space.removeIdRange(IdKind::Domain, 0, 1); - EXPECT_EQ(space.getNumDomainIds(), 1u); + space.removeVarRange(VarKind::Domain, 0, 1); + EXPECT_EQ(space.getNumDomainVars(), 1u); // Remove 1 symbol and 1 range identifier. - space.removeIdRange(IdKind::Symbol, 0, 1); - space.removeIdRange(IdKind::Range, 0, 1); - EXPECT_EQ(space.getNumDomainIds(), 1u); - EXPECT_EQ(space.getNumRangeIds(), 0u); - EXPECT_EQ(space.getNumSymbolIds(), 2u); + space.removeVarRange(VarKind::Symbol, 0, 1); + space.removeVarRange(VarKind::Range, 0, 1); + EXPECT_EQ(space.getNumDomainVars(), 1u); + EXPECT_EQ(space.getNumRangeVars(), 0u); + EXPECT_EQ(space.getNumSymbolVars(), 2u); } TEST(PresburgerSpaceTest, insertIdAttachment) { @@ -56,20 +56,20 @@ TEST(PresburgerSpaceTest, insertIdAttachment) { // Attach attachment to domain ids. int attachments[2] = {0, 1}; - space.setAttachment(IdKind::Domain, 0, &attachments[0]); - space.setAttachment(IdKind::Domain, 1, &attachments[1]); + space.setAttachment(VarKind::Domain, 0, &attachments[0]); + space.setAttachment(VarKind::Domain, 1, &attachments[1]); // Try inserting 2 domain ids. - space.insertId(IdKind::Domain, 0, 2); - EXPECT_EQ(space.getNumDomainIds(), 4u); + space.insertVar(VarKind::Domain, 0, 2); + EXPECT_EQ(space.getNumDomainVars(), 4u); // Try inserting 1 range ids. - space.insertId(IdKind::Range, 0, 1); - EXPECT_EQ(space.getNumRangeIds(), 3u); + space.insertVar(VarKind::Range, 0, 1); + EXPECT_EQ(space.getNumRangeVars(), 3u); // Check if the attachments for the old ids are still attached properly. - EXPECT_EQ(*space.getAttachment(IdKind::Domain, 2), attachments[0]); - EXPECT_EQ(*space.getAttachment(IdKind::Domain, 3), attachments[1]); + EXPECT_EQ(*space.getAttachment(VarKind::Domain, 2), attachments[0]); + EXPECT_EQ(*space.getAttachment(VarKind::Domain, 3), attachments[1]); } TEST(PresburgerSpaceTest, removeIdRangeAttachment) { @@ -79,32 +79,32 @@ TEST(PresburgerSpaceTest, removeIdRangeAttachment) { int attachments[6] = {0, 1, 2, 3, 4, 5}; // Attach attachments to domain identifiers. - space.setAttachment(IdKind::Domain, 0, &attachments[0]); - space.setAttachment(IdKind::Domain, 1, &attachments[1]); + space.setAttachment(VarKind::Domain, 0, &attachments[0]); + space.setAttachment(VarKind::Domain, 1, &attachments[1]); // Attach attachments to range identifiers. - space.setAttachment(IdKind::Range, 0, &attachments[2]); + space.setAttachment(VarKind::Range, 0, &attachments[2]); // Attach attachments to symbol identifiers. - space.setAttachment(IdKind::Symbol, 0, &attachments[3]); - space.setAttachment(IdKind::Symbol, 1, &attachments[4]); - space.setAttachment(IdKind::Symbol, 2, &attachments[5]); + space.setAttachment(VarKind::Symbol, 0, &attachments[3]); + space.setAttachment(VarKind::Symbol, 1, &attachments[4]); + space.setAttachment(VarKind::Symbol, 2, &attachments[5]); // Remove 1 domain identifier. - space.removeIdRange(IdKind::Domain, 0, 1); - EXPECT_EQ(space.getNumDomainIds(), 1u); + space.removeVarRange(VarKind::Domain, 0, 1); + EXPECT_EQ(space.getNumDomainVars(), 1u); // Remove 1 symbol and 1 range identifier. - space.removeIdRange(IdKind::Symbol, 0, 1); - space.removeIdRange(IdKind::Range, 0, 1); - EXPECT_EQ(space.getNumDomainIds(), 1u); - EXPECT_EQ(space.getNumRangeIds(), 0u); - EXPECT_EQ(space.getNumSymbolIds(), 2u); + space.removeVarRange(VarKind::Symbol, 0, 1); + space.removeVarRange(VarKind::Range, 0, 1); + EXPECT_EQ(space.getNumDomainVars(), 1u); + EXPECT_EQ(space.getNumRangeVars(), 0u); + EXPECT_EQ(space.getNumSymbolVars(), 2u); // Check if domain attachments are attached properly. - EXPECT_EQ(*space.getAttachment(IdKind::Domain, 0), attachments[1]); + EXPECT_EQ(*space.getAttachment(VarKind::Domain, 0), attachments[1]); // Check if symbol attachments are attached properly. - EXPECT_EQ(*space.getAttachment(IdKind::Range, 0), attachments[4]); - EXPECT_EQ(*space.getAttachment(IdKind::Range, 1), attachments[5]); + EXPECT_EQ(*space.getAttachment(VarKind::Range, 0), attachments[4]); + EXPECT_EQ(*space.getAttachment(VarKind::Range, 1), attachments[5]); } diff --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h index 6b24ca0d576db..bf9163cf6184c 100644 --- a/mlir/unittests/Analysis/Presburger/Utils.h +++ b/mlir/unittests/Analysis/Presburger/Utils.h @@ -78,7 +78,7 @@ inline PWMAFunction parsePWMAF( IntegerPolyhedron domain = parsePoly(pair.first); result.addPiece( - domain, makeMatrix(numOutputs, domain.getNumIds() + 1, pair.second)); + domain, makeMatrix(numOutputs, domain.getNumVars() + 1, pair.second)); } return result; }