[Mlir-commits] [mlir] 98db55f - [MLIR] IntegerPolyhedron: introduce getNumIdKind to replace calls to assertAtMostNumIdKind

Arjun P llvmlistbot at llvm.org
Fri Dec 10 14:15:00 PST 2021


Author: Arjun P
Date: 2021-12-11T03:42:46+05:30
New Revision: 98db55f108a25953ea743629a874ced3da0058da

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

LOG: [MLIR] IntegerPolyhedron: introduce getNumIdKind to replace calls to assertAtMostNumIdKind

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`.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
index ad32d7a7aba9a..933f20e441225 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
@@ -189,8 +189,8 @@ class IntegerPolyhedron {
   /// 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

diff  --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
index 5fc6533a98c14..3c4f512bf4fbe 100644
--- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
@@ -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() {


        


More information about the Mlir-commits mailing list