diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h --- a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h +++ b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h @@ -212,18 +212,13 @@ /// 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 insertDimId(unsigned pos, unsigned num = 1); - unsigned insertSymbolId(unsigned pos, unsigned num = 1); - unsigned insertLocalId(unsigned pos, unsigned num = 1); unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1) override; /// Append `num` identifiers of the specified kind after the last identifier. - /// of that kind. Return the position of the first appended column. The - /// coefficient columns corresponding to the added identifiers are initialized - /// to zero. - unsigned appendDimId(unsigned num = 1); - unsigned appendSymbolId(unsigned num = 1); - unsigned appendLocalId(unsigned num = 1); + /// 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); /// Adds an inequality (>= 0) from the coefficients specified in `inEq`. void addInequality(ArrayRef inEq); 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 @@ -22,6 +22,11 @@ class PresburgerLocalSpace; +/// 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 IdKind { 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: /// @@ -65,10 +70,7 @@ friend PresburgerLocalSpace; public: - /// 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 IdKind { Symbol, Local, Domain, Range, SetDim = Range }; + using IdKind = IdKind; static PresburgerSpace getRelationSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols); diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h --- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h @@ -105,6 +105,35 @@ // 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. 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 insertDimId(unsigned pos, unsigned num = 1) { + return insertId(IdKind::SetDim, pos, num); + } + unsigned insertSymbolId(unsigned pos, unsigned num = 1) { + return insertId(IdKind::Symbol, pos, num); + } + unsigned insertLocalId(unsigned pos, unsigned num = 1) { + return insertId(IdKind::Local, pos, num); + } + + /// Append `num` identifiers of the specified kind after the last identifier. + /// 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 appendDimId(unsigned num = 1) { + return appendId(IdKind::SetDim, num); + } + unsigned appendSymbolId(unsigned num = 1) { + return appendId(IdKind::Symbol, num); + } + unsigned appendLocalId(unsigned num = 1) { + return appendId(IdKind::Local, num); + } + /// Adds a bound for the identifier 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 diff --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp --- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp +++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp @@ -113,18 +113,6 @@ return maybeLexMin; } -unsigned IntegerPolyhedron::insertDimId(unsigned pos, unsigned num) { - return insertId(IdKind::SetDim, pos, num); -} - -unsigned IntegerPolyhedron::insertSymbolId(unsigned pos, unsigned num) { - return insertId(IdKind::Symbol, pos, num); -} - -unsigned IntegerPolyhedron::insertLocalId(unsigned pos, unsigned num) { - return insertId(IdKind::Local, pos, num); -} - unsigned IntegerPolyhedron::insertId(IdKind kind, unsigned pos, unsigned num) { assert(pos <= getNumIdKind(kind)); @@ -134,22 +122,9 @@ return insertPos; } -unsigned IntegerPolyhedron::appendDimId(unsigned num) { - unsigned pos = getNumDimIds(); - insertId(IdKind::SetDim, pos, num); - return pos; -} - -unsigned IntegerPolyhedron::appendSymbolId(unsigned num) { - unsigned pos = getNumSymbolIds(); - insertId(IdKind::Symbol, pos, num); - return pos; -} - -unsigned IntegerPolyhedron::appendLocalId(unsigned num) { - unsigned pos = getNumLocalIds(); - insertId(IdKind::Local, pos, num); - return pos; +unsigned IntegerPolyhedron::appendId(IdKind kind, unsigned num) { + unsigned pos = getNumIdKind(kind); + return insertId(kind, pos, num); } void IntegerPolyhedron::addEquality(ArrayRef eq) { @@ -1049,8 +1024,8 @@ // i.e. append local ids of `polyB` to `polyA` and insert local ids of `polyA` // to `polyB` at start of its local ids. unsigned initLocals = polyA.getNumLocalIds(); - insertLocalId(polyA.getNumLocalIds(), polyB.getNumLocalIds()); - polyB.insertLocalId(0, initLocals); + insertId(Local, polyA.getNumLocalIds(), polyB.getNumLocalIds()); + polyB.insertId(Local, 0, initLocals); // Get division representations from each poly. std::vector> divsA, divsB; @@ -1138,7 +1113,7 @@ // Append new local variables corresponding to the dimensions to be converted. unsigned convertCount = dimLimit - dimStart; unsigned newLocalIdStart = getNumIds(); - appendLocalId(convertCount); + appendId(Local, convertCount); // Swap the new local variables with dimensions. for (unsigned i = 0; i < convertCount; ++i) @@ -1183,7 +1158,7 @@ assert(dividend.size() == getNumCols() && "incorrect dividend size"); assert(divisor > 0 && "positive divisor expected"); - appendLocalId(); + appendId(Local); // Add two constraints for this new identifier 'q'. SmallVector bound(dividend.size() + 1); diff --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp --- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp +++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp @@ -830,7 +830,7 @@ IntegerPolyhedron poly2(1); poly2.addLocalFloorDiv({1, 0}, 2); // y = [x / 2]. poly2.addEquality({1, -5, 0}); // x = 5y. - poly2.appendLocalId(); // Add local id z. + poly2.appendId(Local); // Add local id z. poly1.mergeLocalIds(poly2); @@ -878,7 +878,7 @@ IntegerPolyhedron poly2(1); poly2.addLocalFloorDiv({1, 0}, 2); // y = [x / 2]. poly2.addEquality({1, -5, 0}); // x = 5y. - poly2.appendLocalId(); // Add local id z. + poly2.appendId(Local); // Add local id z. poly1.mergeLocalIds(poly2);