[Mlir-commits] [mlir] [MLIR][Presburger][WIP] Implement vertex enumeration and chamber decomposition for polytope generating function computation. (PR #78987)

Arjun P llvmlistbot at llvm.org
Mon Jan 22 08:11:28 PST 2024


================
@@ -2498,6 +2498,50 @@ void IntegerRelation::printSpace(raw_ostream &os) const {
   os << getNumConstraints() << " constraints\n";
 }
 
+void IntegerRelation::removeTrivialEqualities() {
+  bool flag;
+  for (unsigned i = 0, e = getNumInequalities(); i < e; i++) {
+    flag = true;
+    for (unsigned j = 0, f = getNumVars(); j < f + 1; j++)
+      if (atEq(i, j) != 0)
+        flag = false;
+    if (flag)
+      removeEquality(i);
+  }
+}
+
+bool IntegerRelation::isFullDim() {
+  removeTrivialEqualities();
+
+  unsigned e = getNumInequalities();
+
+  // If there is a non-trivial equality, the space cannot be full-dimensional.
+  if (e > 0)
+    return false;
+
+  // If along the direction of any of the inequalities, the upper and lower
+  // optima are the same, then the region is not full-dimensional.
+  Simplex simplex(*this);
+  for (unsigned i = 0; i < e; i++) {
+    auto ineq = inequalities.getRow(i);
+    auto upOpt = simplex.computeOptimum(Simplex::Direction::Up, ineq);
+    auto downOpt = simplex.computeOptimum(Simplex::Direction::Down, ineq);
+
+    if (upOpt.getKind() == OptimumKind::Unbounded ||
+        downOpt.getKind() == OptimumKind::Unbounded)
+      continue;
+
+    // Check if the upper and lower optima are equal.
+    if (upOpt.getKind() == OptimumKind::Bounded &&
+        downOpt.getKind() == OptimumKind::Bounded && *upOpt == *downOpt)
+      return false;
+  }
----------------
Superty wrote:

I would suggest adding a function isValidEquality to Simplex.h here
https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Analysis/Presburger/Simplex.h#L773

and you can call computeIntegerBounds (just above) in its implementatino

https://github.com/llvm/llvm-project/pull/78987


More information about the Mlir-commits mailing list