diff --git a/mlir/include/mlir/Analysis/AffineStructures.h b/mlir/include/mlir/Analysis/AffineStructures.h --- a/mlir/include/mlir/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Analysis/AffineStructures.h @@ -59,9 +59,6 @@ /// class FlatAffineConstraints : public IntegerPolyhedron { public: - /// All derived classes of FlatAffineConstraints. - enum class Kind { FlatAffineConstraints, FlatAffineValueConstraints }; - /// Constructs a constraint system reserving memory for the specified number /// of constraints and identifiers. FlatAffineConstraints(unsigned numReservedInequalities, @@ -99,9 +96,11 @@ virtual ~FlatAffineConstraints() = default; /// Return the kind of this FlatAffineConstraints. - virtual Kind getKind() const { return Kind::FlatAffineConstraints; } + Kind getKind() const override { return Kind::FlatAffineConstraints; } - static bool classof(const FlatAffineConstraints *cst) { return true; } + static bool classof(const IntegerPolyhedron *cst) { + return cst->getKind() == Kind::FlatAffineConstraints; + } /// Checks for emptiness by performing variable elimination on all /// identifiers, running the GCD test on each equality constraint, and @@ -250,7 +249,7 @@ LogicalResult unionBoundingBox(const FlatAffineConstraints &other); /// Replaces the contents of this FlatAffineConstraints with `other`. - virtual void clearAndCopyFrom(const FlatAffineConstraints &other); + void clearAndCopyFrom(const IntegerPolyhedron &other) override; /// Returns the smallest known constant bound for the extent of the specified /// identifier (pos^th), i.e., the smallest known constant that is greater @@ -499,7 +498,7 @@ /// Return the kind of this FlatAffineConstraints. Kind getKind() const override { return Kind::FlatAffineValueConstraints; } - static bool classof(const FlatAffineConstraints *cst) { + static bool classof(const IntegerPolyhedron *cst) { return cst->getKind() == Kind::FlatAffineValueConstraints; } @@ -698,7 +697,7 @@ bool areIdsAlignedWithOther(const FlatAffineValueConstraints &other); /// Replaces the contents of this FlatAffineValueConstraints with `other`. - void clearAndCopyFrom(const FlatAffineConstraints &other) override; + void clearAndCopyFrom(const IntegerPolyhedron &other) override; /// Returns the Value associated with the pos^th identifier. Asserts if /// no Value identifier was associated. 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 @@ -50,6 +50,13 @@ /// class IntegerPolyhedron { public: + /// All derived classes of IntegerPolyhedron. + enum class Kind { + FlatAffineConstraints, + FlatAffineValueConstraints, + IntegerPolyhedron + }; + /// Kind of identifier (column). enum IdKind { Dimension, Symbol, Local }; @@ -77,6 +84,11 @@ virtual ~IntegerPolyhedron() = default; + /// Return the kind of this IntegerPolyhedron. + virtual Kind getKind() const { return Kind::IntegerPolyhedron; } + + static bool classof(const IntegerPolyhedron *cst) { return true; } + // Clones this object. std::unique_ptr clone() const; @@ -189,6 +201,9 @@ /// values and removes them. void setAndEliminate(unsigned pos, ArrayRef values); + /// Replaces the contents of this IntegerPolyhedron with `other`. + virtual void clearAndCopyFrom(const IntegerPolyhedron &other); + /// Gather positions of all lower and upper bounds of the identifier at `pos`, /// and optionally any equalities on it. In addition, the bounds are to be /// independent of identifiers in position range [`offset`, `offset` + `num`). diff --git a/mlir/lib/Analysis/AffineStructures.cpp b/mlir/lib/Analysis/AffineStructures.cpp --- a/mlir/lib/Analysis/AffineStructures.cpp +++ b/mlir/lib/Analysis/AffineStructures.cpp @@ -2643,25 +2643,35 @@ // the savings. } -void FlatAffineConstraints::clearAndCopyFrom( - const FlatAffineConstraints &other) { +void FlatAffineConstraints::clearAndCopyFrom(const IntegerPolyhedron &other) { if (auto *otherValueSet = dyn_cast(&other)) assert(!otherValueSet->hasValues() && "cannot copy associated Values into FlatAffineConstraints"); - // Note: Assigment operator does not vtable pointer, so kind does not change. - *this = other; + + // Note: Assigment operator does not vtable pointer, so kind does not + // change. + if (auto *otherValueSet = dyn_cast(&other)) + *this = *otherValueSet; + else + *static_cast(this) = other; } void FlatAffineValueConstraints::clearAndCopyFrom( - const FlatAffineConstraints &other) { + const IntegerPolyhedron &other) { + if (auto *otherValueSet = dyn_cast(&other)) { *this = *otherValueSet; - } else { - *static_cast(this) = other; - values.clear(); - values.resize(numIds, None); + return; } + + if (auto *otherValueSet = dyn_cast(&other)) + *static_cast(this) = *otherValueSet; + else + *static_cast(this) = other; + + values.clear(); + values.resize(numIds, None); } static std::pair 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 @@ -303,6 +303,10 @@ removeIdRange(pos, pos + values.size()); } +void IntegerPolyhedron::clearAndCopyFrom(const IntegerPolyhedron &other) { + *this = other; +} + void IntegerPolyhedron::printSpace(raw_ostream &os) const { os << "\nConstraints (" << getNumDimIds() << " dims, " << getNumSymbolIds() << " symbols, " << getNumLocalIds() << " locals), (" << getNumConstraints()