Skip to content

mlir/Presburger: thoroughly guard debug-print #95247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/include/mlir/Analysis/FlatLinearValueConstraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ class FlatLinearConstraints : public presburger::IntegerPolyhedron {
AffineMap map, std::vector<SmallVector<int64_t, 8>> *flattenedExprs,
bool addConservativeSemiAffineBounds = false);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Prints the number of constraints, dimensions, symbols and locals in the
/// FlatLinearConstraints. Also, prints for each variable whether there is
/// an SSA Value attached to it.
void printSpace(raw_ostream &os) const override;
#endif
};

/// FlatLinearValueConstraints represents an extension of FlatLinearConstraints
Expand Down Expand Up @@ -432,10 +434,12 @@ class FlatLinearValueConstraints : public FlatLinearConstraints {
void projectOut(Value val);
using IntegerPolyhedron::projectOut;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Prints the number of constraints, dimensions, symbols and locals in the
/// FlatAffineValueConstraints. Also, prints for each variable whether there
/// is an SSA Value attached to it.
void printSpace(raw_ostream &os) const override;
#endif

/// Align `map` with this constraint system based on `operands`. Each operand
/// must already have a corresponding dim/symbol in this constraint system.
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class GeneratingFunction {
sumDenominators);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
llvm::raw_ostream &print(llvm::raw_ostream &os) const {
for (unsigned i = 0, e = signs.size(); i < e; i++) {
if (i == 0) {
Expand Down Expand Up @@ -124,6 +125,7 @@ class GeneratingFunction {
}
return os;
}
#endif

private:
unsigned numParam;
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,10 @@ class IntegerRelation {
// false.
bool isFullDim();

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(raw_ostream &os) const;
void dump() const;
#endif

protected:
/// Checks all rows of equality/inequality constraints for trivial
Expand Down Expand Up @@ -834,9 +836,11 @@ class IntegerRelation {
/// is meant to be used within an assert internally.
virtual bool hasConsistentState() const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Prints the number of constraints, dimensions, symbols and locals in the
/// IntegerRelation.
virtual void printSpace(raw_ostream &os) const;
#endif

/// Removes variables in the column range [varStart, varLimit), and copies any
/// remaining valid data into place, updates member variables, and resizes
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ class Matrix {
/// corresponding to 2.
std::pair<Matrix<T>, Matrix<T>> splitByBitset(ArrayRef<int> indicator);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the matrix.
void print(raw_ostream &os) const;
void dump() const;
#endif

/// Return whether the Matrix is in a consistent state with all its
/// invariants satisfied.
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ class MultiAffineFunction {
/// Get this function as a relation.
IntegerRelation getAsRelation() const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(raw_ostream &os) const;
void dump() const;
#endif

private:
/// Assert that the MAF is consistent.
Expand Down Expand Up @@ -220,8 +222,10 @@ class PWMAFunction {
PWMAFunction unionLexMin(const PWMAFunction &func);
PWMAFunction unionLexMax(const PWMAFunction &func);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(raw_ostream &os) const;
void dump() const;
#endif

private:
/// Return a function defined on the union of the domains of `this` and
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@ class PresburgerRelation {
/// dimensional we mean that it is not flat along any dimension.
bool isFullDim() const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the set's internal state.
void print(raw_ostream &os) const;
void dump() const;
#endif

protected:
/// Construct an empty PresburgerRelation with the specified number of
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ class Identifier {
bool operator==(const Identifier &other) const { return isEqual(other); }
bool operator!=(const Identifier &other) const { return !isEqual(other); }

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(llvm::raw_ostream &os) const;
void dump() const;
#endif

private:
/// The value of the identifier.
Expand Down Expand Up @@ -308,8 +310,10 @@ class PresburgerSpace {
/// the same identifiers in the same order.
void mergeAndAlignSymbols(PresburgerSpace &other);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(llvm::raw_ostream &os) const;
void dump() const;
#endif

protected:
PresburgerSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols,
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/Simplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ class SimplexBase {
/// Add all the constraints from the given IntegerRelation.
void intersectIntegerRelation(const IntegerRelation &rel);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the tableau's internal state.
void print(raw_ostream &os) const;
void dump() const;
#endif

protected:
/// Construct a SimplexBase with the specified number of variables and fixed
Expand Down Expand Up @@ -246,12 +248,14 @@ class SimplexBase {
bool restricted : 1;
bool isSymbol : 1;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(raw_ostream &os) const {
os << (orientation == Orientation::Row ? "r" : "c");
os << pos;
if (restricted)
os << " [>=0]";
}
#endif
};

struct Pivot {
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Analysis/Presburger/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ class DivisionRepr {
void
removeDuplicateDivs(llvm::function_ref<bool(unsigned i, unsigned j)> merge);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(raw_ostream &os) const;
void dump() const;
#endif

private:
/// Each row of the Matrix represents a single division dividend. The
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ class ValueBoundsConstraintSet
/// Return an expression that represents a constant.
AffineExpr getExpr(int64_t constant);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Debugging only: Dump the constraint set and the column-to-value/dim
/// mapping to llvm::errs.
void dump() const;
#endif

protected:
/// Dimension identifier to indicate a value is index-typed. This is used for
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Analysis/FlatLinearValueConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@ void FlatLinearValueConstraints::addBound(BoundType type, Value val,
addBound(type, pos, value);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void FlatLinearConstraints::printSpace(raw_ostream &os) const {
IntegerPolyhedron::printSpace(os);
os << "(";
Expand Down Expand Up @@ -1221,6 +1222,7 @@ void FlatLinearValueConstraints::printSpace(raw_ostream &os) const {
os << "Local\t";
os << "const)\n";
}
#endif

void FlatLinearValueConstraints::projectOut(Value val) {
unsigned pos;
Expand Down
13 changes: 7 additions & 6 deletions mlir/lib/Analysis/Presburger/IntegerRelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2500,11 +2500,6 @@ void IntegerRelation::applyDomain(const IntegerRelation &rel) {

void IntegerRelation::applyRange(const IntegerRelation &rel) { compose(rel); }

void IntegerRelation::printSpace(raw_ostream &os) const {
space.print(os);
os << getNumConstraints() << " constraints\n";
}

void IntegerRelation::removeTrivialEqualities() {
for (int i = getNumEqualities() - 1; i >= 0; --i)
if (rangeIsZero(getEquality(i)))
Expand Down Expand Up @@ -2589,6 +2584,12 @@ void IntegerRelation::mergeAndCompose(const IntegerRelation &other) {
*this = result;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void IntegerRelation::printSpace(raw_ostream &os) const {
space.print(os);
os << getNumConstraints() << " constraints\n";
}

void IntegerRelation::print(raw_ostream &os) const {
assert(hasConsistentState());
printSpace(os);
Expand All @@ -2610,7 +2611,7 @@ void IntegerRelation::print(raw_ostream &os) const {
}

void IntegerRelation::dump() const { print(llvm::errs()); }

#endif
unsigned IntegerPolyhedron::insertVar(VarKind kind, unsigned pos,
unsigned num) {
assert((kind != VarKind::Domain || num == 0) &&
Expand Down
12 changes: 7 additions & 5 deletions mlir/lib/Analysis/Presburger/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ Matrix<T> Matrix<T>::getSubMatrix(unsigned fromRow, unsigned toRow,
return subMatrix;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
template <typename T>
void Matrix<T>::print(raw_ostream &os) const {
for (unsigned row = 0; row < nRows; ++row) {
Expand All @@ -406,6 +407,12 @@ void Matrix<T>::print(raw_ostream &os) const {
}
}

template <typename T>
void Matrix<T>::dump() const {
print(llvm::errs());
}
#endif

/// We iterate over the `indicator` bitset, checking each bit. If a bit is 1,
/// we append it to one matrix, and if it is zero, we append it to the other.
template <typename T>
Expand All @@ -421,11 +428,6 @@ Matrix<T>::splitByBitset(ArrayRef<int> indicator) {
return {rowsForOne, rowsForZero};
}

template <typename T>
void Matrix<T>::dump() const {
print(llvm::errs());
}

template <typename T>
bool Matrix<T>::hasConsistentState() const {
if (data.size() != nRows * nReservedColumns)
Expand Down
4 changes: 4 additions & 0 deletions mlir/lib/Analysis/Presburger/PWMAFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ PresburgerSet PWMAFunction::getDomain() const {
return domain;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MultiAffineFunction::print(raw_ostream &os) const {
space.print(os);
os << "Division Representation:\n";
divs.print(os);
os << "Output:\n";
output.print(os);
}
#endif

SmallVector<DynamicAPInt, 8>
MultiAffineFunction::valueAt(ArrayRef<DynamicAPInt> point) const {
Expand Down Expand Up @@ -299,6 +301,7 @@ void PWMAFunction::addPiece(const Piece &piece) {
pieces.push_back(piece);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void PWMAFunction::print(raw_ostream &os) const {
space.print(os);
os << getNumPieces() << " pieces:\n";
Expand All @@ -311,6 +314,7 @@ void PWMAFunction::print(raw_ostream &os) const {
}

void PWMAFunction::dump() const { print(llvm::errs()); }
#endif

PWMAFunction PWMAFunction::unionFunction(
const PWMAFunction &func,
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ bool PresburgerRelation::isFullDim() const {
});
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void PresburgerRelation::print(raw_ostream &os) const {
os << "Number of Disjuncts: " << getNumDisjuncts() << "\n";
for (const IntegerRelation &disjunct : disjuncts) {
Expand All @@ -1058,6 +1059,7 @@ void PresburgerRelation::print(raw_ostream &os) const {
}

void PresburgerRelation::dump() const { print(llvm::errs()); }
#endif

PresburgerSet PresburgerSet::getUniverse(const PresburgerSpace &space) {
PresburgerSet result(space);
Expand Down
4 changes: 4 additions & 0 deletions mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bool Identifier::isEqual(const Identifier &other) const {
return value == other.value;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void Identifier::print(llvm::raw_ostream &os) const {
os << "Id<" << value << ">";
}
Expand All @@ -32,6 +33,7 @@ void Identifier::dump() const {
print(llvm::errs());
llvm::errs() << "\n";
}
#endif

PresburgerSpace PresburgerSpace::getDomainSpace() const {
PresburgerSpace newSpace = *this;
Expand Down Expand Up @@ -324,6 +326,7 @@ void PresburgerSpace::mergeAndAlignSymbols(PresburgerSpace &other) {
}
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void PresburgerSpace::print(llvm::raw_ostream &os) const {
os << "Domain: " << getNumDomainVars() << ", "
<< "Range: " << getNumRangeVars() << ", "
Expand Down Expand Up @@ -356,3 +359,4 @@ void PresburgerSpace::dump() const {
print(llvm::errs());
llvm::errs() << "\n";
}
#endif
2 changes: 2 additions & 0 deletions mlir/lib/Analysis/Presburger/Simplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,7 @@ bool Simplex::isFlatAlong(ArrayRef<DynamicAPInt> coeffs) {
return *upOpt == *downOpt;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void SimplexBase::print(raw_ostream &os) const {
os << "rows = " << getNumRows() << ", columns = " << getNumColumns() << "\n";
if (empty)
Expand Down Expand Up @@ -2157,6 +2158,7 @@ void SimplexBase::print(raw_ostream &os) const {
}

void SimplexBase::dump() const { print(llvm::errs()); }
#endif

bool Simplex::isRationalSubsetOf(const IntegerRelation &rel) {
if (isEmpty())
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Analysis/Presburger/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ void DivisionRepr::insertDiv(unsigned pos, unsigned num) {
denoms.insert(denoms.begin() + pos, num, DynamicAPInt(0));
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void DivisionRepr::print(raw_ostream &os) const {
os << "Dividends:\n";
dividends.print(os);
Expand All @@ -523,6 +524,7 @@ void DivisionRepr::print(raw_ostream &os) const {
}

void DivisionRepr::dump() const { print(llvm::errs()); }
#endif

SmallVector<DynamicAPInt, 8>
presburger::getDynamicAPIntVec(ArrayRef<int64_t> range) {
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ ValueBoundsConstraintSet::areEquivalentSlices(MLIRContext *ctx,
return true;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void ValueBoundsConstraintSet::dump() const {
llvm::errs() << "==========\nColumns:\n";
llvm::errs() << "(column\tdim\tvalue)\n";
Expand Down Expand Up @@ -909,6 +910,7 @@ void ValueBoundsConstraintSet::dump() const {
cstr.dump();
llvm::errs() << "==========\n";
}
#endif

ValueBoundsConstraintSet::BoundBuilder &
ValueBoundsConstraintSet::BoundBuilder::operator[](int64_t dim) {
Expand Down
Loading
Loading