diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h --- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h @@ -24,7 +24,7 @@ namespace mlir { namespace presburger { -/// An IntegerRelation is a PresburgerLocalSpace subject to affine constraints. +/// An IntegerRelation is a PresburgerSpace subject to affine constraints. /// Affine constraints can be inequalities or equalities in the form: /// /// Inequality: c_0*x_0 + c_1*x_1 + .... + c_{n-1}*x_{n-1} + c_n >= 0 @@ -42,7 +42,7 @@ /// /// Since IntegerRelation makes a distinction between dimensions, IdKind::Range /// and IdKind::Domain should be used to refer to dimension identifiers. -class IntegerRelation : public PresburgerLocalSpace { +class IntegerRelation : public PresburgerSpace { public: /// All derived classes of IntegerRelation. enum class Kind { @@ -59,7 +59,7 @@ unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDomain, unsigned numRange, unsigned numSymbols, unsigned numLocals) - : PresburgerLocalSpace(numDomain, numRange, numSymbols, numLocals), + : PresburgerSpace(numDomain, numRange, numSymbols, numLocals), equalities(0, getNumIds() + 1, numReservedEqualities, numReservedCols), inequalities(0, getNumIds() + 1, numReservedInequalities, numReservedCols) { @@ -510,7 +510,7 @@ Matrix inequalities; }; -/// An IntegerPolyhedron is a PresburgerLocalSpace subject to affine +/// An IntegerPolyhedron is a PresburgerSpace subject to affine /// constraints. Affine constraints can be inequalities or equalities in the /// form: /// diff --git a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h --- a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h +++ b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h @@ -102,11 +102,6 @@ return PresburgerSpace::isEqual(other); }; - /// Returns whether the underlying PresburgerLocalSpace is equal to `other`. - bool isSpaceEqual(const PresburgerLocalSpace &other) const { - return PresburgerLocalSpace::isEqual(other); - }; - /// Return whether the `this` and `other` are equal. This is the case if /// they lie in the same space, i.e. have the same dimensions, and their /// domains are identical and their outputs are equal on their domain. @@ -150,7 +145,8 @@ class PWMAFunction : public PresburgerSpace { public: PWMAFunction(unsigned numDims, unsigned numSymbols, unsigned numOutputs) - : PresburgerSpace(/*numDomain=*/0, /*numRange=*/numDims, numSymbols), + : PresburgerSpace(/*numDomain=*/0, /*numRange=*/numDims, numSymbols, + /*numLocals=*/0), numOutputs(numOutputs) { assert(numOutputs >= 1 && "The function must output something!"); } diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h --- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h @@ -1,4 +1,5 @@ -//===- PresburgerRelation.h - MLIR PresburgerRelation Class -----*- C++ -*-===// +//===- PresburgerRelation.h - MLIR PresburgerRelation Class -----*- C++ +//-*-===//:%s // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -121,7 +122,7 @@ /// dimension and symbols. PresburgerRelation(unsigned numDomain = 0, unsigned numRange = 0, unsigned numSymbols = 0) - : PresburgerSpace(numDomain, numRange, numSymbols) {} + : PresburgerSpace(numDomain, numRange, numSymbols, /*numLocals=*/0) {} /// The list of disjuncts that this set is the union of. SmallVector integerRelations; diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h --- a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h @@ -61,21 +61,22 @@ /// be implemented as a space with zero domain. IdKind::SetDim should be used /// to refer to dimensions in such spaces. /// -/// PresburgerSpace does not allow identifiers of kind Local. See -/// PresburgerLocalSpace for an extension that does allow local identifiers. +/// Since locals represent existential quantification, equality of two spaces +/// implies that all kinds of identifers other than locals are equal. class PresburgerSpace { - friend PresburgerLocalSpace; - public: - PresburgerSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols) - : PresburgerSpace(numDomain, numRange, numSymbols, 0) {} + PresburgerSpace(unsigned numDomain = 0, unsigned numRange = 0, + unsigned numSymbols = 0, unsigned numLocals = 0) + : numDomain(numDomain), numRange(numRange), numSymbols(numSymbols), + numLocals(numLocals) {} virtual ~PresburgerSpace() = default; unsigned getNumDomainIds() const { return numDomain; } unsigned getNumRangeIds() const { return numRange; } - unsigned getNumSymbolIds() const { return numSymbols; } unsigned getNumSetDimIds() const { return numRange; } + unsigned getNumSymbolIds() const { return numSymbols; } + unsigned getNumLocalIds() const { return numLocals; } unsigned getNumDimIds() const { return numDomain + numRange; } unsigned getNumDimAndSymbolIds() const { @@ -110,9 +111,14 @@ virtual void removeIdRange(IdKind kind, unsigned idStart, unsigned idLimit); /// Returns true if both the spaces are equal i.e. if both spaces have the - /// same number of identifiers of each kind (excluding Local Identifiers). + /// same number of identifiers of each kind (excluding locals). bool isEqual(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 + /// locals). + bool isEqualWithLocals(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 /// the split become symbols, or some of the symbols immediately after the @@ -123,11 +129,6 @@ void dump() const; private: - PresburgerSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols, - unsigned numLocals) - : numDomain(numDomain), numRange(numRange), numSymbols(numSymbols), - numLocals(numLocals) {} - // Number of identifiers corresponding to domain identifiers. unsigned numDomain; @@ -143,32 +144,6 @@ unsigned numLocals; }; -/// Extension of PresburgerSpace supporting Local identifiers. -class PresburgerLocalSpace : public PresburgerSpace { -public: - PresburgerLocalSpace(unsigned numDomain, unsigned numRange, - unsigned numSymbols, unsigned numLocals) - : PresburgerSpace(numDomain, numRange, numSymbols, numLocals) {} - - unsigned getNumLocalIds() const { return numLocals; } - - /// 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; - - /// Removes identifiers in the column range [idStart, idLimit). - void removeIdRange(IdKind kind, unsigned idStart, unsigned idLimit) override; - - /// Returns true if both the spaces are equal i.e. if both spaces have the - /// same number of identifiers of each kind. - bool isEqual(const PresburgerLocalSpace &other) const; - - void print(llvm::raw_ostream &os) const; - void dump() const; -}; - } // namespace presburger } // namespace mlir diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp --- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp @@ -38,7 +38,7 @@ } void IntegerRelation::append(const IntegerRelation &other) { - assert(PresburgerLocalSpace::isEqual(other) && "Spaces must be equal."); + assert(PresburgerSpace::isEqualWithLocals(other) && "Spaces must be equal."); inequalities.reserveRows(inequalities.getNumRows() + other.getNumInequalities()); @@ -60,12 +60,12 @@ } bool IntegerRelation::isEqual(const IntegerRelation &other) const { - assert(PresburgerLocalSpace::isEqual(other) && "Spaces must be equal."); + assert(PresburgerSpace::isEqualWithLocals(other) && "Spaces must be equal."); return PresburgerRelation(*this).isEqual(PresburgerRelation(other)); } bool IntegerRelation::isSubsetOf(const IntegerRelation &other) const { - assert(PresburgerLocalSpace::isEqual(other) && "Spaces must be equal."); + assert(PresburgerSpace::isEqualWithLocals(other) && "Spaces must be equal."); return PresburgerRelation(*this).isSubsetOf(PresburgerRelation(other)); } @@ -129,7 +129,7 @@ unsigned IntegerRelation::insertId(IdKind kind, unsigned pos, unsigned num) { assert(pos <= getNumIdKind(kind)); - unsigned insertPos = PresburgerLocalSpace::insertId(kind, pos, num); + unsigned insertPos = PresburgerSpace::insertId(kind, pos, num); inequalities.insertColumns(insertPos, num); equalities.insertColumns(insertPos, num); return insertPos; @@ -173,7 +173,7 @@ inequalities.removeColumns(offset + idStart, idLimit - idStart); // Remove eliminated identifiers from the space. - PresburgerLocalSpace::removeIdRange(kind, idStart, idLimit); + PresburgerSpace::removeIdRange(kind, idStart, idLimit); } void IntegerRelation::removeIdRange(unsigned idStart, unsigned idLimit) { @@ -1853,7 +1853,8 @@ // lower bounds and the max of the upper bounds along each of the dimensions. LogicalResult IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) { - assert(PresburgerLocalSpace::isEqual(otherCst) && "Spaces should match."); + assert(PresburgerSpace::isEqualWithLocals(otherCst) && + "Spaces should match."); assert(getNumLocalIds() == 0 && "local ids not supported yet here"); // Get the constraints common to both systems; these will be added as is to @@ -2017,7 +2018,7 @@ } void IntegerRelation::printSpace(raw_ostream &os) const { - PresburgerLocalSpace::print(os); + PresburgerSpace::print(os); os << getNumConstraints() << " constraints\n"; } diff --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp --- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp @@ -68,7 +68,7 @@ else if (kind == IdKind::Symbol) numSymbols += num; else - llvm_unreachable("PresburgerSpace does not support local identifiers!"); + numLocals += num; return absolutePos; } @@ -88,29 +88,7 @@ else if (kind == IdKind::Symbol) numSymbols -= numIdsEliminated; else - llvm_unreachable("PresburgerSpace does not support local identifiers!"); -} - -unsigned PresburgerLocalSpace::insertId(IdKind kind, unsigned pos, - unsigned num) { - if (kind == IdKind::Local) { - numLocals += num; - return getIdKindOffset(IdKind::Local) + pos; - } - return PresburgerSpace::insertId(kind, pos, num); -} - -void PresburgerLocalSpace::removeIdRange(IdKind kind, unsigned idStart, - unsigned idLimit) { - assert(idLimit <= getNumIdKind(kind) && "invalid id limit"); - - if (idStart >= idLimit) - return; - - if (kind == IdKind::Local) - numLocals -= idLimit - idStart; - else - PresburgerSpace::removeIdRange(kind, idStart, idLimit); + numLocals -= numIdsEliminated; } bool PresburgerSpace::isEqual(const PresburgerSpace &other) const { @@ -119,7 +97,7 @@ getNumSymbolIds() == other.getNumSymbolIds(); } -bool PresburgerLocalSpace::isEqual(const PresburgerLocalSpace &other) const { +bool PresburgerSpace::isEqualWithLocals(const PresburgerSpace &other) const { return PresburgerSpace::isEqual(other) && getNumLocalIds() == other.getNumLocalIds(); } @@ -134,14 +112,8 @@ void PresburgerSpace::print(llvm::raw_ostream &os) const { os << "Domain: " << getNumDomainIds() << ", " << "Range: " << getNumRangeIds() << ", " - << "Symbols: " << getNumSymbolIds() << "\n"; + << "Symbols: " << getNumSymbolIds() << ", " + << "Locals: " << getNumLocalIds() << "\n"; } void PresburgerSpace::dump() const { print(llvm::errs()); } - -void PresburgerLocalSpace::print(llvm::raw_ostream &os) const { - PresburgerSpace::print(os); - os << "Locals: " << getNumLocalIds() << "\n"; -} - -void PresburgerLocalSpace::dump() const { print(llvm::errs()); }