forked from OSchip/llvm-project
[MLIR] Add clearAndCopyFrom to IntegerPolyhedron
This patch adds clearAndCopyFrom to IntegerPolyhedron. This requires moving LLVM-style RTTI from FlatAffineConstraints to IntegerPolyhedron. This patch is part of a series of patches to move presburger math to Presburger directory. Reviewed By: arjunp Differential Revision: https://reviews.llvm.org/D116533
This commit is contained in:
parent
e2165e0968
commit
dde7388ad5
|
@ -59,9 +59,6 @@ struct MutableAffineMap;
|
|||
///
|
||||
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 @@ public:
|
|||
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 @@ public:
|
|||
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 @@ public:
|
|||
/// 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 @@ public:
|
|||
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.
|
||||
|
|
|
@ -50,6 +50,13 @@ namespace mlir {
|
|||
///
|
||||
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 @@ public:
|
|||
|
||||
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<IntegerPolyhedron> clone() const;
|
||||
|
||||
|
@ -189,6 +201,9 @@ public:
|
|||
/// values and removes them.
|
||||
void setAndEliminate(unsigned pos, ArrayRef<int64_t> 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`).
|
||||
|
|
|
@ -2643,25 +2643,35 @@ void FlatAffineConstraints::removeTrivialRedundancy() {
|
|||
// the savings.
|
||||
}
|
||||
|
||||
void FlatAffineConstraints::clearAndCopyFrom(
|
||||
const FlatAffineConstraints &other) {
|
||||
void FlatAffineConstraints::clearAndCopyFrom(const IntegerPolyhedron &other) {
|
||||
if (auto *otherValueSet = dyn_cast<const FlatAffineValueConstraints>(&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<const FlatAffineConstraints>(&other))
|
||||
*this = *otherValueSet;
|
||||
else
|
||||
*static_cast<IntegerPolyhedron *>(this) = other;
|
||||
}
|
||||
|
||||
void FlatAffineValueConstraints::clearAndCopyFrom(
|
||||
const FlatAffineConstraints &other) {
|
||||
const IntegerPolyhedron &other) {
|
||||
|
||||
if (auto *otherValueSet =
|
||||
dyn_cast<const FlatAffineValueConstraints>(&other)) {
|
||||
*this = *otherValueSet;
|
||||
} else {
|
||||
*static_cast<FlatAffineConstraints *>(this) = other;
|
||||
values.clear();
|
||||
values.resize(numIds, None);
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto *otherValueSet = dyn_cast<const FlatAffineValueConstraints>(&other))
|
||||
*static_cast<FlatAffineConstraints *>(this) = *otherValueSet;
|
||||
else
|
||||
*static_cast<IntegerPolyhedron *>(this) = other;
|
||||
|
||||
values.clear();
|
||||
values.resize(numIds, None);
|
||||
}
|
||||
|
||||
static std::pair<unsigned, unsigned>
|
||||
|
|
|
@ -303,6 +303,10 @@ void IntegerPolyhedron::setAndEliminate(unsigned pos,
|
|||
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()
|
||||
|
|
Loading…
Reference in New Issue