[Mlir-commits] [mlir] 79be1fe - [MLIR] Simplex::getRationalSample: return an optional, empty if Simplex is empty

Arjun P llvmlistbot at llvm.org
Sun Jan 16 08:32:34 PST 2022


Author: Arjun P
Date: 2022-01-16T22:02:27+05:30
New Revision: 79be1fe0d5a22759fc3d241fe900f099b61e722f

URL: https://github.com/llvm/llvm-project/commit/79be1fe0d5a22759fc3d241fe900f099b61e722f
DIFF: https://github.com/llvm/llvm-project/commit/79be1fe0d5a22759fc3d241fe900f099b61e722f.diff

LOG: [MLIR] Simplex::getRationalSample: return an optional, empty if Simplex is empty

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/Simplex.h b/mlir/include/mlir/Analysis/Presburger/Simplex.h
index 2773a6319079c..f2257834a9303 100644
--- a/mlir/include/mlir/Analysis/Presburger/Simplex.h
+++ b/mlir/include/mlir/Analysis/Presburger/Simplex.h
@@ -182,9 +182,9 @@ class SimplexBase {
   /// Add all the constraints from the given IntegerPolyhedron.
   void intersectIntegerPolyhedron(const IntegerPolyhedron &poly);
 
-  /// Returns a rational sample point. This should not be called when Simplex is
+  /// Returns a rational sample point. Returns an empty optional if Simplex is
   /// empty.
-  SmallVector<Fraction, 8> getRationalSample() const;
+  Optional<SmallVector<Fraction, 8>> getRationalSample() const;
 
   /// Returns the current sample point if it is integral. Otherwise, returns
   /// None.

diff  --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
index 520d17a31babe..fe4b7c4477581 100644
--- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
@@ -759,8 +759,10 @@ Optional<SmallVector<int64_t, 8>> IntegerPolyhedron::findIntegerSample() const {
   // full-dimensional cone and is hence non-empty.
   Simplex shrunkenConeSimplex(cone);
   assert(!shrunkenConeSimplex.isEmpty() && "Shrunken cone cannot be empty!");
+
+  // The sample will always exist since the shrunken cone is non-empty.
   SmallVector<Fraction, 8> shrunkenConeSample =
-      shrunkenConeSimplex.getRationalSample();
+      *shrunkenConeSimplex.getRationalSample();
 
   SmallVector<int64_t, 8> coneSample(llvm::map_range(shrunkenConeSample, ceil));
 

diff  --git a/mlir/lib/Analysis/Presburger/Simplex.cpp b/mlir/lib/Analysis/Presburger/Simplex.cpp
index d00832b21ef8b..64bea50591b11 100644
--- a/mlir/lib/Analysis/Presburger/Simplex.cpp
+++ b/mlir/lib/Analysis/Presburger/Simplex.cpp
@@ -745,8 +745,9 @@ Simplex Simplex::makeProduct(const Simplex &a, const Simplex &b) {
   return result;
 }
 
-SmallVector<Fraction, 8> SimplexBase::getRationalSample() const {
-  assert(!empty && "This should not be called when Simplex is empty.");
+Optional<SmallVector<Fraction, 8>> SimplexBase::getRationalSample() const {
+  if (empty)
+    return {};
 
   SmallVector<Fraction, 8> sample;
   sample.reserve(var.size());
@@ -770,7 +771,9 @@ SimplexBase::getSamplePointIfIntegral() const {
   // If the tableau is empty, no sample point exists.
   if (empty)
     return {};
-  SmallVector<Fraction, 8> rationalSample = getRationalSample();
+
+  // The value will always exist since the Simplex is non-empty.
+  SmallVector<Fraction, 8> rationalSample = *getRationalSample();
   SmallVector<int64_t, 8> integerSample;
   integerSample.reserve(var.size());
   for (const Fraction &coord : rationalSample) {


        


More information about the Mlir-commits mailing list