[MLIR] IntegerPolyhedron: introduce getNumIdKind to replace calls to assertAtMostNumI...
authorArjun P <arjunpitchanathan@gmail.com>
Fri, 10 Dec 2021 21:48:04 +0000 (03:18 +0530)
committerArjun P <arjunpitchanathan@gmail.com>
Fri, 10 Dec 2021 22:12:46 +0000 (03:42 +0530)
Introduce a function `getNumIdKind` that returns the number of ids of the
specified kind. Remove the function `assertAtMostNumIdKind` and instead just
directly assert the inequality with a call to `getNumIdKind`.

mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp

index ad32d7a..933f20e 100644 (file)
@@ -189,8 +189,8 @@ protected:
   /// Return the index at which the specified kind of id starts.
   unsigned getIdKindOffset(IdKind kind) const;
 
-  /// Assert that `value` is at most the number of ids of the specified kind.
-  void assertAtMostNumIdKind(unsigned value, IdKind kind) const;
+  /// Get the number of ids of the specified kind.
+  unsigned getNumIdKind(IdKind kind) const;
 
   /// Removes identifiers in the column range [idStart, idLimit), and copies any
   /// remaining valid data into place, updates member variables, and resizes
index 5fc6533..3c4f512 100644 (file)
@@ -65,7 +65,7 @@ unsigned IntegerPolyhedron::insertLocalId(unsigned pos, unsigned num) {
 }
 
 unsigned IntegerPolyhedron::insertId(IdKind kind, unsigned pos, unsigned num) {
-  assertAtMostNumIdKind(pos, kind);
+  assert(pos <= getNumIdKind(kind));
 
   unsigned absolutePos = getIdKindOffset(kind) + pos;
   if (kind == IdKind::Dimension)
@@ -120,7 +120,7 @@ void IntegerPolyhedron::removeId(unsigned pos) { removeIdRange(pos, pos + 1); }
 
 void IntegerPolyhedron::removeIdRange(IdKind kind, unsigned idStart,
                                       unsigned idLimit) {
-  assertAtMostNumIdKind(idLimit, kind);
+  assert(idLimit <= getNumIdKind(kind));
   removeIdRange(getIdKindOffset(kind) + idStart,
                 getIdKindOffset(kind) + idLimit);
 }
@@ -203,15 +203,14 @@ unsigned IntegerPolyhedron::getIdKindOffset(IdKind kind) const {
   llvm_unreachable("IdKind expected to be Dimension, Symbol or Local!");
 }
 
-void IntegerPolyhedron::assertAtMostNumIdKind(unsigned val, IdKind kind) const {
+unsigned IntegerPolyhedron::getNumIdKind(IdKind kind) const {
   if (kind == IdKind::Dimension)
-    assert(val <= getNumDimIds());
-  else if (kind == IdKind::Symbol)
-    assert(val <= getNumSymbolIds());
-  else if (kind == IdKind::Local)
-    assert(val <= getNumLocalIds());
-  else
-    llvm_unreachable("IdKind expected to be Dimension, Symbol or Local!");
+    return getNumDimIds();
+  if (kind == IdKind::Symbol)
+    return getNumSymbolIds();
+  if (kind == IdKind::Local)
+    return getNumLocalIds();
+  llvm_unreachable("IdKind expected to be Dimension, Symbol or Local!");
 }
 
 void IntegerPolyhedron::clearConstraints() {