[Mlir-commits] [mlir] 9c33a2e - [MLIR][Presburger] Fold loop into assert

Benjamin Kramer llvmlistbot at llvm.org
Sat Jan 13 08:54:08 PST 2024


Author: Benjamin Kramer
Date: 2024-01-13T17:52:58+01:00
New Revision: 9c33a2e9a3202c9e04bd359df14708ad2fa45387

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

LOG: [MLIR][Presburger] Fold loop into assert

This way it doesn't trigger -Wunused-variable when assertions are disabled.

Added: 
    

Modified: 
    mlir/lib/Analysis/Presburger/Barvinok.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/Presburger/Barvinok.cpp b/mlir/lib/Analysis/Presburger/Barvinok.cpp
index a3d210b3b8fd16..4ba4462af0317f 100644
--- a/mlir/lib/Analysis/Presburger/Barvinok.cpp
+++ b/mlir/lib/Analysis/Presburger/Barvinok.cpp
@@ -172,8 +172,10 @@ GeneratingFunction mlir::presburger::detail::unimodularConeGeneratingFunction(
 Point mlir::presburger::detail::getNonOrthogonalVector(
     ArrayRef<Point> vectors) {
   unsigned dim = vectors[0].size();
-  for (const Point &vector : vectors)
-    assert(vector.size() == dim && "all vectors need to be the same size!");
+  assert(
+      llvm::all_of(vectors,
+                   [&](const Point &vector) { return vector.size() == dim; }) &&
+      "all vectors need to be the same size!");
 
   SmallVector<Fraction> newPoint = {Fraction(1, 1)};
   Fraction maxDisallowedValue = -Fraction(1, 0),
@@ -216,11 +218,12 @@ QuasiPolynomial mlir::presburger::detail::getCoefficientInRationalFunction(
          "division by empty denominator in rational function!");
 
   unsigned numParam = num[0].getNumInputs();
-  for (const QuasiPolynomial &qp : num)
-    // We use the `isEqual` method of PresburgerSpace, which QuasiPolynomial
-    // inherits from.
-    assert(num[0].isEqual(qp) &&
-           "the quasipolynomials should all belong to the same space!");
+  // We use the `isEqual` method of PresburgerSpace, which QuasiPolynomial
+  // inherits from.
+  assert(
+      llvm::all_of(
+          num, [&](const QuasiPolynomial &qp) { return num[0].isEqual(qp); }) &&
+      "the quasipolynomials should all belong to the same space!");
 
   std::vector<QuasiPolynomial> coefficients;
   coefficients.reserve(power + 1);
@@ -241,4 +244,4 @@ QuasiPolynomial mlir::presburger::detail::getCoefficientInRationalFunction(
     coefficients[i] = coefficients[i] / den[0];
   }
   return coefficients[power].simplify();
-}
\ No newline at end of file
+}


        


More information about the Mlir-commits mailing list