Skip to content

Commit d0fee98

Browse files
authored
mlir/Presburger: strip dependency on MLIRSupport (#96517)
Strip the Presburger library's dependency on the MLIR Support library, as well as the headers, in the interest of making it leaner. This patch is part of a project to move the Presburger library into LLVM.
1 parent 5627794 commit d0fee98

18 files changed

+112
-151
lines changed

mlir/include/mlir/Analysis/Presburger/Barvinok.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "mlir/Analysis/Presburger/Matrix.h"
3030
#include "mlir/Analysis/Presburger/PresburgerRelation.h"
3131
#include "mlir/Analysis/Presburger/QuasiPolynomial.h"
32-
#include <bitset>
3332
#include <optional>
3433

3534
namespace mlir {

mlir/include/mlir/Analysis/Presburger/IntegerRelation.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
#include "mlir/Analysis/Presburger/Matrix.h"
2020
#include "mlir/Analysis/Presburger/PresburgerSpace.h"
2121
#include "mlir/Analysis/Presburger/Utils.h"
22-
#include "mlir/Support/LogicalResult.h"
2322
#include "llvm/ADT/DynamicAPInt.h"
23+
#include "llvm/ADT/SmallVector.h"
2424
#include <optional>
2525

2626
namespace mlir {
2727
namespace presburger {
2828
using llvm::DynamicAPInt;
2929
using llvm::int64fromDynamicAPInt;
30+
using llvm::SmallVectorImpl;
3031

3132
class IntegerRelation;
3233
class IntegerPolyhedron;
@@ -477,7 +478,7 @@ class IntegerRelation {
477478
/// equality detection; if successful, the constant is substituted for the
478479
/// variable everywhere in the constraint system and then removed from the
479480
/// system.
480-
LogicalResult constantFoldVar(unsigned pos);
481+
bool constantFoldVar(unsigned pos);
481482

482483
/// This method calls `constantFoldVar` for the specified range of variables,
483484
/// `num` variables starting at position `pos`.
@@ -500,7 +501,7 @@ class IntegerRelation {
500501
/// 3) this = {0 <= d0 <= 5, 1 <= d1 <= 9}
501502
/// other = {2 <= d0 <= 6, 5 <= d1 <= 15},
502503
/// output = {0 <= d0 <= 6, 1 <= d1 <= 15}
503-
LogicalResult unionBoundingBox(const IntegerRelation &other);
504+
bool unionBoundingBox(const IntegerRelation &other);
504505

505506
/// Returns the smallest known constant bound for the extent of the specified
506507
/// variable (pos^th), i.e., the smallest known constant that is greater
@@ -773,8 +774,8 @@ class IntegerRelation {
773774
/// Eliminates a single variable at `position` from equality and inequality
774775
/// constraints. Returns `success` if the variable was eliminated, and
775776
/// `failure` otherwise.
776-
inline LogicalResult gaussianEliminateVar(unsigned position) {
777-
return success(gaussianEliminateVars(position, position + 1) == 1);
777+
inline bool gaussianEliminateVar(unsigned position) {
778+
return gaussianEliminateVars(position, position + 1) == 1;
778779
}
779780

780781
/// Removes local variables using equalities. Each equality is checked if it

mlir/include/mlir/Analysis/Presburger/Matrix.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
#define MLIR_ANALYSIS_PRESBURGER_MATRIX_H
1717

1818
#include "mlir/Analysis/Presburger/Fraction.h"
19-
#include "mlir/Support/LLVM.h"
2019
#include "llvm/ADT/ArrayRef.h"
2120
#include "llvm/Support/raw_ostream.h"
22-
23-
#include <bitset>
2421
#include <cassert>
2522

2623
namespace mlir {
2724
namespace presburger {
25+
using llvm::ArrayRef;
26+
using llvm::MutableArrayRef;
27+
using llvm::raw_ostream;
28+
using llvm::SmallVector;
2829

2930
/// This is a class to represent a resizable matrix.
3031
///

mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
#ifndef MLIR_ANALYSIS_PRESBURGER_PRESBURGERSPACE_H
1515
#define MLIR_ANALYSIS_PRESBURGER_PRESBURGERSPACE_H
1616

17-
#include "mlir/Support/TypeID.h"
1817
#include "llvm/ADT/ArrayRef.h"
19-
#include "llvm/Support/ErrorHandling.h"
18+
#include "llvm/ADT/SmallVector.h"
2019
#include "llvm/Support/PointerLikeTypeTraits.h"
20+
#include "llvm/Support/TypeName.h"
2121
#include "llvm/Support/raw_ostream.h"
2222

2323
namespace mlir {
2424
namespace presburger {
25+
using llvm::ArrayRef;
26+
using llvm::SmallVector;
2527

2628
/// Kind of variable. Implementation wise SetDims are treated as Range
2729
/// vars, and spaces with no distinction between dimension vars are treated
@@ -74,7 +76,7 @@ class Identifier {
7476
explicit Identifier(T value)
7577
: value(llvm::PointerLikeTypeTraits<T>::getAsVoidPointer(value)) {
7678
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
77-
idType = TypeID::get<T>();
79+
idType = llvm::getTypeName<T>();
7880
#endif
7981
}
8082

@@ -83,7 +85,7 @@ class Identifier {
8385
template <typename T>
8486
T getValue() const {
8587
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
86-
assert(TypeID::get<T>() == idType &&
88+
assert(llvm::getTypeName<T>() == idType &&
8789
"Identifier was initialized with a different type than the one used "
8890
"to retrieve it.");
8991
#endif
@@ -108,7 +110,7 @@ class Identifier {
108110

109111
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
110112
/// TypeID of the identifiers in space. This should be used in asserts only.
111-
TypeID idType = TypeID::get<void>();
113+
llvm::StringRef idType;
112114
#endif
113115
};
114116

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
#include "mlir/Analysis/Presburger/Matrix.h"
2121
#include "mlir/Analysis/Presburger/PWMAFunction.h"
2222
#include "mlir/Analysis/Presburger/Utils.h"
23-
#include "mlir/Support/LogicalResult.h"
24-
#include "llvm/ADT/ArrayRef.h"
2523
#include "llvm/ADT/SmallBitVector.h"
26-
#include "llvm/ADT/SmallVector.h"
27-
#include "llvm/Support/StringSaver.h"
28-
#include "llvm/Support/raw_ostream.h"
2924
#include <optional>
3025

3126
namespace mlir {
@@ -450,7 +445,7 @@ class LexSimplexBase : public SimplexBase {
450445
/// lexicopositivity of the basis transform. The row must have a non-positive
451446
/// sample value. If this is not possible, return failure. This occurs when
452447
/// the constraints have no solution or the sample value is zero.
453-
LogicalResult moveRowUnknownToColumn(unsigned row);
448+
bool moveRowUnknownToColumn(unsigned row);
454449

455450
/// Given a row that has a non-integer sample value, add an inequality to cut
456451
/// away this fractional sample value from the polytope without removing any
@@ -464,7 +459,7 @@ class LexSimplexBase : public SimplexBase {
464459
///
465460
/// Return failure if the tableau became empty, and success if it didn't.
466461
/// Failure status indicates that the polytope was integer empty.
467-
LogicalResult addCut(unsigned row);
462+
bool addCut(unsigned row);
468463

469464
/// Undo the addition of the last constraint. This is only called while
470465
/// rolling back.
@@ -516,7 +511,7 @@ class LexSimplex : public LexSimplexBase {
516511
MaybeOptimum<SmallVector<Fraction, 8>> getRationalSample() const;
517512

518513
/// Make the tableau configuration consistent.
519-
LogicalResult restoreRationalConsistency();
514+
bool restoreRationalConsistency();
520515

521516
/// Return whether the specified row is violated;
522517
bool rowIsViolated(unsigned row) const;
@@ -631,7 +626,7 @@ class SymbolicLexSimplex : public LexSimplexBase {
631626
/// Return failure if the tableau became empty, indicating that the polytope
632627
/// is always integer empty in the current symbol domain.
633628
/// Return success otherwise.
634-
LogicalResult doNonBranchingPivots();
629+
bool doNonBranchingPivots();
635630

636631
/// Get a row that is always violated in the current domain, if one exists.
637632
std::optional<unsigned> maybeGetAlwaysViolatedRow();
@@ -652,7 +647,7 @@ class SymbolicLexSimplex : public LexSimplexBase {
652647
/// at the time of the call. (This function may modify the symbol domain, but
653648
/// failure statu indicates that the polytope was empty for all symbol values
654649
/// in the initial domain.)
655-
LogicalResult addSymbolicCut(unsigned row);
650+
bool addSymbolicCut(unsigned row);
656651

657652
/// Get the numerator of the symbolic sample of the specific row.
658653
/// This is an affine expression in the symbols with integer coefficients.
@@ -825,7 +820,7 @@ class Simplex : public SimplexBase {
825820
///
826821
/// Returns success if the unknown was successfully restored to a non-negative
827822
/// sample value, failure otherwise.
828-
LogicalResult restoreRow(Unknown &u);
823+
bool restoreRow(Unknown &u);
829824

830825
/// Find a pivot to change the sample value of row in the specified
831826
/// direction while preserving tableau consistency, except that if the

mlir/include/mlir/Analysis/Presburger/Utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
#ifndef MLIR_ANALYSIS_PRESBURGER_UTILS_H
1414
#define MLIR_ANALYSIS_PRESBURGER_UTILS_H
1515

16-
#include "mlir/Support/LLVM.h"
16+
#include "mlir/Analysis/Presburger/Matrix.h"
1717
#include "llvm/ADT/DynamicAPInt.h"
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/ADT/SmallBitVector.h"
20-
21-
#include "mlir/Analysis/Presburger/Matrix.h"
2220
#include <optional>
2321

2422
namespace mlir {

mlir/lib/Analysis/FlatLinearValueConstraints.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "mlir/IR/Builders.h"
1717
#include "mlir/IR/IntegerSet.h"
1818
#include "mlir/Support/LLVM.h"
19+
#include "mlir/Support/LogicalResult.h"
1920
#include "llvm/ADT/STLExtras.h"
2021
#include "llvm/ADT/SmallPtrSet.h"
2122
#include "llvm/ADT/SmallVector.h"
@@ -1247,10 +1248,10 @@ LogicalResult FlatLinearValueConstraints::unionBoundingBox(
12471248
if (!areVarsAligned(*this, otherCst)) {
12481249
FlatLinearValueConstraints otherCopy(otherCst);
12491250
mergeAndAlignVars(/*offset=*/getNumDimVars(), this, &otherCopy);
1250-
return IntegerPolyhedron::unionBoundingBox(otherCopy);
1251+
return success(IntegerPolyhedron::unionBoundingBox(otherCopy));
12511252
}
12521253

1253-
return IntegerPolyhedron::unionBoundingBox(otherCst);
1254+
return success(IntegerPolyhedron::unionBoundingBox(otherCst));
12541255
}
12551256

12561257
//===----------------------------------------------------------------------===//

mlir/lib/Analysis/Presburger/Barvinok.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "mlir/Analysis/Presburger/Utils.h"
1111
#include "llvm/ADT/Sequence.h"
1212
#include <algorithm>
13-
#include <bitset>
1413

1514
using namespace mlir;
1615
using namespace presburger;

mlir/lib/Analysis/Presburger/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@ add_mlir_library(MLIRPresburger
88
PWMAFunction.cpp
99
QuasiPolynomial.cpp
1010
Simplex.cpp
11-
Utils.cpp
12-
13-
LINK_LIBS PUBLIC
14-
MLIRSupport
15-
)
11+
Utils.cpp)

mlir/lib/Analysis/Presburger/IntegerRelation.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "mlir/Analysis/Presburger/PresburgerSpace.h"
2121
#include "mlir/Analysis/Presburger/Simplex.h"
2222
#include "mlir/Analysis/Presburger/Utils.h"
23-
#include "mlir/Support/LLVM.h"
24-
#include "mlir/Support/LogicalResult.h"
2523
#include "llvm/ADT/DenseMap.h"
2624
#include "llvm/ADT/DenseSet.h"
2725
#include "llvm/ADT/STLExtras.h"
@@ -1554,22 +1552,22 @@ static int findEqualityToConstant(const IntegerRelation &cst, unsigned pos,
15541552
return -1;
15551553
}
15561554

1557-
LogicalResult IntegerRelation::constantFoldVar(unsigned pos) {
1555+
bool IntegerRelation::constantFoldVar(unsigned pos) {
15581556
assert(pos < getNumVars() && "invalid position");
15591557
int rowIdx;
15601558
if ((rowIdx = findEqualityToConstant(*this, pos)) == -1)
1561-
return failure();
1559+
return false;
15621560

15631561
// atEq(rowIdx, pos) is either -1 or 1.
15641562
assert(atEq(rowIdx, pos) * atEq(rowIdx, pos) == 1);
15651563
DynamicAPInt constVal = -atEq(rowIdx, getNumCols() - 1) / atEq(rowIdx, pos);
15661564
setAndEliminate(pos, constVal);
1567-
return success();
1565+
return true;
15681566
}
15691567

15701568
void IntegerRelation::constantFoldVarRange(unsigned pos, unsigned num) {
15711569
for (unsigned s = pos, t = pos, e = pos + num; s < e; s++) {
1572-
if (failed(constantFoldVar(t)))
1570+
if (!constantFoldVar(t))
15731571
t++;
15741572
}
15751573
}
@@ -1946,9 +1944,9 @@ void IntegerRelation::fourierMotzkinEliminate(unsigned pos, bool darkShadow,
19461944
for (unsigned r = 0, e = getNumEqualities(); r < e; r++) {
19471945
if (atEq(r, pos) != 0) {
19481946
// Use Gaussian elimination here (since we have an equality).
1949-
LogicalResult ret = gaussianEliminateVar(pos);
1947+
bool ret = gaussianEliminateVar(pos);
19501948
(void)ret;
1951-
assert(succeeded(ret) && "Gaussian elimination guaranteed to succeed");
1949+
assert(ret && "Gaussian elimination guaranteed to succeed");
19521950
LLVM_DEBUG(llvm::dbgs() << "FM output (through Gaussian elimination):\n");
19531951
LLVM_DEBUG(dump());
19541952
return;
@@ -2175,8 +2173,7 @@ static void getCommonConstraints(const IntegerRelation &a,
21752173

21762174
// Computes the bounding box with respect to 'other' by finding the min of the
21772175
// lower bounds and the max of the upper bounds along each of the dimensions.
2178-
LogicalResult
2179-
IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) {
2176+
bool IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) {
21802177
assert(space.isEqual(otherCst.getSpace()) && "Spaces should match.");
21812178
assert(getNumLocalVars() == 0 && "local ids not supported yet here");
21822179

@@ -2204,13 +2201,13 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) {
22042201
if (!extent.has_value())
22052202
// TODO: symbolic extents when necessary.
22062203
// TODO: handle union if a dimension is unbounded.
2207-
return failure();
2204+
return false;
22082205

22092206
auto otherExtent = otherCst.getConstantBoundOnDimSize(
22102207
d, &otherLb, &otherLbFloorDivisor, &otherUb);
22112208
if (!otherExtent.has_value() || lbFloorDivisor != otherLbFloorDivisor)
22122209
// TODO: symbolic extents when necessary.
2213-
return failure();
2210+
return false;
22142211

22152212
assert(lbFloorDivisor > 0 && "divisor always expected to be positive");
22162213

@@ -2230,7 +2227,7 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) {
22302227
auto constLb = getConstantBound(BoundType::LB, d);
22312228
auto constOtherLb = otherCst.getConstantBound(BoundType::LB, d);
22322229
if (!constLb.has_value() || !constOtherLb.has_value())
2233-
return failure();
2230+
return false;
22342231
std::fill(minLb.begin(), minLb.end(), 0);
22352232
minLb.back() = std::min(*constLb, *constOtherLb);
22362233
}
@@ -2246,7 +2243,7 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) {
22462243
auto constUb = getConstantBound(BoundType::UB, d);
22472244
auto constOtherUb = otherCst.getConstantBound(BoundType::UB, d);
22482245
if (!constUb.has_value() || !constOtherUb.has_value())
2249-
return failure();
2246+
return false;
22502247
std::fill(maxUb.begin(), maxUb.end(), 0);
22512248
maxUb.back() = std::max(*constUb, *constOtherUb);
22522249
}
@@ -2284,7 +2281,7 @@ IntegerRelation::unionBoundingBox(const IntegerRelation &otherCst) {
22842281
// union (since the above are just the union along dimensions); we shouldn't
22852282
// be discarding any other constraints on the symbols.
22862283

2287-
return success();
2284+
return true;
22882285
}
22892286

22902287
bool IntegerRelation::isColZero(unsigned pos) const {

mlir/lib/Analysis/Presburger/LinearTransform.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "mlir/Analysis/Presburger/LinearTransform.h"
1010
#include "mlir/Analysis/Presburger/IntegerRelation.h"
1111
#include "mlir/Analysis/Presburger/Matrix.h"
12-
#include "mlir/Support/LLVM.h"
1312
#include <utility>
1413

1514
using namespace mlir;

mlir/lib/Analysis/Presburger/Matrix.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "mlir/Analysis/Presburger/Matrix.h"
1010
#include "mlir/Analysis/Presburger/Fraction.h"
1111
#include "mlir/Analysis/Presburger/Utils.h"
12-
#include "mlir/Support/LLVM.h"
1312
#include "llvm/Support/MathExtras.h"
1413
#include "llvm/Support/raw_ostream.h"
1514
#include <algorithm>

mlir/lib/Analysis/Presburger/PWMAFunction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "mlir/Analysis/Presburger/PresburgerRelation.h"
1212
#include "mlir/Analysis/Presburger/PresburgerSpace.h"
1313
#include "mlir/Analysis/Presburger/Utils.h"
14-
#include "mlir/Support/LLVM.h"
1514
#include "llvm/ADT/STLExtras.h"
1615
#include "llvm/ADT/STLFunctionalExtras.h"
1716
#include "llvm/ADT/SmallVector.h"

0 commit comments

Comments
 (0)