[Mlir-commits] [mlir] 58966dd - [MLIR][Presburger] Remove `spaceKind` from PresburgerSpace
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 10 08:50:55 PST 2022
Author: Groverkss
Date: 2022-03-10T22:20:44+05:30
New Revision: 58966dd42bc4af67ff6b580a8cc3d36abba98add
URL: https://github.com/llvm/llvm-project/commit/58966dd42bc4af67ff6b580a8cc3d36abba98add
DIFF: https://github.com/llvm/llvm-project/commit/58966dd42bc4af67ff6b580a8cc3d36abba98add.diff
LOG: [MLIR][Presburger] Remove `spaceKind` from PresburgerSpace
This patch remove `spaceKind` from PresburgerSpace, making PresburgerSpace only
a space supporting relations.
Sets are still implemented in the same way, i.e. with a zero domain but instead
the asserts to check if the space is still set are added to users of
PresburgerSpace which treat it as a Set space.
Reviewed By: arjunp
Differential Revision: https://reviews.llvm.org/D121357
Added:
Modified:
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
mlir/include/mlir/Analysis/Presburger/PresburgerSet.h
mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
mlir/lib/Analysis/Presburger/IntegerRelation.cpp
mlir/lib/Analysis/Presburger/PWMAFunction.cpp
mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
index c83c85d5a384a..dc9c9b9c2589b 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
@@ -406,21 +406,6 @@ class IntegerRelation : public PresburgerLocalSpace {
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 @@ class IntegerPolyhedron : public IntegerRelation {
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 @@ class IntegerPolyhedron : public IntegerRelation {
// Clones this object.
std::unique_ptr<IntegerPolyhedron> 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
index c233a15c234ab..5d3e729ed4308 100644
--- a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
+++ b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
@@ -151,7 +151,8 @@ class MultiAffineFunction : protected IntegerPolyhedron {
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
index 38548a23f7a3a..100cf6c04c504 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerSet.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSet.h
@@ -114,7 +114,7 @@ class PresburgerSet : public PresburgerSpace {
/// 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<IntegerPolyhedron, 2> integerPolyhedrons;
diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
index 5e5bc55938693..e53e60993798b 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
@@ -54,15 +54,12 @@ enum class IdKind { Symbol, Local, Domain, Range, SetDim = Range };
/// 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 @@ class PresburgerSpace {
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 @@ class PresburgerSpace {
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 @@ class PresburgerSpace {
/// 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 @@ class PresburgerLocalSpace : public PresburgerSpace {
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
index e12057dcb3089..49800db5ee3fc 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -2048,3 +2048,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) &&
+ "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
index 6d6548d4e9840..a945d6d08aa05 100644
--- a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
+++ b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
@@ -84,6 +84,8 @@ bool MultiAffineFunction::isEqual(const MultiAffineFunction &other) const {
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
index ae1bc454dddc4..cbeba2416d3a7 100644
--- 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 PresburgerSpace::insertId(IdKind kind, unsigned pos, unsigned num) {
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 @@ void PresburgerSpace::removeIdRange(IdKind kind, unsigned idStart,
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::setDimSymbolSeparation(unsigned newSymbolCount) {
}
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
index 8f793747f2a5d..b88f83c5ef4e8 100644
--- a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
@@ -14,7 +14,7 @@ using namespace mlir;
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, insertId) {
}
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, insertIdSet) {
}
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);
More information about the Mlir-commits
mailing list