[Mlir-commits] [mlir] 4d787f3 - [mlir] Mark dump() methods with LLVM_DUMP_METHOD (#233398)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Oct 30 01:58:52 PDT 2026


Author: Andrei Golubev
Date: 2026-10-30T09:58:44+01:00
New Revision: 4d787f35aaba8bdb234674188dce2b27f567b798

URL: https://github.com/llvm/llvm-project/commit/4d787f35aaba8bdb234674188dce2b27f567b798
DIFF: https://github.com/llvm/llvm-project/commit/4d787f35aaba8bdb234674188dce2b27f567b798.diff

LOG: [mlir] Mark dump() methods with LLVM_DUMP_METHOD (#233398)

LLVM_DUMP_METHOD is a macro that helps to prevent symbol elimination
from the binary. In practice, user builds might force stripping of
"unused symbols" and dead code via compiler/linker flags. For "probably
unused" symbols such as ::dump() methods, this would mean that they
disappear from the binary and can no longer be used e.g. in a debugger
session.

Note: dump() methods of MLIR classes are now wrapped into `#if
!defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` meaning the methods exist
only in debug builds or when LLVM_ENABLE_DUMP is set (e.g. at CMake
level). Non-debug callers of dump() methods are changed to use print()
instead.

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Builder/FIRBuilder.h
    flang/lib/Optimizer/Builder/FIRBuilder.cpp
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp
    mlir/examples/toy/Ch2/toyc.cpp
    mlir/examples/toy/Ch3/toyc.cpp
    mlir/examples/toy/Ch4/toyc.cpp
    mlir/examples/toy/Ch5/toyc.cpp
    mlir/examples/toy/Ch6/toyc.cpp
    mlir/examples/toy/Ch7/toyc.cpp
    mlir/examples/transform-opt/mlir-transform-opt.cpp
    mlir/include/mlir/Analysis/CallGraph.h
    mlir/include/mlir/Analysis/Liveness.h
    mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
    mlir/include/mlir/Analysis/Presburger/Matrix.h
    mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
    mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
    mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
    mlir/include/mlir/Analysis/Presburger/Simplex.h
    mlir/include/mlir/Analysis/Presburger/Utils.h
    mlir/include/mlir/Debug/ExecutionContext.h
    mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
    mlir/include/mlir/IR/AffineExpr.h
    mlir/include/mlir/IR/AffineMap.h
    mlir/include/mlir/IR/Attributes.h
    mlir/include/mlir/IR/Block.h
    mlir/include/mlir/IR/IntegerSet.h
    mlir/include/mlir/IR/Location.h
    mlir/include/mlir/IR/OpDefinition.h
    mlir/include/mlir/IR/Operation.h
    mlir/include/mlir/IR/OperationSupport.h
    mlir/include/mlir/IR/Types.h
    mlir/include/mlir/IR/Value.h
    mlir/include/mlir/Interfaces/InferTypeOpInterface.h
    mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
    mlir/include/mlir/Pass/PassManager.h
    mlir/lib/Analysis/CallGraph.cpp
    mlir/lib/Analysis/Liveness.cpp
    mlir/lib/Analysis/Presburger/IntegerRelation.cpp
    mlir/lib/Analysis/Presburger/Matrix.cpp
    mlir/lib/Analysis/Presburger/PWMAFunction.cpp
    mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
    mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
    mlir/lib/Analysis/Presburger/Simplex.cpp
    mlir/lib/Analysis/Presburger/Utils.cpp
    mlir/lib/CAPI/IR/AffineExpr.cpp
    mlir/lib/CAPI/IR/AffineMap.cpp
    mlir/lib/CAPI/IR/IR.cpp
    mlir/lib/CAPI/IR/IntegerSet.cpp
    mlir/lib/Conversion/SPIRVCommon/Pattern.h
    mlir/lib/Debug/ExecutionContext.cpp
    mlir/lib/Dialect/Affine/Analysis/Utils.cpp
    mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
    mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
    mlir/lib/IR/AsmPrinter.cpp
    mlir/lib/IR/Location.cpp
    mlir/lib/IR/Operation.cpp
    mlir/lib/Interfaces/InferTypeOpInterface.cpp
    mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
    mlir/lib/Pass/Pass.cpp
    mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
    mlir/lib/Transforms/PrintIR.cpp
    mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index 92ec7ba14272a0..75c07c278054bc 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -692,8 +692,10 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
     return fpMaxminBehavior;
   }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   /// Dump the current function. (debug)
   LLVM_DUMP_METHOD void dumpFunc();
+#endif
 
   /// FirOpBuilder hook for creating new operation.
   void notifyOperationInserted(mlir::Operation *op,

diff  --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index 328304ffb582b7..f0cb10f8177621 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -878,7 +878,9 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc, mlir::Type boxType,
       tdesc);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void fir::FirOpBuilder::dumpFunc() { getFunction().dump(); }
+#endif
 
 static mlir::Value
 genNullPointerComparison(fir::FirOpBuilder &builder, mlir::Location loc,

diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 43c23ba28fa9e7..0bf9e27ecbdf3f 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -3499,7 +3499,6 @@ IntrinsicLibrary::genChdir(std::optional<mlir::Type> resultType,
     // Subroutine form, store status and return none.
     if (!isStaticallyAbsent(args[1])) {
       mlir::Value statusAddr = fir::getBase(args[1]);
-      statusAddr.dump();
       mlir::Value statusIsPresentAtRuntime =
           builder.genIsNotNullAddr(loc, statusAddr);
       builder.genIfThen(loc, statusIsPresentAtRuntime)

diff  --git a/mlir/examples/toy/Ch2/toyc.cpp b/mlir/examples/toy/Ch2/toyc.cpp
index a60738da9d4aeb..4f74d0b6950993 100644
--- a/mlir/examples/toy/Ch2/toyc.cpp
+++ b/mlir/examples/toy/Ch2/toyc.cpp
@@ -87,7 +87,7 @@ static int dumpMLIR() {
     if (!module)
       return 1;
 
-    module->dump();
+    module->print(llvm::errs());
     return 0;
   }
 
@@ -109,7 +109,7 @@ static int dumpMLIR() {
     return 3;
   }
 
-  module->dump();
+  module->print(llvm::errs());
   return 0;
 }
 

diff  --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp
index 3094935567d94c..2ba02f9784ea2a 100644
--- a/mlir/examples/toy/Ch3/toyc.cpp
+++ b/mlir/examples/toy/Ch3/toyc.cpp
@@ -131,7 +131,7 @@ static int dumpMLIR() {
       return 4;
   }
 
-  module->dump();
+  module->print(llvm::errs());
   return 0;
 }
 

diff  --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp
index 36816f0327deeb..8cb211cfff3c94 100644
--- a/mlir/examples/toy/Ch4/toyc.cpp
+++ b/mlir/examples/toy/Ch4/toyc.cpp
@@ -140,7 +140,7 @@ static int dumpMLIR() {
       return 4;
   }
 
-  module->dump();
+  module->print(llvm::errs());
   return 0;
 }
 

diff  --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp
index d62a1c0042f625..b89669210e07fd 100644
--- a/mlir/examples/toy/Ch5/toyc.cpp
+++ b/mlir/examples/toy/Ch5/toyc.cpp
@@ -168,7 +168,7 @@ static int dumpMLIR() {
   if (mlir::failed(pm.run(*module)))
     return 4;
 
-  module->dump();
+  module->print(llvm::errs());
   return 0;
 }
 

diff  --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp
index cfc10a7259180f..0f854eb1ed86ab 100644
--- a/mlir/examples/toy/Ch6/toyc.cpp
+++ b/mlir/examples/toy/Ch6/toyc.cpp
@@ -315,7 +315,7 @@ int main(int argc, char **argv) {
   // If we aren't exporting to non-mlir, then we are done.
   bool isOutputingMLIR = emitAction <= Action::DumpMLIRLLVM;
   if (isOutputingMLIR) {
-    module->dump();
+    module->print(llvm::errs());
     return 0;
   }
 

diff  --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp
index ffd94bc8f71778..03c90b1ee373b8 100644
--- a/mlir/examples/toy/Ch7/toyc.cpp
+++ b/mlir/examples/toy/Ch7/toyc.cpp
@@ -316,7 +316,7 @@ int main(int argc, char **argv) {
   // If we aren't exporting to non-mlir, then we are done.
   bool isOutputingMLIR = emitAction <= Action::DumpMLIRLLVM;
   if (isOutputingMLIR) {
-    module->dump();
+    module->print(llvm::errs());
     return 0;
   }
 

diff  --git a/mlir/examples/transform-opt/mlir-transform-opt.cpp b/mlir/examples/transform-opt/mlir-transform-opt.cpp
index 4b12e7610d0a8f..fcadf1af69c575 100644
--- a/mlir/examples/transform-opt/mlir-transform-opt.cpp
+++ b/mlir/examples/transform-opt/mlir-transform-opt.cpp
@@ -308,8 +308,9 @@ static llvm::LogicalResult processPayloadBuffer(
   }
 
   // If requested, dump the combined transform module.
-  if (clOptions->dumpLibraryModule)
-    transformRoot->dump();
+  if (clOptions->dumpLibraryModule) {
+    transformRoot->print(os);
+  }
 
   // Find the entry point symbol. Even if it had originally been in the payload
   // module, it was cloned into the transform module so only look there.

diff  --git a/mlir/include/mlir/Analysis/CallGraph.h b/mlir/include/mlir/Analysis/CallGraph.h
index 9808aea1239cfb..ad2f4d1528725f 100644
--- a/mlir/include/mlir/Analysis/CallGraph.h
+++ b/mlir/include/mlir/Analysis/CallGraph.h
@@ -208,7 +208,9 @@ class CallGraph {
   iterator end() const { return nodes.end(); }
 
   /// Dump the graph in a human readable format.
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
   void print(raw_ostream &os) const;
 
 private:

diff  --git a/mlir/include/mlir/Analysis/Liveness.h b/mlir/include/mlir/Analysis/Liveness.h
index ca4d8dfab3c919..aa51aa68373508 100644
--- a/mlir/include/mlir/Analysis/Liveness.h
+++ b/mlir/include/mlir/Analysis/Liveness.h
@@ -78,7 +78,9 @@ class Liveness {
   bool isDeadAfter(Value value, Operation *operation) const;
 
   /// Dumps the liveness information in a human readable format.
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// Dumps the liveness information to the given stream.
   void print(raw_ostream &os) const;

diff  --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
index 4b13085eceddfc..f79152f46ca73a 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
@@ -849,7 +849,9 @@ class IntegerRelation {
   bool isFullDim();
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 protected:
   /// Checks all rows of equality/inequality constraints for trivial

diff  --git a/mlir/include/mlir/Analysis/Presburger/Matrix.h b/mlir/include/mlir/Analysis/Presburger/Matrix.h
index 96afef1bd3105f..69177e7ef84d34 100644
--- a/mlir/include/mlir/Analysis/Presburger/Matrix.h
+++ b/mlir/include/mlir/Analysis/Presburger/Matrix.h
@@ -210,7 +210,9 @@ class Matrix {
 
   /// Print the matrix.
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// Return whether the Matrix is in a consistent state with all its
   /// invariants satisfied.

diff  --git a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
index fcc39bf0e0537d..99690dced87c1d 100644
--- a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
+++ b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h
@@ -110,7 +110,9 @@ class MultiAffineFunction {
   IntegerRelation getAsRelation() const;
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 private:
   /// Assert that the MAF is consistent.
@@ -221,7 +223,9 @@ class PWMAFunction {
   PWMAFunction unionLexMax(const PWMAFunction &func);
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 private:
   /// Return a function defined on the union of the domains of `this` and

diff  --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
index f7e06a6b22a95d..8c014f0007eca4 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
@@ -223,7 +223,9 @@ class PresburgerRelation {
 
   /// Print the set's internal state.
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 protected:
   /// Construct an empty PresburgerRelation with the specified number of

diff  --git a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
index c7808e72014706..8e43ec73945826 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
@@ -102,7 +102,9 @@ class Identifier {
   bool operator!=(const Identifier &other) const { return !isEqual(other); }
 
   void print(llvm::raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 private:
   /// The value of the identifier.
@@ -311,7 +313,9 @@ class PresburgerSpace {
   void mergeAndAlignSymbols(PresburgerSpace &other);
 
   void print(llvm::raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 protected:
   PresburgerSpace(unsigned numDomain, unsigned numRange, unsigned numSymbols,

diff  --git a/mlir/include/mlir/Analysis/Presburger/Simplex.h b/mlir/include/mlir/Analysis/Presburger/Simplex.h
index d89bbe37a6b3e0..e7b0fb3dbd6f4e 100644
--- a/mlir/include/mlir/Analysis/Presburger/Simplex.h
+++ b/mlir/include/mlir/Analysis/Presburger/Simplex.h
@@ -205,7 +205,9 @@ class SimplexBase {
 
   /// Print the tableau's internal state.
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 protected:
   /// Construct a SimplexBase with the specified number of variables and fixed

diff  --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h
index 0e6d18279d67ed..1e23fdcbe34153 100644
--- a/mlir/include/mlir/Analysis/Presburger/Utils.h
+++ b/mlir/include/mlir/Analysis/Presburger/Utils.h
@@ -182,7 +182,9 @@ class DivisionRepr {
   removeDuplicateDivs(llvm::function_ref<bool(unsigned i, unsigned j)> merge);
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 private:
   /// Each row of the Matrix represents a single division dividend. The

diff  --git a/mlir/include/mlir/Debug/ExecutionContext.h b/mlir/include/mlir/Debug/ExecutionContext.h
index 93c26e0ce5f82f..1d7d2fd20a8655 100644
--- a/mlir/include/mlir/Debug/ExecutionContext.h
+++ b/mlir/include/mlir/Debug/ExecutionContext.h
@@ -29,10 +29,9 @@ struct ActionActiveStack {
   const Action &getAction() const { return action; }
   int getDepth() const { return depth; }
   void print(raw_ostream &os, bool withContext) const;
-  void dump() const {
-    print(llvm::errs(), /*withContext=*/true);
-    llvm::errs() << "\n";
-  }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
   Breakpoint *getBreakpoint() const { return breakpoint; }
   void setBreakpoint(Breakpoint *breakpoint) { this->breakpoint = breakpoint; }
 

diff  --git a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
index df4145db90a616..ece440125b42cc 100644
--- a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
+++ b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
@@ -264,7 +264,9 @@ struct MemRefDependenceGraph {
 
   void print(raw_ostream &os) const;
 
-  void dump() const { print(llvm::errs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// The block for which this graph is created to perform fusion.
   Block █
@@ -372,7 +374,9 @@ struct ComputationSliceState {
   /// If the validity cannot be determined, returns std::nullopt.
   std::optional<bool> isSliceValid() const;
 
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 private:
   /// Fast check to determine if the computation slice is maximal. Returns true

diff  --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h
index 51b5e972abd41c..effa8588a8a277 100644
--- a/mlir/include/mlir/IR/AffineExpr.h
+++ b/mlir/include/mlir/IR/AffineExpr.h
@@ -87,7 +87,9 @@ class AffineExpr {
   AffineExprKind getKind() const;
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// Returns true if this expression is made out of only symbols and
   /// constants, i.e., it does not involve dimensional identifiers.

diff  --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h
index aa932e7bcda6c6..ed2041657a3dc1 100644
--- a/mlir/include/mlir/IR/AffineMap.h
+++ b/mlir/include/mlir/IR/AffineMap.h
@@ -198,7 +198,9 @@ class AffineMap {
 
   // Prints affine map to 'os'.
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   unsigned getNumDims() const;
   unsigned getNumSymbols() const;

diff  --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index a2f9c5fcda873f..54b08162b70b5c 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -63,7 +63,9 @@ class Attribute {
   /// without a trailing colon type if it has one.
   void print(raw_ostream &os, bool elideType = false) const;
   void print(raw_ostream &os, AsmState &state, bool elideType = false) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// Print the attribute without dialect wrapping.
   void printStripped(raw_ostream &os) const;

diff  --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h
index 3638595358e254..22a105c40f5fe8 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -406,7 +406,9 @@ class alignas(8) Block : public IRObjectWithUseList<BlockOperand>,
 
   void print(raw_ostream &os);
   void print(raw_ostream &os, AsmState &state);
-  void dump();
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump();
+#endif
 
   /// Print out the name of the block without printing its body.
   /// NOTE: The printType argument is ignored.  We keep it for compatibility

diff  --git a/mlir/include/mlir/IR/IntegerSet.h b/mlir/include/mlir/IR/IntegerSet.h
index 3c84131e8ecd5a..2992539d5ad3d9 100644
--- a/mlir/include/mlir/IR/IntegerSet.h
+++ b/mlir/include/mlir/IR/IntegerSet.h
@@ -103,7 +103,9 @@ class IntegerSet {
   void walkExprs(function_ref<void(AffineExpr)> callback) const;
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   friend ::llvm::hash_code hash_value(IntegerSet arg);
 

diff  --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index abc435b9b08ff2..8d78969200392f 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -95,7 +95,9 @@ class Location {
 
   /// Print the location.
   void print(raw_ostream &os) const { impl.print(os); }
-  void dump() const { impl.dump(); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   friend ::llvm::hash_code hash_value(Location arg);
 

diff  --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 38cd7da8495e19..32f757ebceaff0 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -123,7 +123,9 @@ class OpState {
   }
 
   /// Dump this operation.
-  void dump() { state->dump(); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump();
+#endif
 
   /// The source location the operation was defined or derived from.
   Location getLoc() { return state->getLoc(); }

diff  --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index 62366b67c8c1a8..fe0ffe19323bbd 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -345,7 +345,9 @@ class alignas(8) Operation final
 
   void print(raw_ostream &os, const OpPrintingFlags &flags = {});
   void print(raw_ostream &os, AsmState &state);
-  void dump();
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump();
+#endif
 
   // Dump pretty printed IR. This method is helpful for better readability if
   // the Operation is not verified because it won't disable custom printers to

diff  --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index ec0bbf94096950..1352d557c01190 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -541,7 +541,9 @@ class OperationName {
   StringAttr getIdentifier() const { return getImpl()->getName(); }
 
   void print(raw_ostream &os) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// Represent the operation name as an opaque pointer. (Used to support
   /// PointerLikeTypeTraits).

diff  --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index 70599b448f76e6..717218180b2604 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -159,7 +159,9 @@ class Type {
   /// Print the current type.
   void print(raw_ostream &os) const;
   void print(raw_ostream &os, AsmState &state) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   friend ::llvm::hash_code hash_value(Type arg);
 

diff  --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index 0f74954987c058..175f336c66ccb6 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -223,7 +223,9 @@ class Value {
   void print(raw_ostream &os) const;
   void print(raw_ostream &os, const OpPrintingFlags &flags) const;
   void print(raw_ostream &os, AsmState &state) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
   /// Print this value as if it were an operand.
   void printAsOperand(raw_ostream &os, AsmState &state) const;

diff  --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
index 1bfb66e681d8da..80760340c345ff 100644
--- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
+++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
@@ -92,7 +92,9 @@ class ShapeAdaptor {
   explicit operator bool() const { return !val.isNull(); }
 
   /// Dumps textual repesentation to stderr.
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 private:
   // Union storing either ShapedTypeComponents, ShapedType (stored as Type and

diff  --git a/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h b/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
index 50c2dfe64de2bb..89239665922e9c 100644
--- a/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
+++ b/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
@@ -353,7 +353,9 @@ class ValueBoundsConstraintSet
 
   /// Debugging only: Dump the constraint set and the column-to-value/dim
   /// mapping to llvm::errs.
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 
 protected:
   /// Dimension identifier to indicate a value is index-typed. This is used for

diff  --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h
index 0f2a2bd060acd0..6acfa6a33affde 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -148,7 +148,9 @@ class OpPassManager {
   void printAsTextualPipeline(raw_ostream &os, bool pretty = false) const;
 
   /// Raw dump of the pass manager to llvm::errs().
-  void dump();
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump();
+#endif
 
   /// Merge the pass statistics of this class into 'other'.
   void mergeStatisticsInto(OpPassManager &other);

diff  --git a/mlir/lib/Analysis/CallGraph.cpp b/mlir/lib/Analysis/CallGraph.cpp
index 4098c657f63e2a..57e56cc5e1ecb3 100644
--- a/mlir/lib/Analysis/CallGraph.cpp
+++ b/mlir/lib/Analysis/CallGraph.cpp
@@ -176,7 +176,9 @@ void CallGraph::eraseNode(CallGraphNode *node) {
 //===----------------------------------------------------------------------===//
 
 /// Dump the graph in a human readable format.
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void CallGraph::dump() const { print(llvm::errs()); }
+#endif
 void CallGraph::print(raw_ostream &os) const {
   os << "// ---- CallGraph ----\n";
 

diff  --git a/mlir/lib/Analysis/Liveness.cpp b/mlir/lib/Analysis/Liveness.cpp
index 3fcc0b5a6ffef2..5bd7cc00c9004c 100644
--- a/mlir/lib/Analysis/Liveness.cpp
+++ b/mlir/lib/Analysis/Liveness.cpp
@@ -254,7 +254,9 @@ bool Liveness::isDeadAfter(Value value, Operation *operation) const {
 }
 
 /// Dumps the liveness information in a human readable format.
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Liveness::dump() const { print(llvm::errs()); }
+#endif
 
 /// Dumps the liveness information to the given stream.
 void Liveness::print(raw_ostream &os) const {

diff  --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
index 94a15dc3f8663d..e76e2ead02e64c 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -2744,7 +2744,9 @@ void IntegerRelation::print(raw_ostream &os) const {
   os << '\n';
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void IntegerRelation::dump() const { print(llvm::errs()); }
+#endif
 
 unsigned IntegerPolyhedron::insertVar(VarKind kind, unsigned pos,
                                       unsigned num) {

diff  --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 7c55caa767c451..263ada0a05ebae 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -433,10 +433,12 @@ Matrix<T>::splitByBitset(ArrayRef<int> indicator) {
   return {rowsForOne, rowsForZero};
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 template <typename T>
 void Matrix<T>::dump() const {
   print(llvm::errs());
 }
+#endif
 
 template <typename T>
 bool Matrix<T>::hasConsistentState() const {

diff  --git a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
index 2c55e406463458..a472bf14e4ca11 100644
--- a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
+++ b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
@@ -65,7 +65,9 @@ void MultiAffineFunction::print(raw_ostream &os) const {
   output.print(os);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void MultiAffineFunction::dump() const { print(llvm::errs()); }
+#endif
 
 SmallVector<DynamicAPInt, 8>
 MultiAffineFunction::valueAt(ArrayRef<DynamicAPInt> point) const {
@@ -311,7 +313,9 @@ void PWMAFunction::print(raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void PWMAFunction::dump() const { print(llvm::errs()); }
+#endif
 
 PWMAFunction PWMAFunction::unionFunction(
     const PWMAFunction &func,

diff  --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
index ea7dfdcd93c0d4..5dceeb35e8345a 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
@@ -1056,7 +1056,9 @@ void PresburgerRelation::print(raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void PresburgerRelation::dump() const { print(llvm::errs()); }
+#endif
 
 PresburgerSet PresburgerSet::getUniverse(const PresburgerSpace &space) {
   PresburgerSet result(space);

diff  --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
index 532c464925b1a1..208ee418b26c87 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
@@ -30,10 +30,12 @@ void Identifier::print(llvm::raw_ostream &os) const {
   os << "Id<" << value << ">";
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Identifier::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 PresburgerSpace PresburgerSpace::getDomainSpace() const {
   PresburgerSpace newSpace = *this;
@@ -354,7 +356,9 @@ void PresburgerSpace::print(llvm::raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void PresburgerSpace::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif

diff  --git a/mlir/lib/Analysis/Presburger/Simplex.cpp b/mlir/lib/Analysis/Presburger/Simplex.cpp
index f2e6f83e99e57f..aab1534ad30e8c 100644
--- a/mlir/lib/Analysis/Presburger/Simplex.cpp
+++ b/mlir/lib/Analysis/Presburger/Simplex.cpp
@@ -2167,7 +2167,9 @@ void SimplexBase::print(raw_ostream &os) const {
   os << '\n';
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void SimplexBase::dump() const { print(llvm::errs()); }
+#endif
 
 bool Simplex::isRationalSubsetOf(const IntegerRelation &rel) {
   if (isEmpty())

diff  --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index a06a854fd14260..bbe86ddd96f6e1 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -516,7 +516,9 @@ void DivisionRepr::print(raw_ostream &os) const {
   os << "\n";
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void DivisionRepr::dump() const { print(llvm::errs()); }
+#endif
 
 SmallVector<DynamicAPInt, 8>
 presburger::getDynamicAPIntVec(ArrayRef<int64_t> range) {

diff  --git a/mlir/lib/CAPI/IR/AffineExpr.cpp b/mlir/lib/CAPI/IR/AffineExpr.cpp
index 5a0a03b11ae457..bbe59b4ec51941 100644
--- a/mlir/lib/CAPI/IR/AffineExpr.cpp
+++ b/mlir/lib/CAPI/IR/AffineExpr.cpp
@@ -32,7 +32,8 @@ void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback,
 }
 
 void mlirAffineExprDump(MlirAffineExpr affineExpr) {
-  unwrap(affineExpr).dump();
+  unwrap(affineExpr).print(llvm::errs());
+  llvm::errs() << "\n";
 }
 
 bool mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr) {

diff  --git a/mlir/lib/CAPI/IR/AffineMap.cpp b/mlir/lib/CAPI/IR/AffineMap.cpp
index 1889765ef86421..b38b47baf7ed55 100644
--- a/mlir/lib/CAPI/IR/AffineMap.cpp
+++ b/mlir/lib/CAPI/IR/AffineMap.cpp
@@ -32,7 +32,10 @@ void mlirAffineMapPrint(MlirAffineMap affineMap, MlirStringCallback callback,
   unwrap(affineMap).print(stream);
 }
 
-void mlirAffineMapDump(MlirAffineMap affineMap) { unwrap(affineMap).dump(); }
+void mlirAffineMapDump(MlirAffineMap affineMap) {
+  unwrap(affineMap).print(llvm::errs());
+  llvm::errs() << "\n";
+}
 
 MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx) {
   return wrap(AffineMap::get(unwrap(ctx)));

diff  --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index e01e49559eb17a..95e7749a2d8c1d 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -915,7 +915,10 @@ MlirLogicalResult mlirOperationWriteBytecodeWithConfig(
   return wrap(writeBytecodeToFile(unwrap(op), stream, *unwrap(config)));
 }
 
-void mlirOperationDump(MlirOperation op) { return unwrap(op)->dump(); }
+void mlirOperationDump(MlirOperation op) {
+  unwrap(op)->print(llvm::errs(), OpPrintingFlags().useLocalScope());
+  llvm::errs() << "\n";
+}
 
 bool mlirOperationVerify(MlirOperation op) {
   return succeeded(verify(unwrap(op)));
@@ -1219,7 +1222,10 @@ void mlirValueSetType(MlirValue value, MlirType type) {
   unwrap(value).setType(unwrap(type));
 }
 
-void mlirValueDump(MlirValue value) { unwrap(value).dump(); }
+void mlirValueDump(MlirValue value) {
+  unwrap(value).print(llvm::errs(), OpPrintingFlags().useLocalScope());
+  llvm::errs() << "\n";
+}
 
 void mlirValuePrint(MlirValue value, MlirStringCallback callback,
                     void *userData) {
@@ -1340,7 +1346,10 @@ void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData) {
   unwrap(type).print(stream);
 }
 
-void mlirTypeDump(MlirType type) { unwrap(type).dump(); }
+void mlirTypeDump(MlirType type) {
+  unwrap(type).print(llvm::errs());
+  llvm::errs() << "\n";
+}
 
 //===----------------------------------------------------------------------===//
 // Attribute API.
@@ -1379,7 +1388,10 @@ void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback,
   unwrap(attr).print(stream);
 }
 
-void mlirAttributeDump(MlirAttribute attr) { unwrap(attr).dump(); }
+void mlirAttributeDump(MlirAttribute attr) {
+  unwrap(attr).print(llvm::errs());
+  llvm::errs() << "\n";
+}
 
 MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name,
                                          MlirAttribute attr) {

diff  --git a/mlir/lib/CAPI/IR/IntegerSet.cpp b/mlir/lib/CAPI/IR/IntegerSet.cpp
index 43d48e415d27a2..da4dce68d5ede8 100644
--- a/mlir/lib/CAPI/IR/IntegerSet.cpp
+++ b/mlir/lib/CAPI/IR/IntegerSet.cpp
@@ -30,7 +30,10 @@ void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback,
   unwrap(set).print(stream);
 }
 
-void mlirIntegerSetDump(MlirIntegerSet set) { unwrap(set).dump(); }
+void mlirIntegerSetDump(MlirIntegerSet set) {
+  unwrap(set).print(llvm::errs());
+  llvm::errs() << "\n";
+}
 
 MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims,
                                       intptr_t numSymbols) {

diff  --git a/mlir/lib/Conversion/SPIRVCommon/Pattern.h b/mlir/lib/Conversion/SPIRVCommon/Pattern.h
index d947d483f2dd55..42d1b50b9ed55c 100644
--- a/mlir/lib/Conversion/SPIRVCommon/Pattern.h
+++ b/mlir/lib/Conversion/SPIRVCommon/Pattern.h
@@ -38,7 +38,6 @@ struct ElementwiseOpPattern : public OpConversionPattern<Op> {
     if (SPIRVOp::template hasTrait<OpTrait::spirv::UnsignedOp>() &&
         !getElementTypeOrSelf(op.getType()).isIndex() &&
         dstType != op.getType()) {
-      op.dump();
       return op.emitError("bitwidth emulation is not implemented yet on "
                           "unsigned op pattern version");
     }

diff  --git a/mlir/lib/Debug/ExecutionContext.cpp b/mlir/lib/Debug/ExecutionContext.cpp
index cc72bac549ab02..74aa4cdd0ba9a2 100644
--- a/mlir/lib/Debug/ExecutionContext.cpp
+++ b/mlir/lib/Debug/ExecutionContext.cpp
@@ -42,6 +42,13 @@ void ActionActiveStack::print(raw_ostream &os, bool withContext) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void ActionActiveStack::dump() const {
+  print(llvm::errs(), /*withContext=*/true);
+  llvm::errs() << "\n";
+}
+#endif
+
 //===----------------------------------------------------------------------===//
 // ExecutionContext
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
index 0e036dfedbf52e..98fa1f30a0487e 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -859,6 +859,10 @@ void MemRefDependenceGraph::print(raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void MemRefDependenceGraph::dump() const { print(llvm::errs()); }
+#endif
+
 void mlir::affine::getAffineForIVs(Operation &op,
                                    SmallVectorImpl<AffineForOp> *loops) {
   auto *currOp = op.getParentOp();
@@ -949,6 +953,7 @@ void ComputationSliceState::clearBounds() {
   ubOperands.clear();
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void ComputationSliceState::dump() const {
   llvm::errs() << "\tIVs:\n";
   for (Value iv : ivs)
@@ -970,6 +975,7 @@ void ComputationSliceState::dump() const {
       llvm::errs() << "\t\t\t" << ubOp << "\n";
   }
 }
+#endif
 
 /// Fast check to determine if the computation slice is maximal. Returns true if
 /// each slice dimension maps to an existing dst dimension and both the src

diff  --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
index 069191c21b0919..bac1c3ccb82192 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
@@ -38,10 +38,12 @@ void Var::print(llvm::raw_ostream &os) const {
   os << toChar(getKind()) << getNum();
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Var::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 //===----------------------------------------------------------------------===//
 // `Ranks` implementation.

diff  --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
index dce8b003b013bb..ef9794b893a063 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
@@ -134,7 +134,9 @@ class Var {
   std::string str() const;
   void print(llvm::raw_ostream &os) const;
   void print(AsmPrinter &printer) const;
-  void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  LLVM_DUMP_METHOD void dump() const;
+#endif
 };
 static_assert(IsZeroCostAbstraction<Var>);
 

diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 93fdf69cf286d5..a2c4c81a3ecad8 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -59,7 +59,9 @@ using namespace mlir::detail;
 
 void OperationName::print(raw_ostream &os) const { os << getStringRef(); }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void OperationName::dump() const { print(llvm::errs()); }
+#endif
 
 //===--------------------------------------------------------------------===//
 // AsmParser
@@ -4084,10 +4086,12 @@ void Attribute::print(raw_ostream &os, AsmState &state, bool elideType) const {
                                        : AttrTypeElision::Never);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Attribute::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void Attribute::printStripped(raw_ostream &os, AsmState &state) const {
   if (!*this) {
@@ -4133,6 +4137,7 @@ void Type::print(raw_ostream &os, AsmState &state) const {
   AsmPrinter::Impl(os, state.getImpl()).printType(*this);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Type::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
@@ -4147,6 +4152,7 @@ void IntegerSet::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void AffineExpr::print(raw_ostream &os) const {
   if (!expr) {
@@ -4157,10 +4163,12 @@ void AffineExpr::print(raw_ostream &os) const {
   AsmPrinter::Impl(os, state.getImpl()).printAffineExpr(*this);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void AffineExpr::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void AffineMap::print(raw_ostream &os) const {
   if (!map) {
@@ -4210,10 +4218,12 @@ raw_ostream &mlir::operator<<(raw_ostream &os, Value value) {
   return os;
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Value::dump() const {
   print(llvm::errs(), OpPrintingFlags().useLocalScope());
   llvm::errs() << "\n";
 }
+#endif
 
 void Value::printAsOperand(raw_ostream &os, AsmState &state) const {
   // TODO: This doesn't necessarily capture all potential cases.
@@ -4278,10 +4288,12 @@ void Operation::print(raw_ostream &os, AsmState &state) {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Operation::dump() {
   print(llvm::errs(), OpPrintingFlags().useLocalScope());
   llvm::errs() << "\n";
 }
+#endif
 
 void Operation::dumpPretty() {
   print(llvm::errs(), OpPrintingFlags().useLocalScope().assumeVerified());
@@ -4305,7 +4317,9 @@ void Block::print(raw_ostream &os, AsmState &state) {
   OperationPrinter(os, state.getImpl()).print(this);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void Block::dump() { print(llvm::errs()); }
+#endif
 
 /// Print out the name of the block without printing its body.
 void Block::printAsOperand(raw_ostream &os, bool printType) {

diff  --git a/mlir/lib/IR/Location.cpp b/mlir/lib/IR/Location.cpp
index 662681e19d26ab..65dcff100b1553 100644
--- a/mlir/lib/IR/Location.cpp
+++ b/mlir/lib/IR/Location.cpp
@@ -110,6 +110,10 @@ struct FileLineColRangeAttrStorage final
 };
 } // namespace mlir::detail
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void Location::dump() const { impl.dump(); }
+#endif
+
 //===----------------------------------------------------------------------===//
 /// Tablegen Attribute Definitions
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index d262e844603a1a..e33cd151215ec5 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -783,6 +783,10 @@ void OpState::print(Operation *op, OpAsmPrinter &p, StringRef defaultDialect) {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void OpState::dump() { state->dump(); }
+#endif
+
 /// Print an operation name, eliding the dialect prefix if necessary and doesn't
 /// lead to ambiguities.
 void OpState::printOpName(Operation *op, OpAsmPrinter &p,

diff  --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index c31e0ae7470e2e..4aade476714ea9 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -180,6 +180,7 @@ int64_t ShapeAdaptor::getNumElements() const {
   return num;
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void ShapeAdaptor::dump() const {
   if (!hasRank()) {
     llvm::errs() << "<<unranked>>\n";
@@ -196,6 +197,7 @@ void ShapeAdaptor::dump() const {
   llvm::errs() << "rank = " << getRank()
                << " dims = " << llvm::interleaved_array(mapped, "x") << "\n";
 }
+#endif
 
 ShapeAdaptor ValueShapeRange::getValueAsShape(int index) {
   Value val = operator[](index);

diff  --git a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
index d998104e99f4a7..3c52be42b912da 100644
--- a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
+++ b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
@@ -984,6 +984,7 @@ FailureOr<bool> ValueBoundsConstraintSet::areEquivalentSlices(
   return true;
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void ValueBoundsConstraintSet::dump() const {
   llvm::errs() << "==========\nColumns:\n";
   llvm::errs() << "(column\tdim\tvalue)\n";
@@ -1012,6 +1013,7 @@ void ValueBoundsConstraintSet::dump() const {
   cstr.dump();
   llvm::errs() << "==========\n";
 }
+#endif
 
 ValueBoundsConstraintSet::BoundBuilder &
 ValueBoundsConstraintSet::BoundBuilder::operator[](int64_t dim) {

diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 656b8044587737..303562a2af6ee6 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -460,11 +460,13 @@ void OpPassManager::printAsTextualPipeline(raw_ostream &os, bool pretty) const {
       pretty);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void OpPassManager::dump() {
   llvm::errs() << "Pass Manager with " << impl->passes.size() << " passes:\n";
   printAsTextualPipeline(llvm::errs(), /*pretty=*/true);
   llvm::errs() << "\n";
 }
+#endif
 
 static void registerDialectsForPipeline(const OpPassManager &pm,
                                         DialectRegistry &dialects) {

diff  --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 490e0c20f86f6c..0a564a5055cfdf 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -377,8 +377,8 @@ MlirOptMainConfig &MlirOptMainConfig::setPassPipelineParser(
     if (failed(passPipeline.addToPipeline(pm, errorHandler)))
       return failure();
     if (this->shouldDumpPassPipeline()) {
-
-      pm.dump();
+      llvm::errs() << "Pass Manager with " << pm.size() << " passes:\n";
+      pm.printAsTextualPipeline(llvm::errs(), /*pretty=*/true);
       llvm::errs() << "\n";
     }
     return success();

diff  --git a/mlir/lib/Transforms/PrintIR.cpp b/mlir/lib/Transforms/PrintIR.cpp
index 0d6c1112902c21..1f2ba8cc59d79d 100644
--- a/mlir/lib/Transforms/PrintIR.cpp
+++ b/mlir/lib/Transforms/PrintIR.cpp
@@ -26,7 +26,8 @@ struct PrintIRPass : public impl::PrintIRPassBase<PrintIRPass> {
     if (!this->label.empty())
       llvm::dbgs() << " " << this->label;
     llvm::dbgs() << " //----- //\n";
-    getOperation()->dump();
+    getOperation()->print(llvm::dbgs(), OpPrintingFlags().useLocalScope());
+    llvm::dbgs() << "\n";
     markAllAnalysesPreserved();
   }
 };

diff  --git a/mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp b/mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp
index 388ac1174dcdc9..b23e362fdbaba7 100644
--- a/mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp
@@ -30,7 +30,7 @@ void testColumnEchelonForm(const IntMatrix &m, unsigned expectedRank) {
       EXPECT_EQ(rowVec[col], 0);
       if (rowVec[col] != 0) {
         llvm::errs() << "Failed at input matrix:\n";
-        m.dump();
+        m.print(llvm::errs());
       }
     }
     if (rowVec[lastAllowedNonZeroCol] != 0)


        


More information about the Mlir-commits mailing list