[Mlir-commits] [mlir] [mlir][Interfaces] `ValueBoundsConstraintSet`: Add `dump` helper function (PR #86634)

Matthias Springer llvmlistbot at llvm.org
Mon Mar 25 23:46:01 PDT 2024


https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/86634

>From 74216957c62dbd90fefe1e226c5cbabfd60b8398 Mon Sep 17 00:00:00 2001
From: Matthias Springer <springerm at google.com>
Date: Tue, 26 Mar 2024 06:44:57 +0000
Subject: [PATCH] [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

```
---
 .../mlir/Interfaces/ValueBoundsOpInterface.h  |  4 +++
 .../lib/Interfaces/ValueBoundsOpInterface.cpp | 29 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h b/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
index b4ed0967e63f18..bdfd689c7ac4f3 100644
--- a/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
+++ b/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
@@ -259,6 +259,10 @@ class ValueBoundsConstraintSet
   /// Return an expression that represents a constant.
   AffineExpr getExpr(int64_t constant);
 
+  /// Debugging only: Dump the constraint set and the column-to-value/dim
+  /// mapping to llvm::errs.
+  void dump() const;
+
 protected:
   /// Dimension identifier to indicate a value is index-typed. This is used for
   /// internal data structures/API only.
diff --git a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
index 06ec3f4e135e9f..f87bdc534e3160 100644
--- a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
+++ b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
@@ -715,6 +715,35 @@ ValueBoundsConstraintSet::areEquivalentSlices(MLIRContext *ctx,
   return true;
 }
 
+void ValueBoundsConstraintSet::dump() const {
+  llvm::errs() << "==========\nColumns:\n";
+  llvm::errs() << "(column\tdim\tvalue)\n";
+  for (auto it : llvm::enumerate(positionToValueDim)) {
+    llvm::errs() << " " << it.index() << "\t";
+    if (auto valueDim = it.value()) {
+      if (valueDim->second == kIndexValue) {
+        llvm::errs() << "n/a\t";
+      } else {
+        llvm::errs() << valueDim->second << "\t";
+      }
+      llvm::errs() << getOwnerOfValue(valueDim->first)->getName() << " ";
+      if (OpResult result = dyn_cast<OpResult>(valueDim->first)) {
+        llvm::errs() << "(result " << result.getResultNumber() << ")";
+      } else {
+        llvm::errs() << "(bbarg "
+                     << cast<BlockArgument>(valueDim->first).getArgNumber()
+                     << ")";
+      }
+      llvm::errs() << "\n";
+    } else {
+      llvm::errs() << "n/a\tn/a\n";
+    }
+  }
+  llvm::errs() << "\nConstraint set:\n";
+  cstr.dump();
+  llvm::errs() << "==========\n";
+}
+
 ValueBoundsConstraintSet::BoundBuilder &
 ValueBoundsConstraintSet::BoundBuilder::operator[](int64_t dim) {
   assert(!this->dim.has_value() && "dim was already set");



More information about the Mlir-commits mailing list