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 @@ -406,21 +406,6 @@ void dump() const; protected: - /// Constructs a set reserving memory for the specified number - /// of constraints and identifiers. This constructor should not be used - /// directly to create a relation and should only be used to create Sets. - /// Internally this constructs a relation with with no domain and a - /// space with no distinction between domain and range identifiers. - IntegerRelation(unsigned numReservedInequalities, - unsigned numReservedEqualities, unsigned numReservedCols, - unsigned numDims, unsigned numSymbols, unsigned numLocals) - : PresburgerLocalSpace(numDims, numSymbols, numLocals), - equalities(0, getNumIds() + 1, numReservedEqualities, numReservedCols), - inequalities(0, getNumIds() + 1, numReservedInequalities, - numReservedCols) { - assert(numReservedCols >= getNumIds() + 1); - } - /// Checks all rows of equality/inequality constraints for trivial /// contradictions (for example: 1 == 0, 0 >= 1), which may have surfaced /// after elimination. Returns true if an invalid constraint is found; @@ -540,7 +525,8 @@ unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDims, unsigned numSymbols, unsigned numLocals) : IntegerRelation(numReservedInequalities, numReservedEqualities, - numReservedCols, numDims, numSymbols, numLocals) {} + numReservedCols, /*numDomain=*/0, /*numRange=*/numDims, + numSymbols, numLocals) {} /// Constructs a relation with the specified number of dimensions and symbols. IntegerPolyhedron(unsigned numDims = 0, unsigned numSymbols = 0, @@ -567,6 +553,12 @@ // 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; }; } // namespace presburger 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 @@ -151,7 +151,8 @@ class PWMAFunction : public PresburgerSpace { public: PWMAFunction(unsigned numDims, unsigned numSymbols, unsigned numOutputs) - : PresburgerSpace(numDims, numSymbols), numOutputs(numOutputs) { + : PresburgerSpace(/*numDomain=*/0, /*numRange=*/numDims, numSymbols), + numOutputs(numOutputs) { assert(numOutputs >= 1 && "The function must output something!"); } diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerSet.h b/mlir/include/mlir/Analysis/Presburger/PresburgerSet.h --- a/mlir/include/mlir/Analysis/Presburger/PresburgerSet.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSet.h @@ -114,7 +114,7 @@ /// Construct an empty PresburgerSet with the specified number of dimension /// and symbols. PresburgerSet(unsigned numDims = 0, unsigned numSymbols = 0) - : PresburgerSpace(numDims, numSymbols) {} + : PresburgerSpace(/*numDomain=*/0, /*numRange=*/numDims, numSymbols) {} /// The list of polyhedrons that this set is the union of. SmallVector integerPolyhedrons; 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 @@ -54,15 +54,12 @@ /// Dimension identifiers are further divided into Domain and Range identifiers /// to support building relations. /// -/// Spaces with distinction between domain and range identifiers should use -/// IdKind::Domain and IdKind::Range to refer to domain and range identifiers. -/// Identifiers for such spaces are stored in the following order: +/// Identifiers are stored in the following order: /// [Domain, Range, Symbols, Locals] /// -/// Spaces with no distinction between domain and range identifiers should use -/// IdKind::SetDim to refer to dimension identifiers. Identifiers for such -/// spaces are stored in the following order: -/// [SetDim, Symbol, 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 +/// 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. @@ -70,10 +67,8 @@ friend PresburgerLocalSpace; public: - static PresburgerSpace getRelationSpace(unsigned numDomain, unsigned numRange, - unsigned numSymbols); - - static PresburgerSpace getSetSpace(unsigned numDims, unsigned numSymbols); + PresburgerSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols) + : PresburgerSpace(numDomain, numRange, numSymbols, 0) {} virtual ~PresburgerSpace() = default; @@ -127,27 +122,11 @@ void print(llvm::raw_ostream &os) const; void dump() const; -protected: - /// Space constructor for Relation space type. - PresburgerSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols) - : PresburgerSpace(Relation, numDomain, numRange, numSymbols, - /*numLocals=*/0) {} - - /// Space constructor for Set space type. - PresburgerSpace(unsigned numDims, unsigned numSymbols) - : PresburgerSpace(Set, /*numDomain=*/0, numDims, numSymbols, - /*numLocals=*/0) {} - private: - /// Kind of space. - enum SpaceKind { Set, Relation }; - - PresburgerSpace(SpaceKind spaceKind, unsigned numDomain, unsigned numRange, - unsigned numSymbols, unsigned numLocals) - : spaceKind(spaceKind), numDomain(numDomain), numRange(numRange), - numSymbols(numSymbols), numLocals(numLocals) {} - - SpaceKind spaceKind; + 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; @@ -166,13 +145,9 @@ /// Extension of PresburgerSpace supporting Local identifiers. class PresburgerLocalSpace : public PresburgerSpace { public: - static PresburgerLocalSpace getRelationSpace(unsigned numDomain, - unsigned numRange, - unsigned numSymbols, - unsigned numLocals); - - static PresburgerLocalSpace getSetSpace(unsigned numDims, unsigned numSymbols, - unsigned numLocals); + PresburgerLocalSpace(unsigned numDomain, unsigned numRange, + unsigned numSymbols, unsigned numLocals) + : PresburgerSpace(numDomain, numRange, numSymbols, numLocals) {} unsigned getNumLocalIds() const { return numLocals; } @@ -191,17 +166,6 @@ void print(llvm::raw_ostream &os) const; void dump() const; - -protected: - /// Local Space constructor for Relation space type. - PresburgerLocalSpace(unsigned numDomain, unsigned numRange, - unsigned numSymbols, unsigned numLocals) - : PresburgerSpace(Relation, numDomain, numRange, numSymbols, numLocals) {} - - /// Local Space constructor for Set space type. - PresburgerLocalSpace(unsigned numDims, unsigned numSymbols, - unsigned numLocals) - : PresburgerSpace(Set, /*numDomain=*/0, numDims, numSymbols, numLocals) {} }; } // namespace presburger 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 @@ -2048,3 +2048,9 @@ } void IntegerRelation::dump() const { print(llvm::errs()); } + +unsigned IntegerPolyhedron::insertId(IdKind kind, unsigned pos, unsigned num) { + assert((kind != IdKind::Domain || num == 0) && + "Domain has to be zero in a set"); + return IntegerRelation::insertId(kind, pos, num); +} diff --git a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp --- a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp +++ b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp @@ -84,6 +84,8 @@ unsigned MultiAffineFunction::insertId(IdKind kind, unsigned pos, unsigned num) { + assert((kind != IdKind::Domain || num == 0) && + "Domain has to be zero in a set"); unsigned absolutePos = getIdKindOffset(kind) + pos; output.insertColumns(absolutePos, num); return IntegerPolyhedron::insertId(kind, pos, num); 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 @@ -13,30 +13,6 @@ using namespace mlir; using namespace presburger; -PresburgerSpace PresburgerSpace::getRelationSpace(unsigned numDomain, - unsigned numRange, - unsigned numSymbols) { - return PresburgerSpace(numDomain, numRange, numSymbols); -} - -PresburgerSpace PresburgerSpace::getSetSpace(unsigned numDims, - unsigned numSymbols) { - return PresburgerSpace(numDims, numSymbols); -} - -PresburgerLocalSpace -PresburgerLocalSpace::getRelationSpace(unsigned numDomain, unsigned numRange, - unsigned numSymbols, - unsigned numLocals) { - return PresburgerLocalSpace(numDomain, numRange, numSymbols, numLocals); -} - -PresburgerLocalSpace PresburgerLocalSpace::getSetSpace(unsigned numDims, - unsigned numSymbols, - unsigned numLocals) { - return PresburgerLocalSpace(numDims, numSymbols, numLocals); -} - unsigned PresburgerSpace::getNumIdKind(IdKind kind) const { if (kind == IdKind::Domain) return getNumDomainIds(); @@ -85,16 +61,14 @@ unsigned absolutePos = getIdKindOffset(kind) + pos; - if (kind == IdKind::Domain) { - assert(spaceKind == Relation && "IdKind::Domain is not supported in Set."); + if (kind == IdKind::Domain) numDomain += num; - } else if (kind == IdKind::Range) { + else if (kind == IdKind::Range) numRange += num; - } else if (kind == IdKind::Symbol) { + else if (kind == IdKind::Symbol) numSymbols += num; - } else { + else llvm_unreachable("PresburgerSpace does not support local identifiers!"); - } return absolutePos; } @@ -107,16 +81,14 @@ return; unsigned numIdsEliminated = idLimit - idStart; - if (kind == IdKind::Domain) { - assert(spaceKind == Relation && "IdKind::Domain is not supported in Set."); + if (kind == IdKind::Domain) numDomain -= numIdsEliminated; - } else if (kind == IdKind::Range) { + else if (kind == IdKind::Range) numRange -= numIdsEliminated; - } else if (kind == IdKind::Symbol) { + else if (kind == IdKind::Symbol) numSymbols -= numIdsEliminated; - } else { + else llvm_unreachable("PresburgerSpace does not support local identifiers!"); - } } unsigned PresburgerLocalSpace::insertId(IdKind kind, unsigned pos, @@ -160,26 +132,16 @@ } void PresburgerSpace::print(llvm::raw_ostream &os) const { - if (spaceKind == Relation) { - os << "Domain: " << getNumDomainIds() << ", " - << "Range: " << getNumRangeIds() << ", "; - } else { - os << "Dimension: " << getNumDomainIds() << ", "; - } - os << "Symbols: " << getNumSymbolIds() << "\n"; + os << "Domain: " << getNumDomainIds() << ", " + << "Range: " << getNumRangeIds() << ", " + << "Symbols: " << getNumSymbolIds() << "\n"; } void PresburgerSpace::dump() const { print(llvm::errs()); } void PresburgerLocalSpace::print(llvm::raw_ostream &os) const { - if (spaceKind == Relation) { - os << "Domain: " << getNumDomainIds() << ", " - << "Range: " << getNumRangeIds() << ", "; - } else { - os << "Dimension: " << getNumDomainIds() << ", "; - } - os << "Symbols: " << getNumSymbolIds() << ", " - << "Locals: " << getNumLocalIds() << "\n"; + PresburgerSpace::print(os); + os << "Locals: " << getNumLocalIds() << "\n"; } void PresburgerLocalSpace::dump() const { print(llvm::errs()); } diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp --- a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp @@ -14,7 +14,7 @@ using namespace presburger; TEST(PresburgerSpaceTest, insertId) { - PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 2, 1); + PresburgerSpace space(2, 2, 1); // Try inserting 2 domain ids. space.insertId(IdKind::Domain, 0, 2); @@ -26,7 +26,7 @@ } TEST(PresburgerSpaceTest, insertIdSet) { - PresburgerSpace space = PresburgerSpace::getSetSpace(2, 1); + PresburgerSpace space(0, 2, 1); // Try inserting 2 dimension ids. The space should have 4 range ids since // spaces which do not distinguish between domain, range are implemented like @@ -36,7 +36,7 @@ } TEST(PresburgerSpaceTest, removeIdRange) { - PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 1, 3); + PresburgerSpace space(2, 1, 3); // Remove 1 domain identifier. space.removeIdRange(IdKind::Domain, 0, 1);