Skip to content

Commit 79be1fe

Browse files
committed
[MLIR] Simplex::getRationalSample: return an optional, empty if Simplex is empty
1 parent b50c10f commit 79be1fe

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

mlir/include/mlir/Analysis/Presburger/Simplex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ class SimplexBase {
182182
/// Add all the constraints from the given IntegerPolyhedron.
183183
void intersectIntegerPolyhedron(const IntegerPolyhedron &poly);
184184

185-
/// Returns a rational sample point. This should not be called when Simplex is
185+
/// Returns a rational sample point. Returns an empty optional if Simplex is
186186
/// empty.
187-
SmallVector<Fraction, 8> getRationalSample() const;
187+
Optional<SmallVector<Fraction, 8>> getRationalSample() const;
188188

189189
/// Returns the current sample point if it is integral. Otherwise, returns
190190
/// None.

mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,10 @@ Optional<SmallVector<int64_t, 8>> IntegerPolyhedron::findIntegerSample() const {
759759
// full-dimensional cone and is hence non-empty.
760760
Simplex shrunkenConeSimplex(cone);
761761
assert(!shrunkenConeSimplex.isEmpty() && "Shrunken cone cannot be empty!");
762+
763+
// The sample will always exist since the shrunken cone is non-empty.
762764
SmallVector<Fraction, 8> shrunkenConeSample =
763-
shrunkenConeSimplex.getRationalSample();
765+
*shrunkenConeSimplex.getRationalSample();
764766

765767
SmallVector<int64_t, 8> coneSample(llvm::map_range(shrunkenConeSample, ceil));
766768

mlir/lib/Analysis/Presburger/Simplex.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,9 @@ Simplex Simplex::makeProduct(const Simplex &a, const Simplex &b) {
745745
return result;
746746
}
747747

748-
SmallVector<Fraction, 8> SimplexBase::getRationalSample() const {
749-
assert(!empty && "This should not be called when Simplex is empty.");
748+
Optional<SmallVector<Fraction, 8>> SimplexBase::getRationalSample() const {
749+
if (empty)
750+
return {};
750751

751752
SmallVector<Fraction, 8> sample;
752753
sample.reserve(var.size());
@@ -770,7 +771,9 @@ SimplexBase::getSamplePointIfIntegral() const {
770771
// If the tableau is empty, no sample point exists.
771772
if (empty)
772773
return {};
773-
SmallVector<Fraction, 8> rationalSample = getRationalSample();
774+
775+
// The value will always exist since the Simplex is non-empty.
776+
SmallVector<Fraction, 8> rationalSample = *getRationalSample();
774777
SmallVector<int64_t, 8> integerSample;
775778
integerSample.reserve(var.size());
776779
for (const Fraction &coord : rationalSample) {

0 commit comments

Comments
 (0)