Skip to content

Commit

Permalink
[MLIR] IntegerPolyhedron: introduce getNumIdKind to replace calls to …
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
Superty committed Dec 10, 2021
1 parent ea81cea commit 98db55f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 98db55f

Please sign in to comment.