18
18
#include " mlir/Analysis/Presburger/Fraction.h"
19
19
#include " mlir/Analysis/Presburger/IntegerPolyhedron.h"
20
20
#include " mlir/Analysis/Presburger/Matrix.h"
21
+ #include " mlir/Analysis/Presburger/Utils.h"
21
22
#include " mlir/Support/LogicalResult.h"
22
23
#include " llvm/ADT/ArrayRef.h"
23
24
#include " llvm/ADT/Optional.h"
@@ -202,14 +203,6 @@ class SimplexBase {
202
203
// / Add all the constraints from the given IntegerPolyhedron.
203
204
void intersectIntegerPolyhedron (const IntegerPolyhedron &poly);
204
205
205
- // / Returns the current sample point, which may contain non-integer (rational)
206
- // / coordinates. Returns an empty optional when the tableau is empty.
207
- // /
208
- // / Also returns empty when the big M parameter is used and a variable
209
- // / has a non-zero big M coefficient, meaning its value is infinite or
210
- // / unbounded.
211
- Optional<SmallVector<Fraction, 8 >> getRationalSample () const ;
212
-
213
206
// / Print the tableau's internal state.
214
207
void print (raw_ostream &os) const ;
215
208
void dump () const ;
@@ -441,9 +434,18 @@ class LexSimplex : public SimplexBase {
441
434
unsigned getSnapshot () { return SimplexBase::getSnapshotBasis (); }
442
435
443
436
// / Return the lexicographically minimum rational solution to the constraints.
444
- Optional <SmallVector<Fraction, 8 >> getRationalLexMin ();
437
+ presburger_utils::MaybeOptimum <SmallVector<Fraction, 8 >> getRationalLexMin ();
445
438
446
439
protected:
440
+ // / Returns the current sample point, which may contain non-integer (rational)
441
+ // / coordinates. Returns an empty optimum when the tableau is empty.
442
+ // /
443
+ // / Returns an unbounded optimum when the big M parameter is used and a
444
+ // / variable has a non-zero big M coefficient, meaning its value is infinite
445
+ // / or unbounded.
446
+ presburger_utils::MaybeOptimum<SmallVector<Fraction, 8 >>
447
+ getRationalSample () const ;
448
+
447
449
// / Undo the addition of the last constraint. This is only called while
448
450
// / rolling back.
449
451
void undoLastConstraint () final ;
@@ -510,15 +512,16 @@ class Simplex : public SimplexBase {
510
512
// /
511
513
// / Returns a Fraction denoting the optimum, or a null value if no optimum
512
514
// / exists, i.e., if the expression is unbounded in this direction.
513
- Optional<Fraction> computeRowOptimum (Direction direction, unsigned row);
515
+ presburger_utils::MaybeOptimum<Fraction>
516
+ computeRowOptimum (Direction direction, unsigned row);
514
517
515
518
// / Compute the maximum or minimum value of the given expression, depending on
516
519
// / direction. Should not be called when the Simplex is empty.
517
520
// /
518
521
// / Returns a Fraction denoting the optimum, or a null value if no optimum
519
522
// / exists, i.e., if the expression is unbounded in this direction.
520
- Optional <Fraction> computeOptimum (Direction direction,
521
- ArrayRef<int64_t > coeffs);
523
+ presburger_utils::MaybeOptimum <Fraction>
524
+ computeOptimum (Direction direction, ArrayRef<int64_t > coeffs);
522
525
523
526
// / Returns whether the perpendicular of the specified constraint is a
524
527
// / is a direction along which the polytope is bounded.
@@ -537,10 +540,10 @@ class Simplex : public SimplexBase {
537
540
void detectRedundant ();
538
541
539
542
// / Returns a (min, max) pair denoting the minimum and maximum integer values
540
- // / of the given expression. If either of the values is unbounded, an empty
541
- // / optional is returned in its place. If the result has min > max then no
542
- // / integer value exists.
543
- std::pair<Optional< int64_t >, Optional <int64_t >>
543
+ // / of the given expression. If no integer value exists, both results will be
544
+ // / of kind Empty.
545
+ std::pair<presburger_utils::MaybeOptimum< int64_t >,
546
+ presburger_utils::MaybeOptimum <int64_t >>
544
547
computeIntegerBounds (ArrayRef<int64_t > coeffs);
545
548
546
549
// / Returns true if the polytope is unbounded, i.e., extends to infinity in
@@ -569,6 +572,10 @@ class Simplex : public SimplexBase {
569
572
// / None.
570
573
Optional<SmallVector<int64_t , 8 >> getSamplePointIfIntegral () const ;
571
574
575
+ // / Returns the current sample point, which may contain non-integer (rational)
576
+ // / coordinates. Returns an empty optional when the tableau is empty.
577
+ Optional<SmallVector<Fraction, 8 >> getRationalSample () const ;
578
+
572
579
private:
573
580
friend class GBRSimplex ;
574
581
@@ -610,7 +617,8 @@ class Simplex : public SimplexBase {
610
617
// /
611
618
// / Returns a Fraction denoting the optimum, or a null value if no optimum
612
619
// / exists, i.e., if the expression is unbounded in this direction.
613
- Optional<Fraction> computeOptimum (Direction direction, Unknown &u);
620
+ presburger_utils::MaybeOptimum<Fraction> computeOptimum (Direction direction,
621
+ Unknown &u);
614
622
615
623
// / Mark the specified unknown redundant. This operation is added to the undo
616
624
// / log and will be undone by rollbacks. The specified unknown must be in row
0 commit comments