[Mlir-commits] [mlir] [MLIR] Allow setting call stack limit for SourceMgrDiagnosticHandler (PR #123373)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jan 17 09:09:07 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (JoelWee)

<details>
<summary>Changes</summary>

Some of our code generates very deep call stacks, and its inconvenient to have the callstack truncated

---
Full diff: https://github.com/llvm/llvm-project/pull/123373.diff


2 Files Affected:

- (modified) mlir/include/mlir/IR/Diagnostics.h (+3-1) 
- (modified) mlir/lib/IR/Diagnostics.cpp (+4) 


``````````diff
diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index 8429325412dc97..36c433c63b26d1 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -578,6 +578,9 @@ class SourceMgrDiagnosticHandler : public ScopedDiagnosticHandler {
   void emitDiagnostic(Location loc, Twine message, DiagnosticSeverity kind,
                       bool displaySourceLine = true);
 
+  /// Set the maximum depth that a call stack will be printed. Defaults to 10.
+  void setCallStackLimit(unsigned limit);
+
 protected:
   /// Emit the given diagnostic with the held source manager.
   void emitDiagnostic(Diagnostic &diag);
@@ -605,7 +608,6 @@ class SourceMgrDiagnosticHandler : public ScopedDiagnosticHandler {
   std::optional<Location> findLocToShow(Location loc);
 
   /// The maximum depth that a call stack will be printed.
-  /// TODO: This should be a tunable flag.
   unsigned callStackLimit = 10;
 
   std::unique_ptr<detail::SourceMgrDiagnosticHandlerImpl> impl;
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 7eb3d5bcd07f19..19b32120f58905 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -519,6 +519,10 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Diagnostic &diag) {
   }
 }
 
+void SourceMgrDiagnosticHandler::setCallStackLimit(unsigned limit) {
+  callStackLimit = limit;
+}
+
 /// Get a memory buffer for the given file, or nullptr if one is not found.
 const llvm::MemoryBuffer *
 SourceMgrDiagnosticHandler::getBufferForFile(StringRef filename) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/123373


More information about the Mlir-commits mailing list