[Mlir-commits] [mlir] [mlir] Apply dump() pattern. NFC. (PR #89216)

Michael Kruse llvmlistbot at llvm.org
Thu Apr 18 04:40:53 PDT 2024


https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/89216

Apply the pattern for the dump() pattern established in 8c209aa8779de57771b64896f805e14cc0016dcd to all dump() methods in MLIR.

 * Add LLVM_DUMP_METHOD to method implementations to ensure the method body is emitted even without any use so they can be called from the debugger. This is the purpose of the dump() function.
 * No class inline implementation. LLVM_DUMP_METHOD would ensure the method is emitted into every object file, blowing up its size when by design it is never called.
 * No use of LLVM_DUMP_METHOD in public header files. The header files may be included in projects outside of MLIR that are compiled with different flags than the MLIR libraries themselves.
 * Add `const` where appropriate.
 * Implement dump() where implementations were missing.
 * dump() is not emitted into release builds.

>From c84476229641f76db86669cca3ae9456de97bc22 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 18 Apr 2024 13:18:45 +0200
Subject: [PATCH] Apply dump() pattern. NFC.

---
 .../include/mlir/Analysis/DataFlowFramework.h |  2 +-
 mlir/include/mlir/Debug/ExecutionContext.h    |  5 +---
 .../mlir/Dialect/Affine/Analysis/Utils.h      |  2 +-
 .../Linalg/TransformOps/GPUHeuristics.h       |  2 +-
 mlir/include/mlir/IR/Location.h               |  2 +-
 mlir/include/mlir/IR/OpDefinition.h           |  4 ++--
 mlir/include/mlir/IR/Operation.h              | 16 +++++--------
 mlir/include/mlir/IR/Value.h                  |  9 ++++---
 mlir/include/mlir/Pass/PassManager.h          |  2 +-
 mlir/lib/Analysis/CallGraph.cpp               |  5 +++-
 mlir/lib/Analysis/DataFlowFramework.cpp       |  4 +++-
 mlir/lib/Analysis/Liveness.cpp                |  4 +++-
 .../Analysis/Presburger/IntegerRelation.cpp   |  4 +++-
 mlir/lib/Analysis/Presburger/MPInt.cpp        |  4 +++-
 mlir/lib/Analysis/Presburger/Matrix.cpp       |  4 +++-
 mlir/lib/Analysis/Presburger/PWMAFunction.cpp |  7 ++++++
 .../Presburger/PresburgerRelation.cpp         |  3 +++
 .../Analysis/Presburger/PresburgerSpace.cpp   |  6 +++++
 mlir/lib/Analysis/Presburger/Simplex.cpp      |  3 +++
 mlir/lib/Analysis/Presburger/SlowMPInt.cpp    |  3 +++
 mlir/lib/Analysis/Presburger/Utils.cpp        |  3 +++
 mlir/lib/Debug/ExecutionContext.cpp           |  8 +++++++
 mlir/lib/Dialect/Affine/Analysis/Utils.cpp    |  8 +++++++
 .../Linalg/TransformOps/GPUHeuristics.cpp     |  5 ++++
 mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp |  5 ++++
 mlir/lib/IR/AsmPrinter.cpp                    | 24 ++++++++++++++++++-
 mlir/lib/IR/Location.cpp                      |  9 +++++++
 mlir/lib/IR/Operation.cpp                     | 20 ++++++++++++++++
 mlir/lib/IR/Value.cpp                         | 15 ++++++++++++
 mlir/lib/Interfaces/InferTypeOpInterface.cpp  |  3 +++
 .../lib/Interfaces/ValueBoundsOpInterface.cpp |  3 +++
 mlir/lib/Pass/Pass.cpp                        |  5 +++-
 32 files changed, 165 insertions(+), 34 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlowFramework.h b/mlir/include/mlir/Analysis/DataFlowFramework.h
index c76cfac07fc77a..3d22928614261f 100644
--- a/mlir/include/mlir/Analysis/DataFlowFramework.h
+++ b/mlir/include/mlir/Analysis/DataFlowFramework.h
@@ -323,7 +323,7 @@ class AnalysisState {
 
   /// Print the contents of the analysis state.
   virtual void print(raw_ostream &os) const = 0;
-  LLVM_DUMP_METHOD void dump() const;
+  void dump() const;
 
   /// Add a dependency to this analysis state on a program point and an
   /// analysis. If this state is updated, the analysis will be invoked on the
diff --git a/mlir/include/mlir/Debug/ExecutionContext.h b/mlir/include/mlir/Debug/ExecutionContext.h
index fbad04b9a2f1d7..49d35a09dd2a2d 100644
--- a/mlir/include/mlir/Debug/ExecutionContext.h
+++ b/mlir/include/mlir/Debug/ExecutionContext.h
@@ -29,10 +29,7 @@ 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";
-  }
+  void dump() const;
   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 b8f354892ee60a..3d1c3a80a45805 100644
--- a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
+++ b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h
@@ -205,7 +205,7 @@ struct MemRefDependenceGraph {
 
   void print(raw_ostream &os) const;
 
-  void dump() const { print(llvm::errs()); }
+  void dump() const;
 
   /// The block for which this graph is created to perform fusion.
   Block █
diff --git a/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h b/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h
index f9fd32c2031afb..139c390daf67e8 100644
--- a/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h
+++ b/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h
@@ -92,7 +92,7 @@ struct CopyMappingInfo : public MappingInfo {
 public:
   // Pretty-printing and diagnostic methods.
   void print(llvm::raw_ostream &os) const;
-  LLVM_DUMP_METHOD void dump() const;
+  void dump() const;
 
   /// Static quantity determining the number of bits to target in an individual
   /// copy. Assumes that smaller increments of 64, 32, 16, 8 are also valid
diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index d4268e804f4f7a..6092f75136ed1e 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -96,7 +96,7 @@ class Location {
 
   /// Print the location.
   void print(raw_ostream &os) const { impl.print(os); }
-  void dump() const { impl.dump(); }
+  void dump() const;
 
   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 59f094d6690991..82a20f82fd91bd 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -119,7 +119,7 @@ class OpState {
   }
 
   /// Dump this operation.
-  void dump() { state->dump(); }
+  void dump() const;
 
   /// The source location the operation was defined or derived from.
   Location getLoc() { return state->getLoc(); }
@@ -269,7 +269,7 @@ class OpFoldResult : public PointerUnion<Attribute, Value> {
   using PointerUnion<Attribute, Value>::PointerUnion;
 
 public:
-  void dump() const { llvm::errs() << *this << "\n"; }
+  void dump() const;
 
   MLIRContext *getContext() const {
     return is<Attribute>() ? get<Attribute>().getContext()
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index c52a6fcac10c1c..6f3af890c9e8b9 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -1019,16 +1019,12 @@ class alignas(8) Operation final
 
   /// Expose a few methods explicitly for the debugger to call for
   /// visualization.
-#ifndef NDEBUG
-  LLVM_DUMP_METHOD operand_range debug_getOperands() { return getOperands(); }
-  LLVM_DUMP_METHOD result_range debug_getResults() { return getResults(); }
-  LLVM_DUMP_METHOD SuccessorRange debug_getSuccessors() {
-    return getSuccessors();
-  }
-  LLVM_DUMP_METHOD MutableArrayRef<Region> debug_getRegions() {
-    return getRegions();
-  }
-#endif
+  /// @{
+  operand_range debug_getOperands();
+  result_range debug_getResults();
+  SuccessorRange debug_getSuccessors();
+  MutableArrayRef<Region> debug_getRegions();
+  /// @}
 
   /// The operation block that contains this operation.
   Block *block = nullptr;
diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index a74d0faa1dfc4b..fbda9873aa6fd3 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -73,11 +73,10 @@ class alignas(8) ValueImpl : public IRObjectWithUseList<OpOperand> {
 
   /// Expose a few methods explicitly for the debugger to call for
   /// visualization.
-#ifndef NDEBUG
-  LLVM_DUMP_METHOD Type debug_getType() const { return getType(); }
-  LLVM_DUMP_METHOD Kind debug_getKind() const { return getKind(); }
-
-#endif
+  /// @{
+  Type debug_getType() const;
+  Kind debug_getKind() const;
+  /// @}
 
   /// The type of this result and the kind.
   llvm::PointerIntPair<Type, 3, Kind> typeAndKind;
diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h
index 1b2e6a3bc82bb4..8854ddcbdbc9d7 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -148,7 +148,7 @@ class OpPassManager {
   void printAsTextualPipeline(raw_ostream &os) const;
 
   /// Raw dump of the pass manager to llvm::errs().
-  void dump();
+  void dump() const;
 
   /// 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 ccd4676632136b..9b0cc80f48465a 100644
--- a/mlir/lib/Analysis/CallGraph.cpp
+++ b/mlir/lib/Analysis/CallGraph.cpp
@@ -174,8 +174,11 @@ void CallGraph::eraseNode(CallGraphNode *node) {
 //===----------------------------------------------------------------------===//
 // Printing
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 /// Dump the graph in a human readable format.
-void CallGraph::dump() const { print(llvm::errs()); }
+LLVM_DUMP_METHOD void CallGraph::dump() const { print(llvm::errs()); }
+#endif
+
 void CallGraph::print(raw_ostream &os) const {
   os << "// ---- CallGraph ----\n";
 
diff --git a/mlir/lib/Analysis/DataFlowFramework.cpp b/mlir/lib/Analysis/DataFlowFramework.cpp
index 5ef24f201f8a67..01bbd59f616dfe 100644
--- a/mlir/lib/Analysis/DataFlowFramework.cpp
+++ b/mlir/lib/Analysis/DataFlowFramework.cpp
@@ -51,7 +51,9 @@ void AnalysisState::addDependency(ProgramPoint dependent,
   });
 }
 
-void AnalysisState::dump() const { print(llvm::errs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void AnalysisState::dump() const { print(llvm::errs()); }
+#endif
 
 //===----------------------------------------------------------------------===//
 // ProgramPoint
diff --git a/mlir/lib/Analysis/Liveness.cpp b/mlir/lib/Analysis/Liveness.cpp
index a8e0daeabf4061..48cbc59611aa7c 100644
--- a/mlir/lib/Analysis/Liveness.cpp
+++ b/mlir/lib/Analysis/Liveness.cpp
@@ -253,8 +253,10 @@ bool Liveness::isDeadAfter(Value value, Operation *operation) const {
   return endOperation == operation || endOperation->isBeforeInBlock(operation);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 /// Dumps the liveness information in a human readable format.
-void Liveness::dump() const { print(llvm::errs()); }
+LLVM_DUMP_METHOD 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 a3f971db4bd428..82af7285d40271 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -2542,7 +2542,9 @@ void IntegerRelation::print(raw_ostream &os) const {
   os << '\n';
 }
 
-void IntegerRelation::dump() const { print(llvm::errs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void IntegerRelation::dump() const { print(llvm::errs()); }
+#endif
 
 unsigned IntegerPolyhedron::insertVar(VarKind kind, unsigned pos,
                                       unsigned num) {
diff --git a/mlir/lib/Analysis/Presburger/MPInt.cpp b/mlir/lib/Analysis/Presburger/MPInt.cpp
index 587e2b572facf3..f89a2c93bec813 100644
--- a/mlir/lib/Analysis/Presburger/MPInt.cpp
+++ b/mlir/lib/Analysis/Presburger/MPInt.cpp
@@ -29,7 +29,9 @@ llvm::raw_ostream &MPInt::print(llvm::raw_ostream &os) const {
   return os << valLarge;
 }
 
-void MPInt::dump() const { print(llvm::errs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void MPInt::dump() const { print(llvm::errs()); }
+#endif
 
 llvm::raw_ostream &mlir::presburger::operator<<(llvm::raw_ostream &os,
                                                 const MPInt &x) {
diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 4cb6e6b16bc878..e062320c9cd27d 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -422,10 +422,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 {
+LLVM_DUMP_METHOD 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 d55962616de175..39afb584e42aca 100644
--- a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
+++ b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp
@@ -67,6 +67,10 @@ void MultiAffineFunction::print(raw_ostream &os) const {
   output.print(os);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void MultiAffineFunction::dump() const { print(llvm::errs()); }
+#endif
+
 SmallVector<MPInt, 8>
 MultiAffineFunction::valueAt(ArrayRef<MPInt> point) const {
   assert(point.size() == getNumDomainVars() + getNumSymbolVars() &&
@@ -309,7 +313,10 @@ void PWMAFunction::print(raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 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 3af6baae0e7001..e021c304214bdd 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
@@ -1055,7 +1055,10 @@ void PresburgerRelation::print(raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 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 f80df52fb82908..4ac5a504fd5881 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
@@ -28,10 +28,13 @@ void Identifier::print(llvm::raw_ostream &os) const {
   os << "Id<" << value << ">";
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void Identifier::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 PresburgerSpace PresburgerSpace::getDomainSpace() const {
   PresburgerSpace newSpace = *this;
@@ -351,7 +354,10 @@ void PresburgerSpace::print(llvm::raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 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 1969cce93ad2e0..7964d60a8d561e 100644
--- a/mlir/lib/Analysis/Presburger/Simplex.cpp
+++ b/mlir/lib/Analysis/Presburger/Simplex.cpp
@@ -2152,7 +2152,10 @@ void SimplexBase::print(raw_ostream &os) const {
   os << '\n';
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void SimplexBase::dump() const { print(llvm::errs()); }
+#endif
 
 bool Simplex::isRationalSubsetOf(const IntegerRelation &rel) {
   if (isEmpty())
diff --git a/mlir/lib/Analysis/Presburger/SlowMPInt.cpp b/mlir/lib/Analysis/Presburger/SlowMPInt.cpp
index ae6f2827be9268..7c81bfdf2672ec 100644
--- a/mlir/lib/Analysis/Presburger/SlowMPInt.cpp
+++ b/mlir/lib/Analysis/Presburger/SlowMPInt.cpp
@@ -36,7 +36,10 @@ llvm::hash_code detail::hash_value(const SlowMPInt &x) {
 /// ---------------------------------------------------------------------------
 void SlowMPInt::print(llvm::raw_ostream &os) const { os << val; }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void SlowMPInt::dump() const { print(llvm::errs()); }
+#endif
 
 llvm::raw_ostream &detail::operator<<(llvm::raw_ostream &os,
                                       const SlowMPInt &x) {
diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index f717a4de5d7283..7db638bebe4148 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -516,7 +516,10 @@ void DivisionRepr::print(raw_ostream &os) const {
   os << "\n";
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void DivisionRepr::dump() const { print(llvm::errs()); }
+#endif
 
 SmallVector<MPInt, 8> presburger::getMPIntVec(ArrayRef<int64_t> range) {
   SmallVector<MPInt, 8> result(range.size());
diff --git a/mlir/lib/Debug/ExecutionContext.cpp b/mlir/lib/Debug/ExecutionContext.cpp
index f7505b6608c814..a4e884279ce86c 100644
--- a/mlir/lib/Debug/ExecutionContext.cpp
+++ b/mlir/lib/Debug/ExecutionContext.cpp
@@ -44,6 +44,14 @@ void ActionActiveStack::print(raw_ostream &os, bool withContext) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+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 194ee9115e3d7a..667bcd8f56b01a 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -630,6 +630,11 @@ void MemRefDependenceGraph::print(raw_ostream &os) const {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void MemRefDependenceGraph::dump() const { print(llvm::errs()); }
+#endif
+
 void mlir::affine::getAffineForIVs(Operation &op,
                                    SmallVectorImpl<AffineForOp> *loops) {
   auto *currOp = op.getParentOp();
@@ -720,6 +725,8 @@ void ComputationSliceState::clearBounds() {
   ubOperands.clear();
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void ComputationSliceState::dump() const {
   llvm::errs() << "\tIVs:\n";
   for (Value iv : ivs)
@@ -741,6 +748,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/Linalg/TransformOps/GPUHeuristics.cpp b/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
index 38abdd122d633d..3c807c386a24e4 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
@@ -265,3 +265,8 @@ void transform::gpu::CopyMappingInfo::print(llvm::raw_ostream &os) const {
   llvm::interleaveComma(threadMapping, os << "}, threadMapping: {");
   os << "}}";
 }
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void transform::gpu::CopyMappingInfo::dump() const { print(llvm::errs()); }
+#endif
\ No newline at end of file
diff --git a/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp b/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp
index 5916ffba78e246..3deeb92659ae24 100644
--- a/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp
+++ b/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp
@@ -81,6 +81,11 @@ void Polynomial::print(raw_ostream &os, ::llvm::StringRef separator,
 
 void Polynomial::print(raw_ostream &os) const { print(os, " + ", "**"); }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void Polynomial::dump() const { print(llvm::errs()); }
+#endif
+
 std::string Polynomial::toIdentifier() const {
   std::string result;
   llvm::raw_string_ostream os(result);
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index e915b97d9ff17b..b2bce97d024380 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -59,7 +59,10 @@ using namespace mlir::detail;
 
 void OperationName::print(raw_ostream &os) const { os << getStringRef(); }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void OperationName::dump() const { print(llvm::errs()); }
+#endif
 
 //===--------------------------------------------------------------------===//
 // AsmParser
@@ -3744,10 +3747,13 @@ void Attribute::print(raw_ostream &os, AsmState &state, bool elideType) const {
                                        : AttrTypeElision::Never);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void Attribute::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void Attribute::printStripped(raw_ostream &os, AsmState &state) const {
   if (!*this) {
@@ -3793,20 +3799,25 @@ void Type::print(raw_ostream &os, AsmState &state) const {
   AsmPrinter::Impl(os, state.getImpl()).printType(*this);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void Type::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
 
+LLVM_DUMP_METHOD
 void AffineMap::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
 
+LLVM_DUMP_METHOD
 void IntegerSet::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void AffineExpr::print(raw_ostream &os) const {
   if (!expr) {
@@ -3817,10 +3828,13 @@ void AffineExpr::print(raw_ostream &os) const {
   AsmPrinter::Impl(os, state.getImpl()).printAffineExpr(*this);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void AffineExpr::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void AffineMap::print(raw_ostream &os) const {
   if (!map) {
@@ -3865,10 +3879,13 @@ void Value::print(raw_ostream &os, AsmState &state) const {
      << "' at index: " << arg.getArgNumber();
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void Value::dump() const {
   print(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 void Value::printAsOperand(raw_ostream &os, AsmState &state) const {
   // TODO: This doesn't necessarily capture all potential cases.
@@ -3928,10 +3945,12 @@ void Operation::print(raw_ostream &os, AsmState &state) {
   }
 }
 
-void Operation::dump() {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void Operation::dump() {
   print(llvm::errs(), OpPrintingFlags().useLocalScope());
   llvm::errs() << "\n";
 }
+#endif
 
 void Block::print(raw_ostream &os) {
   Operation *parentOp = getParentOp();
@@ -3950,7 +3969,10 @@ void Block::print(raw_ostream &os, AsmState &state) {
   OperationPrinter(os, state.getImpl()).print(this);
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 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 c548bbe4b6c860..9c8f690f150985 100644
--- a/mlir/lib/IR/Location.cpp
+++ b/mlir/lib/IR/Location.cpp
@@ -68,6 +68,15 @@ bool LocationAttr::classof(Attribute attr) {
                    UnknownLoc>(attr);
 }
 
+//===----------------------------------------------------------------------===//
+// Location
+//===----------------------------------------------------------------------===//
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void Location::dump() const { impl.dump(); }
+#endif
+
 //===----------------------------------------------------------------------===//
 // CallSiteLoc
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index db903d540761b7..a349ebcf31c72b 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -259,6 +259,21 @@ void Operation::insertOperands(unsigned index, ValueRange operands) {
   assert(operands.empty() && "inserting operands without an operand storage");
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD Operation::operand_range Operation::debug_getOperands() {
+  return getOperands();
+}
+LLVM_DUMP_METHOD Operation::result_range Operation::debug_getResults() {
+  return getResults();
+}
+LLVM_DUMP_METHOD SuccessorRange Operation::debug_getSuccessors() {
+  return getSuccessors();
+}
+LLVM_DUMP_METHOD MutableArrayRef<Region> Operation::debug_getRegions() {
+  return getRegions();
+}
+#endif
+
 //===----------------------------------------------------------------------===//
 // Diagnostics
 //===----------------------------------------------------------------------===//
@@ -777,6 +792,11 @@ void OpState::print(Operation *op, OpAsmPrinter &p, StringRef defaultDialect) {
   }
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void OpState::dump() const { llvm::errs() << *this << "\n"; }
+#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/IR/Value.cpp b/mlir/lib/IR/Value.cpp
index 178765353cc105..1c9244c9999550 100644
--- a/mlir/lib/IR/Value.cpp
+++ b/mlir/lib/IR/Value.cpp
@@ -15,6 +15,21 @@
 using namespace mlir;
 using namespace mlir::detail;
 
+//===----------------------------------------------------------------------===//
+// ValueImpl
+//===----------------------------------------------------------------------===//
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD Type ValueImpl::debug_getType() const { return getType(); }
+LLVM_DUMP_METHOD ValueImpl::Kind ValueImpl::debug_getKind() const {
+  return getKind();
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+// Value
+//===----------------------------------------------------------------------===//
+
 /// If this value is the result of an Operation, return the operation that
 /// defines it.
 Operation *Value::getDefiningOp() const {
diff --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index e52d0e17cda22b..f7750dd64b46e2 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -171,6 +171,8 @@ int64_t ShapeAdaptor::getNumElements() const {
   return num;
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void ShapeAdaptor::dump() const {
   if (!hasRank()) {
     llvm::errs() << "<<unranked>>\n";
@@ -188,6 +190,7 @@ void ShapeAdaptor::dump() const {
   llvm::interleave(mapped, llvm::errs(), "x");
   llvm::errs() << "]\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 ffa4c0b55cad7c..51c723c4a5d2f2 100644
--- a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
+++ b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
@@ -909,6 +909,8 @@ ValueBoundsConstraintSet::areEquivalentSlices(MLIRContext *ctx,
   return true;
 }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
 void ValueBoundsConstraintSet::dump() const {
   llvm::errs() << "==========\nColumns:\n";
   llvm::errs() << "(column\tdim\tvalue)\n";
@@ -937,6 +939,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 57a6c20141d2c1..49414c45119ad3 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -407,11 +407,14 @@ void OpPassManager::printAsTextualPipeline(raw_ostream &os) const {
        MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.end()});
 }
 
-void OpPassManager::dump() {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void OpPassManager::dump() const {
   llvm::errs() << "Pass Manager with " << impl->passes.size() << " passes:\n";
   printAsTextualPipeline(llvm::errs());
   llvm::errs() << "\n";
 }
+#endif
 
 static void registerDialectsForPipeline(const OpPassManager &pm,
                                         DialectRegistry &dialects) {



More information about the Mlir-commits mailing list