Skip to content

Commit 7421695

Browse files
[mlir][Interfaces] ValueBoundsConstraintSet: Add dump helper function
This commit adds a helper function that dumps the constraint set and the mapping of columns to values/dims. For debugging only. Example output: ``` Columns: column dim value owner 0 1 linalg.fill 1 1 tensor.extract_slice 2 n/a affine.min 3 n/a scf.for 4 n/a func.func Constraint set: Domain: 0, Range: 1, Symbols: 4, Locals: 0 6 constraints (None None None None None const) 1 -1 0 0 0 0 = 0 0 1 -1 0 0 0 = 0 0 0 -1 -1 1 0 >= 0 0 0 -1 0 0 4 >= 0 0 0 0 1 0 0 >= 0 0 0 0 -1 1 -1 >= 0 ```
1 parent 6f44bb7 commit 7421695

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ class ValueBoundsConstraintSet
259259
/// Return an expression that represents a constant.
260260
AffineExpr getExpr(int64_t constant);
261261

262+
/// Debugging only: Dump the constraint set and the column-to-value/dim
263+
/// mapping to llvm::errs.
264+
void dump() const;
265+
262266
protected:
263267
/// Dimension identifier to indicate a value is index-typed. This is used for
264268
/// internal data structures/API only.

mlir/lib/Interfaces/ValueBoundsOpInterface.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,35 @@ ValueBoundsConstraintSet::areEquivalentSlices(MLIRContext *ctx,
715715
return true;
716716
}
717717

718+
void ValueBoundsConstraintSet::dump() const {
719+
llvm::errs() << "==========\nColumns:\n";
720+
llvm::errs() << "(column\tdim\tvalue)\n";
721+
for (auto it : llvm::enumerate(positionToValueDim)) {
722+
llvm::errs() << " " << it.index() << "\t";
723+
if (auto valueDim = it.value()) {
724+
if (valueDim->second == kIndexValue) {
725+
llvm::errs() << "n/a\t";
726+
} else {
727+
llvm::errs() << valueDim->second << "\t";
728+
}
729+
llvm::errs() << getOwnerOfValue(valueDim->first)->getName() << " ";
730+
if (OpResult result = dyn_cast<OpResult>(valueDim->first)) {
731+
llvm::errs() << "(result " << result.getResultNumber() << ")";
732+
} else {
733+
llvm::errs() << "(bbarg "
734+
<< cast<BlockArgument>(valueDim->first).getArgNumber()
735+
<< ")";
736+
}
737+
llvm::errs() << "\n";
738+
} else {
739+
llvm::errs() << "n/a\tn/a\n";
740+
}
741+
}
742+
llvm::errs() << "\nConstraint set:\n";
743+
cstr.dump();
744+
llvm::errs() << "==========\n";
745+
}
746+
718747
ValueBoundsConstraintSet::BoundBuilder &
719748
ValueBoundsConstraintSet::BoundBuilder::operator[](int64_t dim) {
720749
assert(!this->dim.has_value() && "dim was already set");

0 commit comments

Comments
 (0)