[Mlir-commits] [mlir] dde7388 - [MLIR] Add clearAndCopyFrom to IntegerPolyhedron

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 5 10:09:46 PST 2022


Author: Groverkss
Date: 2022-01-05T23:39:26+05:30
New Revision: dde7388ad5bb19ddd1cb2ac4669ff3012723dd69

URL: https://github.com/llvm/llvm-project/commit/dde7388ad5bb19ddd1cb2ac4669ff3012723dd69
DIFF: https://github.com/llvm/llvm-project/commit/dde7388ad5bb19ddd1cb2ac4669ff3012723dd69.diff

LOG: [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

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/AffineStructures.h
    mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
    mlir/lib/Analysis/AffineStructures.cpp
    mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/AffineStructures.h b/mlir/include/mlir/Analysis/AffineStructures.h
index bb76b4ff13d23..3991628a61004 100644
--- a/mlir/include/mlir/Analysis/AffineStructures.h
+++ b/mlir/include/mlir/Analysis/AffineStructures.h
@@ -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 @@ class FlatAffineConstraints : public IntegerPolyhedron {
   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 @@ class FlatAffineConstraints : public IntegerPolyhedron {
   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 @@ class FlatAffineValueConstraints : public FlatAffineConstraints {
   /// 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 @@ class FlatAffineValueConstraints : public FlatAffineConstraints {
   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
index 9185ea14cd53d..eae56e3acd0ab 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
@@ -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 @@ class IntegerPolyhedron {
 
   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 @@ class IntegerPolyhedron {
   /// 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`).

diff  --git a/mlir/lib/Analysis/AffineStructures.cpp b/mlir/lib/Analysis/AffineStructures.cpp
index b6f592a710234..6c11bf74a4141 100644
--- a/mlir/lib/Analysis/AffineStructures.cpp
+++ b/mlir/lib/Analysis/AffineStructures.cpp
@@ -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>

diff  --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
index 03de0e97aaee5..06b39cbc0f8b7 100644
--- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
@@ -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()


        


More information about the Mlir-commits mailing list